metofficedatapointapi的简单包装器。
MetOffer的Python项目详细描述
================ 梅托弗V.2.0
metoffer是英国提供的api的简单包装。
Met Office <http://www.metoffice.gov.uk>
称为数据点。它
可用于检索天气观测和预报。在它的
heart是有方法检索数据的MetOffer
类
通过api提供,并将它们作为python对象提供。
其中还包括一些函数和类,这些函数和类对于
解释数据。
这个项目现在维护在<https://github.com/sludgedesk/metoffer>
。
示例
获取距离提供的纬度最近的气象局场地的预测 经度,以三小时为间隔进行预测:
>>> import metoffer
>>> api_key = '01234567-89ab-cdef-0123-456789abcdef'
>>> M = metoffer.MetOffer(api_key)
>>> x = M.nearest_loc_forecast(51.4033, -0.3375, metoffer.THREE_HOURLY)
为了实现这一点,最好使用 方便功能,使数据不经常变化(例如数据 可能会被缓存。
将此数据解析为一个实例:
>>> y = metoffer.Weather(x)
>>> y.name
'HAMPTON COURT PALACE'
>>> y.country
'ENGLAND'
>>> y.continent
'EUROPE'
>>> y.lat
51.4007
>>> y.lon
-0.3337
>>> y.elevation
4.0
>>> y.ident # The Met Office site ident
'351747'
>>> y.data_date
'2014-06-14T23:00:00Z'
>>> y.dtype
'Forecast'
>>> import pprint
>>> pprint.pprint(y.data)
[{'Feels Like Temperature': (17, 'C', 'F'),
'Max UV Index': (1, '', 'U'),
'Precipitation Probability': (7, '%', 'Pp'),
'Screen Relative Humidity': (63, '%', 'H'),
'Temperature': (19, 'C', 'T'),
'Visibility': ('VG', '', 'V'),
'Weather Type': (7, '', 'W'),
'Wind Direction': ('NNE', 'compass', 'D'),
'Wind Gust': (18, 'mph', 'G'),
'Wind Speed': (11, 'mph', 'S'),
'timestamp': (datetime.datetime(2014, 6, 14, 18, 0), '')},
{'Feels Like Temperature': (15, 'C', 'F'),
'Max UV Index': (0, '', 'U'),
'Precipitation Probability': (0, '%', 'Pp'),
'Screen Relative Humidity': (72, '%', 'H'),
'Temperature': (16, 'C', 'T'),
'Visibility': ('VG', '', 'V'),
'Weather Type': (0, '', 'W'),
'Wind Direction': ('NNE', 'compass', 'D'),
'Wind Gust': (18, 'mph', 'G'),
'Wind Speed': (9, 'mph', 'S'),
'timestamp': (datetime.datetime(2014, 6, 14, 21, 0), '')},
[...]
{'Feels Like Temperature': (16, 'C', 'F'),
'Max UV Index': (0, '', 'U'),
'Precipitation Probability': (2, '%', 'Pp'),
'Screen Relative Humidity': (66, '%', 'H'),
'Temperature': (16, 'C', 'T'),
'Visibility': ('VG', '', 'V'),
'Weather Type': (0, '', 'W'),
'Wind Direction': ('NNE', 'compass', 'D'),
'Wind Gust': (13, 'mph', 'G'),
'Wind Speed': (7, 'mph', 'S'),
'timestamp': (datetime.datetime(2014, 6, 18, 21, 0), '')}]
进一步解释数据:
>>> for i in y.data:
... print("{} - {}".format(i["timestamp"][0].strftime("%d %b, %H:%M"), metoffer.WEATHER_CODES[i["Weather Type"][0]]))
...
14 Jun, 18:00 - Cloudy
14 Jun, 21:00 - Clear night
15 Jun, 00:00 - Clear night
15 Jun, 03:00 - Cloudy
[...]
18 Jun, 09:00 - Partly cloudy (day)
18 Jun, 12:00 - Partly cloudy (day)
18 Jun, 15:00 - Cloudy
18 Jun, 18:00 - Cloudy
18 Jun, 21:00 - Clear night
>>> metoffer.VISIBILITY[y.data[0]["Visibility"][0]]
'Very good - Between 20-40 km'
>>> metoffer.guidance_UV(y.data[0]["Max UV Index"][0])
'Low exposure. No protection required. You can safely stay outside'
墙面装饰类
可用方法:
loc_forecast
。返回位置特定的预测数据(包括 可用站点和时间功能)。nearest_loc_forecast
。尽可能在离拉特龙最近的地点施工 协调并返回给定时间步的预测数据。loc_observations
。返回特定位置的观测数据,包括 可用站点列表(时间步长为每小时)。nearest_loc_obs
。找出离纬度和经度坐标最近的地点 并返回观测数据。text_forecast
。返回地区、国家公园的文本预测数据 或者山区。text_uk_extremes
。返回英国极端的文本数据。stand_alone_imagery
。返回独立图像和 包括图像的uri。map_overlay_forecast
。返回Forecast Map覆盖的功能数据。map_overlay_obs
。返回观测地图覆盖的功能数据。
站点类
描述用于保存站点元数据的对象。也描述了方法
(distance_to_coords
)返回站点实例与任何给定实例的“距离”
纬度和经度坐标。这个“距离”是一个用来引导
MetOffer.nearest_loc_forecast
和MetOffer.nearest_loc_obs
。很简单
计算两组坐标之间的差并得出
毕达哥拉斯定理的价值。
天气类
对返回的天气数据(包括相关元数据)的全部保留。它解析 将metoffer位置特定数据的dict返回到天气实例中。 使用单个或多个时间步。有几点 注意:
所有dict键都有一个元组,即使没有明显的需要,例如 有“时间戳”和“天气类型”。timestamp'是一个2元组 是一个三元组。这是一个特色。
当气象局没有对某一类别的观测记录时, 我不会给你任何回报的。
对于解析的每日预测,“时间戳”的小时和分钟 DateTime.DateTime对象是多余的。事实上,这是误导 跟随他们。相反,这次在第二个 元组的一部分。这在“白天”和“夜晚”之间交替 连续的口述。类别通常是特定于一天中的时间。 这就是api提供它的方式。注意,它可能会把你弄出来。
文本预测类
保留所有返回的文本区域预测,包括相关的元-
数据,通过分析MetOffer.text_forecast
返回的数据创建。
有用功能
parse_sitelist
。从检索到的网站列表数据返回网站实例列表。get_nearest_site
。返回可使用的字符串(站点ID)列表 作为调用loc_forecast
的“请求”以及loc_observations
。guidance_UV
。英国气象局关于基于紫外线的紫外线暴露指南 索引。extract_data_key
。返回将度量类型映射到其描述的dict。 以及测量单位。
反馈和错误报告
联系:
斯蒂芬b默里sbm199@gmail.com @污泥台
法律
版权所有2012-2014、2018 Stephen B Murray
根据由 自由软件基金会,或者许可证的第3版,或者 选项)任何更高版本。
你应该收到一份GNU通用公共许可证的副本 这个包裹。如果没有,请参见http://www.gnu.org/licenses/