【问题标题】:Need assistance in modifying the python script to return wind direction in degrees需要帮助修改 python 脚本以返回以度为单位的风向
【发布时间】:2012-05-01 22:00:41
【问题描述】:

我是脚本新手,只专门研究过 arcpy 模块。我目前正在使用脚本从“http://weather.noaa.gov/pub/data/observations/metar/stations”获取风的详细信息。我需要在 Web 应用程序中集成风向,并且需要帮助修改脚本以仅以度数返回风向,这是我从“http://pypi.python.org/pypi/”下载脚本的链接元/" 我尝试通过添加一个仅返回方向的函数来对 Metar.py 进行更改

 def windDirection(self):
      """
      Return a textual description of the wind conditions.

      Units may be specified as "MPS", "KT", "KMH", or "MPH".
      """
      if self.wind_speed == None:
          return "missing"
      elif self.wind_speed.value() == 0.0:
          text = "calm"
      else:
          wind_speed = self.wind_speed.string(units)
          text = "%s"(self.wind_dir.directVal)
      return text

还在 Datatypes.py 中添加了一个函数

def directVal( self ):
    if not self._compass:
      degrees = 22.5 * round(self._degrees/22.5)
      if degrees == 360.0:
        self._directVal = "N"
      else:
        for name, d in direction.compass_dirs.iteritems():
          if d == degrees:
            self._directVal = name
            break
    return self._directVal

我不确定如何将此值作为报告以外的单独文本返回。请帮忙。

【问题讨论】:

  • 进行此更改有帮助吗? text = "%s" % (self.wind_dir.directVal, )
  • 这条线有什么用途? wind_speed = self.wind_speed.string(units)
  • 不,它没有。我已将风函数复制到新函数 directVal()。我可以跳过上面一行,因为我没有在返回值中指定单位。
  • 谢谢大家...我让它工作了...

标签: python


【解决方案1】:

METAR 数据的另一种方法(如果您在美国)是连接到该站的 NOAA 观测 XML 数据。虽然这有点冗长,但您可以使用我的 PARFAIT API 得到一个简单的答案。要返回 LAX 机场当前的风速,您可以使用 Current Weather API:http://parfait.snarkybox.com/current.php?icao=klax&datum=current_observation,wind_mph

API 网站上提供了完整说明:parfait dot snarkybox dot com。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    • 2018-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多