Skip to content

Commit c303d54

Browse files
authored
Merge pull request #451 from iiasa/enh/report-extr
Add reporting of resource extraction to IAMC structure
2 parents ccb9393 + dc81640 commit c303d54

File tree

17 files changed

+530
-100
lines changed

17 files changed

+530
-100
lines changed

doc/api/report/index.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,37 @@ API reference
139139
.. automodule:: message_ix_models.report
140140
:members:
141141

142+
General-purpose code:
143+
142144
.. autosummary::
143145

144146
Config
147+
defaults
145148
prepare_reporter
146149
register
147150
report
148151

152+
The following submodules prepare reporting of specific measures or quantities:
153+
154+
.. autosummary::
155+
:toctree: _autosummary
156+
:template: autosummary-module.rst
157+
:recursive:
158+
159+
extraction
160+
161+
.. currentmodule:: message_ix_models.report.key
162+
163+
Keys
164+
----
165+
166+
.. automodule:: message_ix_models.report.key
167+
:members:
168+
169+
Pre-set :class:`genno.Key` instances
170+
and :class:`genno.Keys` in this module can be referenced across modules,
171+
instead of hand-typing the same strings in multiple places.
172+
149173
.. currentmodule:: message_ix_models.report.plot
150174

151175
Plots
@@ -167,17 +191,25 @@ Operators
167191

168192
.. autosummary::
169193

194+
broadcast_wildcard
195+
call
170196
codelist_to_groups
171197
compound_growth
172198
exogenous_data
173199
filter_ts
174200
from_url
201+
get_commodity_groups
175202
get_ts
176203
gwp_factors
177204
make_output_path
178205
model_periods
206+
node_glb
207+
nodes_world_agg
179208
remove_ts
209+
select_allow_empty
210+
select_expand
180211
share_curtailment
212+
zeros_like
181213

182214
The following functions, defined elsewhere,
183215
are exposed through :mod:`.operator`
@@ -186,6 +218,8 @@ Operators
186218
.. autosummary::
187219

188220
message_ix_models.util.add_par_data
221+
message_ix_models.util.merge_data
222+
message_ix_models.util.nodes_ex_world
189223

190224
Other operators or genno-compatible functions are provided by:
191225

@@ -219,6 +253,7 @@ Utilities
219253

220254
.. autosummary::
221255

256+
IAMCConversion
222257
add_replacements
223258
collapse
224259
collapse_gwp_info

doc/pkg-data/codelists.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@ These codes have the following annotations:
1818
``units`` (mandatory)
1919
Units typically associated with this commodity.
2020
``iea-eweb-flow`` (optional)
21-
List of ``FLOW`` codes from the IEA :ref:`tools-iea-web` associated with this MESSAGEix-GLOBIOM commodity.
21+
List of ``FLOW`` codes from the IEA :ref:`tools-iea-web`
22+
associated with this MESSAGEix-GLOBIOM commodity.
2223
``iea-eweb-product`` (optional)
23-
List of ``PRODUCT`` codes from the IEA :ref:`tools-iea-web` associated with this MESSAGEix-GLOBIOM commodity.
24+
List of ``PRODUCT`` codes from the IEA :ref:`tools-iea-web`
25+
associated with this MESSAGEix-GLOBIOM commodity.
26+
``report`` (optional)
27+
English name for IAMC-structured reporting output.
28+
See :func:`.add_replacements`.
29+
``report-only`` (optional)
30+
:class:`bool`.
31+
If :any:`True`,
32+
the code is ignored by :func:`.bare.get_spec`.
2433

2534
.. literalinclude:: ../../message_ix_models/data/commodity.yaml
2635
:language: yaml

doc/whatsnew.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Next release
1111
- New method :meth:`~.report.Config.iter_callbacks`.
1212

1313
- New function :func:`.tools.iamc.compare` (:pull:`178`).
14+
- New module :mod:`.report.extraction` for reporting of resource extraction (:pull:`451`).
15+
- New reporting operators (:pull:`451`):
16+
:func:`.get_commodity_groups`,
17+
:func:`.node_glb`, and
18+
:func:`.zeros_like`.
1419
- Expand :doc:`api/report/index` documentation (:pull:`178`)
1520
to cover features implemented/not implemented by :mod:`genno`-based reporting.
1621
Module globals :data:`.NOT_IMPLEMENTED_MEASURE` and :data:`.NOT_IMPLEMENTED_IAMC`

message_ix_models/data/commodity.yaml

Lines changed: 100 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ biomass:
66
coal:
77
name: Coal
88
units: GWa
9-
report: Solids|Fossil
109
# NB same value as "Coking coal"; this choice is arbitrary
1110
# NB in message_doc, this appears as "Hard coal", but this
1211
# term usually refers to anthracite, which has a higher
@@ -33,6 +32,45 @@ coal:
3332
- PEAT
3433
- SUBCOAL
3534

35+
crude_1:
36+
description: Crude oil resource.
37+
38+
crude_2:
39+
description: Crude oil resource.
40+
41+
crude_3:
42+
description: Crude oil resource.
43+
44+
Oil|Conventional:
45+
description: Reporting aggregate for oil resources.
46+
report-only: true
47+
child: [crude_1, crude_2, crude_3]
48+
49+
crude_4:
50+
description: Crude oil resource.
51+
52+
crude_5:
53+
description: Crude oil resource.
54+
55+
crude_6:
56+
description: Crude oil resource.
57+
58+
crude_7:
59+
description: Crude oil resource.
60+
61+
crude_8:
62+
description: Crude oil resource.
63+
64+
Oil|Unconventional:
65+
description: Reporting aggregate for oil resources.
66+
report-only: true
67+
child: [crude_4, crude_5, crude_6, crude_7, crude_8]
68+
69+
Oil:
70+
description: Reporting aggregate for oil resources.
71+
report-only: true
72+
child: [Oil|Conventional, Oil|Unconventional]
73+
3674
crudeoil:
3775
name: Crude oil
3876
description: >-
@@ -76,10 +114,52 @@ fueloil:
76114
gas:
77115
name: Natural Gas
78116
units: GWa
79-
report: Gases
80117
ipcc-1996-name: "Natural Gas (Dry)"
81118
iea-eweb-product: [NATGAS]
82119

120+
gas_1:
121+
description: Natural gas resource.
122+
123+
gas_2:
124+
description: Natural gas resource.
125+
126+
gas_3:
127+
description: Natural gas resource.
128+
129+
gas_4:
130+
description: Natural gas resource.
131+
132+
Gas|Conventional:
133+
description: Reporting aggregate for gas resources.
134+
report-only: true
135+
child: [gas_1, gas_2, gas_3, gas_4]
136+
137+
gas_5:
138+
description: Natural gas resource.
139+
140+
gas_6:
141+
description: Natural gas resource.
142+
143+
gas_7:
144+
description: Natural gas resource.
145+
146+
gas_8:
147+
description: Natural gas resource.
148+
149+
Gas|Unconventional:
150+
description: Reporting aggregate for gas resources.
151+
report-only: true
152+
child: [gas_5, gas_6, gas_7, gas_8]
153+
154+
_Gas:
155+
description: >-
156+
Reporting aggregate for gas resources.
157+
The ID is prefixed with an underscore to distinguish from "gas",
158+
which is not a component.
159+
report-only: true
160+
report: Gas
161+
child: [Gas|Conventional, Gas|Unconventional]
162+
83163
hydrogen:
84164
name: Gaseous hydrogen
85165
units: GWa
@@ -115,6 +195,15 @@ lignite:
115195
name: Lignite
116196
ipcc-1996-name: "Lignite"
117197

198+
_Coal:
199+
description: >-
200+
Reporting aggregate for coal resources.
201+
The ID is prefixed with an underscore to distinguish from "coal",
202+
which is only 1 of multiple children.
203+
report-only: true
204+
report: Coal
205+
child: [coal, lignite]
206+
118207
methanol:
119208
name: Methanol
120209
units: GWa
@@ -143,6 +232,15 @@ transport:
143232
units: GWa
144233
iea-eweb-flow: [DOMESAIR, DOMESNAV, RAIL, ROAD, TRNONSPE]
145234

235+
uranium:
236+
description: Uranium resource.
237+
238+
_Uranium:
239+
description: Reporting aggregate for uranium resources.
240+
report-only: true
241+
report: Uranium
242+
child: [uranium]
243+
146244
# The following codes also appear in a recent (2020-02-28) SSP2 scenario, but
147245
# are not currently used by model.bare.create_res.
148246
#
@@ -205,14 +303,6 @@ transport:
205303
# cooling__nuc_lc
206304
# cooling__solar_th_ppl
207305
# CrpLnd
208-
# crude_1
209-
# crude_2
210-
# crude_3
211-
# crude_4
212-
# crude_5
213-
# crude_6
214-
# crude_7
215-
# crude_8
216306
# Def_CO2_G4M
217307
# Def_CO2_GLO
218308
# dumagr
@@ -260,15 +350,6 @@ transport:
260350
# freshwater_instream
261351
# FuelWood
262352
# FuelWood_G4M
263-
# gas
264-
# gas_1
265-
# gas_2
266-
# gas_3
267-
# gas_4
268-
# gas_5
269-
# gas_6
270-
# gas_7
271-
# gas_8
272353
# gas_afr
273354
# gas_cpa
274355
# gas_eeu
@@ -355,7 +436,6 @@ transport:
355436
# u5t
356437
# upstream_landuse
357438
# uq
358-
# uranium
359439
# VOC_LandUseChangeEM
360440
# VOC_SavanBurnEM
361441
# water_constraint

message_ix_models/model/bare.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ def get_spec(context) -> Spec:
129129
# Add levels
130130
add.set["level"] = get_codes("level")
131131

132-
# Add commodities
133-
add.set["commodity"] = get_codes("commodity")
132+
# Add commodities. Omit those with the annotation ``report-only: true``
133+
add.set["commodity"].extend(
134+
filter(
135+
lambda c: not c.eval_annotation(id="report-only"), get_codes("commodity")
136+
)
137+
)
134138

135139
# Add units, associated with commodities
136140
units = set(

message_ix_models/model/transport/structure.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections.abc import Sequence
22
from copy import deepcopy
3-
from itertools import chain
43
from typing import Any
54

65
from sdmx.model.common import Code
@@ -10,6 +9,7 @@
109
from message_ix_models.model import disutility
1110
from message_ix_models.model.structure import generate_set_elements, get_region_codes
1211
from message_ix_models.util import load_package_data, package_data_path
12+
from message_ix_models.util.sdmx import leaf_ids
1313

1414
from .util import region_path_fallback
1515

@@ -67,22 +67,15 @@ def get_technology_groups(
6767

6868
result: dict[str, list[str]] = {"historical-only": [], "LDV usage": []}
6969

70-
def _leaf_ids(node) -> list[str]:
71-
"""Recursively collect leaf IDs."""
72-
return list(
73-
chain(*[_leaf_ids(c) if len(c.child) else (c.id,) for c in node.child])
74-
)
75-
7670
for tech in t_list:
7771
if len(tech.child):
7872
# Code with child codes → a group of technologies → store all the leaf IDs
79-
result[tech.id] = _leaf_ids(tech)
80-
else:
73+
result[tech.id] = leaf_ids(tech)
74+
elif tech.eval_annotation(id="historical-only") is True:
8175
# Code without children = an individual technology → add to certain groups
82-
if tech.eval_annotation(id="historical-only") is True:
83-
result["historical-only"].append(tech.id)
84-
if tech.eval_annotation(id="is-disutility") is True:
85-
result["LDV usage"].append(tech.id)
76+
result["historical-only"].append(tech.id)
77+
elif tech.eval_annotation(id="is-disutility") is True:
78+
result["LDV usage"].append(tech.id)
8679

8780
return result
8881

0 commit comments

Comments
 (0)