message_ix_models.tools.iea.web.IEA_EWEB
- class message_ix_models.tools.iea.web.IEA_EWEB(*args, **kwargs)[source]
Bases:
ExoDataSourceProvider of exogenous data from the IEA Extended World Energy Balances.
- __init__(*args, **kwargs)[source]
Create an instance and prepare info for
transform()/get().The base implementation:
Sets
options—if not already set—by passing kwargs toOptions.Raises an exception if there are other/unhandled args or kwargs.
If
keyis not set, constructs it with:Name
nameormeasurein lower case.Dimensions
dims.
Subclasses may pre-empt this behaviour by setting
keystatically or dynamically.
A concrete class implementation must:
Set
options, either directly or by callingsuper().__init__()with or without keyword arguments.Set
key, either directly or by callingsuper().__init__(). In the latter case, it may setname,measure, and/ordimsto control the behaviour.Raise an exception if unrecognized or invalid kwargs are passed.
and may:
Transform kwargs or
optionsarguments into other values, for instance by mapping certain values to others, applying regular expressions, or other operations.Store those values as instance attributes for use in
get().Log messages that give information that helps to debug exceptions.
It must not perform any time- or memory-intensive operations, such as actually loading or fetching data. Those operations should be in
get().
Methods
__init__(*args, **kwargs)Create an instance and prepare info for
transform()/get().add_tasks(c, *args[, context, strict])Add tasks to c to provide and transform the data.
get()Load and process the data.
transform(c, base_key)Prepare c to transform raw data from base_key.
Attributes
Key for the returned
Quantity.Trueto allow the class to look up and use test data.wherekeyword argument topath_fallback().Instance of the
Optionsclass.- class Options(aggregate: bool = True, interpolate: bool = True, measure: str = '', name: str = '', dims: tuple[str, ...] = ('n', 'y'), provider: str = '', edition: str = '', product: str | list[str] = '', flow: str | list[str] = '', transform: message_ix_models.tools.iea.web.TRANSFORM = <TRANSFORM.A: 1>, regions: str = '')[source]
Bases:
BaseOptions- aggregate: bool = True
TrueifExoDataSource.transform()should aggregate data on the \(n\) dimension.
- classmethod from_args(source_id: str | ExoDataSource, *args, **kwargs)
Construct an instance from keyword arguments.
- Parameters:
source_id – For backwards-compatibility with
prepare_computer().
- interpolate: bool = True
TrueifExoDataSource.transform()should interpolate data on the \(y\) dimension.
- transform: TRANSFORM = 1
Either “A” (default) or “B”. See
transform().
- classmethod add_tasks(c: Computer, *args, context: Context | None = None, strict: bool = True, **kwargs) tuple
Add tasks to c to provide and transform the data.
The first returned key is
key, and will trigger the following tasks:Load or retrieve data by invoking
ExoDataSource.get().If
BaseOptions.aggregateisTrue, aggregate on the \(n\) (node) dimension according toConfig.regions.If
BaseOptions.interpolateisTrue, interpolate on the \(y\) (year) dimension according toConfig.years.
Steps (2) and (3) are added by
transform()and may differ in concrete classes.Other returned keys include further transformations:
key + "y0_indexed": same askey, but indexed to the values as of the first model period.
Other keys that are created but not returned can be accessed on c:
key + "message_ix_models.foo.bar.CLASS": the raw data, with a tag from the fully-qualified name of the ExoDataSource class.
To support the loading and transformation of data,
add_structure()is first called with c.Todo
Add option/tasks to index to a particular label on the \(n\) dimension.
- key: Key = <energy:n-y-product-flow:iea>
Key for the returned
Quantity. This may either be set statically on a concrete subclass, or created via__init__().
- options: Options
Instance of the
Optionsclass.A concrete class that overrides
Optionsshould redefine this attribute, to facilitate type checking.
- transform(c: Computer, base_key: Key) Key[source]
Prepare c to transform raw data from base_key.
Map IEA
COUNTRYcodes to ISO 3166-1 alpha-3 codes, where such mapping exists. Seeget_mapping()andCOUNTRY_NAME.
The next steps depend on whether
transform="A"ortransform="B"was given with the source_kw.transform="A"(default)Aggregate using “n::groups”—the same as
ExoDataSource.transform(). This operates on the \(n\) labels transformed to alpha-3 codes by step (1) above.
transform="B"Compute intermediate quantities using
transform_B().Aggregate using the groups returned by
get_node_groups_B().
This method does not prepare interpolation or aggregation on \(y\).
- use_test_data: bool = False
Trueto allow the class to look up and use test data. If no test data exists, this setting has no effect. See_where().
- where: list['str | Path'] = ['local']
wherekeyword argument topath_fallback(). See_where().