IAMconsortium / pyam

Analysis & visualization of energy & climate scenarios
https://pyam-iamc.readthedocs.io/
Apache License 2.0
227 stars 118 forks source link

Add `to_ixmp4()` method #797

Closed danielhuppmann closed 7 months ago

danielhuppmann commented 11 months ago

Please confirm that this PR has done the following:

Description of PR

This PR adds a method to_ixmp4() to easily save all scenarios in an IamDataFrame (including meta indicators) to an ixmp4 platform database instance.

The method name to_ixmp4() doesn't seem elegant, any alternative suggestions of comments?

codecov[bot] commented 11 months ago

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (98cb3ed) 94.6% compared to head (0da2f88) 94.8%. Report is 1 commits behind head on main.

Files Patch % Lines
pyam/ixmp4.py 94.4% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #797 +/- ## ======================================= + Coverage 94.6% 94.8% +0.1% ======================================= Files 62 64 +2 Lines 6040 6089 +49 ======================================= + Hits 5719 5775 +56 + Misses 321 314 -7 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

danielhuppmann commented 10 months ago

Nice catch, @phackstock. A roll-back is not possible in ixmp4 (because the creation of a run and adding of a run are separate actions), and there is no possibility (yet) to delete a run., but I'll add a to-do.

phackstock commented 10 months ago

Ah I see, then the quick fix might be to still use a try except and delete the whole run if we encounter an error. Just to avoid having half finished ghost runs.

danielhuppmann commented 10 months ago

Added an issue to delete runs in ixmp4, see https://github.com/iiasa/ixmp4/issues/29.

Added a quickfix and tests to at least test for the obvious failures...

Once this PR is merged, I'll add a method read_ixmp4().