Add Output Area crosswalk and geographic assignment (Phase 1)#291
Open
vahid-ahmadi wants to merge 2 commits intomainfrom
Open
Add Output Area crosswalk and geographic assignment (Phase 1)#291vahid-ahmadi wants to merge 2 commits intomainfrom
vahid-ahmadi wants to merge 2 commits intomainfrom
Conversation
Port the US-side clone-and-prune calibration methodology to the UK, starting with Output Area (OA) level geographic infrastructure: - Build unified UK OA crosswalk from ONS, NRS, and NISRA data (235K areas: 189K E+W OAs + 46K Scotland OAs) - Population-weighted OA assignment with country constraints - Constituency collision avoidance for cloned records - Tests validating crosswalk completeness and assignment correctness This is Phase 1 of a 6-phase pipeline to enable OA-level calibration, analogous to the US Census Block approach. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
This PR implements Phase 1 of a 6-phase pipeline to enable Output Area (OA) level calibration — the UK equivalent of the US Census Block approach.
Why are we doing this?
The US pipeline (
policyengine-us-data) uses a clone-and-prune approach that produces much finer geographic granularity than our current UK methodology:This PR is going down to Output Area level (~235K OAs across the UK), which is the UK equivalent of the US Census Block. This PR is the first step.
What this PR does (Phase 1: OA Crosswalk & Geographic Assignment)
1. Unified UK Output Area Crosswalk
Downloads and combines geographic lookups from three national statistics agencies into a single crosswalk:
```
OA → LSOA/DataZone → MSOA/IntermediateZone → LA → Constituency → Region → Country
```
Data sources:
Output: `storage/oa_crosswalk.csv.gz` (1.4MB compressed) — 235,243 areas, 65M population, 632 constituencies, 363 LAs, 11 regions
2. Geographic Assignment Engine
Assigns population-weighted random Output Areas to cloned FRS household records, with two key constraints:
3. Tests — 19 passing, 1 skipped (NI)
Validates crosswalk completeness (OA counts, population totals, hierarchy nesting, country prefixes) and assignment correctness (country constraints, collision avoidance, population-weighted sampling, save/load roundtrip).
Known limitations
What comes next (Phases 2-6)
Phase 2: Clone-and-Assign
Clone each FRS household N times (start with N=10), assign each clone a different OA. Insert into `create_datasets.py` after imputations, before calibration.
US ref: PRs #457, #531
Phase 3: L0 Calibration Engine
Port L0-regularized optimization from US side. HardConcrete gates to actively drop records, producing sparse datasets. Add `l0-python` dependency.
US ref: PRs #364, #365
Phase 4: Sparse Matrix Builder
Build sparse `(n_targets × n_records*n_clones)` calibration matrix. Simulate PolicyEngine-UK per clone, wire existing `targets/sources/` into sparse matrix rows.
US ref: PRs #456, #489
Phase 5: SQLite Target Database
Hierarchical target storage: UK → Country → Region → LA → Constituency → MSOA → LSOA → OA. Migrate existing CSV/Excel targets into SQLite.
US ref: PRs #398, #488
Phase 6: Local Area Publishing
Generate per-area H5 files from sparse weights. Modal integration for scale.
US ref: PR #465
File summary