Python客户端,用于访问德国联邦气象服务机构(德意志气象局,DWD)的天气数据。
项目描述
dwdweather2
Python客户端,用于访问德国联邦气象服务机构(德意志气象局,DWD)的天气数据。
安装
pip install dwdweather2
概要
命令行使用
获取具有每日分辨率的全部站点
dwdweather stations --resolution=daily
获取具有每小时分辨率的全部站点(默认值)
dwdweather stations --resolution=hourly
获取具有10分钟分辨率的全部站点
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
选择具有每日分辨率的数据集
dwdweather weather 44 2020-06-01 --resolution=daily
选择具有每小时分辨率的数据集
dwdweather weather 44 2020-06-01T08 --resolution=hourly
选择具有10分钟分辨率的数据集
dwdweather weather 2667 2019-06-01T15:20 --resolution=10_minutes
作为库的使用
from datetime import datetime
from dwdweather import DwdWeather
# Create client object.
dwd = DwdWeather(resolution="hourly")
# Find closest station to position.
closest = dwd.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 = dwd.query(station_id=closest["station_id"], timestamp=query_hour)
print(result)
DwdWeather.query()返回一个字典,其中包含如doc/usage-library.rst中概述的完整键集。
注意
数据被缓存在本地sqlite3数据库中,以提高连续调用的查询性能。
当首次请求DwdWeather.stations()或DwdWeather.nearest_station()时,填充“站点缓存”
“站点缓存”不会自动刷新。使用DwdWeather.import_stations()来完成此操作。
当首次使用DwdWeather.query()访问度量时,“度量缓存”将被填充,并且每当无法从缓存满足查询时,将更新缓存。
默认情况下,缓存位于~/.dwd-weather目录。可以使用DwdWeather()的cachepath参数来控制。
对于完整的历史范围,每个站点的数据量约为60 MB,并且显然会随着时间的推移而增加。
如果查询天气数据且无法从缓存中满足查询,则从服务器加载数据 - 即使数据在几秒钟前已更新。如果服务器没有请求时间的请求数据(例如,由于它尚未可用),这会无必要地导致网络流量和等待时间。当然,这里有改进的空间。
许可证
代码许可证
在MIT许可证下授权。有关详细信息,请参阅LICENSE。
数据许可证
项目信息
致谢
感谢Marian Steinbach,所有其他贡献者和DWD。
变更日志
请参阅文件CHANGES.rst。
其他项目
项目详情
dwdweather2-0.14.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9fddb9e66fb8b5cc3ef324d99dc968d27aed50669a32018b0c409d5f6c53508a |
|
MD5 | f751af3bb402d9f25e20c589fd93e58a |
|
BLAKE2b-256 | 5a918d4bd93ce13b4e447497716417f7c88cd0b6f51f053c7265bd291154dbc8 |