You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -21,7 +21,7 @@ Each layer of this “stack” builds on the features in the level below:
21
21
- Calculations for specific technologies
22
22
* - ``message_ix``
23
23
- Energy model framework
24
-
- Common sets/parameters (``output``)
24
+
- MESSAGE-specific sets/parameters (``output``)
25
25
- Derived quantities (``tom``)
26
26
* - ``ixmp``
27
27
- Optimization models & data
@@ -37,7 +37,7 @@ Each layer of this “stack” builds on the features in the level below:
37
37
These features are accessible through :class:`.Reporter`, which can produce multiple **reports** from one or more Scenarios.
38
38
A report and the quantities that enter it is identified by a **key**, and may…
39
39
40
-
- perform arbitrarily complex calculations while intelligently handling units;
40
+
- perform arbitrarily complex calculations, handling dimensionality and units;
41
41
- read and make use of data that is ‘exogenous’ to (not included in) a Scenario;
42
42
- produce output as Python or R objects (in code), or write to files or databases;
43
43
- calculate only a requested subset of quantities; and
@@ -57,10 +57,16 @@ See :doc:`genno:usage` in the genno documentation for an introduction to concept
57
57
In :mod:`message_ix.report`:
58
58
59
59
- The :class:`.Reporter` class is an extended version of the :class:`genno.Computer` class.
60
-
- :mod:`ixmp` parameters, scalars, equations, and time-series data all become quantities for the purpose of reporting.
61
-
- For example, the |MESSAGEix| parameter ``resource_cost``, defined with the dimensions (node `n`, commodity `c`, grade `g`, year `y`) is identified by the key ``resource_cost:n-c-g-y``.
62
-
When summed across the grade/`g` dimension, it has dimensions `n`, `c`, `y` and is identified by the key ``resource_cost:n-c-y``.
63
-
- :meth:`.Reporter.from_scenario` automatically sets up keys and tasks (such as ``resource_cost:n-c-g-y``) that simply retrieve raw/unprocessed data from a :class:`~message_ix.Scenario` and return it as a :any:`genno.Quantity`.
60
+
- :mod:`ixmp` parameters, scalars, equations, and time-series data
61
+
all become ‘quantities’ for the purpose of reporting.
62
+
- For example, the |MESSAGEix| parameter ``resource_cost``
63
+
defined with the dimensions (node `n`, commodity `c`, grade `g`, year `y`)
64
+
is identified by the key ``resource_cost:n-c-g-y``.
65
+
When summed across the grade/`g` dimension, it has dimensions `n`, `c`, `y`
66
+
and is identified by the key ``resource_cost:n-c-y``.
67
+
- :meth:`.Reporter.from_scenario` automatically sets up keys and tasks
68
+
(such as ``resource_cost:n-c-g-y``) that simply retrieve raw/unprocessed data from a :class:`~message_ix.Scenario`
69
+
and return it as a :any:`genno.Quantity`.
64
70
- Operators are defined as functions in modules including:
65
71
:mod:`message_ix.report.operator`,
66
72
:mod:`ixmp.report.operator`, and
@@ -72,10 +78,14 @@ Usage
72
78
73
79
A |MESSAGEix| reporting workflow has the following steps:
74
80
75
-
1. Obtain a :class:`.Scenario` object from an :class:`~ixmp.Platform`.
76
-
2. Use :meth:`.Reporter.from_scenario` to prepare a Reporter object with many calculations automatically prepared.
77
-
3. (optionally) Use the built-in features of :class:`.Reporter` to describe additional calculations.
78
-
4. Use :meth:`.get` 1 or more times to execute tasks, including all the calculations on which they depend:
81
+
1. Obtain a :class:`.Scenario` object from a :class:`~ixmp.Platform`.
82
+
2. Use :meth:`.Reporter.from_scenario` to prepare a Reporter object
83
+
with many calculations automatically prepared.
84
+
See below.
85
+
3. (optionally) Use the built-in features of :class:`.Reporter`
86
+
to describe additional calculations.
87
+
4. Use :meth:`.get` 1 or more times to execute tasks,
88
+
including all the calculations on which they depend:
79
89
80
90
.. code-block:: python
81
91
@@ -88,12 +98,173 @@ A |MESSAGEix| reporting workflow has the following steps:
88
98
rep.get("all")
89
99
90
100
Note that keys and tasks are **described** in steps (2–3), but they are not **executed** until :meth:`.get` is called—or the results of one task are required by another.
91
-
This design allows the Reporter to skip unneeded (and potentially slow) computations and deliver good performance.
101
+
This design allows the Reporter to skip unneeded (and potentially slow)
102
+
tasks and re-use intermediate results to deliver good performance.
92
103
The Reporter's :attr:`~genno.Computer.graph` may contain thousands of tasks for retrieving model quantities and calculating derived quantities, but a particular call to :meth:`.get` may only execute a few of these.
It is used to calculate ``{…}:*:historical+current``
205
+
and ``{…}:*:historical+weighted``. [#key-notation]_
206
+
207
+
Similar quantities exist for ``out``, ``emi``, and ``inv``,
208
+
with keys like ``out:*:historical+full`` etc.
209
+
- ``in:*:historical+current``:
210
+
The subset of ``in:*:historical+full`` where :math:`y^V = y^A`.
211
+
Use this quantity to represent an assumption that
212
+
*all activity in each historical period* :math:`y^A < y_0` *is attributable to
213
+
the technology vintage constructed in the same ('current') period*.
214
+
In other words, this uses ``input`` intensity values for :math:`(y^V=y^A, y^A)`,
215
+
and omits/ignores values for earlier vintages :math:`(y^V < y^A, y^A)`,
216
+
even if the |technical_lifetime| and |historical_new_capacity| of those earlier vintages
217
+
implies they could be active in the period |yA|.
218
+
219
+
Similar quantities exist for ``out``, ``emi``, and ``inv``.
220
+
- ``in:*:historical+weighted``:
221
+
a sum of ``in:*:historical+full`` across the ``yv`` dimension,
222
+
weighted by ``share:*:in+historical``.
223
+
The latter quantity **must** be supplied exogenously by the user.
224
+
This can be done by overriding the placeholder task created by
225
+
:meth:`.from_scenario`:
226
+
227
+
.. code-block:: python
228
+
229
+
k = rep.full_key("share:*:in+historical")
230
+
rep.add(k, ...) # Some task that returns share values, e.g. from file
231
+
232
+
``share:*:{…}+historical`` values give the fractional contribution
233
+
of each technology vintage :math:`y^V`
234
+
to the ``historical_activity`` in each :math:`y^A`.
235
+
Therefore they **should** sum to 1.0 across the ``yv`` dimension
236
+
for each combination of other indices.
237
+
238
+
Similar quantities exist for ``out``, ``emi``, and ``inv``.
239
+
- ``in:*:ref+current``, ``in:*:ref+weighted``, and ``in:*:ref+full``:
240
+
Same as above, but computed using ``ref_activity`` instead of ``historical_activity``.
241
+
242
+
Similar quantities exist for ``out``, ``emi``, and ``inv``.
243
+
244
+
.. [#key-notation] These string representations of :class:`genno.Key` use
245
+
an asterisk for the dimensions (such as ``name:*:tag``)
246
+
to indicate “all dimensions for this ``name`` and ``tag``”;
247
+
and ``{…}`` to indicate “any string”.
248
+
249
+
.. _default-reports:
250
+
251
+
Time series data (:data:`.PYAM_CONVERT`, :data:`.TASKS1`)
252
+
Tasks that transform :class:`~genno.Quantity` with varying number of dimensions
253
+
to the :mod:`ixmp` :ref:`structure for time-series data <ixmp:data-tsdata>`
254
+
(also called the “IAMC data structure”),
255
+
specifically as instances of :class:`pyam.IamDataFrame`.
256
+
257
+
These include:
258
+
259
+
- ``<name>::pyam`` for most of the above derived quantities.
260
+
- ``CAP::pyam`` (from ``CAP``)
261
+
- ``CAP_NEW::pyam`` (from ``CAP_NEW``)
262
+
- ``message::system``, ``message::costs``, and ``message::emissions``:
263
+
concatenation of subsets of the above time series data.
264
+
- ``message::default``: concatenation of all of the above time series data.
94
265
95
266
Customization
96
-
=============
267
+
-------------
97
268
98
269
A Reporter prepared with :meth:`.from_scenario` always contains a key
99
270
``scenario``, referring to the Scenario to be reported.
@@ -112,8 +283,12 @@ The method :meth:`.Reporter.add` can be used to add *arbitrary* Python code that
112
283
rep.add("custom", (my_custom_report, "scenario"))
113
284
rep.get("custom")
114
285
115
-
In this example, the function ``my_custom_report()`` *could* run to thousands of lines; read to and write from multiple files; invoke other programs or Python scripts; etc.
116
-
In order to take advantage of the performance-optimizing features of the Reporter, such calculations can instead be composed from atomic (i.e. small, indivisible) operators or functions.
286
+
In this example, the function ``my_custom_report()`` **may** run to thousands of lines;
287
+
read to and write from multiple files;
288
+
invoke other programs or Python scripts; etc.
289
+
In order to take advantage of the performance-optimizing features of the Reporter,
290
+
such calculations **should** instead be composed from atomic (small, indivisible) operators
291
+
or functions.
117
292
See the :mod:`genno` documentation for more.
118
293
119
294
API reference
@@ -146,66 +321,6 @@ Their documentation is repeated below for convenience.
146
321
configure
147
322
.. currentmodule:: message_ix.report
148
323
149
-
:meth:`ixmp.Reporter.from_scenario <ixmp.report.Reporter.from_scenario>` automatically adds keys based on the contents of the :class:`.Scenario` argument;
150
-
that is, every :mod:`ixmp` set, parameter, variable, and equation available in the Scenario.
151
-
:meth:`message_ix.Reporter.from_scenario <.Reporter.from_scenario>` extends this to add additional keys for derived quantities specific to the MESSAGEix model framework.
152
-
These include:
153
-
154
-
.. tip:: Use :meth:`~genno.Computer.full_key` to retrieve the full-dimensionality :class:`~genno.Key` for any of these quantities.
155
-
156
-
- ``out`` = ``output`` × ``ACT``; that is, the product of ``output`` (output efficiency) and ``ACT`` (activity)
- ``addon conversion``, the model parameter ``addon_conversion`` (note space versus underscore), except broadcast across individual add-on technologies (`ta`) rather than add-on types (`type_addon`).
173
-
- ``addon up``, which is ``addon_up`` similarly broadcast.
174
-
- ``addon ACT`` = ``addon conversion`` × ``ACT``
175
-
- ``addon in`` = ``input`` × ``addon ACT``
176
-
- ``addon out`` = ``output`` × ``addon ACT``
177
-
- ``addon potential`` = ``addon up`` × ``addon ACT``, the maximum potential activity by add-on technology.
178
-
- ``price emission``, the model variable ``PRICE_EMISSION`` broadcast across emission species (`e`) *and* technologies (`t`) rather than types (`type_emission`, `type_tec`).
179
-
180
-
Other added keys include:
181
-
182
-
- :mod:`message_ix` adds the standard short symbols for |MESSAGEix| dimensions (sets) based on :data:`.common.DIMS`.
183
-
Each of these is also available in a Reporter: for example :py:`rep.get("n")` returns a list with the elements of the |MESSAGEix| set named "node";
184
-
:py:`rep.get("t")` returns the elements of the set "technology", and so on.
185
-
These keys can be used as input to other computations.
186
-
- ``y0`` = the ``firstmodelyear`` or :math:`y_0` (:class:`int`).
187
-
- ``y::model`` = only the periods in the `year` set (``y``) that are equal to or greater than ``y0``.
188
-
189
-
.. _default-reports:
190
-
191
-
- Computations to convert internal :class:`~genno.Quantity` data format to the IAMC data format, specifically as :class:`pyam.IamDataFrame` objects.
192
-
These include:
193
-
194
-
- ``<name>::pyam`` for most of the above derived quantities.
195
-
- ``CAP::pyam`` (from ``CAP``)
196
-
- ``CAP_NEW::pyam`` (from ``CAP_NEW``)
197
-
198
-
- ``map_<name>`` as "one-hot" or indicator quantities for the respective |MESSAGEix| mapping sets ``cat_<name>``.
199
-
- Standard reports ``message::system``, ``message::costs``, and ``message::emissions`` per :data:`TASKS1`.
200
-
- The report ``message::default``, collecting all of the above reports.
0 commit comments