Repository navigation
alter demographic adjustment - #701
tomjemmett wants to merge 2 commits into
Conversation
rather than load the values in, values are passed in via params file
✅ A new build is available.You can use the following to use pull the image into your local environment: docker pull ghcr.io/the-strategy-unit/nhp_model:pr-701 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## remove_tretspef_grouped #701 +/- ##
=========================================================
Coverage 100.00% 100.00%
=========================================================
Files 20 20
Lines 1214 1196 -18
Branches 61 61
=========================================================
- Hits 1214 1196 -18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Removing the "variant" key from generate_run_params leaves run_all (run.py:172) reading run_params["variant"], which will raise a runtime KeyError that the mocked unit tests do not catch.
2 open issues
What changed in this PR
This PR implements the demographic-adjustment rework described in issues #703–#705. It removes the model's support for selecting among multiple population variants per model run and stops reading demographic/birth factors from parquet files on disk. Instead, the demographic and birth growth factors are now supplied directly in the parameters file under a new demographic_adjustment object, and _load_demog_factors computes the growth factors (horizon ÷ baseline) into pd.Series keyed by (sex, age). This supports custom population projections without changing the data pipeline.
Changes:
generate_run_paramsno longer selects variants/probabilities, and_load_demog_factorsbuildsdemog_factors/birth_factorsSeries fromparams["demographic_adjustment"]rather than from the data loader.- The
Data/Localinterfaces dropget_demographic_factors/get_birth_factors, andactivity_resamplingconsumes the new(sex, age)-indexed Series directly. - The params schema and sample are restructured to embed
demographic_adjustment(variant + population/births baseline/horizon tables), with tests and golden-file snapshots updated accordingly.
| File | Description |
|---|---|
| src/nhp/model/model.py | Rewrites _load_demog_factors to build Series from params and removes variant selection from generate_run_params; docstring left stale. |
| src/nhp/model/activity_resampling.py | Simplifies demographic/birth adjustments to use the new (sex, age) Series directly. |
| src/nhp/model/data/local.py | Removes get_demographic_factors/get_birth_factors loaders. |
| src/nhp/model/data/data.py | Removes the abstract get_demographic_factors/get_birth_factors interface methods. |
| src/nhp/model/params/params-schema.json | Replaces demographic_factors.variant_probabilities with the demographic_adjustment object and supporting $defs. |
| src/nhp/model/params/params-sample.json | Embeds the full population/births baseline/horizon tables. |
| tests/unit/nhp/model/test_model.py | Updates demog-factor and run-param tests to the new Series/params shape. |
| tests/unit/nhp/model/test_activity_resampling.py | Updates fixtures/assertions to the (demog_type, sex, age) index. |
| tests/unit/nhp/model/data/test_local.py | Removes tests for deleted loader methods. |
| tests/unit/nhp/model/data/test_data.py | Removes tests for deleted abstract methods. |
| tests/integration/.../*.csv, tests/e2e/.../*.csv | Regenerated golden snapshots reflecting the new computation. |
Review effort: Balanced
| return { | ||
| "variant": variants, | ||
| "seeds": rng.integers(0, 65535, model_runs).tolist(), |
| demog = self.params["demographic_adjustment"] | ||
|
|
||
| pop = demog["population"] | ||
| self.demog_factors = pd.Series( |


closes #703, closes #704, closes #705
updates the model and the parameters schema to remove support for multiple variants to be used within a model run, and to pass the demographic/birth factors directly in the params file, rather than reading these values from disk
Stack created with GitHub Stacks CLI • Give Feedback 💬