phenodata 是一个用于开放获取物候数据的采集和处理工具包
项目描述
phenodata
为人类提供的物候数据采集。
关于
phenodata 是一个用于开放获取物候数据的采集和处理工具包。它基于 pandas,可以作为独立程序使用,也可以作为库使用。
目前,它实现了获取德国气象局(DWD)气候数据中心(CDC)FTP服务器上发布的物候观测数据的包装器。添加其他物候数据库和API的适配器是可能的,也是受欢迎的。
致谢
感谢许多德国气象局(DWD)的观测者、全球物候监测计划(GPM)以及幕后工作的人们对记录观测数据并将优秀的 datasets 供社区使用的承诺。你们知道你们是谁。
注释
请注意,phenodata 是 beta 级别的软件,仍在开发中。欢迎各种贡献,以便使其更加稳固。
在 1.0 版本发布之前,可能会出现重大更改,因此建议进行版本锁定,尤其是在将 phenodata 作为库使用时。
概要
使用 phenodata 以及交互式探索数据集的最简单方法是使用其命令行界面。
以下两个示例将从 DWD 的网络获取观测数据,仅关注“开花开始”阶段事件,并使用适合人类消费的值以表格格式呈现结果。
获取 DWD 的“即时”数据集(Sofortmelder)。
phenodata observations \
--source=dwd --dataset=immediate --partition=recent \
--year=2023 --station=brandenburg \
--species-preset=mellifera-de-primary \
--phase="beginning of flowering" \
--humanize --sort=Datum --format=rst
获取 DWD 的“年度”数据集(Jahresmelder)。
phenodata observations \
--source=dwd --dataset=annual --partition=recent \
--year="2022,2023" --station=berlin \
--species-preset=mellifera-de-primary \
--phase="beginning of flowering" \
--humanize --sort=Datum --format=rst
输出示例
phenodata 可以以不同的格式生成输出。这是一个reStructuredText 格式的表格。
日期 |
物种 |
阶段 |
站点 |
---|---|---|---|
2018-02-17 |
普通雪花莲 |
开花开始 |
柏林-达莱姆,柏林 |
2018-02-19 |
普通榛子 |
开花开始 |
柏林-达莱姆,柏林 |
2018-03-30 |
山羊柳 |
开花开始 |
柏林-达莱姆,柏林 |
2018-04-07 |
蒲公英 |
开花开始 |
柏林-达莱姆,柏林 |
2018-04-15 |
樱桃(晚熟) |
开花开始 |
柏林-达莱姆,柏林 |
2018-04-21 |
冬油菜 |
开花开始 |
柏林-达莱姆,柏林 |
2018-04-23 |
苹果(早熟) |
开花开始 |
柏林-达莱姆,柏林 |
2018-05-03 |
苹果(晚熟) |
开花开始 |
柏林-达莱姆,柏林 |
2018-05-24 |
黑刺李 |
开花开始 |
柏林-达莱姆,柏林 |
2018-08-20 |
普通石楠 |
开花开始 |
柏林-达莱姆,柏林 |
用法
简介
对于大多数获取任务,您必须选择 DWD 的两种不同数据集之一,即 年度报告 或 即时报告。此外,必须选择数据分区,它可以是 recent 或 historical。
截至 2023 年,目前的“历史”数据集从过去延伸到 2021 年。所有后续观测数据都存储在 recent 数据集分区中。
DWD 以按物种分开的文件发布数据,这意味着每种植物的数据将存储在不同的文件中。默认情况下,phenodata 将获取所有物种(植物)的数据,以便能够对整个数据集进行所有类型的查询。
如果您只对有限种类的物种(植物)感兴趣,可以通过使用filename选项仅选择特定文件进行检索,从而提高数据获取性能。
例如,当使用--filename=Hasel,Schneegloeckchen时,仅检索包含Hasel或Schneegloeckchen的文件名,从而最小化获取所有文件所需的工作量。
安装
要从PyPI安装软件,请调用
pip install 'phenodata[sql]' --upgrade
库的使用
本段代码示例演示了如何在独立程序中将phenodata用作库。有关可立即运行的代码示例,请查阅示例目录。
>>> import pandas as pd
>>> from phenodata.ftp import FTPSession
>>> from phenodata.dwd.cdc import DwdCdcClient
>>> from phenodata.dwd.pheno import DwdPhenoData
>>> cdc_client = DwdCdcClient(ftp=FTPSession())
>>> client = DwdPhenoData(cdc=cdc_client, humanizer=None, dataset="immediate")
>>> options = {
... # Select data partition.
... "partition": "recent",
...
... # Filter by file names and years.
... "filename": ["Hasel", "Raps", "Mais"],
... "year": [2018, 2019, 2020],
...
... # Filter by station identifier.
... "station-id": [13346]
... }
>>> observations: pd.DataFrame = client.get_observations(options, humanize=False)
>>> observations.info()
[...]
>>> observations
[...]
命令行使用
本节为您介绍如何在命令行中使用phenodata程序。
$ phenodata --help Usage: phenodata info phenodata list-species --source=dwd [--format=csv] phenodata list-phases --source=dwd [--format=csv] phenodata list-stations --source=dwd --dataset=immediate [--all] [--filter=berlin] [--sort=Stationsname] [--format=csv] phenodata nearest-station --source=dwd --dataset=immediate --latitude=52.520007 --longitude=13.404954 [--format=csv] phenodata nearest-stations --source=dwd --dataset=immediate --latitude=52.520007 --longitude=13.404954 [--all] [--limit=10] [--format=csv] phenodata list-quality-levels --source=dwd [--format=csv] phenodata list-quality-bytes --source=dwd [--format=csv] phenodata list-filenames --source=dwd --dataset=immediate --partition=recent [--filename=Hasel,Schneegloeckchen] [--year=2017] phenodata list-urls --source=dwd --dataset=immediate --partition=recent [--filename=Hasel,Schneegloeckchen] [--year=2017] phenodata (observations|forecast) --source=dwd --dataset=immediate --partition=recent [--filename=Hasel,Schneegloeckchen] [--station-id=164,717] [--species-id=113,127] [--phase-id=5] [--quality-level=10] [--quality-byte=1,2,3] [--station=berlin,brandenburg] [--species=hazel,snowdrop] [--species-preset=mellifera-de-primary] [--phase=flowering] [--quality=ROUTKLI] [--year=2017] [--forecast-year=2021] [--humanize] [--show-ids] [--language=german] [--long-station] [--sort=Datum] [--sql=sql] [--format=csv] [--verbose] phenodata drop-cache --source=dwd phenodata --version phenodata (-h | --help) Data acquisition options: --source=<source> Data source. Currently, only "dwd" is a valid identifier. --dataset=<dataset> Data set. Use "immediate" or "annual" for "--source=dwd". --partition=<dataset> Partition. Use "recent" or "historical" for "--source=dwd". --filename=<file> Filter by file names (comma-separated list) Direct filtering options: --year=<year> Filter by year (comma-separated list) --station-id=<station-id> Filter by station identifiers (comma-separated list) --species-id=<species-id> Filter by species identifiers (comma-separated list) --phase-id=<phase-id> Filter by phase identifiers (comma-separated list) Humanized filtering options: --station=<station> Filter by strings from "stations" data (comma-separated list) --species=<species> Filter by strings from "species" data (comma-separated list) --phase=<phase> Filter by strings from "phases" data (comma-separated list) --species-preset=<preset> Filter by strings from "species" data (comma-separated list) The preset will get loaded from the "presets.json" file. Forecasting options: --forecast-year=<year> Use as designated forecast year. Postprocess filtering options: --sql=<sql> Apply given SQL query before output. Data output options: --format=<format> Output data in designated format. Choose one of "tabular", "json", "csv", or "string". Use "md" for Markdown output, or "rst" for reStructuredText. With "tabular:foo", it is also possible to specify other tabular output formats. [default: tabular:psql] --sort=<sort> Sort by given field names. (comma-separated list) --humanize Resolve identifier-based fields to human-readable labels. --show-ids Show identifiers alongside resolved labels, when using "--humanize". --language=<language> Use labels in designated language, when using "--humanize" [default: english]. --long-station Use long station name including "Naturraumgruppe" and "Naturraum". --limit=<limit> Limit output of "nearest-stations" to designated number of entries. [default: 10] --verbose Turn on verbose output.
示例
探索phenodata的最佳方法是通过运行几个示例调用。
“元数据”部分将向您介绍不同的命令,用于查询监测站/站点信息,并列出将要获取的实际文件,以便了解数据来源。
“观测”部分将演示获取、处理和格式化实际观测数据的命令示例。
元数据
显示物种列表,包括它们的德语、英语和拉丁名称
phenodata list-species --source=dwd
显示阶段列表,包括它们的德语和英语名称
phenodata list-phases --source=dwd
所有报告/监测站点的列表
phenodata list-stations --source=dwd --dataset=immediate
带有过滤的站点列表
phenodata list-stations --source=dwd --dataset=annual --filter="Fränkische Alb"
显示给定位置的最近站点
phenodata nearest-station --source=dwd --dataset=immediate \ --latitude=52.520007 --longitude=13.404954
显示给定位置的20个最近站点
phenodata nearest-stations \ --source=dwd --dataset=immediate \ --latitude=52.520007 --longitude=13.404954 --limit=20
年度报告者的最近观测文件名列表
phenodata list-filenames \ --source=dwd --dataset=annual --partition=recent
与上述相同,但按文件名过滤
phenodata list-filenames \ --source=dwd --dataset=annual --partition=recent \ --filename=Hasel,Kornelkirsche,Loewenzahn,Schneegloeckchen
列出完整URL而不是仅文件名
phenodata list-urls \ --source=dwd --dataset=annual --partition=recent \ --filename=Hasel,Kornelkirsche,Loewenzahn,Schneegloeckchen
观测
基本
使用基于文件名的过滤在数据获取时间观测榛子和雪花莲
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --filename=Hasel,Schneegloeckchen
观测榛子和雪花莲(dito),但针对特定站点标识符
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --filename=Hasel,Schneegloeckchen --station-id=7521,7532
特定站点标识符和特定年份的所有观测
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --station-id=7521,7532 --year=2020,2021
特定站点和物种标识符的所有观测
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --station-id=7521,7532 --species-id=113,127
所有标记为无效的观测
phenodata list-quality-bytes --source=dwd phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --quality-byte=5,6,7,8
人性化的输出
选项--humanize将通过将标识符字段解析为适当的可读文本标签来改进文本输出。
在“柏林-达勒姆”站对“榛子”、“雪花莲”、“苹果”和“梨”物种进行观测,如果可能的话,以德语输出文本
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --filename=Hasel,Schneegloeckchen,Apfel,Birne \ --station-id=12132 \ --humanize \ --language=german
人性化的搜索
当使用--humanize选项时,您可以使用非标识符过滤选项--station、--species和--phase,以使用可读文本标签进行过滤而不是数字标识符。
使用现实世界位置名称查询观测
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --filename=Hasel,Schneegloeckchen \ --station=berlin,brandenburg \ --humanize --sort=Datum
查询特定年份在慕尼黑附近,物种名称为“榛子”和“雪花莲”的观测
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --station=münchen \ --species=hazel,snowdrop \ --year=2022 \ --humanize --sort=Datum
现在,让我们查询任何“开花”观测。将有开花开始、普遍开花和开花结束
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --station=münchen \ --phase=flowering \ --year=2022 \ --humanize --sort=Datum
与之前相同的观测,但有ROUTKLI质量标记
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --station=münchen \ --phase=flowering \ --quality="nicht beanstandet" \ --year=2022 \ --humanize --sort=Datum
现在,让我们查询那些经过修正的字段值(Feldwert korrigiert)
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --station=münchen \ --phase=flowering \ --quality=korrigiert \ --humanize --sort=Datum
使用预设进行过滤
使用 --humanize 选项时,您还可以通过名称使用预定义的缩写来指定物种列表。例如,mellifera-de-primary 预设定义在 presets.json 文件中,如下所示:
Hasel, Schneeglöckchen, Sal-Weide, Löwenzahn, Süßkirsche, Apfel, Winterraps, Robinie, Winter-Linde, Heidekraut
然后,您可以使用选项 --species-preset=mellifera-de-primary 来代替 --species 选项,以仅过滤指定的物种。
此示例列出了在科隆指定的年份中所有“开花开始”的观测数据,仅针对名为 mellifera-de-primary 的物种列表。结果将按物种和日期排序,并在可能的情况下以德语显示可读标签。
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --phase="beginning of flowering" \ --year=2021,2022,2023 \ --station=köln \ --species-preset=mellifera-de-primary \ --humanize --language=german --sort=Spezies,Datum
使用 SQL 过滤
Phenodata 使用 DuckDB Python API 允许您直接查询由数据采集子系统生成的 pandas DataFrame。此示例使用 SQL 语句按站点名称过滤结果,并按日期排序。
phenodata observations \ --source=dwd --dataset=annual --partition=recent \ --year=2019,2020,2021,2022,2023 \ --species-preset=mellifera-de-primary --phase="beginning of flowering" \ --humanize --language=german \ --sql="SELECT * FROM data WHERE Station LIKE '%Berlin%' ORDER BY Datum" \ --format=md
项目信息
资源
贡献
如果您想贡献,我们将非常欢迎。花些时间四处看看,找到错误、设计问题或拼写错误,然后向我们发送拉取请求或创建一个问题。提前感谢您的努力,作者们真的非常感激任何形式的帮助和反馈。
讨论
关于 phenodata 的开发和应用的讨论正在进行中 Hiveeyes 论坛。享受阅读它们,如果您认为您可以贡献一些东西或分享您用该程序所做的事情,不要犹豫,写一篇文章。
https://community.hiveeyes.org/t/phanologischer-kalender-fur-trachtpflanzen/664
https://community.hiveeyes.org/t/phanologischer-kalender-2020/2893
https://community.hiveeyes.org/t/phanologie-und-imkerliche-eingriffe-bei-den-bienen/705
https://community.hiveeyes.org/t/phenological-calendar-for-france/800
开发
为了在您的工作站上设置开发环境,请参阅 开发沙盒 文档。当您看到软件测试成功时,您应该准备好开始开发了。
代码许可
本项目受 GNU AGPL 许可协议的约束,请参阅 LICENSE。
数据许可
免责声明
本项目及其作者与 DWD、GPM、USA-NPN 或任何其他组织没有任何关联。这是一个由社区构思的独立项目,旨在使数据更容易获取,以开放数据和开放科学数据的精神。作者们认为,如果公共数据可以轻松加载到 pandas 数据框和 Xarray 数据集中,世界将变得更好。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
构建分发
phenodata-0.13.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9c450ff861c727567d43af708c97f9a582921d60e2f918bc7404d34c5479ef23 |
|
MD5 | 14334b6cc9442c4b3d1bd724e7ef8953 |
|
BLAKE2b-256 | 418002e336f92de5201889cfe784fda492ed608f24036eb48d9cd8ff9f8b7052 |
phenodata-0.13.1-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b3f40af845a973be3f38c59d10c5351291b4ea4e871d0a4f7cef69081e5bbe6c |
|
MD5 | 37b87b13b251153e67abf07770677d01 |
|
BLAKE2b-256 | 3667a941cc4a4e1b27c982d35369d94ed7cf12ca0e3ddd1beb5e940c237eb58c |