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
Functions
|
Make a codelist for the concept id, given data. |
Return common metadata for IAMC-like data and structures. |
|
|
|
|
Return IAMC-like data structures describing data. |
|
Create a DSD and code lists for a particular measure from variable parts. |
|
Make structures for IAMC-like "VARIABLE" data. |
|
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.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
intcodes 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 generatedMaintainableArtefact.
- 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:
- 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_keysgenerates 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-dsdThe URN of dsd. This allows an unambiguous association to the full-dimensionality data structure definition.
iamc-full-keyThe
repr()of adictcorresponding 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