跳转到主要内容

检查netcdf文件是否符合UGRID规范

项目描述

ugrid-checks

ci-tests ci-wheels conda-forge pypi bsd-3-clause black

版本 : 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文档:请参阅代码文档字符串以获取更多详细信息。

运行时需求

已知问题

  • 未知

提出问题

请在以下位置创建问题:https://github.com/pp-mo/ugrid-checks

变更日志

  • TODO:移动到单独的文件?

  • v0.2.0

    • #45 实现了对变量数据内容的所有检查,受数据大小的阈值限制
    • #48 放宽了对有效变量名称的要求
  • v0.1.2

    • 发布日期:2022-02-27
      • #36 修复了A304的错误
        允许面节点连接具有_FillValue,因为这用于灵活的2D网格。
  • v0.1.1

    • 发布日期:2022-02-24
      • #23 结构报告错误修复
        • 报告可选连接性,之前缺失
        • 报告位置索引集,之前使用时出错
      • #26 修正了语句代码
        一些语句(R109-R112范围)被报告为错误的语句代码
  • v0.1.0

    • 发布日期:2022-02-09

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

ugrid-checks-0.2.0.tar.gz (35.4 kB 查看散列)

上传日期:

构建分布

ugrid_checks-0.2.0-py3-none-any.whl (34.2 kB 查看散列)

上传日期: Python 3

由以下支持