Skip to content

v0.8.0

Choose a tag to compare

@cboettig cboettig released this 21 Sep 23:21
· 92 commits to main since this release
2532470

The raster hex path used to size itself by the grid and the host. It now sizes itself by the data and the pod.

That is one sentence for eight changes, and it is also the reason this is 0.8.0 rather than 0.7.1: the memory profile of every generated job changes.

0.8.0 is also the first version that records itself into the data it writes — see Provenance below, which matters for auditing anything built earlier.


Cost follows the raster, not the cell (#215)

A chunk enumerated every descendant of its chunk cell — 7^(res − chunk_res), 5,764,801 for a res-8 h0 — whatever the raster actually covered. A 196×169 pixel raster in California paid for all 5,764,801 cells: a 196× overshoot, and the reason 109 small species rasters totalling 13 MB could not be hexed in a working day.

The hierarchy is now descended a level at a time: a subtree whose footprint misses the source is dropped whole, one that lies entirely inside is taken whole without descending. Work follows the source's perimeter rather than its area.

case, res 8 before after ratio
the 196×169 raster 5,764,801 29,465 196×
CONUS-scale 5,764,801 2,923,988 2.0×
antimeridian seam 5,764,801 281,573 20.5×
polar 5,764,801 350,442 16.5×

It is faster than the enumeration it replaces in every one of those cases, including the one where it prunes least, because it never materialises the ids it is about to discard. Each chunk now prints the figure that explains its own memory and runtime, at the point it is decided:

✓ 29,465 of 5,764,801 cells reach the source (0.5% of the chunk)

The prune is lossless by the margin the sub-chunk overlap test already used, checked against exhaustive enumeration of all 5,764,801 children rather than sampled. The antimeridian is the sharp edge: a cell wrapping the dateline has a planar box that can exclude 86° of longitude it actually covers, so cells are judged on their true two-interval footprint.

CNG_HEX_PRUNE_CELLS=0 restores the full enumeration.


The fill-code collapse writes no pixels (#209)

exactextract honours one band nodata, so a categorical source's extra fill codes (#108) were remapped by staging an uncompressed copy of the entire source. That copy is grid pixels × bytes per pixel — independent of the source's compression, and independent of the chunk the pod is working, so all 122 pods wrote the same full-grid file: 34 GB per pod for the LANDFIRE CONUS Int16 grid, against the ephemeral-storage: 40Gi the generator itself emits. Every pod on the two largest layers of a tranche was evicted.

The remap is a pure per-pixel value substitution, which GDAL expresses as a VRT <LUT>: 34 GB → a few kilobytes, applied on read.

Integer bands only — a lookup table interpolates between its entries, so a float source would be silently distorted. Float sources keep a materialised copy, now compressed. A source that cannot be expressed exactly is refused rather than approximated.

Worth knowing which sources were affected: the generator's preprocess step already collapses the codes once, but it is skipped when the source is already a single-band COG needing no clip — so the full fill list reached the hex pods precisely when the input was in the best shape.


Three things were sized from the host, not the pod

default now
worker processes os.cpu_count() — the node's cores the cgroup CPU quota, else 8
DuckDB's buffer manager (parent and each worker) 80% of host RAM DUCKDB_MEMORY_LIMIT, 85% of the pod
GDAL's block cache, per worker process 5% of host RAM — 12.6 GiB each on a 251 GiB node GDAL_CACHEMAX=512 MB

On NRP the first meant ⚠ falling back to 256 host CPUs inside a pod limited to cpu: 8 — a 32× oversubscription. It is a memory setting more than a CPU one: the same LANDFIRE res-10 layer peaked at 190.5 GiB and completed no slice in 3 h 40 m at 48–64 workers, against ~37 GiB with all six complete at 8.

The block cache is the one that scales with the fan-out, since a hex pod runs many processes and only the single-process preprocess step had ever bounded it. Bounding DuckDB also changes its behaviour under pressure from fail to spill.


pandas is out of the accumulation path

Three changes, all the same idea — let the C++ and the database do the work they are for:

  • Results reach the partition through worker-written parquet parts and one DuckDB statement. They used to be collected as pandas frames, held in a list and pd.concat-ed, which allocates the result while the inputs are still referenced — 1.95× the list it consumes, at exactly the process's largest moment.
  • exactextract serialises through GDAL where OGR can write Parquet, so a chunk's rows never become a Python object at all. Feature-detected: the runtime image ships the driver, most distribution GDALs do not, and the pandas writer remains the fallback. fractions gains most — its parallel unique/frac arrays were exploded with np.repeat over object arrays and are now list columns that DuckDB UNNESTs.
  • The chunk's cells are built in DuckDB, straight to a file exactextract reads by path. The GeoDataFrame of shapely polygons cost ~201 MiB per 100,000-cell chunk — 125 MiB of it boundary strings — in every worker, for every chunk. Now +137 MiB, and what remains sits inside something with a memory limit that spills rather than Python objects that only grow.

The antimeridian keeps the tested path throughout: those cells are still split with shapely and handed over as a second source, because integrating a 360° ribbon instead of the true footprint is #88.


Provenance: what built this dataset (new)

Every published parquet — the hex partitions, the merged data_0.parquet, the vector repartition output and the GeoParquet — now records the version that produced it, in the file's own key-value metadata rather than a sidecar, so it survives copies and syncs:

SELECT key, value FROM parquet_kv_metadata('s3://bucket/dataset/hex/h0=*/data_0.parquet');
-- cng_datasets_version  0.8.0
-- built_at              2026-09-21T23:06:45Z
-- gdal_version          3.13.0
-- duckdb_version        1.5.4

Why this matters for anything built earlier

Nothing recorded it before. And generated manifests pin ghcr.io/boettiger-lab/datasets:latest, which is rebuilt on every push to main — so a past build did not necessarily run a released version at all.

A dataset carrying no cng_datasets_version was built before 0.8.0, and is worth checking against 0.7.0's correctness fixes, both of which are undetectable from the output alone:

  • the multi-band read (#214) — the hex path silently read band 1 and labelled it with --value-column. This published 384,922,346 rows of annual forb & grass cover documented as perennial cover: two variables in the same 0–100 domain, with the right row count and the right schema.
  • the h0 position/base-cell confusion (#213, #218) — a subset list computed the obvious way, from the H3 library, is in range, silently wrong, and builds a different part of the world while the job reports success.

The library versions are recorded because two of this project's sharper problems were environment-dependent rather than code-dependent — a GDAL without WarpOptions(cutlineWKT=) (#197), and one without OGR's Parquet driver — and neither was answerable after the fact from the dataset alone.


Upgrading

  • Nothing to change. No flags are removed and no output layout moves; the h0=*/data_0.parquet shape is unchanged, including through the chunked merge.
  • Expect different memory behaviour. Pods bound their own DuckDB and GDAL now. If you had raised memory to work around OOMs that were really GDAL caches or an unbounded DuckDB, those requests are likely now oversized.
  • Pin the image if you want reproducibility. Versioned tags work again as of #224 — ghcr.io/boettiger-lab/datasets:0.8.0 — where before, every tag build since v0.5.0 had silently failed and only :latest existed.
  • Two escape hatches, for comparing a suspect run like for like: CNG_HEX_PRUNE_CELLS=0 and CNG_HEX_GDAL_WRITER=0.

Full changelog: v0.7.0...v0.8.0