Skip to content

Country↔grid grouping core via cross_level_align #34

Description

@Polichinel

Epic: #31 · Depends on: #33

Background

The heart of the migration. The original loops per (country, time, target), gathers that country's grid cells + the country total, calls the scaling math, and scatters the result back (views_reporting/.../dataset_export.py to_reconciler / reconcile_pg_dataset). We do the same, frames-native and vectorised, on top of the slice-1 leaf reconcile_proportional (PR #30, views_postprocessing/reconciliation/proportional.py).

Work

  • Take a cm frame, a pgm frame, and an injected (time, priogrid_gid) → country_id mapping.
  • Use views_frames.cross_level_align to label each pgm row with its country; group by (time, country_id); for each group gather the cells + the matching country total, call reconcile_proportional, and scatter the result back into a new pgm frame.
  • Pure numpy + views-frames; avoid per-row Python loops where vectorisable.

Acceptance criteria

  • On the S0 fixture, per-country reconciled values reproduce the oracle within a tight, documented tolerance.
  • Zeros preserved, output non-negative, per-draw country sums hold (inherited from the leaf).
  • Returns a new pgm frame; input untouched.

Validation

  • Unit tests on the grouping/scatter against hand-computed small cases + S0-fixture slices.

Notes

  • cross_level_align requires a (time, unit)-keyed mapping. Our geography is time-invariant, so broadcast the static cell→country assignment over the frame's (time, unit) rows (or use cross_level_align_arrays at scale).

Metadata

Metadata

Assignees

No one assigned

    Labels

    implementationCode implementation workreconciliationForecast reconciliation migration (views-reporting -> here)storyA single reviewable unit of an epic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions