Refactor disagg calls into cornerstone_disagg_pipeline.py#453
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
e412ad3 to
2ad75e6
Compare
|
@WesIngwersen there is some duplication in this PR still, for example, between |
2ad75e6 to
202b7d1
Compare
| for code in present: | ||
| x.loc[code] = parent_go * float(shares.loc[code]) | ||
| return x | ||
| return distribute_waste_parent_x_using_v_row_shares(x_cs) |
There was a problem hiding this comment.
Noting this still calling a specific waste disagg function
| return Udom_cs, Uimp_cs | ||
|
|
||
|
|
||
| def derive_cornerstone_VA_after_waste() -> pd.DataFrame: |
| Ytot_orig = load_2017_Ytot_usa() | ||
| Ytot = commodity_corresp() @ Ytot_orig | ||
| Ytot.index.name = 'sector' | ||
| weights = get_waste_disagg_weights() |
| return Ytot | ||
|
|
||
|
|
||
| def distribute_waste_parent_x_using_v_row_shares( |
WesIngwersen
left a comment
There was a problem hiding this comment.
Useful and needed refactoring to move disaggregation functionality largely into a separate module. Can use further work to make it more generic but this is good progress and I tested code to generate various models and it does not break it.
…rts from derived_cornerstone.py
|
btw I'm running the integration tests on this branch to make sure they pass |
* refactor(publish): extract shared model getters from excel writer Move cached getters, location suffix helpers, and cache clearing into model_objects and cache_reset so XLSX and other publishers share one path. * feat(publish): emit cornerstone CO2e supply-chain factors CSV Add purchaser-price CO2e tables from N with year rebase via cornerstone industry PI, placeholder Phi/margins, and emission_factors CLI. * move files inside `emission_factors` * fix runtime typing error * fix application of price ratio * use commodity PI instead of industry PI * resolve remaining conflicts with #453

cc:
Closes:
What changed? Why?
Extracts the cornerstone sector-disaggregation orchestration logic from
derived_cornerstone.pyinto a new dedicated module,cornerstone_disagg_pipeline.py.The new module owns:
cornerstone_sector_disagg_active— single gate replacing the previouselectricity_reallocation_enabledchecks scattered across public routersget_waste_disagg_weights— moved fromderived_cornerstoneelectricity_reallocation_enabled— moved fromderived_cornerstonederive_disagg_io_bundle— replaces_derive_cornerstone_io_after_electricity_reallocationderive_disagg_Ytot_with_trade— replaces_derive_cornerstone_Ytot_with_tradedistribute_waste_parent_x_using_v_row_shares— extracted from_distribute_waste_parent_x_using_v_row_sharesderived_cornerstone.pypublic routers (derive_cornerstone_V,derive_cornerstone_U_with_negatives,derive_cornerstone_VA,derive_cornerstone_Ytot_full_cs_matrix,derive_cornerstone_Aq) now gate oncornerstone_sector_disagg_active()instead ofelectricity_reallocation_enabled(). Baseline (no-disagg) IO helpers are renamed_derive_cornerstone_V_baseline,_derive_cornerstone_U_baseline, and_derive_cornerstone_VA_baselineto make the routing intent explicit. The_normalize_E_for_wastehelper is removed as it was no longer used. Import aliases were removed fromderived_cornerstone.py.inflate_cornerstone_V_with_industry_piis extracted intoinflation_helpers_cornerstone.pyto replace inline inflation logic inderive_cornerstone_V.Monkeypatches in
test_waste_disagg_pipeline_integration.pyare updated to targetdisagg_weights_module.load_disagg_weightsdirectly rather than patching throughderived_cornerstone, reflecting the moved import site.Testing
Existing test suite passes. Cache-clearing lists in
test_electricity_reallocation.pyandtest_waste_disagg_pipeline_integration.pyare updated to reference the relocated cached functions (derive_disagg_io_bundle,derive_disagg_Ytot_with_trade,cornerstone_sector_disagg_active) incornerstone_disagg_pipeline.