检查netcdf文件是否符合UGRID规范
项目描述
ugrid-checks
版本 : 0.2.0
一个用于检查netcdf文件是否符合UGRID规范的工具。
它将文件与UGRID的符合性规则进行比较,还可以生成文件网格内容的摘要。
安装
可在PyPI和conda-forge上获得。
要安装
> pip install ugrid-checks
或
> conda create -n ugrid_checker ugrid-checks
命令行:检查
$ ugrid-checker -h
usage: ugrid-checker [-h] [-q] [-i IGNORE] [-e] [-d MAX_DATASIZE] [-s] [--nonmesh] [-v] [file]
Check a netcdf-CF file for conformance to the UGRID conventions.
positional arguments:
file File to check.
optional arguments:
-h, --help show this help message and exit
-q, --quiet don't print a checking report if there were no problems
-i IGNORE, --ignore IGNORE
a list of errorcodes to ignore.
-e, --errorsonly ignore all warnings ("Axxx"= advise codes), and only report errors ("Rxxx"= require codes).
-d MAX_DATASIZE, --max-datasize MAX_DATASIZE
maximum array-size, above which variable-data checks are skipped. Default=200.0 (Mb).
-s, --summary print a summary of UGRID mesh information found in the file
--nonmesh include a list of non-mesh variables in the summary
-v, --version print version information
$
基本用法
$ ugrid-checker data_C4.nc
UGRID conformance checks complete.
No problems found.
Done.
$
$ ugrid-checker data_C4_warn_error.nc
UGRID conformance checks complete.
List of checker messages :
*** FAIL R106 : Mesh variable "topology" attribute 'face_coordinates' refers to a variable "longitude", but there is no such variable in the dataset.
*** FAIL R108 : Mesh variable "topology" has face_coordinates="latitude longitude", which is not a list of variables in the dataset.
... WARN A304 : Mesh connectivity variable "edge_nodes" of mesh "topology" has a '_FillValue' attribute, which should not be present on a "edge_node_connectivity" connectivity.
Total of 3 problems logged :
2 Rxxx requirement failures
1 Axxx advisory recommendation warnings
Done.
$
控制检查
-e
/ --errorsonly
选项仅检查需求(即“错误”),并跳过建议(即“警告”)。
-i
/ --ignore
选项根据它们的Axxx/Rxxx代码跳过特定的检查。
见代码列表。
示例
$ ugrid-checker data_C4_warn_error.nc --errorsonly --ignore r106,r108
Ignoring codes:
R106, R108
UGRID conformance checks complete.
No problems found.
Done.
$
命令行:结构分析
使用-s
/ --summary
选项可以打印文件网格内容的摘要。
$ ugrid-checker data_C4.nc --summary --quiet
File mesh structure
-------------------
Meshes
"topology"
node("num_node")
coordinates : "node_lat", "node_lon"
face("dim0")
face_node_connectivity : "face_nodes"
coordinates : "latitude", "longitude"
Mesh Data Variables
"sample_data"
mesh : "topology"
location : "face"
$
符合性规则和代码列表
所使用的所有错误/警告代码都在UGRID一致性规则中定义。每个都有一个识别码:“Rxxx”用于需求,“Axxx”用于建议性规则。
请查看以下列表:UGRID 草案一致性规则
注意:这些目前仅在初步草案版本中可用,尚未被纳入UGRID规范。
限制
不支持3-D/体积
草案一致性规则目前不涵盖3-D网格,因此检查代码也不涵盖。目前也在讨论是否需要在UGRID的未来版本中“修复”此功能,甚至删除它。请参阅此开发者讨论。
或者,这可以在未来添加。
Python API
检查器作为一个可导入的模块“ugrid_checks”提供。
直接运行模块将调用命令行界面,
例如:$ python -m ugrid_checks file.nc
与$ ugrid-checker file.nc
相同。
在Python中,模块可以使用如下方式使用
>>> from ugrid_checks.check import check_dataset
>>> print(check_dataset.__doc__)
Run UGRID conformance checks on a file.
Optionally print a result summary.
Optionally ignore errors below a logging level.
Returns a checker object with a file analysis and checking log records.
Parameters
----------
file : string, Path or :class:`NcFileSummary`
path to, or representation of a netcdf input file
print_summary : bool, default=True
print a results summary at the end
omit_advisories : bool, default False
If set, log only 'requirements' Rxxx statements, and ignore the
advisory 'Axxx' ones.
ignore_codes : list(str) or None, default None
A list of error codes to ignore.
max_data_mb : float, default 200.0
A rough size threshold (in Mb), beyond which we will skip data checks.
Set to 0 for no checking, or -1 for no size limit.
Returns
-------
checker : Checker
A checker for the file.
>>>
>>> checker = check_dataset('data_C4_warn.nc', print_summary=False)
>>>
>>> type(checker)
<class 'ugrid_checks.check.Checker'>
>>>
>>> print(checker.checking_report())
UGRID conformance checks complete.
List of checker messages :
... WARN A304 : Mesh connectivity variable "edge_nodes" of mesh "topology" has a '_FillValue' attribute, which should not be present on a "edge_node_connectivity" connectivity.
Total of 1 problems logged :
0 Rxxx requirement failures
1 Axxx advisory recommendation warnings
Done.
>>>
>>> print(checker.structure_report())
Meshes
"topology"
node("num_node")
coordinates : "node_lat", "node_lon"
face("dim0")
face_node_connectivity : "face_nodes"
coordinates : "latitude", "longitude"
Mesh Data Variables
"sample_data"
mesh : "topology"
location : "face"
>>>
目前尚无构建API文档:请参阅代码文档字符串以获取更多详细信息。
运行时需求
- Python >= 3.7
- netCDF4
已知问题
- 未知
提出问题
请在以下位置创建问题:https://github.com/pp-mo/ugrid-checks
变更日志
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
ugrid-checks-0.2.0.tar.gz (35.4 kB 查看散列)
构建分布
ugrid_checks-0.2.0-py3-none-any.whl (34.2 kB 查看散列)