Skip to content

Commit 126283a

Browse files
Change the
main functions in the kaya_factors and kaya_variables modules to compute_ kaya_factors and compute_kaya_variables. Also add test case for GDP (MER) fallback for Kaya Factors calculation.
1 parent 5557830 commit 126283a

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

pyam/compute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def kaya_variables(self, append=False):
296296
297297
"""
298298

299-
kaya_variables_frame = kaya_variables.kaya_variables(self._df)
299+
kaya_variables_frame = kaya_variables.compute_kaya_variables(self._df)
300300
if kaya_variables_frame is None:
301301
return None
302302
if append:
@@ -353,7 +353,7 @@ def kaya_factors(self, append=False):
353353
kaya_variables = self.kaya_variables(append=False)
354354
if kaya_variables is None:
355355
return None
356-
kaya_factors_frame = kaya_factors.kaya_factors(kaya_variables)
356+
kaya_factors_frame = kaya_factors.compute_kaya_factors(kaya_variables)
357357
if kaya_factors_frame is None:
358358
return None
359359
if append:

pyam/kaya/kaya_factors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pyam.kaya import input_variable_names, kaya_factor_names, kaya_variable_names
33

44

5-
def kaya_factors(kaya_variables_frame):
5+
def compute_kaya_factors(kaya_variables_frame):
66
kaya_factors = pyam.concat(
77
[
88
_calc_gnp_per_p(kaya_variables_frame),

pyam/kaya/kaya_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414

1515

16-
def kaya_variables(input_data):
16+
def compute_kaya_variables(input_data):
1717
if _is_input_data_incomplete(input_data):
1818
return None
1919

tests/test_feature_kaya_factors.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,35 @@ def test_calling_kaya_factors_multiple_times():
113113
obs.compute.kaya_factors(append=True)
114114
obs.compute.kaya_factors(append=True)
115115
assert_iamframe_equal(TEST_DF.append(EXP_DF_FOR_APPEND), obs)
116+
117+
def test_kaya_factors_uses_gdp_mer_fallback():
118+
"""Test that kaya_factors uses GDP_MER when GDP_PPP is not available"""
119+
# Create test data without GDP_PPP
120+
df_no_gdp_ppp = TEST_DF.filter(variable="GDP|PPP", keep=False)
121+
122+
# Create expected result using GDP|MER instead of GDP|PPP for calculations
123+
exp_no_gdp_ppp = IamDataFrame(
124+
pd.DataFrame(
125+
[ # 8 EJ / 5 billion USD = 1.6
126+
["FE/GNP", "EJ / USD / billion", 1.6],
127+
# 5 billion USD / 1000 million = 0.005
128+
["GNP/P", "USD * billion / million / a", 0.005],
129+
["NFC/TFC", "", 0.833333],
130+
["PEDEq/FE", "", 1.250000],
131+
["PEFF/PEDEq", "", 0.900000],
132+
["TFC/PEFF", "Mt CO2/EJ", 1.333333],
133+
["Population", "million", 1000],
134+
["Total Fossil Carbon", "Mt CO2/yr", 12.0],
135+
],
136+
columns=["variable", "unit", 2010],
137+
),
138+
model="model_a",
139+
scenario="scen_a",
140+
region="World",
141+
)
142+
143+
# Compute kaya factors
144+
obs = df_no_gdp_ppp.compute.kaya_factors()
145+
146+
# Verify results match expected
147+
assert_iamframe_equal(exp_no_gdp_ppp, obs)

0 commit comments

Comments
 (0)