python客户端访问来自德国联邦气象局deutscher wetterdienst(dwd)的天气数据。
dwdweather2的Python项目详细描述
dwdwdweather2
从Deutscher Wetterdienst访问天气数据的Python客户端 联邦气象局 德国。
安装
pip install dwdweather2
概要
命令行用法
获取分辨率为hourly的所有电台(默认):
dwdweather stations
使用10_minutes分辨率获取所有电台:
dwdweather stations --resolution 10_minutes
获取最近的站点(第一个参数是经度,第二个参数是纬度):
dwdweather station 7.0 51.0
将电台导出为csv:
dwdweather stations --type csv --file stations.csv
将站点导出为geojson:
dwdweather stations --type geojson --file stations.geojson
在车站获取特定小时的天气(UTC):
dwdweather weather 2667 2019-06-01T15:00
要将导入限制为指定的类别,请运行如下程序:
dwdweather weather 2667 2019-06-01T15:00 --categories air_temperature precipitation pressure
最后,要在执行任何工作之前删除缓存数据库,请使用--reset-cache选项:
dwdweather stations --reset-cache
选择分辨率为10_minutes的数据集:
dwdweather weather 2667 2019-06-01T15:20 --resolution=10_minutes
用作库
fromdatetimeimportdatetimefromdwdweatherimportDwdWeather# Create client object.dw=DwdWeather()# Find closest station to position.closest=dw.nearest_station(lon=7.0,lat=51.0)# The hour you're interested in.# The example is 2014-03-22 12:00 (UTC).query_hour=datetime(2014,3,22,12)result=dw.query(station_id=closest["station_id"],hour=query_hour)print(result)
DwdWeather.query()返回包含 doc/usage-library.rst中列出的可能键。
注释
- 数据缓存在本地sqlite3数据库中以改进查询 连续调用的性能。
- “站点缓存”在第一次请求时填充 DwdWeather.stations()或DwdWeather.nearest_station()
- “站点缓存”不会自动刷新。使用 DwdWeather.import_stations()这样做。
- “度量缓存”在首次访问度量时使用 DwdWeather.query(),并在查询无法执行时更新 从缓存中完成。
- 默认情况下,缓存位于~/.dwd-weather目录中。 这可以使用的cachepath参数控制 DwdWeather()。
- 在整个历史范围内,每个站点的数据量大约为60 MB 而且很明显会随着时间的推移而增加。
- 如果查询到天气数据,并且无法从 缓存,数据从服务器加载-即使数据已经 一秒钟前更新的。如果服务器没有 请求的时间(例如,因为它还不可用),这个 不必要地导致网络流量和等待时间。当然是空间 为了改善这里。
状态
这个软件还处于初级阶段。还没有测试用例。只有 使用Python3.6进行测试。使用风险自负。
学分
感谢Marian Steinbach,Philipp Klaus和所有来自 DWD
更改日志
请参阅文件CHANGES.rst。