message_ix
message_ix copied to clipboard
Add `.models.shift_period()`
This PR adds a function shift_period() that implements, purely in Python, the behaviour of Scenario.clone(…, shift_first_model_year). Because the latter is currently implemented in the Java code underlying ixmp.JDBCBackend, it cannot be extended in parallel with changes to the implementation of MESSAGE in GAMS (or, in the future, other implementations).
- Partly addresses #254.
- Also due to limitations of
ixmp.JDBCBackend, is it not supported to set values on model data items of type "variable" or "equation" directly. Thus, this PR can't be completed without iiasa/ixmp#552, iiasa/ixmp#400, or similar. - cf. also iiasa/ixmp#424. While the behaviour is currently provided as an argument to the
clone()command, the new function is distinct. - This PR does not directly address, but will make it much easier to address:
- #542
- #543
- #867
- The operation of shifting the first model period forward in time is lossy, because parameters like
historical_activityhave fewer dimensions than the corresponding variables (e.g.ACT). For the opposite operation—shifting the first model period backwards in time—essentially the scenario must be solved again to generate the corresponding solution data in e.g.ACT.
More to be added
How to review
To be added
PR checklist
- [ ] Complete the implementation
- [ ] Invoke
shift_period()frommessage_ix.Scenario.clone(…)if the corresponding argument is given.
- [ ] Invoke
- [ ] Continuous integration checks all ✅
- [ ] Add or expand tests; coverage checks both ✅
- [ ] Add, expand, or update documentation.
- [ ] Update release notes.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 96.5%. Comparing base (f97e386) to head (b3c35ad).
Additional details and impacted files
@@ Coverage Diff @@
## main #873 +/- ##
=======================================
- Coverage 96.5% 96.5% -0.1%
=======================================
Files 60 60
Lines 5155 5179 +24
=======================================
+ Hits 4976 4999 +23
- Misses 179 180 +1
| Files with missing lines | Coverage Δ | |
|---|---|---|
| message_ix/message.py | 100.0% <100.0%> (ø) |
|
| message_ix/tests/test_models.py | 100.0% <100.0%> (ø) |
This will address https://github.com/iiasa/ixmp/issues/75.