feat: add export for REMIND/mrindustry - #160
Conversation
for more information, see https://pre-commit.ci
|
@leonieschweiger @bennet21 could I please get your quick first reactions, especially concerning the points mentioned above in the PR description? Thanks! |
|
|
||
| def steel_scrap(mfa: fd.MFASystem) -> fd.FlodymArray: | ||
| """Total scrap available after trade and before the model diverts any surplus to excess scrap.""" | ||
| return mfa.stocks["in_use"].outflow.sum_to(("t", "r", "g")) |
There was a problem hiding this comment.
Should be after collection.
|
Looks great! See my one comment. folder could be named |
|
Thanks @tobiasdiez. For cement production, I'd say you should include losses as well (prod_cement => sysenv). Is there a specific reason you call it raw production? |
Okay, done!
No not really, removed the
Added! |
leonieschweiger
left a comment
There was a problem hiding this comment.
Looks great, thanks!
With regards to the exported variables: In REMIND, we only model the production of high value chemicals (HVC), the precursor of plastic production. This is why we need the HVC input into plastic production here (see my suggestions) - sorry for not specifying this earlier!
| def get_remind_input_variables(self) -> list[RemindInputVariable]: | ||
| def plastics_production(mfa: fd.MFASystem) -> fd.FlodymArray: | ||
| """Plastics output after polymerization losses and before trade""" | ||
| return mfa.flows["polymerization => primary_market"].sum_to(("t", "r")) |
There was a problem hiding this comment.
| def get_remind_input_variables(self) -> list[RemindInputVariable]: | |
| def plastics_production(mfa: fd.MFASystem) -> fd.FlodymArray: | |
| """Plastics output after polymerization losses and before trade""" | |
| return mfa.flows["polymerization => primary_market"].sum_to(("t", "r")) | |
| def get_remind_input_variables(self) -> list[RemindInputVariable]: | |
| def hvc_input(mfa: fd.MFASystem) -> fd.FlodymArray: | |
| """HVC input into plastics production""" | |
| return mfa.flows["HVC_input => polymerization"].sum_to(("t", "r")) |
| return [ | ||
| RemindInputVariable( | ||
| name="plastics_production", | ||
| calculation_function=plastics_production, | ||
| unit="t/yr", | ||
| ), |
There was a problem hiding this comment.
| return [ | |
| RemindInputVariable( | |
| name="plastics_production", | |
| calculation_function=plastics_production, | |
| unit="t/yr", | |
| ), | |
| return [ | |
| RemindInputVariable( | |
| name="HVC_input", | |
| calculation_function=hvc_input, | |
| unit="t/yr", | |
| ), |
Co-authored-by: Leonie Schweiger <leonie.schweiger@pik-potsdam.de>
Thanks for the suggestion. I now went with the even simpler |
Thanks Leonie! I've now applied your suggestions. |
|
Thanks a lot! This is now officially ready for review. |
| calculation_function=lambda mfa: mfa.stocks["in_use"].outflow.sum_to( | ||
| ("t", "r", "g") | ||
| ), | ||
| calculation_function=SteelDataExporter._steel_scrap, |
There was a problem hiding this comment.
I am afraid this change is not intended, though it would be nice.
PRISMA's definition is pre-collection, what we need for REMIND is post-collection.
You could call this third function _eol or _scrap_pre_collection (and the other one _scrap_post_collection) or so.
Additional info:
In the long run, I would like to have the IAMC export to include both (and be comprehensive in general), possibly with the CIRCOMOD nomenclature or our own.
The piamInterfaces package can then map these onto project-specific nomenclatures.
There was a problem hiding this comment.
I'm not sure if I follow completely. At the moment, this is only a refactoring to extract and reuse this code. It shouldn't have changed anything in the IAMC export. Do you mean that because in the future these two will be different, it doesn't make sense now to use the same function? Or do you mean that I need to export something else for mrindustry (and if so, what)?
There was a problem hiding this comment.
The confusion was my bad, this comment was misleading and I didn't check your fix.
IAMC export and mrindustry export need two different quantities for steel scrap. The one for IAMC export needs to remain as is.
However, what I meant with the comment linked above is that the scrap quantity for mrindustry should be something else.
I'll just post the proposed end result here for simplicity.
For IAMC:
def _eol_scrap_potential(mfa: fd.MFASystem) -> fd.FlodymArray:
"""End-of-life scrap available before collection and trade"""
return mfa.stocks["in_use"].outflow.sum_to(("t", "r", "g"))
For mrindustry:
def _total_available_scrap(mfa: fd.MFASystem) -> fd.FlodymArray:
"""Home and new scrap, plus old scrap after collection and trade, but before the model diverts any surplus to excess scrap"""
return mfa.flows["forming => scrap_market"] + mfa.flows["fabrication => scrap_market"] + mfa.flows["recycling => scrap_market"]
JakobBD
left a comment
There was a problem hiding this comment.
Great stuff!
Apart from the one comment, good to merge.
NB:
I originally would have hard-coded some functionality into this output function, where the files are directly put into the sources folder on the cluster and a new version sub-folder is created.
But I now too prefer to move this step to a stand-alone script (as you probably intended). It is cleaner that way, and much less dangerous.
When I started working on this, it was still unclear how to integrate it with mrindustry, and so I went with the most straightforward implementation. But now that Falk confirmed that a separate orchestration script is the way to go, I agree that renaming & moving it to the |
| """Cement output after production losses and before trade""" | ||
| return ( | ||
| mfa.flows["prod_cement => market_cement"] + mfa.flows["prod_cement => sysenv"] | ||
| ).sum_to(("t", "r")) |
There was a problem hiding this comment.
The documentation and function seem inconsistent. If it's after losses, why add losses?
Which one should it be @bennet21?
There was a problem hiding this comment.
When #164 is merged, this should be
| """Cement output after production losses and before trade""" | |
| return ( | |
| mfa.flows["prod_cement => market_cement"] + mfa.flows["prod_cement => sysenv"] | |
| ).sum_to(("t", "r")) | |
| """Cement output before trade and construction losses""" | |
| return mfa.flows["prod_cement => market_cement"].sum_to(("t", "r")) |
Co-authored-by: Jakob Duerrwaechter <jakob.duerrwaechter@pik-potsdam.de>
Add an option to export data that should then be used in
mrindustry.Each output variable is written as a seperate csv file under
data/<material>/output/export/remind_input.A few ponits for consideration: