message_ix_models.model.transport.ldv.LDV

class message_ix_models.model.transport.ldv.LDV(*args, **kwargs)[source]

Bases: MaybeAdaptR11Source

Provider of exogenous data on LDVs.

Parameters:

source_kw – Must include exactly the keys “measure” (must be one of “fuel economy”, “fix_cost”, or “inv_cost”), “nodes”, and “scenario”.

__init__(*args, **kwargs) None[source]

Create an instance and prepare info for transform()/get().

The base implementation:

  • Sets options—if not already set—by passing kwargs to Options.

  • Raises an exception if there are other/unhandled args or kwargs.

  • If key is not set, constructs it with:

    • Name name or measure in lower case.

    • Dimensions dims.

    Subclasses may pre-empt this behaviour by setting key statically or dynamically.

A concrete class implementation must:

  • Set options, either directly or by calling super().__init__() with or without keyword arguments.

  • Set key, either directly or by calling super().__init__(). In the latter case, it may set name, measure, and/or dims to control the behaviour.

  • Raise an exception if unrecognized or invalid kwargs are passed.

and may:

  • Transform kwargs or options arguments 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()

Return the data.

transform(c, base_key)

Add tasks to c to transform raw data from base_key.

Attributes

filename

Names of expected files given measure.

measures

Set of measures recognized by a subclass.

use_test_data

True to allow the class to look up and use test data.

where

where keyword argument to path_fallback().

options

Instance of the Options class.

key

Key for the returned Quantity.

class Options(aggregate: bool = True, interpolate: bool = True, measure: str = '', name: str = '', dims: tuple[str, ...] = ('n', 'y'), nodes: str = '', scenario: str = '')

Bases: BaseOptions

aggregate: bool = True

True if ExoDataSource.transform() should aggregate data on the \(n\) dimension.

dims: tuple[str, ...] = ('n', 'y')

Dimensions for the returned Key/Quantity.

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

True if ExoDataSource.transform() should interpolate data on the \(y\) dimension.

measure: str = ''

Identifier for the primary measure of retrieved/returned data.

name: str = ''

Name for the returned Key/Quantity.

nodes: str = ''

ID of the node code list.

scenario: str = ''

Scenario identifier.

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:

  1. Load or retrieve data by invoking ExoDataSource.get().

  2. If BaseOptions.aggregate is True, aggregate on the \(n\) (node) dimension according to Config.regions.

  3. If BaseOptions.interpolate is True, interpolate on the \(y\) (year) dimension according to Config.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 as key, 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.

Parameters:
  • context – Passed to add_structure().

  • strict – Passed to add_structure().

Return type:

tuple of Key

filename: Mapping[str, str] = {'fix_cost': 'ldv-fix_cost.csv', 'fuel economy': 'ldv-fuel-economy.csv', 'inv_cost': 'ldv-inv_cost.csv'}

Names of expected files given measure.

get() :data:`~genno.core.quantity.AnyQuantity`

Return the data.

Implementations in concrete classes may load data from file, retrieve from remote sources or local caches, generate data, or anything else.

The Quantity returned by this method must have dimensions corresponding to key. If the original/upstream/raw data has different dimensionality (fewer or more dimensions; different dimension IDs), a concrete class must transform these, make appropriate selections, etc.

key: Key

Key for the returned Quantity. This may either be set statically on a concrete subclass, or created via __init__().

measures: set[str] = {'fix_cost', 'fuel economy', 'inv_cost'}

Set of measures recognized by a subclass.

options: Options

Instance of the Options class.

A concrete class that overrides Options should redefine this attribute, to facilitate type checking.

transform(c: Computer, base_key: Key) Key

Add tasks to c to transform raw data from base_key.

base_key refers to the Quantity returned by get(). Via add_tasks(), transform() adds additional tasks to c that further transform the data. (Such operations may be done in get() directly, but transform() allows use of genno operators and conveniences.)

In the default implementation:

  1. If aggregate is True, aggregate the data ( genno.operator.aggregate()) on the \(n\) dimension using the key “n::groups”.

  2. If interpolate is True, interpolate the data ( genno.operator.interpolate()) on the \(y\) dimension using “y::coords”.

Concrete classes may override this method to, for instance, change how aggregate and interpolate are handled, or add further steps. Such overrides may call the base implementation, or not.

Returns:

referring to the data from base_key after any transformation. This may be the same as base_key.

Return type:

Key

use_test_data: bool = False

True to 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'] = []

where keyword argument to path_fallback(). See _where().