Skip to content

Commit 32f5405

Browse files
committed
Merge branch 'nexus-upd' of https://github.com/iiasa/message-ix-models into nexus-upd
2 parents 04b2254 + 15ccb54 commit 32f5405

File tree

266 files changed

+30701
-2338
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+30701
-2338
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Reduce the number of merge conflicts
22
doc/whatsnew.rst merge=union
33
# Git LFS
4-
*.csv.gz filter=lfs diff=lfs merge=lfs -text
4+
*.gz filter=lfs diff=lfs merge=lfs -text
55
*.xlsx filter=lfs diff=lfs merge=lfs -text
6+
*.xz filter=lfs diff=lfs merge=lfs -text
67
*.zip filter=lfs diff=lfs merge=lfs -text

.github/workflows/pytest.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ jobs:
6262
version: 25.1.1
6363
license: ${{ secrets.GAMS_LICENSE }}
6464

65+
- uses: ts-graphviz/setup-graphviz@v1
66+
with:
67+
macos-skip-brew-update: true
68+
6569
- name: Install packages and dependencies
6670
# By default, install:
6771
# - ixmp, message_ix: from GitHub branches/tags per matrix.upstream-version (above)
@@ -93,12 +97,6 @@ jobs:
9397
--local-cache --jvmargs="-Xmx6G"
9498
shell: bash
9599

96-
- name: Test documentation build using Sphinx
97-
if: startsWith(matrix.version.os, 'ubuntu')
98-
env:
99-
RTD_TOKEN_MESSAGE_DATA: ${{ secrets.RTD_TOKEN_MESSAGE_DATA }}
100-
run: make --directory=doc SPHINXOPTS="-n --color" html
101-
102100
- name: Upload test coverage to Codecov.io
103101
uses: codecov/codecov-action@v3
104102

@@ -110,6 +108,7 @@ jobs:
110108
steps:
111109
- uses: actions/checkout@v3
112110
- uses: actions/setup-python@v4
111+
with: { python-version: "3.11" }
113112

114113
- name: Force recreation of pre-commit virtual environment for mypy
115114
if: github.event_name == 'schedule' # Comment this line to run on a PR

.gitignore

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,21 @@ pip-log.txt
3838
pip-delete-this-directory.txt
3939

4040
# Unit test / coverage reports
41-
htmlcov/
42-
.tox/
43-
.nox/
4441
.benchmarks
42+
.cache
4543
.coverage
4644
.coverage.*
47-
.cache
48-
nosetests.xml
49-
coverage.xml
50-
*.cover
51-
*.py,cover
5245
.hypothesis/
46+
.nox/
5347
.pytest_cache/
5448
.ruff_cache
49+
.tox/
50+
*.cover
51+
*.py,cover
52+
coverage.xml
53+
htmlcov/
54+
nosetests.xml
55+
/prof/
5556

5657
# Translations
5758
*.mo
@@ -71,7 +72,7 @@ instance/
7172
.scrapy
7273

7374
# Sphinx documentation
74-
doc/_autosummary/
75+
doc/**/_autosummary/
7576
doc/_build/
7677
doc/*.inv
7778

@@ -138,6 +139,8 @@ dmypy.json
138139
# Generated and temporary data files
139140
debug/
140141
cache/
142+
# LibreOffice lock files
143+
.~lock*#
141144

142145
# VSCode settings
143146
.vscode

.pre-commit-config.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@ repos:
1010
language: python
1111
entry: bash -c ". ${PRE_COMMIT_MYPY_VENV:-/dev/null}/bin/activate 2>/dev/null; mypy $0 $@"
1212
additional_dependencies:
13-
- "mypy <1.5"
13+
- mypy >= 1.8.0
14+
- plotnine
1415
- pytest
1516
- sdmx1
1617
- types-PyYAML
1718
- types-tqdm
1819
- "ixmp @ git+https://github.com/iiasa/ixmp.git@main"
1920
- "message-ix @ git+https://github.com/iiasa/message_ix.git@main"
2021
args: ["."]
21-
- repo: https://github.com/psf/black-pre-commit-mirror
22-
rev: 23.7.0
23-
hooks:
24-
- id: black
2522
- repo: https://github.com/astral-sh/ruff-pre-commit
26-
rev: v0.0.287
23+
rev: v0.1.13
2724
hooks:
2825
- id: ruff
26+
- id: ruff-format
27+
args: [ --check ]

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
prune message_ix_models/data/test/advance
2+
prune message_ix_models/data/test/iea
13
prune message_ix_models/data/test/MESSAGEix-GLOBIOM_1.1_R11_no-policy_baseline
4+
prune message_ix_models/data/test/ssp
5+
prune message_ix_models/data/water/*
6+
exclude message_ix_models/data/water/*.tar.xz

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ See the `online documentation <https://docs.messageix.org/projects/models/>`_ fo
2525
License
2626
=======
2727

28-
Copyright © 2020–2023 IIASA Energy, Climate, and Environment (ECE) program
28+
Copyright © 2020–2024 IIASA Energy, Climate, and Environment (ECE) program
2929

3030
Licensed under the Apache License, version 2.0.

doc/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ BUILDDIR = _build
1212
help:
1313
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1414

15-
.PHONY: help Makefile
15+
clean-autosummary:
16+
find . -name "$(BUILDDIR)" -prune -o -iname _autosummary -print0 | xargs -0 rm -rf
17+
18+
.PHONY: help clean-autosummary Makefile
1619

1720
# Catch-all target: route all unknown targets to Sphinx using the new
1821
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19-
%: Makefile
22+
.DEFAULT: Makefile
2023
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

doc/api/data-sources.rst

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
Tools for specific data sources
2+
*******************************
3+
4+
.. _tools-iea:
5+
6+
International Energy Agency (IEA) (:mod:`.tools.iea`)
7+
=====================================================
8+
9+
The IEA publishes many kinds of data.
10+
Each distinct data source is handled by a separate submodule of :mod:`message_ix_models.tools.iea`.
11+
12+
Documentation for all module contents:
13+
14+
.. currentmodule:: message_ix_models.tools
15+
16+
.. autosummary::
17+
:toctree: _autosummary
18+
:template: autosummary-module.rst
19+
:recursive:
20+
21+
iea
22+
23+
.. _tools-iea-web:
24+
25+
(Extended) World Energy Balances (:mod:`.tools.iea.web`)
26+
--------------------------------------------------------
27+
28+
.. contents::
29+
:local:
30+
:backlinks: none
31+
32+
.. note:: These data are **proprietary** and require a paid subscription.
33+
34+
The approach to handling proprietary data is the same as in :mod:`.project.advance` and :mod:`.project.ssp`:
35+
36+
- Copies of the data are stored in the (private) :mod:`message_data` repository using Git LFS.
37+
This respository is accessible only to users who have a license for the data.
38+
- :mod:`message_ix_models` contains only a ‘fuzzed’ version of the data (same structure, random values) for testing purposes.
39+
- Non-IIASA users must obtain their own license to access and use the data; obtain the data themselves; and place it on the system where they use :mod:`message_ix_models`.
40+
41+
The module :mod:`message_ix_models.tools.iea.web` attempts to detect and support both the providers/formats described below.
42+
The code supports using data from any of the above locations and formats, in multiple ways:
43+
44+
- Use :func:`.tools.iea.web.load_data` to load data as :class:`pandas.DataFrame` and apply further pandas processing.
45+
- Use :class:`.IEA_EWEB` via :func:`.tools.exo_data.prepare_computer` to use the data in :mod:`genno` structured calculations.
46+
47+
The **documentation** for the `2023 edition <https://iea.blob.core.windows.net/assets/0acb1453-1221-421b-9131-632ce71a4c1a/WORLDBAL_Documentation.pdf>`__ of the IEA source/format is publicly available.
48+
49+
Structure
50+
~~~~~~~~~
51+
52+
The data have the following conceptual dimensions, each enumerated by a different list of codes:
53+
54+
- ``FLOW``, ``PRODUCT``: for both of these, the lists of codes appearing in the data are the same from 2021 and 2023 inclusive.
55+
- ``COUNTRY``: The data provided by IEA directly contain codes that are all caps, abbreviated country names, for instance "DOMINICANR".
56+
The data provided by the OECD contain ISO 3166-1 alpha-3 codes, for instance "DOM".
57+
In both cases, there are additional labels denoting country groupings; these are defined in the documentation linked above.
58+
59+
Changes visible in these lists include:
60+
61+
- 2022 → 2023:
62+
63+
- New codes: ASEAN, BFA, GREENLAND, MALI, MRT, PSE, TCD.
64+
- Removed: MASEAN.
65+
66+
- 2021 → 2022:
67+
68+
- New codes: GNQ, MDG, MKD, RWA, SWZ, UGA.
69+
- Removed: EQGUINEA, GREENLAND, MALI, MBURKINAFA, MCHAD, MMADAGASCA, MMAURITANI, MPALESTINE, MRWANDA, MUGANDA, NORTHMACED.
70+
71+
- TIME: always a year.
72+
- MEASURE: unit of measurement, either "TJ" or "ktoe".
73+
74+
:mod:`message_ix_models` is packaged with SDMX structure data (stored in :file:`message_ix_models/data/sdmx/`) comprising code lists extracted from the raw data for the COUNTRY, FLOW, and PRODUCT dimensions.
75+
These can be used with other package utilities, for instance:
76+
77+
.. code-block:: python
78+
79+
>>> from message_ix_models.util.sdmx import read
80+
81+
# Read a code list from file: codes used in the
82+
# 2022 edition data from the OECD provider
83+
>>> cl = read("IEA:PRODUCT_OECD(2022)")
84+
85+
# Show some of its elements
86+
>>> print("\n".join(sorted(cl.items[:5])))
87+
ADDITIVE
88+
ANTCOAL
89+
AVGAS
90+
BIODIESEL
91+
BIOGASES
92+
93+
The documentation linked above has full descriptions of each code.
94+
95+
IEA provider/format
96+
~~~~~~~~~~~~~~~~~~~
97+
98+
From 2023 (or earlier), the data are provided directly on the IEA website at https://www.iea.org/data-and-statistics/data-product/world-energy-balances.
99+
These data are available in two formats; ‘IVT’ or “Beyond 20/20” format (not supported by this module) or fixed-width text files.
100+
The latter are characterized by:
101+
102+
- Multiple ZIP archives with names like :file:`WBIG[12].zip`, each containing a portion of the data and typically 110–130 MiB compressed size
103+
- …each containing a single, fixed-with TXT file with a name like :file:`WORLDBIG[12].TXT`, typically 3–4 GiB uncompressed,
104+
- …with no column headers, but data resembling::
105+
106+
WORLD HARDCOAL 1960 INDPROD KTOE ..
107+
108+
…that appear to correspond to, respectively, the COUNTRY, PRODUCT, TIME, FLOW, and MEASURE dimensions and "Value" column of the above data, respectively.
109+
110+
OECD provider/format
111+
~~~~~~~~~~~~~~~~~~~~
112+
113+
Up until 2023, the EWEB data were available from the OECD iLibrary with DOI `10.1787/enestats-data-en <https://doi.org/10.1787/enestats-data-en>`__.
114+
These files were characterized by:
115+
116+
- Single ZIP archives with names like :file:`cac5fa90-en.zip`; typically ~850 MiB compressed size,
117+
- …containing a single CSV file with a name like :file:`WBIG_2022-2022-1-EN-20230406T100006.csv`, typically >20 GiB uncompressed,
118+
- …with a particular list of columns like: "MEASURE", "Unit", "COUNTRY", "Country", "PRODUCT", "Product", "FLOW", "Flow", "TIME", "Time", "Value", "Flag Codes", "Flags",
119+
- …with contents that duplicated code IDs—for instance, in the "FLOW" column—with human-readable labels—for instance in the "Flow" column:
120+
121+
============ ===
122+
Column name Example value
123+
============ ===
124+
MEASURE [1]_ KTOE
125+
Unit ktoe
126+
COUNTRY WLD
127+
Country World
128+
PRODUCT COAL
129+
Product Coal and coal products
130+
FLOW INDPROD
131+
Flow Production
132+
TIME 2012
133+
Time 2012
134+
Value 1234.5678
135+
Flag Codes M
136+
Flags Missing value; data cannot exist
137+
============ ===
138+
139+
.. [1] the column is sometimes labelled "UNIT", but the contents appear to be the same.
140+
141+
This source is discontinued and will not publish subsequent editions of the data.

doc/api/model-snapshot.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Usage
1010

1111
From the command line, download data for a single snapshot::
1212

13-
$ mix-models snapshot fetch 0
13+
$ mix-models fetch snapshot-0
1414

1515
…where :program:`0` is the ID of a snapshot; see :data:`.SNAPSHOTS`.
1616

@@ -25,7 +25,7 @@ In code, use :func:`.snapshot.load`:
2525
2626
snapshot.load(scenario, 0)
2727
28-
.. note:: For snapshot 0, contrary to the `description of the Zenodo item <https://10.5281/zenodo.5793870>`__, the file cannot be loaded using :meth:`.Scenario.read_excel`.
28+
.. note:: For snapshot 0, contrary to the `description of the Zenodo item <https://doi.org/10.5281/zenodo.5793870>`__, the file cannot be loaded using :meth:`.Scenario.read_excel`.
2929
This limitation will be fixed in subsequent snapshots.
3030

3131
Code reference

doc/api/project.rst

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,73 @@
11
.. currentmodule:: message_ix_models.project
22

3-
Specific research projects (:mod:`.project`)
4-
********************************************
3+
Specific research projects (:mod:`~message_ix_models.project`)
4+
**************************************************************
5+
6+
.. contents::
7+
:local:
8+
:backlinks: none
59

610
.. automodule:: message_ix_models.project
711
:members:
812

13+
.. currentmodule:: message_ix_models.project.advance
14+
15+
ADVANCE (:mod:`.project.advance`)
16+
=================================
17+
18+
.. automodule:: message_ix_models.project.advance
19+
20+
.. automodule:: message_ix_models.project.advance.data
21+
:members:
22+
23+
Although free of charge, the ADVANCE data can not be downloaded automatically.
24+
This source requires that users first submit personal information to register before being able to retrieve the data.
25+
:mod:`message_ix_models` does not circumvent this requirement.
26+
Thus:
27+
28+
- A copy of the data are stored in :mod:`message_data`.
29+
- :mod:`message_ix_models` contains only a ‘fuzzed’ version of the data (same structure, random values) for testing purposes.
930

1031
.. currentmodule:: message_ix_models.project.ssp
1132

1233
Shared Socioeconomic Pathways (:mod:`.project.ssp`)
1334
===================================================
1435

36+
Structure
37+
---------
38+
39+
The enumerations :obj:`SSP_2017` and :obj:`SSP_2024` contain one member from the corresponding SDMX code lists.
40+
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:
41+
42+
.. code-block:: py
43+
44+
>>> from message_ix_models.project.ssp import SSP_2017, SSP_2024
45+
>>> x = SSP_2017["2"]
46+
>>> y = SSP_2024["2"]
47+
>>> str(y)
48+
"ICONICS:SSP(2024).2"
49+
>>> x == y
50+
False
51+
1552
.. automodule:: message_ix_models.project.ssp
1653
:members:
54+
55+
Data
56+
----
57+
58+
.. automodule:: message_ix_models.project.ssp.data
59+
:members:
60+
61+
Although free of charge, neither the 2017 or 2024 SSP data can be downloaded automatically.
62+
Both sources require that users first submit personal information to register before being able to retrieve the data.
63+
:mod:`message_ix_models` does not circumvent this requirement.
64+
Thus:
65+
66+
- A copy of the data are stored in :mod:`message_data`.
67+
- :mod:`message_ix_models` contains only a ‘fuzzed’ version of the data (same structure, random values) for testing purposes.
68+
69+
.. todo:: Allow users without access to :mod:`message_data` to read a local copy of this data from a :attr:`.Config.local_data` subdirectory.
70+
71+
.. autosummary::
72+
SSPOriginal
73+
SSPUpdate

0 commit comments

Comments
 (0)