feat(publish): integrate Phi purchaser-price adjustment#464
Merged
Conversation
Wire PRO:PUR into SEF export, Excel Phi sheet, and USEEIO baseline diagnostics (N_new_purchaser / N_old_purchaser).
WesIngwersen
approved these changes
Jun 15, 2026
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.
cc:
Closes: #435
What changed? Why?
Margins-based producer-to-purchaser ratios (Phi) from #440 are wired into supply-chain factor export, Excel publish, and USEEIO baseline diagnostics. Phi converts producer-price N to purchaser price so comparisons against USEEIO phoebe workbooks and purchaser-price reporting use consistent valuation.
Transform helpers (
derive_PRO_to_PUR_ratio.py)margins_phi_active(cfg)— true whenuseeio_marginsorcornerstone_industry_avg_marginsis set (notceda_marginsalone).phi_for_sectors(sector_index)— returnsderive_phi_cornerstone_usa()aligned to sectors, or identity 1.0 when margins methodology is inactive.apply_phi_to_ef_vector(ef)— elementwiseef * phi.Diagnostics and publish both import these helpers from transform; publish does not own Phi derivation logic.
Supply-chain emission factors export
--purchaser_price/--no-purchaser_price(default on).adjust_publish_matrix()inplaceholders.pyrebases todollar_yearvia commodity CPI, then optionally multiplies columns by Phi.placeholder_phiremoved; real Phi replaces it.Excel publish
get_Phi()inmodel_objects.pyreturns a single-column DataFrame keyed bymodel_base_year, orNonewhen margins methodology is inactive (sheet omitted). Multi-yearPhipanel deferred — see TODO below.Phisheet added to workbook writerSheetSpeclist.clear_all_publish_caches().USEEIO baseline diagnostics
Purchaser adjustment applies only when both conditions hold:
diagnostics_baseline_source == 'gcs_useeio_xlsx'(pinned USEEIO Excel baseline).useeio_marginsorcornerstone_industry_avg_margins).When eligible,
pull_efs_for_diagnosticscomputesN_new_purchaserandN_old_purchaserviaapply_phi_to_ef_vectoron the inflated/new producer N vectors (workbookNis producer-price).N_perc_diffcompares purchaser vs purchaser.N_and_diffsmerge order: construct → inflated merge → purchaser merge.combine_ef_diagnosticsreads new N with fallbackN_new_purchaser→N_new_inflated→N_new, and pinned baseline old N with fallbackN_old_purchaser→N_old_inflated.config_summaryrecordspurchaser_price_adjustment_applied.D diagnostics are unchanged (Phi applies to N only). Both sides use bedrock
derive_phi_cornerstone_usa()Phi atmodel_base_year.Follow-ups (not in this branch)
placeholder_margin_efremains zeros).Rho/TauExcel sheets.TODO (team confirmation pending)
model_base_yearonly; CPI handles--dollar_year. supply-chain-factors / useeior applyPhi[currency_year](year-specific margins inflation). Follow-up:derive_phi_cornerstone_usa_panel,get_Phi()sector×year panel,phi_for_sectors(..., year=dollar_year)in SEF export — see planphi-panel-timeseries.Validation scope (years and comparisons)
Phi year:
derive_phi_cornerstone_usa(),get_Phi(), and USEEIO diagnostics purchaser columns use Phi atmodel_base_yearonly (2017 foruseeio_phoebe_23).get_Phi()emits a single column; the ExcelPhisheet has no other year columns yet.Pinned workbook comparison (CI,
eeio_integration):test_published_phi_matches_useeio_workbookcompares bedrock Phi to the phoebe workbookPhisheet column 2017 only (1% rtol). Other workbook year columns are not tested.Supply-chain factor CSV — no external published parity in CI:
test_sef_phi_wiring(eeio_integration)--dollar_year2024 equalsN_producer / CPI(2017→2024) × Phi(2017). Not compared to the USEEIO workbook, supply-chain-factors CSV, or Zenodo NAICS publish.Diagnostics:
N_new_purchaservsN_old_purchaseron the phoebe pin. With defaultuseeio_phoebe_23(model_base_year2017), both sides sit at 2017 USD andN_perc_diffis purchaser vs purchaser (~−1% median on local pin runs). Not a comparison to published SEF CSV or Zenodo NAICS factors.Comparison targets (operator)
generate_diagnosticswithuseeio_phoebe_23+useeio_baseline_pin.json; readN_perc_diffmodel_base_yearunless comparing at that dollar year.uv run python -m bedrock.publish.emission_factors.cli --config_name useeio_phoebe_23 --dollar_year 2024Phi(model_base_year)+ commodity CPI to 2024; Cornerstone codes, not NAICS. Manual compare to Zenodo v1.4.0.model_base_year == --dollar_year(2017 on default config)--dollar_year 2024is not comparable to default diagnosticsN_new_purchaserwithout an extra CPI step.combine_ef_diagnosticsprefersN_new_purchaser/N_old_purchaserwhen input Sheets include them (documented invalidation/analysis/README.md).Testing
Unit tests (phi helpers and Excel writer):
Phi wiring and dollar-year rebasing on SEF export:
Pinned phoebe USEEIO workbook Phi parity:
Validation module (diagnostics CLI and baseline loaders):
Parity notes
Phicolumn 2017 within 1% rtol (eeio_integrationonly).N_perc_diffvs pinned workbook onuseeio_phoebe_23(local pin runs).