Skip to content

Implement print to excel for PR3#463

Open
jvendries wants to merge 1 commit into
jv_electricity_disagg_PR3from
jv_print_electricity_PR3_to_excel
Open

Implement print to excel for PR3#463
jvendries wants to merge 1 commit into
jv_electricity_disagg_PR3from
jv_print_electricity_PR3_to_excel

Conversation

@jvendries

@jvendries jvendries commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

cc:
Closes:

What changed? Why?

Adds a new analysis module for exporting three-stage electricity pipeline matrices (V, extended U, and Y) at each checkpoint — after waste disaggregation, after electricity reallocation, and after electricity disaggregation — to an Excel workbook for offline PR3 inspection.

The disaggregation_matrices.py module introduces a PipelineStage dataclass to hold per-checkpoint tables, a _build_stage_tables() function that replicates the waste → reallocation → disaggregation pipeline read-only, and write_electricity_disaggregation_intermediate_outputs() which writes a 16-sheet workbook alongside GO weight and disaggregation weight CSVs. An electricity_balance sheet is included to verify preservation of key metrics (gross output, commodity totals, value added, final demand) across the reallocation → disaggregation boundary.

A CLI entry point (write_221100_disaggregation_matrices.py) is provided to invoke the export with a config YAML that has all three pipeline flags enabled. Generated output files are excluded from version control via .gitignore.

Testing

Unit tests cover:

  • assert_disaggregation_export_config raises when any required flag is disabled
  • write_electricity_disaggregation_intermediate_outputs writes the expected Excel workbook with all 16 sheets and both CSV files, and confirms the aggregate electricity sector (221100) is absent from the post-disaggregation V matrix
  • _build_electricity_balance_summary correctly computes a zero delta and passing check for gross output row
  • _derive_y_after_waste_disagg does not call the electricity row split function and preserves the aggregate electricity sector in the output index

jvendries commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jvendries jvendries self-assigned this Jun 9, 2026
@jvendries jvendries marked this pull request as ready for review June 9, 2026 17:19
@jvendries jvendries requested a review from bl-young June 9, 2026 17:19
@jvendries jvendries changed the base branch from jv_electricity_disagg_PR3 to graphite-base/463 June 9, 2026 19:33
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch from 36c1a36 to cb4e7d7 Compare June 9, 2026 19:34
@jvendries jvendries changed the base branch from graphite-base/463 to jv_electricity_disagg_PR3 June 9, 2026 19:34

@bl-young bl-young left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main concern with this approach is unintended opportunities for drift or deviation from the core pipeline given that this script to some extent hard codes some of the derivation. How different would it be to use the existing publish tools to get out what you need across 2 or 3 model configs?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like something that doesn't need additional tests



def assert_disaggregation_export_config() -> None:
"""Require waste + reallocation + disaggregation flags (mirrors USAConfig validator)."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary to have this again? wouldn't this be covered already?

@jvendries

Copy link
Copy Markdown
Contributor Author

My main concern with this approach is unintended opportunities for drift or deviation from the core pipeline given that this script to some extent hard codes some of the derivation. How different would it be to use the existing publish tools to get out what you need across 2 or 3 model configs?

The main driver for this decision was to keep all the printing and analysis pathing independent from the core pipeline and contained within bedrock/analysis/electricity/ to avoid the confusion between intermediate outputs required for the electricity disaggregation, specifically the after waste tables.

A secondary consideration was ease of review for this PR vs #463 by avoiding any confusion on which printing was related to which PR.

What I'd propose is once #463 is merged, then we can re-work this PR to use existing publish tools. Would this be an acceptable course of action?

@jvendries jvendries changed the base branch from jv_electricity_disagg_PR3 to graphite-base/463 June 9, 2026 21:09
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch from cb4e7d7 to 41e9b43 Compare June 9, 2026 21:10
@jvendries jvendries changed the base branch from graphite-base/463 to jv_electricity_disagg_PR3 June 9, 2026 21:10
@jvendries jvendries changed the base branch from jv_electricity_disagg_PR3 to graphite-base/463 June 15, 2026 20:21
@jvendries jvendries force-pushed the graphite-base/463 branch from 8218c3f to 10187f4 Compare June 15, 2026 20:22
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch from 41e9b43 to 98e9e49 Compare June 15, 2026 20:22
@jvendries jvendries changed the base branch from graphite-base/463 to jv_electricity_disagg_PR3 June 15, 2026 20:22
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch from 98e9e49 to 9820d15 Compare June 17, 2026 15:51
@jvendries jvendries force-pushed the jv_electricity_disagg_PR3 branch 2 times, most recently from 53cccd9 to 8920451 Compare June 17, 2026 16:53
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch 2 times, most recently from a1f6655 to f5271c7 Compare June 18, 2026 21:19
@jvendries jvendries force-pushed the jv_electricity_disagg_PR3 branch 2 times, most recently from 93416b2 to f31e667 Compare June 19, 2026 23:46
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch from f5271c7 to 5189c68 Compare June 19, 2026 23:46
@jvendries jvendries force-pushed the jv_electricity_disagg_PR3 branch from f31e667 to 309998f Compare June 23, 2026 16:27
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch from 5189c68 to ff7e43e Compare June 23, 2026 16:27
@jvendries jvendries force-pushed the jv_electricity_disagg_PR3 branch from 309998f to 669acb4 Compare June 24, 2026 19:52
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch from ff7e43e to 03cd4d0 Compare June 24, 2026 19:52
@jvendries jvendries force-pushed the jv_electricity_disagg_PR3 branch from 669acb4 to 120547f Compare June 25, 2026 01:20
@jvendries jvendries force-pushed the jv_print_electricity_PR3_to_excel branch from 03cd4d0 to 7f6de22 Compare June 25, 2026 01:20
@WesIngwersen WesIngwersen self-requested a review July 1, 2026 21:15

@WesIngwersen WesIngwersen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully generated electricity_pipeline_stages_V_U_Y.xlsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants