Code reference

Handle data and structure for IAMC-like formats.

Todo

Add a function to generate distinct DSDs for each data flow in a data set.

Todo

Add function(s) to reshape IAMC-like data.

Submodules

cli

CLI for iamc.

Functions

cl_for_data(data, id, **ma_kwargs)

Make a codelist for the concept id, given data.

common_structures()

Return common metadata for IAMC-like data and structures.

get_agencies()

provides()

structures_for_data(data[, base_id, maintainer])

Return IAMC-like data structures describing data.

structures_for_measure(measure, parts, ...)

Create a DSD and code lists for a particular measure from variable parts.

structures_for_variable(data, **ma_kwargs)

Make structures for IAMC-like "VARIABLE" data.

variable_cl_for_dsd(dsd[, codelist])

Generate an SDMX codelist with IAMC "VARIABLE" codes corresponding to dsd.

transport_data.iamc.cl_for_data(data: Series, id: str, **ma_kwargs) Codelist[source]

Make a codelist for the concept id, given data.

Parameters:

ma_kwargs – Keyword arguments for MaintainableArtefact.

transport_data.iamc.common_structures()[source]

Return common metadata for IAMC-like data and structures.

Returns:

with id “IAMC”, containing the concepts for the IAMC dimensions and attribute.

Return type:

ConceptScheme

transport_data.iamc.get_agencies()[source]
transport_data.iamc.provides()[source]
transport_data.iamc.structures_for_data(data: DataFrame, base_id: str = 'GENERATED', maintainer: Agency | None = None) StructureMessage[source]

Return IAMC-like data structures describing data.

Parameters:
  • data (pandas.DataFrame) –

    Data in IAMC tabular format.

    • Either long (with a “YEAR” column) or wide (no “YEAR” column but one or more columns with int codes for the “YEAR” dimension).

    • Column names in any case. Upper-cased column names must appear in the IAMC concept scheme (get_iamc_structures()).

  • maintainer (Agency, optional) – Maintainer to be associated with generated MaintainableArtefact.

Returns:

including:

  • The “IAMC” ConceptScheme from get_iamc_structures().

  • A data structure definition with ID base_id.

  • One code list for each dimension.

  • A “MEASURE” concept scheme including the unique measures: that is, parts appearing before the first pipe (“|”) separator in the “VARIABLE” column of data.

  • For each measure: 0 or more code lists, each containing codes for a single dimension in the parts of “VARIABLE” column values beyond the first pipe (“|”) separator.

Return type:

StructureMessage

transport_data.iamc.structures_for_measure(measure: Concept, parts: DataFrame, **ma_kwargs) list[source]

Create a DSD and code lists for a particular measure from variable parts.

Parameters:

ma_kwargs – Keyword arguments for MaintainableArtefact.

transport_data.iamc.structures_for_variable(data: Series, **ma_kwargs) list[source]

Make structures for IAMC-like “VARIABLE” data.

Parameters:

ma_kwargs – Keyword arguments for MaintainableArtefact.

Returns:

A sequence of SDMX structures.

Return type:

list

transport_data.iamc.variable_cl_for_dsd(dsd: BaseDataStructureDefinition, codelist: Codelist | None = None) Codelist[source]

Generate an SDMX codelist with IAMC “VARIABLE” codes corresponding to dsd.

The dimensions of dsd are each enumerated by an associated codelist. DataStructureDefinition.iter_keys generates one key for each member of the Cartesian product of these sets.

variable_cl_for_dsd() collapses each of these into a code whose ID is a constructed IAMC “VARIABLE” name like “Primary Measure|Foo|Bar|Baz”. In these:

  • The part before the first pipe (“Primary Measure|”) is the name of the concept identity for the primary measure of dsd.

  • The remaining parts (“Foo|Bar|Baz”) are the names of the codes for each dimension of dsd.

If the code lists that enumerate dsd contain codes with the special ID “_T”, then variable_cl_for_dsd() also generates corresponding IAMC-style names for aggregates. In the above example, if the third dimension contains a “_T”

Every code also has annotations with the following IDs and text:

iamc-full-dsd

The URN of dsd. This allows an unambiguous association to the full-dimensionality data structure definition.

iamc-full-key

The repr() of a dict corresponding to a full resolution key, mapping dimension ID to code ID; for example “{‘dim_0’: ‘FOO’, ‘dim_1’: ‘BAR’, ‘dim_2’: ‘BAZ’}”. This allows to restore or recover a valid key within dsd, given the IAMC “VARIABLE”.

If codelist is supplied, the new codes are appended.

Parameters:
  • dsd – Existing data structure definition.

  • codelist (Codelist, optional) – Existing code list.

Returns:

The same object as codelist, if supplied, else a new code list with id “VARIABLE”.

Return type:

Codelist