Home / Market / netcdf cf time audit

netcdf cf time audit

Audit NetCDF CF-Conventions time coordinates offline with xarray and cftime across reference units, Gregorian vs. 360_day/noleap calendars, Feb 30, time_bnds, and round-trips.

skill★ 508920 dlgithubCC-BY-4.0 content; MIT code; upstream exceptions applyInstall in CosmosUpstream Source

Documentation & Preview

--- name: netcdf-cf-time-audit description: "Audit NetCDF CF-Conventions time coordinates offline with xarray and cftime across reference units, Gregorian vs. 360_day/noleap calendars, Feb 30, time_bnds, and round-trips." category: data risk: safe source: self source_type: self date_added: "2026-12-01" author: Koushik-Katkam tags: [netcdf, cf-conventions, xarray, cftime, climate, time-coordinates]

---

NetCDF CF Time Audit

Overview

Audit NetCDF CF-Conventions time coordinates offline using xarray (xarray.coders.CFDatetimeCoder(use_cftime=True)), cftime, and netCDF4 (CF-1.11 / CF-Conventions calendar and time-coordinate rules). Verifies reference epochs and units, non-Gregorian 360_day (including February 30) and noleap (365_day) calendar decoding, standard vs. non-Gregorian leap-day stepping, bounds (time_bnds) interval consistency, NetCDF write/read round-trips, and explicit rejection of invalid units, unsupported calendars, or lossy pandas datetime64 coercions.

Distinction from existing weather and scientific-data skills:

When to Use

Prerequisites

How It Works

1. Inspect raw NetCDF time attributes before decoding

  1. Read raw units, calendar, and bounds attributes directly via netCDF4.Dataset(..., "r"), validate coordinate dimensionality (strictly 1-D non-empty), inspect masked/fill values before coercion, and reject non-finite (NaN/inf) values as structured findings.
  2. Validate CF units format ("<unit> since <reference-datetime>") against the harness's supported fixed-duration unit subset (seconds, minutes, hours, days) — explicitly distinguishing non-uniform "months since" / "years since" or unsupported udunits strings from universally malformed units.
  3. Explicitly classify unknown calendar strings ("mars_sol") as UNSUPPORTED.

2. Decode strictly with CFDatetimeCoder(use_cftime=True) and verify monotonicity & exact tuples

Run the local verification suite in NetCDF CF time audit harness:

  1. Monotonic coordinate validation: Assert strictly monotonic increasing (or explicitly permitted monotonic decreasing) time values; reject constant duplicates or time reversals (INVALID_TIME_ORDER).
  2. Exact decoded (year, month, day, hour, minute, second, microsecond) comparison & tuples: Compare exact cftime timestamps including fractional-second microsecond precision between cftime.num2date and xr.coders.CFDatetimeCoder(use_cftime=True), catching xarray decoding errors as structured FAIL findings rather than uncaught exceptions.
  3. Block lossy datetime64 coercion: Prove that attempting to coerce 360_day coordinates containing February 30 into standard numpy.datetime64 / Python datetime fails explicitly instead of silently dropping or shifting dates.
  4. time_bnds consistency: Verify (N, 2) unmasked finite bounds shape, endpoint order matching the time axis (descending for a decreasing axis), and coordinate containment between the endpoint values.
  5. Encode/decode round-trip: Persist to NetCDF4 with explicit encoding={"time": {"units": ..., "calendar": ...}} and re-read verifying identical cftime timestamps, calendar, and units.

Examples

Run the self-contained verification suite in NetCDF CF time audit harness:

User request: "Audit our 360_day climate NetCDF output to make sure Feb 30 decodes accurately and time_bnds match."
Inputs: Local NetCDF4 dataset with CF units ('days since 2025-01-01 00:00:00'), calendar='360_day', and time_bnds.
Expected result: CFDatetimeCoder(use_cftime=True) preserves Datetime360Day(2025, 2, 30) across NetCDF round-trip,
  noleap skips 2024-02-29 cleanly, out-of-bounds time_bnds fail with INVALID_TIME_BOUNDS, and unsupported calendars
  return UNSUPPORTED.

Limitations

Safety and Side Effects

Sources and related skills