检查数据集和SOS端点是否符合标准
项目描述
IOOS合规性检查器
IOOS合规性检查器是一个基于Python的工具,用于数据提供者检查本地或远程的netCDF文件是否符合CF和ACDD文件标准。该Python模块可以作为命令行工具使用,也可以作为可以集成到其他软件的库。
开发了合规性检查器的基于Web的版本,以使更广泛的受众能够访问该检查器。使用Web版本,提供者只需提供一个链接或上传他们的数据集,就可以获得合规性检查器提供的全部功能。
它目前支持以下来源和标准
标准 | 来源 | .nc/OPeNDAP/.cdl | SOS |
---|---|---|---|
ACDD (1.1, 1.3) | 内置 | X | - |
CF (1.8) | 内置 | X | - |
CF (1.7) | 内置 | X | - |
CF (1.6) | 内置 | X | - |
IOOS SOS | 内置 | - | GetCapabilities, DescribeSensor |
IOOS (1.1) | 内置 | X | - |
IOOS (1.2) | 内置 | X | - |
滑翔机DAC | ioos/cc-plugin-glider | X | - |
NCEI (1.1, 2.0) | ioos/cc-plugin-ncei | X | - |
对数据提供者的建议
虽然这个工具的命令行版本可以循环运行,但如果所有文件都是按照相同的方式创建的,就没有必要检查每个文件。简而言之,这个工具不是用来识别您数据处理流程中的错误的。然而,它旨在帮助您确定您的流程是否符合标准。如果您出于任何原因更改了处理流程,运行一个文件通过合规性检查器以确保您流程的更改不会影响文件的合规性。
如果您认为需要批量运行文件通过合规性检查器,请联系IOOS项目办公室操作部门寻求协助。
合规性检查器Web工具
IOOS合规性检查器的前端伴侣。
https://compliance.ioos.us/index.html
源代码可在GitHub上获取
https://github.com/ioos/compliance-checker-web
使用方法
从下拉菜单中选择您要运行的测试。然后,上传您的数据集或提供一个指向远程数据集(OPeNDAP)的URL,然后点击“提交”。
合规性检查器的输出将为您提供一份全面的问题列表和需要采取的措施。您可以通过点击“下载报告”按钮将合规性检查器的报告作为文本文件下载。
API
除了IOOS合规性检查器项目的基于Web的前端之外,还为有兴趣批量处理通过OPeNDAP托管文件的用户提供了一个API。有关如何使用API的详细信息,可在合规性检查器Web wiki页面上找到。
这里有一些示例
HTML输出
JSON输出
合规性检查器命令行工具
概念与术语
每个合规标准都通过一个检查套件执行,其功能类似于Python标准单元测试。检查套件根据元数据标准对数据集进行检测,返回一个结果列表,然后汇总成一个总结。
每个结果都有一个(通过/总数)分数、权重(高/中/低)、一个计算机可读的名称、一个可选的人类可读消息列表,以及可选的子结果列表。
然后通过聚合名称,然后乘以分数并求和来计算单个分数。
计算机可读的名称字段控制结果如何聚合在一起——为了防止检查套件的整体分数因变量数量而变化,可以通过名称属性将结果分组在一起。分组的结果将只添加到一个顶级条目。
有关实现的更多详细信息,请参阅开发维基页面。
安装
有关安装说明,请参阅安装维基。
命令行使用
compliance-checker可以对本地文件(.nc文件、.cdl元数据文件、SOS GetCapabilities/DescribeSensor请求的.xml文件)或对远程URL(OPeNDAP数据URL、SOS GetCapabilities/DescribeSensor URL)进行操作。
如果您旨在检查netCDF-dump,也称为CDL文件,则文件必须以.cdl
结尾,以便检查套件能够正确解析其内容。
警告 CF/ACDD检查将访问数据,因此如果使用远程OPeNDAP URL,请确保大小合理!
usage: cchecker.py [-h] [--test TEST] [--criteria [{lenient,normal,strict}]]
[--verbose] [--describe-checks] [--skip-checks SKIP_CHECKS]
[-f {text,html,json,json_new}] [-o OUTPUT] [-O OPTION] [-V]
[-l] [-d DOWNLOAD_STANDARD_NAMES]
[dataset_location [dataset_location ...]]
positional arguments:
dataset_location Defines the location of the dataset to be checked.
The location can be a local netCDF file, a remote
OPeNDAP endpoint, a remote netCDF file which returns
content-type header of 'application/x-netcdf', or an
ERDDAP TableDAP endpoint. Note that the ERDDAP TableDAP
endpoint will currently attempt to fetch the entire
TableDAP dataset.
optional arguments:
-h, --help show this help message and exit
--test TEST, -t TEST, --test= TEST, -t= TEST
Select the Checks you want to perform. Defaults to
'acdd' if unspecified. Versions of standards can be
specified via `-t <test_standard>:<version>`. If
`<version>` is omitted, or is "latest", the latest
version of the test standard is used.
--criteria [{lenient,normal,strict}], -c [{lenient,normal,strict}]
Define the criteria for the checks. Either Strict,
Normal, or Lenient. Defaults to Normal.
--verbose, -v Increase output. May be specified up to three times.
--describe-checks, -D
Describes checks for checkers specified using `-t`. If
`-t` is not specified, lists checks from all available
checkers.
--skip-checks SKIP_CHECKS, -s SKIP_CHECKS
Specifies tests to skip. Can take the form of either
`<check_name>` or `<check_name>:<skip_level>`. The
first form skips any checks matching the name. In the
second form <skip_level> may be specified as "A", "M",
or "L". "A" skips all checks and is equivalent to
calling the first form. "M" will only show high
priority output from the given check and will skip
medium and low. "L" will show both high and medium
priority issues, while skipping low priority issues.
-f {text,html,json,json_new}, --format {text,html,json,json_new}
Output format(s). Options are 'text', 'html', 'json',
'json_new'. The difference between the 'json' and the
'json_new' formats is that the 'json' format has the
check as the top level key, whereas the 'json_new'
format has the dataset name(s) as the main key in the
output follow by any checks as subkeys. Also, 'json'
format can be only be run against one input file,
whereas 'json_new' can be run against multiple files.
-o OUTPUT, --output OUTPUT
Output filename(s). If '-' is supplied, output to
stdout. Can either be one or many files. If one file
is supplied, but the checker is run against many
files, all the output from the checks goes to that
file (does not presently work with 'json' format). If
more than one output file is supplied, the number of
input datasets supplied must match the number of
output files.
-O OPTION, --option OPTION
Additional options to be passed to the checkers.
Multiple options can be specified via multiple
invocations of this switch. Options should be prefixed
with a the checker name followed by the option, e.g.
'<checker>:<option_name>' Available options:
'cf:enable_appendix_a_checks' - Allow check results
against CF Appendix A for attribute location and data
types.
-V, --version Display the IOOS Compliance Checker version
information.
-l, --list-tests List the available tests
-d DOWNLOAD_STANDARD_NAMES, --download-standard-names DOWNLOAD_STANDARD_NAMES
Specify a version of the cf standard name table to
download as packaged version. Either specify a version
number (e.g. "72") to fetch a specific version or
"latest" to get the latest CF standard name table.
示例
检查本地文件与CF 1.6
$ compliance-checker --test=cf:1.6 compliance_checker/tests/data/examples/hycom_global.nc
--------------------------------------------------------------------------------
IOOS Compliance Checker Report
cf:1.6 check
--------------------------------------------------------------------------------
Corrective Actions
hycom_global.nc has 9 potential issues
Errors
--------------------------------------------------------------------------------
Name Reasoning
§3.2 Either long_name or standard_name Attribute long_name or/and standard_name
is highly recommended for variable time: is highly recommended for variable time
§4.3.1 depth is a valid vertical vertical coordinates not defining
coordinate: pressure must include a positive
attribute that is either 'up' or 'down'
Warnings
--------------------------------------------------------------------------------
Name Reasoning
§2.6.1 Global Attribute Conventions Conventions global attribute does not
includes CF-1.6: contain "CF-1.6". The CF Checker only
supports CF-1.6 at this time.
§2.6.2 Recommended Attributes: institution should be defined source
should be defined references should be
defined
§2.6.2 Recommended Global Attributes: global attribute history should exist
and be a non-empty string
§8.1 Packed Data defined by water_u Attributes add_offset and scale_factor
contains valid packing: are not of type float or double.
§8.1 Packed Data defined by water_v Attributes add_offset and scale_factor
contains valid packing: are not of type float or double.
检查远程文件与ACDD 1.3
远程数据集URL来自OPeNDAP端点的数据URL部分。
$ compliance-checker --test=acdd:1.3 "http://sos.maracoos.org/stable/dodsC/hrecos/stationHRMARPH-agg.ncml"
检查远程ERDDAP数据集
将ERDDAP的TableDAP
或GridDAP
URL提供给检查器
$ compliance-checker --test ioos:1.2 "https://pae-paha.pacioos.hawaii.edu/erddap/griddap/pibhmc_bathy_60m_guam"
确保提供不带格式扩展的URL(无.nc
、.ncCF
等)。
一些ERDDAP数据集的示例
- https://pae-paha.pacioos.hawaii.edu/erddap/tabledap/AWS-HIMB
- http://erddap.secoora.org/erddap/tabledap/edu_usf_marine_comps_1407d550
- http://erddap.cencoos.org/erddap/tabledap/bodega-bay-bml_wts
- http://erddap.cencoos.org/erddap/tabledap/fort-point
- http://erddap.cencoos.org/erddap/tabledap/edu_humboldt_humboldt
- http://erddap.cencoos.org/erddap/tabledap/edu_calpoly_marine_morro
- http://erddap.cencoos.org/erddap/tabledap/mlml_mlml_sea
- http://erddap.cencoos.org/erddap/tabledap/mlml_mlml_met
- http://erddap.cencoos.org/erddap/tabledap/mlml_monterey
- http://erddap.cencoos.org/erddap/tabledap/edu_humboldt_tdp
将结果写入文本文件
$ compliance-checker --test=acdd:1.3 --format=text --output=/tmp/report.txt compliance_checker/tests/data/examples/hycom_global.nc
将结果写入JSON文件
$ compliance-checker --test=acdd:1.3 --format=json --output=/tmp/report.json compliance_checker/tests/data/examples/hycom_global.nc
将结果写入HTML文件
$ compliance-checker --test=acdd:1.3 --format=html --output=/tmp/report.html compliance_checker/tests/data/examples/hycom_global.nc
将多个输入文件的多项输出文本到一个输出文件
$ compliance-checker --test=cf:1.6 --format text --output=/tmp/combined_output.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
从多个输入文件输出HTML和文本文件(第一部分)
在这种情况下,您将得到2个文件/tmp/combined_output.txt
和/tmp/combined_output.html
,其中包含两个输入文件的cf检查结果,因为您只指定了一个输出文件名。
$ compliance-checker --test=cf:1.6 --format text --format html --output=/tmp/combined_output.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
从多个输入文件输出HTML和文本文件(第二部分)
在这种情况下,您将得到4个文件/tmp/hycom.txt
、/tmp/hycom.html
、/tmp/ww3.txt
和/tmp/ww3.html
,其中包含cf检查结果,因为您指定的输出文件名与输入文件名一样多。
$ compliance-checker --test=cf:1.6 --format text --format html --output=/tmp/hycom.txt --output=/tmp/ww3.txt compliance_checker/tests/data/examples/hycom_global.nc compliance_checker/tests/data/examples/ww3.nc
下载特定CF标准名称表用于测试
注意 在CF测试期间,如果文件在全局属性中指定了与封装版本不匹配的cf标准名称表版本(例如::standard_name_vocabulary = "CF Standard Name Table v30" ;
),则会尝试下载指定的版本。如果失败,将回退到封装版本。
$ compliance-checker -d 35
Downloading cf-standard-names table version 35 from: http://cfconventions.org/Data/cf-standard-names/35/src/cf-standard-name-table.xml
或者,您可以通过名为CF_STANDARD_NAME_TABLE的环境变量指定标准名称表的绝对路径,合规性检查器将使用该版本。
Python使用
如果您有兴趣将IOOS合规性检查器集成到自己的Python项目中,请查看以下Python代码示例
from compliance_checker.runner import ComplianceChecker, CheckSuite
# Load all available checker classes
check_suite = CheckSuite()
check_suite.load_all_available_checkers()
# Run cf and adcc checks
path = '/path/or/url/to/your/dataset'
checker_names = ['cf', 'acdd']
verbose = 0
criteria = 'normal'
output_filename = '/output/report.json'
output_format = 'json'
"""
Inputs to ComplianceChecker.run_checker
path Dataset location (url or file)
checker_names List of string names to run, should match keys of checkers dict (empty list means run all)
verbose Verbosity of the output (0, 1, 2)
criteria Determines failure (lenient, normal, strict)
output_filename Path to the file for output
output_format Format of the output
@returns If the tests failed (based on the criteria)
"""
return_value, errors = ComplianceChecker.run_checker(path,
checker_names,
verbose,
criteria,
output_filename=output_filename,
output_format=output_format)
# Open the JSON output and get the compliance scores
with open(output_filename, 'r') as fp:
cc_data = json.load(fp)
scored = cc_data[cc_test[0]]['scored_points']
possible = cc_data[cc_test[0]]['possible_points']
log.debug('CC Scored {} out of {} possible points'.format(scored, possible))
合规性检查插件
已经开发出单独的插件,以补充合规性检查工具,并针对准备提交到不同数据汇编中心的数据制定了规范。这些插件的版本号不一定与合规性检查器的版本相对应,但它们都设计为与合规性检查器工具一起运行。
当前插件版本
这是一个针对GliderDAC文件的检查器
这是一个针对NCEI netCDF模板v1.1和v2.0文件的检查器。
这些插件必须单独安装,但它们在基础合规性检查软件之上运行。
pip install cc-plugin-ncei
检查是否正确安装,列出测试
compliance-checker -l
您应该看到
IOOS compliance checker available checker suites (code version):
- ncei-grid (2.1.0)
- ncei-grid:1.1 (2.1.0)
- ncei-grid:2.0 (2.3.0)
- ncei-grid:latest (2.1.0)
- ncei-point (2.3.0)
- ncei-point:1.1 (2.1.0)
- ncei-point:2.0 (2.3.0)
etc ....
一旦安装了插件,使用方式与内置检查器类似。
插件使用示例
- 在THREDDS端点运行NCEI点检查
compliance-checker -t ncei-point -v "https://data.nodc.noaa.gov/thredds/dodsC/testdata/mbiddle/GOLD_STANDARD_NETCDF/1.1/NODC_point_template_v1.1_2016-06-15_133710.844375.nc"
- 在本地数据集上运行NCEI轨迹配置文件正交检查
compliance-checker -t ncei-trajectory-profile-orthogonal -v ~/data/sample-trajectory-profile.nc
- 从网格文件检查输出JSON
compliance-checker -t ncei-grid -f json -o ~/Documents/sample_grid_report.json ~/Documents/sample_grid_report.nc
免责声明
IOOS合规性检查器的目标是检查您的文件是否与我们解读的某些数据集元数据标准相符,以用作生成合规文件的指南。合规性检查器不应被视为关于您的文件是否100%“合规”的权威来源。相反,我们建议用户将结果作为实现合规性的指南。
杂项/致谢
贡献者
CF检查器的部分基于Michael Decker的工作,http://repositories.iek.fz-juelich.de/hg/CFchecker/