Multidimensional Processing API

Convert multidimensional cubes (NetCDF, Zarr) to H3-indexed GeoParquet through GDAL multidimensional reads. The cng-datasets mdim-workflow jobs call these same functions.

N-D cube (time, lat, lon) → H3 hex processing (issue #181).

class cng_datasets.mdim.CubeSource(paths: Sequence[str], variables: Sequence[str])[source]

Bases: object

A (time, lat, lon) variable — or several sharing a grid — over 1+ files.

__init__(paths: Sequence[str], variables: Sequence[str])[source]
nearest_pixel(lat: ndarray, lon: ndarray)[source]

(iy, ix) storage indices of the pixel containing each point, -1 if outside the grid. Points are in [-180, 180] longitude.

property pixel_deg: Tuple[float, float]

(lat, lon) spacing in degrees, from the median step.

read(variable: str, t0: int, t1: int, y0: int, y1: int, x0: int, x1: int) → ndarray[source]

Values as float64 (time, lat, lon) in storage lat/lon order, with nodata and values outside the CF valid range as NaN, and CF scale/offset applied. [t0, t1) must lie in one file.

tiles(window) → Iterator[Tuple[int, int, int, int]][source]

Split a window into pieces that each lie within one storage block, so every read decodes each chunk it touches exactly once.

time_groups(t_lo: int, t_hi: int, pixels: int, budget_bytes: float) → Iterator[Tuple[int, int]][source]

Global time ranges [t0, t1) to read together: block-aligned within each file, never crossing a file, and grouped up to budget_bytes of float64 per variable.

windows(lat_lo, lat_hi, lon_intervals) → List[Tuple[int, int, int, int]][source]

Storage-index windows (y0, y1, x0, x1) whose pixel centres fall in the footprint. Usually one; two when the footprint crosses the source’s longitude seam.

class cng_datasets.mdim.MdimProcessor(inputs: Sequence[str], variables: Sequence[str], output_parquet_path: str, h3_resolution: int, parent_resolutions: List[int] | None = None, chunk_resolution: int = 0, h0_subset: List[int] | None = None, h0_grid_path: str = 's3://public-grids/hex/h0-valid.parquet', hex_resampling: str = 'mean', time_agg: str = 'none', time_start: str | None = None, time_end: str | None = None, placement: str = 'auto', read_budget_bytes: float = 536870912, allow_empty_window: bool = False)[source]

Bases: object

Hex one spatial chunk of a (time, lat, lon) cube into H3 cells.

__init__(inputs: Sequence[str], variables: Sequence[str], output_parquet_path: str, h3_resolution: int, parent_resolutions: List[int] | None = None, chunk_resolution: int = 0, h0_subset: List[int] | None = None, h0_grid_path: str = 's3://public-grids/hex/h0-valid.parquet', hex_resampling: str = 'mean', time_agg: str = 'none', time_start: str | None = None, time_end: str | None = None, placement: str = 'auto', read_budget_bytes: float = 536870912, allow_empty_window: bool = False)[source]
process_chunk(chunk_index: int) → str | None[source]

Hex chunk chunk_index; returns the parquet written, or None.

process_region(unit_index: int) → str | None[source]

Time fan-out (#267): every chunk of the region over this processor’s time range, in one read of the grid.

For sources whose chunks span the whole grid (NEX-GDDP: one global day per chunk), a spatial fan-out makes every pod fetch every chunk. Here a pod owns a slice of time instead, reads each chunk once, and writes one part per h0 partition — part-t{unit}-*.parquet under the staging prefix, which merge-chunks concatenates into data_0.parquet.

cng_datasets.mdim.decode_cf_time(values, units: str, calendar: str | None = None) → DecodedTime[source]

Decode CF time offsets values on calendar (default standard).