Skip to content
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

Adding new years to a MESSAGE scenario #161

Merged
merged 49 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
b17a12d
main function f_addNewYear added for adding new time steps
behnam-zakeri Feb 3, 2019
24cbd19
test for function f_addNewYear added
behnam-zakeri Feb 3, 2019
bd9fc75
Create README.md
behnam-zakeri Feb 4, 2019
221480d
release notes updated
behnam-zakeri Feb 4, 2019
6445078
Merge remote-tracking branch 'origin/add_year' into add_year
behnam-zakeri Feb 4, 2019
61afa10
Update README.md
behnam-zakeri Feb 4, 2019
fdc1a06
Update README.md
behnam-zakeri Feb 4, 2019
22a0ab2
Update README.md
behnam-zakeri Feb 4, 2019
f19a7bd
Update README.md
behnam-zakeri Feb 4, 2019
dfc9630
Update README.md
behnam-zakeri Feb 4, 2019
017be48
Update RELEASE_NOTES.md
behnam-zakeri Feb 4, 2019
a9bf775
Update f_addNewYear.py
behnam-zakeri Feb 4, 2019
c6d4a22
Update README.md
behnam-zakeri Apr 9, 2019
a66e566
Use message_ix.tools instead of toolbox namespace
khaeru May 2, 2019
aae58ae
main function f_addNewYear added for adding new time steps
behnam-zakeri Feb 3, 2019
d8ad78f
test for function f_addNewYear added
behnam-zakeri Feb 3, 2019
82cd3c3
Create README.md
behnam-zakeri Feb 4, 2019
c2ff8d9
release notes updated
behnam-zakeri Feb 4, 2019
80ab098
Update README.md
behnam-zakeri Feb 4, 2019
a49e88c
Update README.md
behnam-zakeri Feb 4, 2019
072cc5e
Update README.md
behnam-zakeri Feb 4, 2019
9bf566e
Update README.md
behnam-zakeri Feb 4, 2019
35813ab
Update README.md
behnam-zakeri Feb 4, 2019
fafb960
Update RELEASE_NOTES.md
behnam-zakeri Feb 4, 2019
5ac25a9
Update f_addNewYear.py
behnam-zakeri Feb 4, 2019
f772635
Update README.md
behnam-zakeri Apr 9, 2019
5d3701a
Use message_ix.tools instead of toolbox namespace
khaeru May 2, 2019
cf8f2e7
Rewrite add_year CLI using Click.
khaeru May 2, 2019
e9c1649
Link the README for the new tool into the docs build
khaeru May 2, 2019
83da650
merge add_year into add_year_v1.0
behnam-zakeri May 2, 2019
3cec109
cleanup of main function
behnam-zakeri May 2, 2019
ead8656
cleanup of main function
behnam-zakeri May 2, 2019
0376ea8
cleaned interface 1d
behnam-zakeri May 6, 2019
439d062
md file deleted
behnam-zakeri May 6, 2019
c88c1ad
reformatted to function and clean-up
behnam-zakeri May 6, 2019
f54ca38
Merge branch 'add_year' of github.com:behnam2015/message_ix into add_…
khaeru May 7, 2019
ba9c4ce
Use find_packages() in setup.py
khaeru May 7, 2019
7094bbe
Update docstrings
khaeru May 7, 2019
2e40f88
Revamped the test to explicitly test each function
behnam-zakeri May 8, 2019
afa5071
Improve init to account for models with no first year specified
behnam-zakeri May 8, 2019
cdd7b1d
replaced math.isclose with pytest.approx in the test
behnam-zakeri May 8, 2019
58d4f37
Copyedit documentation
khaeru May 8, 2019
94e9a98
Fix sc_new creation in demo code
khaeru May 8, 2019
55dc30e
adding check for first model year
behnam-zakeri May 8, 2019
00f14bb
release notes updated
behnam-zakeri Jun 17, 2019
bfe37a8
Merge branch 'master' into add_year
behnam-zakeri Jun 17, 2019
61d06ac
Remove references to f_addYear.py per @gidden
khaeru Jun 21, 2019
9c557a6
Merge branch 'master' into add_year
khaeru Jun 21, 2019
1bcb147
Fix typo in test_add_year.py
khaeru Jun 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# Next Release

- [#161](https://github.com/iiasa/message_ix/pull/161): A feature for adding new periods to a scenario.
- [#205](https://github.com/iiasa/message_ix/pull/205): Implement required changes related to timeseries-support and cloning across platforms (see [ixmp:#142](https://github.com/iiasa/ixmp/pull/142)).
- [#196](https://github.com/iiasa/message_ix/pull/196): Improve testing by re-using :mod:`ixmp` apparatus.
- [#187](https://github.com/iiasa/message_ix/pull/187): Test for cumulative bound on emissions.
Expand Down
9 changes: 9 additions & 0 deletions doc/source/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ common model design choices.

efficiency
debugging

Model-building tools
--------------------

.. toctree::
:maxdepth: 1
:glob:

tools/*
1 change: 1 addition & 0 deletions doc/source/tools/add_year.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../../../message_ix/tools/add_year/README.rst
Empty file added message_ix/tools/__init__.py
Empty file.
86 changes: 86 additions & 0 deletions message_ix/tools/add_year/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Add model years to an existing Scenario
=======================================

Description
-----------

This tool adds new modeling years to an existing :class:`ixmp.Scenario` (hereafter "reference scenario"). For instance, in a scenario define with::

history = [690]
model_horizon = [700, 710, 720]
sc_ref.add_horizon({'year': history + model_horizon,
'firstmodelyear': model_horizon[0]})

…additional years can be added::

sc_new = message_ix.Scenario(mp, sc_ref.model, sc_ref.scenario,
version='new')
add_year(sc_ref, sc_new, [705, 712, 718, 725])

At this point, ``sc_new`` will have the years [700, 705, 710, 712, 718, 720, 725], and original or interpolated data for all these years in all parameters.


The tool operates by creating a new empty Scenario (hereafter "new scenario") and:

- Copying all **sets** from the reference scenario, adding new time steps to relevant sets (e.g., adding 2025 between 2020 and 2030 in the set ``year``)
- Copying all **parameters** from the reference scenario, adding new years to relevant parameters, and calculating missing values for the added years.

Features
~~~~~~~~

- It can be used for any MESSAGE scenario, from tutorials, country-level, and global models.
- The new years can be consecutive, between existing years, and/or after the model horizon.
- The user can define for what regions and parameters the new years should be added. This saves time when adding the new years to only one parameter of the reference scenario, when other parameters have previously been successfully added to the new scenario.

Usage
-----

The tool can be used either:

1. Directly from the command line::

$ python -m message_ix.tools.add_year \
--model_ref MESSAGE_Model \
--scen_ref baseline \
--years_new 2015,2025,2035,2045

For the full list of input arguments, run::

$ python -m message_ix.tools.add_year --help

2. By calling the function :meth:`message_ix.tools.add_year.add_year` from a Python script.


Technical details
-----------------

1. An existing scenario is loaded and the desired new years are specified.
2. A new (empty) scenario is created for adding the new years.
3. The new years are added to the relevant sets, ``year`` and ``type_year``.

- The sets ``firstmodelyear``, ``lastmodelyear``, ``baseyear_macro``, and ``initializeyear_macro`` are modified, if needed.
- The set ``cat_year`` is modified for the new years.

4. The new years are added to the index sets of relevant parameters, and the missing data for the new years are calculated based on interpolation of adjacent data points. The following steps are applied:

a. Each non-empty parameter is loaded from the reference scenario.
b. The year-related indexes (0, 1, or 2) of the parameter are identified.
c. The new years are added to the parameter, and the missing data is calculated based on the number of year-related indexes. For example:

- The parameter ``inv_cost`` has index ``year_vtg``, to which the new years are added.
- The parameter ``output`` has indices ``year_act`` and ``year_vtg``. The new years are added to *both* of these dimensions.
d. Missing data is calculated by interpolation.
e. For parameters with 2 year-related indices (e.g. ``output``), a final check is applied so ensure that the vintaging is correct. This step is done based on the lifetime of each technology.

5. The changes are committed and saved to the new scenario.

.. warning::
The tool does not ensure that the new scenario will solve after adding the
new years. The user needs to load the new scenario, check some key
parameters (like bounds) and solve the new scenario.

API reference
-------------

.. automodule:: message_ix.tools.add_year
:members:
Loading