Skip to content

Commit d03db33

Browse files
authored
Merge pull request #349 from iiasa/transport/2025-w20
Transport improvements from 2025-W20
2 parents 6b3089e + 145ba3e commit d03db33

File tree

120 files changed

+6058
-2529
lines changed

Some content is hidden

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

120 files changed

+6058
-2529
lines changed

doc/api/tools.rst

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,70 +30,76 @@ Exogenous data (:mod:`.tools.exo_data`)
3030
:members:
3131
:exclude-members: ExoDataSource, prepare_computer
3232

33+
The tools in this module support use of data from arbitrary sources and formats in model-building code.
34+
For each source/format, a subclass of :class:`.ExoDataSource` adds tasks to a :class:`genno.Computer`
35+
that retrieve/load and transform the source data into :class:`genno.Quantity`.
36+
37+
An example using one such class, :class:`message_ix_models.project.advance.data.ADVANCE`.
38+
39+
.. code-block:: python
40+
41+
from genno import Computer
42+
43+
from message_ix_models.project.advance.data import ADVANCE
44+
45+
# Keyword arguments corresponding to ADVANCE.Options
46+
kw = dict(
47+
measure="Transport|Service demand|Road|Passenger|LDV",
48+
model="MESSAGE",
49+
scenario="ADV3TRAr2_Base",
50+
)
51+
52+
# Add tasks to retrieve and transform data
53+
c = Computer()
54+
keys = c.apply(ADVANCE, context=context, **kw)
55+
56+
# Retrieve some of the data
57+
q_result = c.get(keys[0])
58+
59+
# Pass the data into further calculations
60+
c.add("derived", "mul", keys[1], k_other)
61+
3362
.. autosummary::
3463

3564
MEASURES
3665
SOURCES
66+
BaseOptions
3767
DemoSource
3868
ExoDataSource
69+
add_structure
3970
iamc_like_data_for_query
4071
prepare_computer
4172
register_source
4273

43-
.. autofunction:: prepare_computer
44-
45-
The first returned key, like ``{measure}:n-y``, triggers the following computations:
46-
47-
1. Load data by invoking a :class:`ExoDataSource`.
48-
2. Aggregate on the |n| (node) dimension according to :attr:`.Config.regions`.
49-
3. Interpolate on the |y| (year) dimension according to :attr:`.Config.years`.
50-
51-
Additional key(s) include:
52-
53-
- ``{measure}:n-y:y0 indexed``: same as ``{measure}:n-y``, indexed to values as of |y0| (the first model year).
54-
55-
See particular data source classes, like :class:`.SSPOriginal`, for particular examples of usage.
56-
57-
.. todo:: Extend to also prepare to compute values indexed to a particular |n|.
58-
5974
.. autoclass:: ExoDataSource
6075
:members:
6176
:private-members: _where
62-
:special-members: __init__, __call__
63-
64-
.. currentmodule:: message_ix_models.tools.advance
77+
:special-members: __init__
6578

66-
ADVANCE data (:mod:`.tools.advance`)
67-
====================================
68-
69-
.. deprecated:: 2023.11
70-
Use :mod:`.project.advance` instead.
71-
72-
.. autosummary::
73-
get_advance_data
74-
advance_data
79+
As an abstract class ExoDataSource **must** be subclassed to be used.
80+
Concrete subclasses **must** implement at least the :meth:`~ExoDataSource.get` method
81+
that performs the loading of the raw data when executed,
82+
and **may** override others, as described below.
7583

76-
.. autodata:: LOCATION
84+
The class method :meth:`.ExoDataSource.add_tasks` adds tasks to a :class:`genno.Computer`.
85+
It returns a :class:`genno.Key` that refers to the loaded and transformed data.
86+
This method usually **should not** be modified for subclasses.
7787

78-
This is a location relative to a parent directory.
79-
The specific parent directory depends on whether :mod:`message_data` is available:
88+
The behaviour of a subclass can be customized in these ways:
8089

81-
Without :mod:`message_data`:
82-
The code finds the data within :ref:`local-data` (see discussion there for how to configure this location).
83-
Users should:
90+
1. Create a subclass of :class:`.BaseOptions`
91+
and set it as the :attr:`~.ExoDataSource.Options` class attribute.
92+
2. Override :meth:`~.ExoDataSource.__init__`,
93+
which receives keyword arguments via :meth:`.add_tasks`.
94+
3. Override :meth:`~.ExoDataSource.transform`,
95+
which is called to add further tasks which will transform the data.
8496

85-
1. Visit https://tntcat.iiasa.ac.at/ADVANCEWP2DB/dsd?Action=htmlpage&page=about and register for access to the data.
86-
2. Log in.
87-
3. Download the snapshot with the file name given in :data:`LOCATION` to a subdirectory :file:`advance/` within their local data directory.
97+
See the documentation for these methods and attributes for further details.
8898

89-
With :mod:`message_data`:
90-
The code finds the data within :ref:`private-data`.
91-
The snapshot is stored directly in the repository using Git LFS.
99+
.. autofunction:: prepare_computer
92100

93-
.. automodule:: message_ix_models.tools.advance
94-
:members:
95-
:exclude-members: LOCATION
96-
:private-members:
101+
.. deprecated:: 2025-06-06
102+
Use :py:`c.apply(SOURCE.add_tasks, …)` as shown above.
97103

98104
.. currentmodule:: message_ix_models.tools.iamc
99105

@@ -103,6 +109,14 @@ IAMC data structures (:mod:`.tools.iamc`)
103109
.. automodule:: message_ix_models.tools.iamc
104110
:members:
105111

112+
.. currentmodule:: message_ix_models.tools.policy
113+
114+
Policies (:mod:`.tools.policy`)
115+
===============================
116+
117+
.. automodule:: message_ix_models.tools.policy
118+
:members:
119+
106120
.. _tools-wb:
107121

108122
World Bank structures (:mod:`.tools.wb`)

doc/whatsnew.rst

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,75 @@ Next release
77
- Update :mod:`.add_AFOLU_CO2_accounting`
88
and :mod:`.add_alternative_TCE_accounting`
99
for |ssp-scenariomip| (:pull:`354`).
10+
- New module :mod:`.tools.policy` for representing ‘policy’ information (:pull:`349`).
1011
- New workflow step :func:`.model.workflow.step_0` (:pull:`354`).
12+
13+
By topic:
14+
15+
.. contents::
16+
:local:
17+
:backlinks: none
18+
19+
Base model and variants
20+
-----------------------
21+
22+
- Add ``TCE`` to :ref:`emission-yaml` (:pull:`349`).
23+
- Add 9 ``*_bunker`` technologies to :ref:`technology-yaml` (:pull:`349`).
1124
- Improve and extend :doc:`/material/index`.
12-
See :doc:`/model/material/v1.2.0` for details.
25+
See :doc:`/material/v1.2.0` for details.
1326

1427
- Improve :mod:`.material.data_cement` (:pull:`361`).
1528

29+
- Improve :doc:`/transport/index` (:pull:`349`).
30+
31+
- Use version "3.2.beta" of SSP socioeconomic data.
32+
- Force scale-1 to 1.0 for (technology=F ROAD, commodity=gas).
33+
- :attr:`Config.policy <.transport.config.Config.policy>` is a :class:`set` of :class:`.Policy` instances,
34+
instead of :class:`bool`.
35+
- New classes :class:`~.transport.policy.ExogenousEmissionPrice`, :class:`~.transport.policy.TaxEmission`.
36+
- Add version 1.1.0 of the ``IIASA_ECE:CL_TRANSPORT_SCENARIO`` code list.
37+
- Update input data for :data:`.act_non_ldv`,
38+
:data:`.activity_freight`,
39+
:data:`.elasticity_f`,
40+
:data:`.load_factor_ldv`,
41+
passenger mode share,
42+
:data:`.pdt_cap`,
43+
:data:`.pdt_cap_ref`, and
44+
:data:`.t_share_ldv`.
45+
- Add snapshot/reference ``PRICE_EMISSION`` data from |ssp-scenariomip| scenarios.
46+
- New :class:`.model.emissions.PRICE_EMISSION` to use snapshot data from file (:pull:`349`).
47+
48+
Projects and applications
49+
-------------------------
50+
51+
- Update :mod:`.navigate.workflow` (:pull:`349`).
52+
:func:`~.navigate.workflow.tax_emission` uses :mod:`message_ix_models.tools.add_tax_emission`,
53+
not the version in :mod:`message_data`.
54+
- :class:`.SSPUpdate` supports version "3.2.beta" of the SSP socioeconomic data (:pull:`349`).
1655
- Improve :mod:`.ssp.transport` (:pull:`355`):
1756

1857
- Modify data for variable=“Final Energy|Bunkers|International Aviation” and related (:issue:`308`).
1958
- Omit year=2020 from modified data.
2059
- New CLI utility :program:`mix-models ssp ceds-data-for-transport`.
2160

61+
Utilities, tools, and housekeeping
62+
----------------------------------
63+
64+
- Simplify API and usage of :class:`.ExoDataSource` and its subclasses (:pull:`349`).
65+
66+
- Most data source classes now have a corresponding :class:`.BaseOptions` subclass
67+
that indicate the options/arguments understood by that data source.
68+
- Adjust existing ExoDataSource classes and usage.
69+
70+
- Improve :class:`.URNLookupEnum`, add :class:`.ItemSchemeEnumType`
71+
and use these for :any:`.SSP_2017` and :any:`SSP_2024` (:pull:`349`).
72+
This class supports type checking and use of SDMX item scheme members as Python :class:`.Enum` members.
73+
- Recompress :doc:`/project/advance` using LZMA (:pull:`349`).
74+
- Remove :py:`message_ix_model.tools.advance` (:pull:`349`)
75+
that had been deprecated since :ref:`v2023.11.24`.
76+
- :func:`.iamc_like_data_for_query` handles LZMA-compressed TAR files (:pull:`349`).
77+
- Adjust type hints for `iiasa/ixmp#581 <https://github.com/iiasa/ixmp/pull/581>`_ (:pull:`349`).
78+
2279
v2025.5.28
2380
==========
2481

@@ -362,6 +419,8 @@ v2024.1.29
362419
- Adjust :mod:`.report.compat` for genno version 1.22 (:issue:`141`, :pull:`142`).
363420
- Raise informative exception from :meth:`.ScenarioInfo.io_units` (:pull:`151`).
364421

422+
.. _v2023.11.24:
423+
365424
v2023.11.24
366425
===========
367426

message_ix_models/data/emission.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ SO2:
3939
name: Sulfur dioxide
4040
report: Sulfur
4141

42+
TCE:
43+
name: (missing)
44+
type: TCE
45+
4246
VOC:
4347
name: Volatile organic compounds
4448

@@ -79,7 +83,6 @@ VOC:
7983
# SF6
8084
# SO2_LandUseChangeEM
8185
# SO2_SavanBurnEM
82-
# TCE
8386
# TCE_CO2
8487
# TCE_non-CO2
8588
# VOC_LandUseChangeEM

message_ix_models/data/sdmx/IIASA_ECE_AGENCIES(0.1).xml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
<mes:Structure xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:com="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" xmlns:data="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/structurespecific" xmlns:str="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure" xmlns:mes="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message" xmlns:gen="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic" xmlns:footer="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message/footer">
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<mes:Structure xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:com="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" xmlns:md="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/metadata/generic" xmlns:md_ss="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/metadata/structurespecific" xmlns:data="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/structurespecific" xmlns:str="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure" xmlns:mes="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message" xmlns:gen="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic" xmlns:footer="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message/footer">
23
<mes:Header>
4+
<mes:ID>none</mes:ID>
35
<mes:Test>false</mes:Test>
4-
<mes:Prepared>2023-09-04T16:31:44.700655</mes:Prepared>
5-
<mes:Source xml:lang="en">Generated by message_ix_models 2023.5.32.dev20+g8d51636</mes:Source>
6+
<mes:Prepared>2025-05-19T22:09:29.424849</mes:Prepared>
7+
<mes:Sender id="none"/>
8+
<mes:Source xml:lang="en">Generated by message_ix_models 2025.1.11.dev398+gdaf97af4a.d20250504</mes:Source>
69
</mes:Header>
710
<mes:Structures>
811
<str:OrganisationSchemes>
9-
<str:AgencyScheme version="0.1" isExternalReference="false" isFinal="false" agencyID="IIASA_ECE" id="AGENCIES" urn="urn:sdmx:org.sdmx.infomodel.base.AgencyScheme=IIASA_ECE:AGENCIES(0.1)">
12+
<str:AgencyScheme isExternalReference="false" isFinal="false" agencyID="IIASA_ECE" version="0.1" id="AGENCIES" urn="urn:sdmx:org.sdmx.infomodel.base.AgencyScheme=IIASA_ECE:AGENCIES(0.1)">
1013
<com:Description xml:lang="en">Agencies referenced by data structures in message_ix_models</com:Description>
11-
<str:Agency id="IIASA_ECE">
14+
<str:Agency id="IIASA_ECE" urn="urn:sdmx:org.sdmx.infomodel.base.Agency=IIASA_ECE:AGENCIES(0.1).IIASA_ECE">
1215
<com:Name xml:lang="en">IIASA Energy, Climate, and Environment Program</com:Name>
1316
</str:Agency>
1417
<str:Agency id="ICONICS">
@@ -17,7 +20,7 @@
1720
<str:URI>https://depts.washington.edu/iconics/</str:URI>
1821
</str:Contact>
1922
</str:Agency>
20-
<str:Agency id="IEA">
23+
<str:Agency id="IEA" urn="urn:sdmx:org.sdmx.infomodel.base.Agency=IIASA_ECE:AGENCIES(0.1).IEA">
2124
<com:Name xml:lang="en">International Energy Agency</com:Name>
2225
<str:Contact>
2326
<str:URI>https://iea.org</str:URI>

0 commit comments

Comments
 (0)