Implement reaggregation - #744
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Reaggregation appears to be publish-layer only, not used in the snapshot
The *_reaggregated getters are wired through model_objects.py (and diagnostics/deck), but generate_snapshots.py still writes derive_Aq_usa() / derive_B_usa_non_finetuned() - i.e. the 407-sector G/T/D-disaggregated matrices, with no collapse to 221100.
For a config with reaggregation, that means:
- Published Excel/SEF: 405-sector model
- Snapshot parquets + diagnostics "old" baseline: 407-sector model
I don't believe that to be the intended outcome?
08869a5 to
a1bf537
Compare
a1bf537 to
5ad042e
Compare
Yes, that was a gap. The USA snapshot derives ( |
|
I think the PR description might be a bit out of date. I was a bit surprised to see the manipulations to 1) EToday The suggestion is to split those two functions so they have different jobs:
Concrete changes:
Why the split: B is computed at 407 as 2) PhiRuntime EF adjustment is already correct — Publish and snapshots still duplicate logic: Suggested change: one published helper in No internal/public split needed for Phi — margins are 405-native; reaggregation is just |
6602509 to
fe5c3c8
Compare
Implemented the fixes suggested for E and Phi handling, and updated the PR description. |
Merge activity
|

cc:
Closes: cornerstone-data/methods#92
What changed? Why?
Adds a new
implement_electricity_reaggregationflag and supporting pipeline that collapses the post-3-way-split G/T/D sectors (221110, 221121, 221122) back into a single monetary 221100 sector, producing a published 405-sector model. This sits after the existing reallocation + 3-way disaggregation steps but does not use mixed physical units, making it mutually exclusive withimplement_electricity_mixed_units.The reaggregation step:
cornerstone_disagg_pipeline.pyderive_cornerstone_Aq_reaggregated,derive_cornerstone_B_reaggregated,derive_cornerstone_V_reaggregated,derive_cornerstone_U_set_reaggregated,derive_cornerstone_VA_reaggregated,derive_cornerstone_x_reaggregated,derive_disagg_Ytot_reaggregated,derive_cornerstone_y_nab_reaggregated) inderived_cornerstone.pyget_V,get_U,get_Udom,get_x,get_A,get_Adom,get_B,get_D,get_q,get_Phi, andget_Rhoinmodel_objects.pythrough the reaggregated path when the flag is activephi[221100] = 1.0and restoresrho[221100]from the 221110 price index panel under reaggregation2025_usa_cornerstone_v0_3_electricity_reaggregation(production) andtest_usa_config_waste_disagg_electricity_reaggregation(test)derive_E_usanow use the published 405-column path under reaggregation;load_E_from_flowsaremains the internal 407 path so per-child E/x is available before the q-weighted B collapsederive_phi_cornerstone_usa_panel_publishedis introduced to apply electricity producer-price overrides (G/T/D → 1.0 under disaggregation; 221100 → 1.0 under reaggregation) and reindex to 405 before writing snapshots or populatingget_PhiThe diagnostics deck renames the
currentimplementation tomecs_mixed_unitsthroughout (pairs, tests, README, CLI help text) and adds a newreaggregated_vs_productionpair. This fifth pair uses customtable_stepsandhist_stepsending atreaggregationinstead ofmixed_units, and replaces slide 1's class-MWh table with a 221100 q/x (USD) table via a newqx_gridsfunction. Histogram rendering now readspair.hist_stepsinstead of a module-level constant, allowing per-pair step sequences. The EIA G/T/D class-MWh table intables.yamlis expanded from a combined Com+Ind+Trans+Exports row to individual rows matchingCLASS_ORDER, andEIA_CLASS_GROUPSis updated accordingly.A new
ceda_electricitydiagnostics subpackage is added with two PPTX decks: Deck A compares the electricity reaggregation run against the CEDA v8.1 baseline (N/D histograms, D/A-effect scatter, focus-sector table for key countries), and Deck B shows a cumulative g1→g5e ABSR + electricity ladder with per-step N/D histogram panels, BLy net waterfall charts, and a USA 221100 callout comparing g5, g5+electricity, and electricity-only results.Testing
test_electricity_reaggregation.pycovers: block-collapse identity, no-op when flag is off, error when children are missing, U reconstruction from collapsed A/q, q-weighted B collapse, published axis shape (221100 present, G/T/D absent), integration identities (q sum, U = A·q, B·q invariant, L·y = q), Phi/Rho values on the product YAML, and a check that reaggregated D/N differ from non-disagg productiontest_derive_E_usa_reagg.pycovers column collapse and passthrough behavior ofderive_E_usaunder the reaggregation flagtest_usa_config.pyextended with parsing, prerequisite-flag, and mutual-exclusion tests forimplement_electricity_reaggregationtest_phi_helpers.pyextended with tests forderive_phi_cornerstone_usa_panel_publishedunder both reaggregation-on and disaggregation-on pathsmecs_mixed_unitskeys; new deck tests coverreaggregated_vs_productionpair schema, shared ladder steps,qx_gridsoutput,load_impl_bundlestep filtering,derive_steprouting, EF grid headers, and full PPTX write with slide-title assertioncurrent*keys remain inIMPLEMENTATIONSorPAIRS