Skip to content
Back to skills

Netcdf Cf Time Audit

ASecurity

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.

  • 50,717 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
ai-agentspythongoawstestinggitdocumentation

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add sickn33/agentic-awesome-skills --skill netcdf-cf-time-audit --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Netcdf Cf Time Audit?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Netcdf Cf Time Audit
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sickn33-netcdf-cf-time-audit/badge)](https://www.skillsdirectory.com/skills/sickn33-netcdf-cf-time-audit)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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:
- `xarray-coordinate-alignment`: aligns and merges already-loaded xarray datasets (`xr.align`, `xr.merge`) without auditing raw NetCDF CF `units`, `calendar`, `time_bnds`, or `cftime` round-trips.
- `weather-data-reproducibility`: creates SHA-256 provenance manifests for downloaded weather datasets rather than testing CF time coordinate decoding/encoding invariants.
- `weather-observation-fetching` and `weather-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`, or `standard` calendars.
- Catching silent calendar corruption caused by loading NetCDF with default numpy/pandas coercion or invalid CF `units` (`"months since ..."`).
- Auditing `time_bnds` variables alongside `time` centers/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.3` and `scipy==1.18.1` require `>=3.12`; `xarray==2026.9.0` and `cftime==1.6.6` require `>=3.11`; tested with Python `3.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

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](references/netcdf-cf-time-harness.md):

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](references/netcdf-cf-time-harness.md):

```text
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 `time` coordinate and optional `bounds` variable using `netCDF4==1.7.4`, `xarray==2026.9.0`, and `cftime==1.6.6` under 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_tuples` summarizes `(year, month, day, hour, minute, second)` cleanly while `decoded_timestamps_us` preserves 7-tuple sub-second `microsecond` precision when inspecting fractional offsets.
- `julian` vs. `standard` (`gregorian` mixed Julian/Gregorian reform at 1582-10-15) historical edge cases prior to 1582 require explicit historical epoch checks beyond modern `2024`–`2025` fixtures.

## 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.

## Sources and related skills

- [CF Conventions Documentation](https://cfconventions.org/)
- Related skills: [xarray-coordinate-alignment](https://github.com/sickn33/agentic-awesome-skills/blob/e4dcf3977b6d1e18a2539f630bd82c2433d283e2/skills/xarray-coordinate-alignment/SKILL.md), [weather-data-reproducibility](https://github.com/sickn33/agentic-awesome-skills/blob/e4dcf3977b6d1e18a2539f630bd82c2433d283e2/skills/weather-data-reproducibility/SKILL.md), [weather-model-data-fetching](https://github.com/sickn33/agentic-awesome-skills/blob/e4dcf3977b6d1e18a2539f630bd82c2433d283e2/skills/weather-model-data-fetching/SKILL.md), [weather-observation-fetching](https://github.com/sickn33/agentic-awesome-skills/blob/e4dcf3977b6d1e18a2539f630bd82c2433d283e2/skills/weather-observation-fetching/SKILL.md).

Files in this skill

  • SKILL.md7.1 KB
  • references/netcdf-cf-time-harness.md18.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.