Skip to content

Optional: guardrail + convenience for density (Mg/ha) rasters (mean already works; sum is the trap) #105

Description

@cboettig

Optional ergonomics — not a capability gap

(Reframed after discussion in data-workflows.) On reflection this is not a missing reducer: cng-datasets already handles per-area/density rasters correctly via --hex-resampling mean. Filing for the datasets team to assess two optional ergonomics improvements.

Background (data-workflows #202, resolved)

The Conservation International carbon rasters (Noon et al. 2022) store carbon as density, Mg C ha⁻¹, on a ~300 m WGS84 grid. They had been hexed with --hex-resampling sum, which produced a meaningless sum of densities ~6–7× below the true total (irrecoverable-2018: 21 Gt vs published 139 Gt).

The root cause was the reducer choice, not the tool. sum is only for values already integrated per pixel (e.g. GHS-POP persons/cell); a density is intensive and aggregates with mean, with the total being mean_density × cell_area.

What the tool already does right

--hex-resampling mean correctly yields the area-weighted mean density per H3 cell for a density raster. The correct total is then mean × H3 cell area (a query-time derivation, or bake it in downstream). No core capability is missing — we corrected all 10 carbon layers this way, and the decision rule ("read the source units; the reducer follows the units, not the conceptual quantity") is now documented in the data-workflows AGENTS.md.

Optional improvements for the datasets team to weigh

  1. sum-on-density guardrail (low effort, high value): when --hex-resampling sum is used and the source band's units/metadata look per-area (ha, /ha, km-2, density, …), emit a warning — "summing a per-area density is usually wrong; did you mean mean (then × cell area for a total)?" This would have caught the carbon mistake automatically.
  2. --density-to-total convenience (pure sugar): a flag emitting mean × exact H3 cell ground area, so a density→total product is one step and uses the exact per-cell area instead of a manual latitude approximation. Equivalent to today's mean + a downstream multiply.

Neither blocks anything — the correct path works today. The operator-decision safeguard lives in data-workflows AGENTS.md; this issue is only about optional tooling ergonomics.

Related: #95 (max/min — done), #88/#92 (seam geometry).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions