Skip to content

Commit 3c589c0

Browse files
committed
Update docs, docstrings for #259; add to whatsnew
1 parent 2acaf26 commit 3c589c0

File tree

10 files changed

+118
-13
lines changed

10 files changed

+118
-13
lines changed

doc/api/util.rst

+9
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ Submodules:
1010

1111
click
1212
context
13+
genno
1314
importlib
1415
_logging
1516
node
1617
pooch
18+
pycountry
1719
scenarioinfo
1820
sdmx
1921

@@ -158,6 +160,13 @@ Commonly used:
158160

159161
If no base scenario can be loaded, :func:`.bare.create_res` is called to generate a base scenario.
160162

163+
:mod:`.util.genno`
164+
==================
165+
166+
.. currentmodule:: message_ix_models.util.genno
167+
168+
.. automodule:: message_ix_models.util.genno
169+
:members:
161170

162171
:mod:`.util.importlib`
163172
======================

doc/project/ssp.rst

+17
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,20 @@ Transport
5454
:members:
5555

5656
Use :program:`mix-models ssp transport --help in.xlsx out.xlsx` to invoke :func:`.main`.
57+
Data are read from PATH_IN, in :file:`.xlsx` or :file:`.csv` format.
58+
If :file:`.xlsx`, the data are first temporarily converted to :file:`.csv`.
59+
Data are written to PATH_OUT; if not given, this defaults to the same path and suffix as PATH_IN, with "_out" added to the stem.
60+
61+
For example:
62+
63+
.. code-block:: shell
64+
65+
mix-models ssp transport --method=B \
66+
SSP_SSP2_v2.1_baseline.xlsx
67+
68+
…produces a file :file:`SSP_SSP2_v2.1_baseline_out.xlsx` in the same directory.
69+
70+
As of 2025-01-25:
71+
72+
- Method 'B' (that is, :func:`.prepare_method_B`; see its documentation) is the preferred method.
73+
- The code is tested on :file:`.xlsx` files in the (internal) directories under `SharePoint > ECE > Documents > SharedSocioeconomicPathways2023 > Scenario_Vetting <https://iiasahub.sharepoint.com/sites/eceprog/Shared%20Documents/Forms/AllItems.aspx?csf=1&web=1&e=APKv0Z&CID=23fa0a51%2Dc303%2D4381%2D8c6d%2D143305cbc5a1&FolderCTID=0x012000AA9481BF7BE9264E85B14105F7F082FF&id=%2Fsites%2Feceprog%2FShared%20Documents%2FSharedSocioEconomicPathways2023%2FScenario%5FVetting&viewid=956acd8a%2De1e7%2D4ae9%2Dab1b%2D0506911bae11>`_, for example :file:`v2.1_Internal_version_Dec13_2024/Reporting_output/SSP_SSP2_v2.1_baseline.xlsx`.

doc/transport/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Run the entire workflow
142142
The options result in the following behaviour:
143143

144144
- :program:`--platform=ixmp-dev`: store MESSAGEix-Transport scenarios on the :mod:`ixmp` platform named "ixmp-dev".
145-
- :program:`--base=auto`: identify the base scenario URLs using :func:`.base_scenario_url` / the file :file:`base-scenario-url.json`, according to other config settings.
145+
- :program:`--base=auto`: identify the base scenario URLs using :func:`.base_scenario_url` / the file :ref:`CL_TRANSPORT_SCENARIO`, according to other config settings.
146146
- :program:`--model-extra="ci nightly"`: append the string " ci nightly" to the model name of any created Scenario.
147147
This avoids accidentally producing new versions of ‘production’ (model name, scenario name) combinations.
148148
- :program:`--from=""`: start from the very first step in the workflow—load the identified base scenario—and perform all subsequent workflow steps, up to and including…

doc/transport/input.rst

+49-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ This value is retrieved from the :attr:`.model.Config.regions` setting on a :cla
2020

2121
.. _transport-config:
2222

23-
Configuration
24-
=============
23+
Configuration and model structure
24+
=================================
2525

2626
General (:file:`config.yaml`, required)
2727
---------------------------------------
@@ -50,13 +50,45 @@ This file gives code lists for other MESSAGE concepts/sets/dimensions.
5050

5151
→ View :source:`message_ix_models/data/transport/set.yaml` on GitHub
5252

53+
.. _CL_TRANSPORT_SCENARIO:
54+
55+
Code list ``CL_TRANSPORT_SCENARIO``
56+
-----------------------------------
57+
58+
This code list, stored in the file :file:`message_ix_models/data/sdmx/IIASA_ECE_CL_TRANSPORT_SCENARIO(1.0.0).xml`, contains an SDMX code list for distinct MESSAGEix-Transport scenarios.
59+
The codes have IDs like ``LED-SSP1`` that give a short identifier used in :mod:`.transport.workflow` and elsewhere, and names that give a complete, human-readable description.
60+
Every code has all of following annotations:
61+
62+
``SSP-URN``
63+
Complete URN of a code in ``ICONICS:SSP(2024)`` or another code list for the SSP used for sociodemographic input data and to control other settings in :mod:`.transport.build`.
64+
65+
Example annotation text: ``'urn:sdmx:org.sdmx.infomodel.codelist.Code=ICONICS:SSP(2024).1'``
66+
67+
``is-LED-Scenario``
68+
Example annotation text: ``True``
69+
70+
:func:`repr` of Python :any:`True` or :any:`False`, the former indicating that "Low Energy Demand (LED)" settings should be used.
71+
See also :attr:`Config.project <.transport.config.Config.project>`.
72+
73+
``EDITS-activity-id``
74+
Example annotation text: ``'HA'``
75+
76+
For :doc:`/project/edits`, the identity of an ITF PASTA scenario providing exogenous transport activity.
77+
78+
``base-scenario-URL``
79+
Example annotation text: ``'ixmp://ixmp-dev/SSP_SSP1_v1.1/baseline_DEFAULT_step_13'``
80+
81+
URL of a base scenario used to build the corresponding MESSAGEix-Transport scenario.
82+
83+
5384
.. _transport-data-files:
5485

5586
Input data files
5687
================
5788

5889
:data:`.transport.files.FILES` gives a list of all data files.
59-
Through :func:`.transport.build.main` (ultimately, :func:`.transport.build.add_exogenous_data`), each of these files is connected to a :class:`genno.Computer` used for model-building, and its contents appear at the key given in the list below.
90+
Through :func:`.transport.build.main` (ultimately, :func:`.transport.build.add_exogenous_data`), each of these files is connected to a :class:`genno.Computer` used for model-building.
91+
Its content are available at the corresponding key, which is used as an input for further model-building computations.
6092

6193
.. admonition:: Example
6294

@@ -67,9 +99,22 @@ Through :func:`.transport.build.main` (ultimately, :func:`.transport.build.add_e
6799
Not all files are currently or always used in model-building computations.
68100
Some submodules of :mod:`~.model.transport` use additional data files via other mechanisms.
69101
Most of the files have a header comment including a precise description of the quantity, source of the data, and units of measurement.
70-
In some cases extended information is below (where a header comment would be too long).
102+
In some caseswhere a header comment would be too long—extended information is below.
71103
The :program:`git` history of files, or the GitHub "blame" view can also be used to inspect the edit history of each file, line by line.
72104

105+
.. _transport-input-emi-intensity:
106+
107+
:file:`emi-intensity.csv` → ``emissions intensity:t-c-e:transport``
108+
-------------------------------------------------------------------
109+
110+
Measure
111+
Emissions intensity of energy use
112+
Units
113+
g (of emissions species) / MJ (of input energy)
114+
115+
See the file :source:`on GitHub <message_ix_models/data/transport/emi-intensity.csv>` for inline comments and commit history.
116+
Currently only used in :mod:`.ssp.transport`.
117+
73118
:file:`ldv-activity.csv` → ``ldv activity:n:exo``
74119
-------------------------------------------------
75120

doc/whatsnew.rst

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
What's new
22
**********
33

4-
.. Next release
5-
.. ============
4+
Next release
5+
============
6+
7+
- Update :class:`.IEA_EWEB` to support :py:`transform="B"` / :func:`.transform_B` (:issue:`230`, :pull:`259`).
8+
- Update :doc:`/transport/index` (:pull:`259`).
9+
10+
- Adjust constraints on :py:`t="conm_ar"`.
11+
- Recompute :attr:`.minimum_activity` for transport technologies.
12+
- Adjust freight activity, freight and passenger mode shares for some regions.
13+
- Drop :file:`base-scenario-url.json`; store base scenario URLs in :ref:`CL_TRANSPORT_SCENARIO`.
14+
- Simplify and consolidate tests.
15+
16+
- Add :func:`.prepare_method_B` to :mod:`.ssp.transport` (:pull:`259`).
17+
- New utility :class:`.sdmx.AnnotationsMixIn` (:pull:`259`).
618

719
v2025.1.10
820
==========

message_ix_models/model/transport/files.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Input data flows for MESSAGEix-Transport, read from CSV files.
2+
3+
See :ref:`transport-data-files` for documentation of the data flows in :data:`FILES`.
4+
"""
5+
16
import logging
27
from functools import lru_cache
38
from pathlib import Path

message_ix_models/project/ssp/transport.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,20 @@ def prepare_method_B(
338338
1. From the :class:`.IEA_EWEB` 2024 edition, select data for :math:`y = 2019` and
339339
the :data:`FLOWS`.
340340
2. Aggregate IEA EWEB to align with MESSAGEix-GLOBIOM |c|.
341-
3. Reverse the sign of flow=AVBUNK; these values are negative in the source data.
341+
3. Reverse the sign of values for flow=AVBUNK. These are negative in the source
342+
data, but their absolute value must be added to values for flow=DOMESAIR.
342343
4. Compute the ratio :math:`(AVBUNK + DOMESAIR) / TOTTRANS`, the share of aviation
343344
in final energy.
344345
5. From the input data (`k_input`), select the values matching :data:`EXPR_FE`, that
345346
is, final energy use by aviation.
346-
6. Load emissions intensity of aviation final energy use :file:`emi-intensity.csv` /
347-
:data:`emi_intensity`.
347+
6. Load emissions intensity of aviation final energy use from the file
348+
:ref:`transport-input-emi-intensity`.
348349
7. Multiply (4) × (5) × (6) to compute the estimate of
349350
``Emissions|*|Energy|Demand|Transportation|Aviation``.
350-
8. Subtract (7) from:
351-
``Emissions|*|Energy|Demand|Transportation|Road Rail and Domestic Shipping``.
351+
8. Estimate
352+
``Emissions|*|Energy|Demand|Transportation|Road Rail and Domestic Shipping`` as
353+
the negative of (7).
354+
9. Adjust `k_emi_in` by adding (7) and (8).
352355
"""
353356
from message_ix_models.model.transport import build
354357
from message_ix_models.model.transport import files as exo

message_ix_models/types.py

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525

2626
class MaintainableArtefactArgs(TypedDict):
27+
"""Some keyword arguments to :class:`sdmx.model.common.MaintainableArtefact`."""
28+
2729
is_external_reference: Optional[bool]
2830
is_final: Optional[bool]
2931
maintainer: Any

message_ix_models/util/genno.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def insert(c: "Computer", key: "KeyLike", operation, tag: str = "pre") -> "KeyLi
3030
3131
It is also possible to insert `operation` that mutates its input in certain ways.
3232
33-
.. todo:: Migrate to :py:`genno.Computer.insert()`.
33+
.. todo:: Migrate to :py:`genno.Computer.insert()` or similar.
3434
3535
Returns
3636
-------

message_ix_models/util/sdmx.py

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ class AnnotationsMixIn:
3737

3838
# TODO Type with overrides: list → list
3939
def get_annotations(self, _rtype: Union[type[list], type[dict]]):
40+
"""Return a collection of :class:`.Annotation` for the fields of the object.
41+
42+
Returns
43+
-------
44+
list of :class:`Annotation <sdmx.model.common.Annotation>`
45+
if `_rtype` is :class:`list`.
46+
dict
47+
if `_rtype` is :class:`dict`. The dict has the one key "annotations", mapped
48+
to a :class:`list` of Annotations. This can be used as a keyword argument
49+
to the constructor of a :class:`.AnnotableArtefact` subclass.
50+
"""
4051
result = []
4152
for f in fields(self):
4253
anno_id = f.name.replace("_", "-")
@@ -51,6 +62,7 @@ def get_annotations(self, _rtype: Union[type[list], type[dict]]):
5162

5263
@classmethod
5364
def from_obj(cls: type["Self"], obj: common.AnnotableArtefact) -> "Self":
65+
"""Return a new instance of `cls` given an AnnotableArtefact `obj`."""
5466
args = []
5567
for f in fields(cls):
5668
anno_id = f.name.replace("_", "-")

0 commit comments

Comments
 (0)