跳转到主要内容

Python客户端,用于访问德国联邦气象服务机构(德意志气象局,DWD)的天气数据。

项目描述

https://img.shields.io/badge/Python-2.7-green.svg https://img.shields.io/pypi/v/dwdweather2.svg https://img.shields.io/github/tag/panodata/dwdweather2.svg https://assets.okfn.org/images/ok_buttons/od_80x15_red_green.png https://assets.okfn.org/images/ok_buttons/oc_80x15_blue.png https://assets.okfn.org/images/ok_buttons/os_80x15_orange_grey.png https://img.shields.io/badge/code%20style-black-000000.svg

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 (22.5 kB 查看哈希值)

上传时间 源代码

由以下支持