-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kaya_variables, kaya_factors, and kaya_lmdi methods to the comput… #884
base: main
Are you sure you want to change the base?
Conversation
…e module. Also add the kaya subdirectory that contains the implementation for the kaya methods. (IAMconsortium#875)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #884 +/- ##
=======================================
+ Coverage 95.0% 95.1% +0.1%
=======================================
Files 64 74 +10
Lines 6134 6579 +445
=======================================
+ Hits 5828 6260 +432
- Misses 306 319 +13 ☔ View full report in Codecov by Sentry. |
Thanks for the PR! Looks like the legacy-test is failing is because the unit's are ordered differently
Will take a look more closely next week, don't worry about the failing test for now, will think about how to avoid that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a first look at the PR and made a few comments for improvements, Quite a lot of material here...
It would be helpful if you could remove the LMDI decomposition and add that as a separate PR later.
scenarios : iterable of tuples (model, scenario, region) | ||
The (model, scenario, region) combinations to be included. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering about two issues with the scenarios filter:
- Why not just compute kaya-variables for all data in the IamDataFrame?
- If it's necessary to filter, why not allow filter-kwargs and add those below, like?
def kaya_variables(self, append=False, **kwargs) _data = self._df.filter(**kwargs) ...
I'm concerned about adding an argument "scenarios" that is actually a combination of model-scenario-region, that's quite confusing...
@@ -249,6 +251,248 @@ def bias(self, name, method, axis): | |||
""" | |||
_compute_bias(self._df, name, method, axis) | |||
|
|||
def kaya_variables(self, scenarios, append=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a method kaya_variables
and an imported module with the same name, which then also has a method of that name... Hard to follow the code logic here.
TEST_DF = IamDataFrame( | ||
pd.DataFrame( | ||
[ | ||
[input_variable_names.POPULATION, "million", 1000], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a testing perspective, it would be useful to have the actual values here, not the module-internal translation...
[input_variable_names.POPULATION, "million", 1000], | |
["Population", "million", 1000], |
kaya_variable_frames.append(_calc_pop(input)) | ||
kaya_variable_frames.append(_calc_gdp(input)) | ||
kaya_variable_frames.append(_calc_fe(input)) | ||
kaya_variable_frames.append(_calc_pe(input)) | ||
kaya_variable_frames.append(_calc_pe_ff(input)) | ||
kaya_variable_frames.append(_calc_tfc(input)) | ||
kaya_variable_frames.append(_calc_nfc(input)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be more efficient (and easier to read) to do:
kaya_variable_frames.append(_calc_pop(input)) | |
kaya_variable_frames.append(_calc_gdp(input)) | |
kaya_variable_frames.append(_calc_fe(input)) | |
kaya_variable_frames.append(_calc_pe(input)) | |
kaya_variable_frames.append(_calc_pe_ff(input)) | |
kaya_variable_frames.append(_calc_tfc(input)) | |
kaya_variable_frames.append(_calc_nfc(input)) | |
kaya_variable_frames.append = pyam.concat( | |
[ | |
_calc_pop(input), | |
_calc_gdp(input), | |
_calc_fe(input), | |
_calc_pe(input), | |
_calc_pe_ff(input), | |
_calc_tfc(input), | |
_calc_nfc(input), | |
] | |
) |
) | ||
if input.empty: | ||
break | ||
kaya_factors_frames.append(_calc_gnp_per_p(input)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in my other comment, this could be simplified using pyam.concat()
.
@@ -0,0 +1,7 @@ | |||
Pop_LMDI = "Population (LMDI)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the current IAMC-variable naming convention, it would be preferably to use square brackets for these identifiers.
Pop_LMDI = "Population (LMDI)" | |
Pop_LMDI = "Population [LMDI]" |
"""Compute the variables needed to compute Kaya factors | ||
for the Kaya Decomposition Analysis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first sentence of the docstring should fit in one line, per numpy conventions.
"""Compute the variables needed to compute Kaya factors | |
for the Kaya Decomposition Analysis. | |
"""Compute the variables needed to compute Kaya factors |
"""Compute the Kaya factors needed to compute factors | ||
for the Kaya Decomposition Analysis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Compute the Kaya factors needed to compute factors | |
for the Kaya Decomposition Analysis. | |
"""Compute the factors for the Kaya Decomposition Analysis |
ignore_units=True, | ||
append=False, | ||
).rename(unit={"unknown": ""}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be possible to directly se the resulting unit.
ignore_units=True, | |
append=False, | |
).rename(unit={"unknown": ""}) | |
ignore_units="", | |
append=False, | |
) |
…e module. Also add the kaya subdirectory that contains the implementation for the kaya methods. (#875)
Please confirm that this PR has done the following:
Description of PR
This PR adds three methods to the public api of the
compute
module:kaya_variables()
,kaya_factors()
, andkaya_lmdi()
. The implementation for these methods is in the newkaya
submodule.