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

Add data providers for SSP data #125

Merged
merged 56 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f3b1685
Add .util.pycountry.iso_3166_alpha_3()
khaeru Sep 13, 2023
1be7b06
Add .exo_data.iamc_like_data_for_query()
khaeru Sep 13, 2023
b0a4cf7
Add .project.ssp.data with a ExoDataSource for SSP data
khaeru Sep 13, 2023
16660b6
Generate synthetic SSP update data for testing
khaeru Sep 13, 2023
ac6aca4
Fall back to synthetic test data for SSPUpdate
khaeru Sep 13, 2023
d03c1ed
Don't package synthetic test data
khaeru Sep 13, 2023
caa9ad7
Add strict=True kwarg to exo_data.prepare_computer()
khaeru Sep 13, 2023
f6e8927
Add pyarrow to dependencies
khaeru Sep 13, 2023
2bb21ca
Force regions="R14" in test_ssp
khaeru Sep 13, 2023
df0c984
Use discard_on_error() to avoid locking in report()
khaeru Sep 14, 2023
4978a71
Add report function filter_ts()
khaeru Sep 14, 2023
a3ff944
Use default report config from message_ix_models
khaeru Sep 14, 2023
061f49e
Add .report.plot
khaeru Sep 14, 2023
3e16530
Add plotnine to mypy exclusions
khaeru Sep 14, 2023
05a877f
Tolerate mixed case column names in iamc_like_data_for_query()
khaeru Sep 15, 2023
0c7bbc7
Implement Plot.add_tasks()
khaeru Sep 15, 2023
9157f78
Add plotnine to "report" optional dependencies
khaeru Sep 15, 2023
b68361c
Add ScenarioInfo.{path,url}; convert to dataclass
khaeru Sep 18, 2023
8901661
Test ScenarioInfo.{path,url}
khaeru Sep 18, 2023
c44a8d8
Add a configuration class for .report settings
khaeru Sep 19, 2023
0d6335c
Add ScenarioInfo.from_url()
khaeru Sep 19, 2023
8994dc8
Store ScenarioInfo.platform_name when setting url
khaeru Sep 19, 2023
6f845cb
Add ScenarioInfo(…, empty=True) for fast creation
khaeru Sep 19, 2023
550b636
Ensure a .report.Config on every Context instance
khaeru Sep 19, 2023
98897df
Add ConfigHelper.update()
khaeru Sep 19, 2023
b25ed5d
Add .Config.scenarios
khaeru Sep 19, 2023
8c3f9d5
Add --urls-from-file common Click option
khaeru Sep 19, 2023
4649ba0
Adjust order in .report.register(); reduce verbosity
khaeru Sep 19, 2023
5170e44
Simplify .report and .report.cli using Config class
khaeru Sep 19, 2023
8251ec5
Update report docstrings
khaeru Sep 19, 2023
af7f352
Update report tests
khaeru Sep 19, 2023
76b7790
Update test of Context.__repr__
khaeru Sep 19, 2023
a8b923c
Handle no platform info in ScenarioInfo.url
khaeru Sep 19, 2023
a0e2c0f
Add equation and variable data from snapshot 0 for testing
khaeru Oct 11, 2023
d40906d
Gitignore output from pytest-profiling
khaeru Oct 11, 2023
b910d22
Test report.sim.add_simulated_solution()
khaeru Oct 11, 2023
b7d4b46
Use data from file in add_simulated_solution()
khaeru Oct 11, 2023
790859c
Read only parameter data in snapshot.read_excel()
khaeru Oct 11, 2023
35fd0e5
Handle index sets in sim.dims_of()
khaeru Oct 11, 2023
26bab30
Add SSPOriginal for 2017 SSP data
khaeru Oct 11, 2023
bd3180a
Raise a clearer exception in iamc_like_data_for_query
khaeru Oct 11, 2023
40d2d3a
Generate synthetic original SSP data for testing
khaeru Oct 11, 2023
0b2abdd
Add iamc_like_data_for_query(…, replace=)
khaeru Oct 12, 2023
cb12a8d
Update "mix-models ssp make-test-data"
khaeru Oct 12, 2023
e74f551
Mark add_simulated_solution() as not implemented for message_ix ≤ 3.5
khaeru Oct 12, 2023
fa1f3d9
Improve coverage in .report, .util
khaeru Oct 12, 2023
0e42d18
Document #125; add to whatsnew
khaeru Oct 13, 2023
25d6a0b
Make test_cli_techs() insensitive to trailing output
khaeru Oct 13, 2023
4e4376f
Add .report.sim to docs, whatsnew
khaeru Oct 13, 2023
41df7a6
Mark test_prepare_reporter per version compat
khaeru Oct 13, 2023
80464da
Work around python/mypy bug with unreleased fix
khaeru Oct 16, 2023
347d251
Work around #131
khaeru Oct 16, 2023
b675bce
Warn, don't raise for unknown exo_data measure
khaeru Oct 16, 2023
0d0ad68
Correct typo in SSPOriginal docstring
khaeru Oct 16, 2023
4cacde5
Make test_default_path_cb() insensitive to trailing output
khaeru Oct 16, 2023
6a0236d
Include parent in codelist_to_groups()
khaeru Oct 16, 2023
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reduce the number of merge conflicts
doc/whatsnew.rst merge=union
# Git LFS
*.csv.gz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.xlsx filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,21 @@ pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.benchmarks
.cache
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.nox/
.pytest_cache/
.ruff_cache
.tox/
*.cover
*.py,cover
coverage.xml
htmlcov/
nosetests.xml
/prof/

# Translations
*.mo
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
language: python
entry: bash -c ". ${PRE_COMMIT_MYPY_VENV:-/dev/null}/bin/activate 2>/dev/null; mypy $0 $@"
additional_dependencies:
- "mypy <1.5"
- mypy
- pytest
- sdmx1
- types-PyYAML
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
prune message_ix_models/data/test/MESSAGEix-GLOBIOM_1.1_R11_no-policy_baseline
prune message_ix_models/data/test/ssp
44 changes: 42 additions & 2 deletions doc/api/project.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.. currentmodule:: message_ix_models.project

Specific research projects (:mod:`.project`)
********************************************
Specific research projects (:mod:`~message_ix_models.project`)
**************************************************************

.. contents::
:local:
:backlinks: none

.. automodule:: message_ix_models.project
:members:
Expand All @@ -12,5 +16,41 @@ Specific research projects (:mod:`.project`)
Shared Socioeconomic Pathways (:mod:`.project.ssp`)
===================================================

Structure
---------

The enumerations :obj:`SSP_2017` and :obj:`SSP_2024` contain one member from the corresponding SDMX code lists.
These can be used to uniquely identify both an SSP narrative *and* the set in which it occurs, in applications where this distinction is meaningful:

.. code-block:: py

>>> from message_ix_models.project.ssp import SSP_2017, SSP_2024
>>> x = SSP_2017["2"]
>>> y = SSP_2024["2"]
>>> str(y)
"ICONICS:SSP(2024).2"
>>> x == y
False

.. automodule:: message_ix_models.project.ssp
:members:

Data
----

.. automodule:: message_ix_models.project.ssp.data
:members:

Although free, neither the 2017 or 2024 SSP data can be downloaded automatically.
Both sources require that users first submit personal information to register before being able to retrieve the data.
:mod:`message_ix_models` does not circumvent this requirement.
Thus:

- A copy of the data are stored in :mod:`message_data`.
- :mod:`message_ix_models` contains only a ‘fuzzed’ version of the data (same structure, random values) for testing purposes.

.. todo:: Allow users without access to :mod:`message_data` to read a local copy of this data from a :attr:`.Config.local_data` subdirectory.

.. autosummary::
SSPOriginal
SSPUpdate
28 changes: 25 additions & 3 deletions doc/api/report/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Not public:
Introduction
============

See :doc:`the discussion in the MESSAGEix docs <message_ix:reporting>` about the stack.
See :doc:`the discussion in the MESSAGEix docs <message-ix:reporting>` about the stack.
In short, :mod:`message_ix` must not contain reporting code that references ``coal_ppl``, because not every model built on the MESSAGE framework will have a technology with this name.
Any reporting specific to ``coal_ppl`` must be in :mod:`message_ix_models`, since all models in the MESSAGEix-GLOBIOM family will have this technology.

Expand Down Expand Up @@ -95,21 +95,35 @@ API reference

.. autosummary::

Config
prepare_reporter
register
report

.. currentmodule:: message_ix_models.report.plot

Plots
-----

.. automodule:: message_ix_models.report.plot
:members:

.. currentmodule:: message_ix_models.report.computations

Operators
---------

.. currentmodule:: message_ix_models.report.computations
.. automodule:: message_ix_models.report.computations
:members:

:mod:`message_ix_models.report.computations` provides the following:

.. autosummary::

codelist_to_groups
compound_growth
exogenous_data
filter_ts
from_url
get_ts
gwp_factors
Expand Down Expand Up @@ -158,7 +172,7 @@ Utilities


Command-line interface
----------------------
======================

.. currentmodule:: message_ix_models.report.cli
.. automodule:: message_ix_models.report.cli
Expand Down Expand Up @@ -192,3 +206,11 @@ Command-line interface
-o, --output PATH Write output to file instead of console.
--from-file FILE Report multiple Scenarios listed in FILE.
--help Show this message and exit.

Testing
=======


.. currentmodule:: message_ix_models.report.sim
.. automodule:: message_ix_models.report.sim
:members:
19 changes: 18 additions & 1 deletion doc/api/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,34 @@ Exogenous data (:mod:`.tools.exo_data`)

.. automodule:: message_ix_models.tools.exo_data
:members:
:exclude-members: ExoDataSource
:exclude-members: ExoDataSource, prepare_computer

.. autosummary::

MEASURES
SOURCES
DemoSource
ExoDataSource
iamc_like_data_for_query
prepare_computer
register_source

.. autofunction:: prepare_computer

The first returned key, like ``{measure}:n-y``, triggers the following computations:

1. Load data by invoking a :class:`ExoDataSource`.
2. Aggregate on the |n| (node) dimension according to :attr:`.Config.regions`.
3. Interpolate on the |y| (year) dimension according to :attr:`.Config.years`.

Additional key(s) include:

- ``{measure}:n-y:y0 indexed``: same as ``{measure}:n-y``, indexed to values as of |y0| (the first model year).

See particular data source classes, like :class:`.SSPOriginal`, for particular examples of usage.

.. todo:: Extend to also prepare to compute values indexed to a particular |n|.

.. autoclass:: ExoDataSource
:members:
:special-members: __init__, __call__
Expand Down
13 changes: 12 additions & 1 deletion doc/api/util.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Commonly used:

.. autodata:: message_ix_models.util.cache.SKIP_CACHE


:mod:`.util.click`
==================

Expand All @@ -66,6 +65,11 @@ Commonly used:
.. automodule:: message_ix_models.util.click
:members:

:data:`PARAMS` contains, among others:

- :program:`--urls-from-file=…` Path to a file containing scenario URLs, one per line.
These are parsed and stored on :attr:`.Config.scenarios`.

:mod:`.util.config`
===================

Expand Down Expand Up @@ -181,6 +185,13 @@ Commonly used:
.. automodule:: message_ix_models.util.pooch
:members:

:mod:`.util.pycountry`
======================

.. currentmodule:: message_ix_models.util.pycountry

.. automodule:: message_ix_models.util.pycountry
:members:

:mod:`.util.scenarioinfo`
=========================
Expand Down
7 changes: 7 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@
}

rst_prolog = """
.. role:: py(code)
:language: python

.. |Code| replace:: :class:`~sdmx.model.common.Code`
.. |Platform| replace:: :class:`~ixmp.Platform`
.. |Scenario| replace:: :class:`~message_ix.Scenario`

.. |n| replace:: :math:`n`
.. |y| replace:: :math:`y`
.. |y0| replace:: :math:`y_0`
"""


Expand Down
21 changes: 19 additions & 2 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
What's new
**********

.. Next release
.. ============
Next release
============

- New providers for exogenous data from the :class:`.SSPOriginal` and :class:`.SSPUpdate` (:pull:`125`) sources.
- Improved :class:`.ScenarioInfo` (:pull:`125`):

- New attributes :attr:`~.ScenarioInfo.model`, :attr:`~.ScenarioInfo.scenario`, :attr:`~.ScenarioInfo.version`, and (settable) :attr:`~.ScenarioInfo.url`; class method :meth:`~.ScenarioInfo.from_url` to allow storing |Scenario| identifiers on ScenarioInfo objects.
- New property :attr:`~.ScenarioInfo.path`, giving a valid path name for scenario-specific file I/O.

- Improvements to :mod:`~message_ix_models.report` (:pull:`125`):

- New :class:`.report.Config` class collecting recognized settings for the module.
- :py:`context["report"]` always exists as an instance of :class:`.report.Config`.
- New submodule :class:`.report.plot` with base class and 5 plots of time-series data stored on Scenarios.
- Submodule :class:`.report.sim` provides :func:`add_simulated_solution` for testing reporting configuration.
- New operator :func:`.filter_ts`.

- New reusable command-line option :program:`--urls-from-file` in :mod:`.util.click` (:pull:`125`).
- Add `pyarrow <https://pypi.org/project/pyarrow/>`_ to dependencies (:pull:`125`).

v2023.9.12
==========
Expand Down
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Loading
Loading