# Multidimensional (cube) processing `cng-datasets mdim` hexes a **(time, lat, lon) cube** into H3 partitions, with no per-slice COGs. The source can be zarr, netCDF, or anything else GDAL's multidimensional API opens, and a series split across files (one netCDF per year) can be passed as several `--input`s in time order. Non-spatial axes stay as columns; they are never fanned out into jobs. ```bash cng-datasets mdim \ --input 'ZARR:"/vsicurl/https://cadcat.s3.us-west-2.amazonaws.com/loca2/ucsd/gfdl-esm4/ssp370/r1i1p1f1/day/tasmax/d03"' \ --variable tasmax \ --output-parquet s3://bucket/loca2/hex/ \ --resolution 6 --parent-resolutions 0 \ --h0-index 50 \ --time-agg year --time-start 2040-01-01 --time-end 2069-12-31 ``` Output uses the same layout as `raster`: `hex/h0={cell}/data_0.parquet`, or `part-{cell}.parquet` at `--chunk-resolution` > 0, with completion markers for `merge-chunks`. Each file has columns `h`, the parents, the time key, and one column per `--variable`. ## From Python `MdimProcessor` hexes one chunk at a time, the unit a cluster pod runs. Chunks are h0 cells at the default `chunk_resolution=0`, and `chunk_cells()` lists them. ```python from cng_datasets.mdim import MdimProcessor proc = MdimProcessor( inputs=['ZARR:"/vsicurl/https://cadcat.s3.us-west-2.amazonaws.com/loca2/ucsd/gfdl-esm4/ssp370/r1i1p1f1/day/tasmax/d03"'], variables=["tasmax"], output_parquet_path="loca2/hex", h3_resolution=6, parent_resolutions=[0], time_agg="year", time_start="2040-01-01", time_end="2069-12-31", ) for i in range(len(proc.chunk_cells())): proc.process_chunk(i) ``` `CubeSource` is the reader underneath: it opens the inputs, decodes their time axis and reads windows of the grid. ## How it reads GDAL reads **chunk-aligned slabs**, so a query transfers only the chunks it overlaps. On the LOCA2 store, a 1-day, 1° read moved one compressed chunk (72 MiB). A NEX-GDDP netCDF file reads in place over `/vsicurl/` (1.1 MiB for the same window). DuckDB does everything after the read: H3 indexing, the reduction and the parquet write. The DuckDB `zarr` extension was evaluated first and scans whole stores in v0.1.1 (#181); it can come in later as a second reader. ## Placement How pixels are put into cells depends on their size relative to the cells: | `--placement` | when (`auto`) | what | |---|---|---| | `aggregate` | pixels smaller than cells | each pixel centre goes to its H3 cell, and the cell reduces its pixels | | `sample` | pixels larger than cells | each cell reads the pixel containing its centre | Neither placement is area-weighted, so `--hex-resampling` is `mean`, `min` or `max`, and **`sum` is refused**. Extensive or density variables should still go through a 2-D COG and `cng-datasets raster` (`exact-extract`). ## Missing values `_FillValue`, `scale_factor` and `add_offset` are applied as CF specifies, and values outside `valid_min`, `valid_max` or `valid_range` are treated as missing. The range is compared in stored units, before scale and offset. ## Time CF time is decoded from the coordinate's units and `calendar`: `standard`, `gregorian`, `proleptic_gregorian`, `noleap`/`365_day`, `all_leap`/`366_day` and `360_day`. - `--time-agg none` writes a `time` DATE column. A calendar with dates that don't exist in the Gregorian calendar (`360_day`'s 30 February, `all_leap`'s 29 February every year) is refused here. - `month` writes `year` and `month` columns, and `year` writes `year`. Both are exact on every calendar. - `--time-start` / `--time-end` (`YYYY-MM-DD`) restrict the range read. ## Limits (v1) - Variables must be exactly (time, lat, lon) on a 1-D lat/lon grid. Depth, ensemble and other axes aren't supported yet. ## Fan-out on the cluster `cng-datasets mdim-workflow` generates the same pipeline shape as `raster-workflow`: setup-bucket → hex (one `mdim` pod per chunk) → merge (when `--chunk-resolution` > 0). The orchestrator stops as soon as a step fails. ```bash cng-datasets mdim-workflow --dataset climate/nex-gddp-tas \ $(for y in $(seq 2015 2100); do echo --input /vsicurl/https://nex-gddp-cmip6.s3.us-west-2.amazonaws.com/NEX-GDDP-CMIP6/ACCESS-CM2/ssp245/r1i1p1f1/tas/tas_day_ACCESS-CM2_ssp245_r1i1p1f1_gn_${y}_v2.0.nc; done) \ --variable tas --bucket public-climate --h3-resolution 5 --time-agg year \ --h0-cells 9,19,20,21,34,36 --output-dir catalog/climate/k8s/nex-gddp-tas kubectl apply -f catalog/climate/k8s/nex-gddp-tas/configmap.yaml \ -f catalog/climate/k8s/nex-gddp-tas/workflow.yaml ``` Flags shared with `raster-workflow`: - `--h0-subset` (grid positions) or `--h0-cells` (H3 base cell numbers) limits a regional source to the h0 cells it overlaps. See [Positions are not H3 base cell numbers](raster_processing.md#positions-are-not-h3-base-cell-numbers). - `--chunk-resolution N` splits each h0 into its res-N descendants, adding a merge step. - `--backend armada` writes Armada job sets, and `--backend auto` uses Armada only past the ~200-pod guideline for one indexed Job. `--armada-queue` defaults to the namespace (`geo-workflows`). - `--hex-memory` (16Gi), `--hex-cpu` (4) and `--max-parallelism` (50) size the hex pods. A chunked build's `merge-chunks` log suggests sizes for the next build from what the pods used, and keeps them with the build's shape in `.usage.json`. - `--no-validate-source` skips opening the first input at generation time, for a source that is not readable from where you generate. ### Which axis the fan-out splits over `--fan-out auto` (the default) reads the first input's chunk shape: | source chunks | fan-out | each pod | |---|---|---| | spatial tiles (LOCA2: `1952×123×139`) | **space** | one h0, or a sub-h0 chunk, over all time; reads only the tiles under it | | one chunk spans the whole grid (NEX-GDDP: `1×600×1440`) | **time** | one input file, or a slice of a single input, over every h0; reads each chunk once | Splitting a whole-grid source over space would make every pod fetch every chunk: about 122× the transfer for a global run (#267). Under `time`, units are **one per input file**, or, for a single input, runs of whole `--time-agg` keys of about `--time-unit-steps` steps. Each pod writes `part-t{unit}-*.parquet` into every h0 partition it touches, and `merge-chunks` concatenates them into `data_0.parquet`. A month or year must not be split across files, because the merge only concatenates. A pod whose input starts or ends mid-key refuses to run. `--fan-out space|time` overrides the choice. Generation opens the first input, so a wrong variable, an unsupported calendar or an empty time window fails before anything is applied. Read public object-store sources through `/vsicurl/https://…`, not `s3://`: inside the cluster, `s3://` resolves to the NRP Ceph endpoint, not AWS.