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.
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: netcdf-cf-time-auditdescription: "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: datarisk: safesource: selfsource_type: selfdate_added: "2026-12-01"author: Koushik-Katkamtags: [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:
xarray-coordinate-alignment: aligns and merges already-loaded xarray datasets (xr.align,xr.merge) without auditing raw NetCDF CFunits,calendar,time_bnds, orcftimeround-trips.weather-data-reproducibility: creates SHA-256 provenance manifests for downloaded weather datasets rather than testing CF time coordinate decoding/encoding invariants.weather-observation-fetchingandweather-model-data-fetching: retrieve METAR/ISD/IGRA station reports and AWS S3/NOMADS GRIB2 slices rather than auditing NetCDF CF time metadata.
When to Use
- Validating climate/GCM or synthetic NetCDF datasets using
360_day,noleap(365_day),all_leap,proleptic_gregorian, orstandardcalendars. - Catching silent calendar corruption caused by loading NetCDF with default numpy/pandas coercion or invalid CF
units("months since ..."). - Auditing
time_bndsvariables alongsidetimecenters/edges before downstream regridding or temporal aggregation. - Do not use this skill to fetch remote OPeNDAP/THREDDS endpoints or rewrite production archives in place.
Prerequisites
- Python
3.12+with pinned NetCDF/xarray dependencies (numpy==2.5.3andscipy==1.18.1require>=3.12;xarray==2026.9.0andcftime==1.6.6require>=3.11; tested with Python3.12.10,xarray==2026.9.0,cftime==1.6.6,netCDF4==1.7.4,scipy==1.18.1,numpy==2.5.3,pytest==9.1.1). - No network access, remote catalogs, or external files required (fixtures run cleanly in temporary directories).
How It Works
1. Inspect raw NetCDF time attributes before decoding
- Read raw
units,calendar, andboundsattributes directly vianetCDF4.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. - Validate CF
unitsformat ("<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. - Explicitly classify unknown
calendarstrings ("mars_sol") asUNSUPPORTED.
2. Decode strictly with CFDatetimeCoder(use_cftime=True) and verify monotonicity & exact tuples
Run the local verification suite in NetCDF CF time audit harness:
- Monotonic coordinate validation: Assert strictly monotonic increasing (or explicitly permitted monotonic decreasing) time values; reject constant duplicates or time reversals (
INVALID_TIME_ORDER). - Exact decoded
(year, month, day, hour, minute, second, microsecond)comparison & tuples: Compare exactcftimetimestamps including fractional-secondmicrosecondprecision betweencftime.num2dateandxr.coders.CFDatetimeCoder(use_cftime=True), catchingxarraydecoding errors as structuredFAILfindings rather than uncaught exceptions. - Block lossy datetime64 coercion: Prove that attempting to coerce
360_daycoordinates containing February 30 into standardnumpy.datetime64/ Pythondatetimefails explicitly instead of silently dropping or shifting dates. time_bndsconsistency: 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.- Encode/decode round-trip: Persist to NetCDF4 with explicit
encoding={"time": {"units": ..., "calendar": ...}}and re-read verifying identicalcftimetimestamps,calendar, andunits.
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
- Audits the CF
timecoordinate and optionalboundsvariable usingnetCDF4==1.7.4,xarray==2026.9.0, andcftime==1.6.6under CF-1.11 fixed-duration time units (seconds,minutes,hours,days); calendar-varying units such as"months since"/"years since"are excluded from this fixed-duration subset (UNSUPPORTED_OR_INVALID_UNIT). decoded_tuplessummarizes(year, month, day, hour, minute, second)cleanly whiledecoded_timestamps_uspreserves 7-tuple sub-secondmicrosecondprecision when inspecting fractional offsets.julianvs.standard(gregorianmixed Julian/Gregorian reform at 1582-10-15) historical edge cases prior to 1582 require explicit historical epoch checks beyond modern2024–2025fixtures.
Safety and Side Effects
- Strictly offline and read-only against user-supplied files (writes synthetic NetCDF fixtures solely inside temporary pytest directories).
- Never modifies existing scientific archives in place or queries remote data portals.