DCAT到Intake目录翻译层
项目描述
intake-dcat
这些目录是描述公共数据集元数据和访问信息的标准化格式,详情请参阅此处。许多Socrata和ESRI数据门户发布描述其目录的data.json
文件。以下是一些示例:
https://data.lacity.org/data.json
http://geohub.lacity.org/data.json
该项目为用户提供了一种有见地的将数据集从这些目录加载到科学Python生态系统的途径。目前,它将CSV文件加载到Pandas数据框中,将GeoJSON文件加载到GeoDataFrames中,并将ESRI Shapefiles加载到GeoDataFrames中。未来的格式可能包括plain JSON和Parquet。
需求
intake >= 0.4.4
intake_geopandas >= 0.2.2
geopandas >= 0.5.0
安装
intake-dcat
已发布在PyPI上。您可以通过在终端运行以下命令来安装它
pip install intake-dcat
您可以通过打开examples/
目录中的示例笔记本来测试功能
使用方法
可以使用以下方式导入此包
from intake_dcat import DCATCatalog
加载目录
您可以通过提供data.json
文件的URL来从DCAT目录加载数据
catalog = DCATCatalog('http://geohub.lacity.org/data.json', name='geohub')
len(list(catalog))
您可以显示目录中的条目
for entry_id, entry in catalog.items():
display(entry)
如果目录中的条目太多,一次性打印不方便,您可以通过搜索一个术语(例如“district”)来缩小范围
for entry_id, entry in catalog.search('district').items():
display(entry)
加载数据集
一旦您已经确定了一个数据集,您可以使用read()
将其加载到一个数据框中
df = entry.read()
这将根据源格式自动将数据集加载到Pandas数据框或GeoDataFrame中。
指定目录
您可以使用URL直接在Python中读取DCATCatalog
,如上所述,但也可以编写一个包含DCATCatalog
条目的目录文件。这允许您更容易地指定用于分发和版本控制的DCAT目录。
例如,此 YAML 文件为两个开放数据目录创建了条目
metadata:
version: 1
sources:
# Here we have two data sources for this catalog, which are themselves
# DCAT catalogs, one for LA open data, and the other for LA GeoHub
la_open_data:
# We identify them as being loaded with the DCAT driver
driver: dcat
# Here we specify the args used to load the catalog
args:
# The URL to the catalog
url: https://data.lacity.org/data.json
# An optional name for the catalog.
name: la-open-data
la_geohub:
driver: dcat
args:
url: http://geohub.lacity.org/data.json
name: la_geohub
# We can also specify a subset of the datasets in the catalog using an "items"
# dictionary. If these are specified, only these datasets will be available in
# the resulting catalog. They will be available under the more human-readable
# name specified as the key.
items:
# So, this dataset will be available as "bikeways"
bikeways: http://geohub.lacity.org/datasets/2602345a7a8549518e8e3c873368c1d9_0
city_boundary: http://geohub.lacity.org/datasets/09f503229d37414a8e67a7b6ceb9ec43_7
bike_racks: http://geohub.lacity.org/datasets/3b022cced9704108af157d3d5eedb268_2
命令行界面
intake-dcat
提供了一个小的命令行界面,用于一些常用操作。这些操作使用 intake-dcat <子命令> <选项>
调用
镜像命令
此命令加载一个清单文件,该文件列出一组 DCAT 条目,将它们上传到指定的 s3 桶,并输出一个新的具有相同条目的目录,指向该桶。
以下是一个示例清单:
# Name of the LA open data portal
la-open-data:
# URL to the open data portal catalog
url: https://data.lacity.org/data.json
# The s3 bucket to upload the data to
bucket_uri: s3://my-bucket
# A list of data resources to mirror
items:
lapd_metrics: https://data.lacity.org/api/views/t6kt-2yic
# Name of the LA GeoHub data portal
la-geohub:
# URL to the open data portal catalog
url: http://geohub.lacity.org/data.json
# The s3 bucket to upload the data to
bucket_uri: s3://my-bucket
# A list of data resources to mirror
items:
bikeways: http://geohub.lacity.org/datasets/2602345a7a8549518e8e3c873368c1d9_0
city_boundary: http://geohub.lacity.org/datasets/09f503229d37414a8e67a7b6ceb9ec43_7
可以使用以下命令进行镜像:
intake-dcat mirror manifest.yml > new-catalog.yml
此命令使用 boto3
库,并假设它可以找到 AWS 凭据。更多信息请参阅 此文档。
创建命令
此命令从 DCAT 目录创建一个新的 intake 目录,并将其输出到标准输出。以下是一个示例命令:
intake-dcat create data.lacity.org/data.json > catalog.yml
项目详情
下载文件
下载您平台的文件。如果您不确定选择哪个,请了解有关 安装软件包 的更多信息。
源分布
构建分布
intake-dcat-0.4.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | a8b7b447c5f6460ffce9bd498f74ad5b314bcdb084f72547b2e3e77a65afdc7c |
|
MD5 | 8904a00911de7d4abe07ca2eca442bdc |
|
BLAKE2b-256 | 62e25f895b963d693bfa51e96a46701c676b4ca7b784eb4848462483b985cfe8 |
intake_dcat-0.4.0-py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 8da19e677ce18282b69331aa93d733a4969dc8bbaf640e58039feef3e61b113a |
|
MD5 | 22d5f993404d0e80ab4c5ae6e3f0f224 |
|
BLAKE2b-256 | 08ce2da44862d372a9b1b272d2e658cd36a62cdda31d25bea70c148863ca3665 |