-
Notifications
You must be signed in to change notification settings - Fork 157
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
Clean up message_ix.macro #327
Conversation
bfe5fb2
to
f51e056
Compare
Codecov Report
@@ Coverage Diff @@
## main #327 +/- ##
=====================================
Coverage 92.6% 92.7%
=====================================
Files 41 41
Lines 3167 3236 +69
=====================================
+ Hits 2934 3000 +66
- Misses 233 236 +3
|
e9d9430
to
0663c65
Compare
I have some smaller suggestions to revise the macro_input.xlsx file.
I have implemented the suggested modifications in the attached multiregion_macro_input.xlsx file with the changes marked in yellow. |
Thanks @volker-krey for the suggestions and the sample file. I'll include them. I'll also try to see if we can make the calibration run for different lastmodel_years in the same model. That should also make it easier to calibrate a scenario with different last model year using the same input data file. |
0663c65
to
22eac70
Compare
message_ix/macro.py
Outdated
# users define certain nodes, sectors and level for MACRO | ||
self.nodes = set(self.data['config']['node'].dropna()) | ||
self.sectors = set(self.data['config']['sector'].dropna()) | ||
self.levels = set(self.data['config']['level'].dropna()) |
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.
I would suggest adding another line here to be able to obtain the unique mapping of the different sector, commodity, and level combinations.
self.sector_mapping = self.data["config"]
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.
Thanks @GamzeUnlu95 for the suggestion. Can you please make a pull request and suggest your changes?
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.
Done in this PR.
message_ix/macro.py
Outdated
clone.add_set("mapping_macro_sector", [s, s, "useful"]) | ||
for s, l in product(c.sectors, c.levels): | ||
clone.add_set('sector', s) | ||
clone.add_set("mapping_macro_sector", [s, s, l]) |
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.
Here we assume sector and commodity names are the same. We could differentiate this by using a mapping table obtained from the excel "config" sheet including a commodity column.
sector_mapping_df = c.sector_mapping
for i in sector_mapping_df.index:
s = sector_mapping_df.iloc[i, sector_mapping_df.columns.get_loc("sector")]
c = sector_mapping_df.iloc[i, sector_mapping_df.columns.get_loc("commodity")]
l = sector_mapping_df.iloc[i, sector_mapping_df.columns.get_loc("level")]
clone.add_set('sector', s)
clone.add_set("mapping_macro_sector", [s, c, l])
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.
@GamzeUnlu95 , nice suggestion. If possible, please make a PR and add these suggestions in the code, and in the Excel file, so that I can run and approve them.
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.
Done in this PR.
b0dd16e
to
6fdab49
Compare
This reverts commit 85578e8.
Okay, I have hopefully fixed the unit errors mentioned in #327 (review) and #327 (review). I also applied latest black and rebased on |
Some comments on the two remaining checkboxes above:
Per "documentation", since there wasn't any (#315), no risk. I added a placeholder section in doc/macro.rst; I would strongly suggest we copy the description of the input file format from this PR description into some clear, simple sentences there. Without this (i.e. saying only "look at the test data specimen"), the input file format is completely undocumented and users have little hope to independently construct one.
I added the PR to the release notes. However, it's important to consider: will existing users need to change anything if they start using this code, i.e. compared to what was released in v3.4, in order to avoid unexpected results? This must be added in a "Migration notes" subsection above "All changes". |
Thanks @khaeru for resolving the technical issues and improving the code. I added documentation for the input data file, and also a few sentences as "Migration Notes" to warn that these changes will not work with the previous versions of the Excel data file. |
Excellent. That looks like exactly what we need, so I will request a review and then @LauWien can dispatch that to an available colleague, e.g. as you suggested in Slack. |
How soon should the PR get reviewed (E.g. best by the end of this week or end of next week)? Many thanks in advance! This helps to find a colleague :) |
End of next week is probably fine. |
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.
Looks great :)
Just some suggestions.
Co-authored-by: Laura Wienpahl <[email protected]>
@LauWien thanks for the review—please merge once checks again pass. |
This PR improves the code in
message_ix.macro.py
for the following items. Some of these issues were identified when #223 was conditionally merged, and some items are additional improvements.initialize_year_macro
before calibration (partly addressing Clarify add_macro() behaviour on a non-'clean' Scenario #320)baseyear_macro
from the code (not needed in GAMS anymore)How to review
New tests are added to check the improvements in this PR. You can view changes in the code and run the code and tests under
test_macro.py
.Notice: if you wish to test the code on a input data file, please update your data for:
"config": in the new format, there are three columns ("node, "sector", "level") in "config" to specify those members of these sets that are included in MACRO calibration. Please see the sample input file in: message_ix/tests/data/westeros_macro_input.xlsx
you need to add a "unit" column to all input parameters for specifying the unit (Please see the format in the file above).
Tests added.
These improvements shouldn't change the main behaviour and documentation. However, this will change the format of the input data file. This has been explained in the documentation.
Release notes added, including the "migration notes" for the format of the input data file.