Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ load_E_from_flowsa: true
new_ghg_method: true
use_E_data_year_for_x_in_B: True
implement_waste_disaggregation: True
cornerstone_industry_avg_margins: True
cornerstone_industry_avg_margins: True
apply_inflation_to_V: True
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import numpy as np
import pandas as pd

from bedrock.transform.eeio.derived_cornerstone import derive_cornerstone_q
from bedrock.transform.eeio.derived_cornerstone import derive_cornerstone_V
from bedrock.utils.economic.inflation_helpers_cornerstone import (
adjust_summary_A_dollar_year,
derive_cornerstone_q_and_vnorm_for_year,
get_summary_commodity_price_index,
get_summary_commodity_price_ratio,
)
from bedrock.utils.math.formulas import compute_q
from bedrock.utils.taxonomy.bea.v2017_industry_summary import (
USA_2017_SUMMARY_INDUSTRY_CODES,
)
Expand All @@ -28,11 +29,11 @@
def test_ita_q_at_2017_matches_derive_cornerstone_q() -> None:
"""Under ITA, ``q[y] = C_m[2017] @ x[y]`` is exact when ``y == 2017``
(because C_m and x are then both from the 2017 V). The result must
therefore agree with ``derive_cornerstone_q()`` (which is V.sum(axis=0)
directly off 2017 V) within numerical noise.
therefore agree with V.sum(axis=0) directly off the uninflated 2017 V
within numerical noise.
"""
q_ita = derive_cornerstone_q_and_vnorm_for_year(2017)[0]
q_truth = derive_cornerstone_q()
q_truth = compute_q(V=derive_cornerstone_V(apply_inflation=False))

aligned_ita = q_ita.reindex(q_truth.index, fill_value=0.0)
# The BEA detail x for 2017 may differ slightly from V.sum(axis=1) due to
Expand All @@ -42,7 +43,7 @@ def test_ita_q_at_2017_matches_derive_cornerstone_q() -> None:
rel_dev = ((aligned_ita - q_truth).abs() / q_truth.abs())[nonzero]
assert (
rel_dev.median() < 0.01
), f"ITA q at 2017 deviates from derive_cornerstone_q (median rel dev {rel_dev.median():.2%})"
), f"ITA q at 2017 deviates from 2017 V.sum (median rel dev {rel_dev.median():.2%})"


def test_ita_vnorm_columns_are_stochastic() -> None:
Expand Down
4 changes: 3 additions & 1 deletion bedrock/utils/economic/inflation_helpers_cornerstone.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ def derive_cornerstone_q_and_vnorm_for_year(
)

cfg = get_usa_config()
V_2017 = derive_cornerstone_V()
V_2017 = derive_cornerstone_V(
apply_inflation=False
) # Flip inflation to false to stay in USD 2017
x_2017 = compute_x(V=V_2017)
# C_m: commodity × industry, each row sums to 1 (within-industry split).
C_m = compute_commodity_mix_matrix(V=V_2017, x=x_2017)
Expand Down
Loading