Prepare xarray Datasets for CF-1.12 compliant NetCDF output
Project description
nc-check
Prepare xarray.Dataset objects to be written as CF-1.12-compliant NetCDF files.
Install
uv sync
Install optional CF checker dependencies (recommended for full CF checks):
uv sync --extra cf
Usage
import xarray as xr
import nc_check # Registers the .check dataset accessor
ds = xr.Dataset(
data_vars={"temp": (("time", "lat", "lon"), [[[280.0]]])},
coords={"time": [0], "lat": [10.0], "lon": [20.0]},
)
issues = ds.check.compliance(report_format="python")
fixed = ds.check.make_cf_compliant()
ocean_report = ds.check.ocean_cover(report_format="python")
time_report = ds.check.time_cover(report_format="python")
By default (report_format="auto"), reports adapt to environment:
- Jupyter notebooks: HTML
- CLI terminals: rich tables
- Other environments (scripts/tests): Python dicts
You can request rich table reports printed to stdout:
ds.check.compliance(report_format="tables")
CLI usage:
# Prints readable rich tables to stdout (default behavior)
nc-check input.nc
# Explicit check modes
nc-check compliance input.nc
nc-check compliance input.nc --engine heuristic
nc-check ocean-cover input.nc
nc-check time-cover input.nc
nc-check all input.nc
nc-check all input.nc --engine cfchecker
# Explicit coordinate names when they differ from lon/lat/time
nc-check ocean-cover input.nc --lon-name x --lat-name y --time-name t
nc-check time-cover input.nc --time-name t
nc-check all input.nc --lon-name x --lat-name y --time-name t
# Saves an HTML report beside input.nc as input_report.html
nc-check input.nc --save-report
# With "all", saves one combined report:
# input_all_report.html
nc-check all input.nc --save-report
For notebooks, use HTML output and optionally save it:
html = ds.check.compliance(
report_format="html",
report_html_file="cf-report.html",
)
You can choose which conventions to check:
ds.check.compliance(conventions="cf,ferret")
ds.check.compliance(conventions="ferret") # custom-only checks
ds.check.compliance(engine="heuristic") # force built-in heuristic engine
ds.check.compliance(engine="cfchecker") # require cfchecker path
# Explicit coordinate names
ds.check.ocean_cover(lon_name="x", lat_name="y", time_name="t")
ds.check.time_cover(time_name="t")
ds.check.all(lon_name="x", lat_name="y", time_name="t")
compliance() runs cf-checker against an
in-memory NetCDF payload created from dataset metadata (no .nc file written to disk).
With report_format="python" it returns a dictionary of detected issues.
make_cf_compliant() returns a new dataset with safe automatic fixes, including:
Conventions = "CF-1.12"- standard coordinate attributes for inferred
time,lat, andlonaxes - creation of missing dimension coordinates for inferred axes
- global extent attributes derived from inferred axes:
time_coverage_start,time_coverage_end,geospatial_lat_min,geospatial_lat_max,geospatial_lon_min, andgeospatial_lon_max
ocean_cover() runs fast ocean-grid checks and returns a report with:
- east/west edge-of-map detection (persistent missing longitude columns, reported by longitude),
- land/ocean sanity checks at fixed reference points (offset detection).
report_format="auto"by default.- When
var_nameis omitted, all data variables with inferred lat/lon dimensions are checked.
time_cover() runs time-dimension missing-data checks and reports missing
time-slice ranges.
report_format="auto"by default.- When
var_nameis omitted, all data variables are checked. - Time coordinate units/type validation is reported by
compliance().
You can disable individual checks:
ds.check.ocean_cover(
check_edge_of_map=True,
check_land_ocean_offset=True,
report_format="python",
)
ds.check.time_cover(
report_format="python",
)
Notes:
cfcheckerrequires the systemudunits2library viacfunits.- For large files, prefer opening with lazy chunks:
xr.open_dataset(path, chunks={}). - The built-in
ferretconvention flags coordinate_FillValueusage as an error. - If
cfcheckercannot run,compliance()falls back to heuristic checks and includes achecker_errorfield in the response. - You can choose the compliance engine explicitly with
engine="heuristic"orengine="cfchecker"(CLI:--engine). - The report
enginefield reflects what ran:cfchecker,heuristic, ornone(when CF checks are skipped, e.g.conventions="ferret"). - You can bias standard-name suggestions by domain, e.g.
ds.check.compliance(domain="ocean")(also supportsatmosphere,land,cryosphere, andbiogeochemistry).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nc_check-0.2.0.tar.gz.
File metadata
- Download URL: nc_check-0.2.0.tar.gz
- Upload date:
- Size: 40.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c50d9c0b869aaf78f48594cf95ab7adbda44216aaf1a4b1515ba21f195a0d849
|
|
| MD5 |
79f0c0938b8ecb3b8a4afb898bd68df8
|
|
| BLAKE2b-256 |
d00bba70ed481e453549d2f4d02dbfc67c4857e58676b9e64e29b2352cdab998
|
File details
Details for the file nc_check-0.2.0-py3-none-any.whl.
File metadata
- Download URL: nc_check-0.2.0-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1330219e74ce371b3412ad0f0dbac1b064c6ed7e2a86ecd4565da86c8d8a55f
|
|
| MD5 |
69e29cd64e63175b785d877060aa84a0
|
|
| BLAKE2b-256 |
3ef254651e51c4dbd761b4e127b1c23312d90df36181ce32716ee7a1b3e6efc1
|