Pyam (compat.pyam)

Package documentation

genno.compat.pyam.computations.as_pyam(scenario, quantity, rename={}, collapse: Optional[Callable] = None, replace={}, drop: Union[Collection[str], str] = 'auto', unit=None)[source]

Return a pyam.IamDataFrame containing quantity.

Warnings are logged if the arguments result in additional, unhandled columns in the resulting data frame that are not part of the IAMC spec.


scenario – Any objects with model and scenario attributes of type str, e.g. ixmp.Scenario.


ValueError – If the resulting data frame has duplicate values in the standard IAMC index columns. pyam.IamDataFrame cannot handle this data.

genno.compat.pyam.computations.concat(*args, **kwargs)[source]

Concatenate args, which must all be pyam.IamDataFrame.

genno.compat.pyam.computations.write_report(quantity, path)[source]

Write the report identified by key to the file at path.

If quantity is a pyam.IamDataFrame and path ends with ‘.csv’ or ‘.xlsx’, use pyam methods to write the file to CSV or Excel format, respectively. Otherwise, equivalent to genno.computations.write_report().

genno.compat.pyam.util.clean_units(df: pandas.core.frame.DataFrame, unit=None) pandas.core.frame.DataFrame[source]

Convert magnitudes and units of df to unit in str.


ValueError – if there is more than one unit.

genno.compat.pyam.util.collapse(df: pandas.core.frame.DataFrame, columns: Mapping[str, Sequence[str]] = {}, sep='|') pandas.core.frame.DataFrame[source]

Collapse columns into the IAMC columns of df.

genno.compat.pyam.util.drop(df: pandas.core.frame.DataFrame, columns: Union[Collection[str], str]) pandas.core.frame.DataFrame[source]

Drop columns if given, or all non-IAMC columns.


compat.pyam adds a iamc: configuration file section.


Handle one entry from the iamc: config section.

Computer-specific configuration.

Invokes Computer.convert_pyam() (plus extra computations) to reformat data from Quantity into a pyam.IamDataFrame data structure. Each entry contains:

variable: (str)

Variable name. This is used two ways: it is placed in ‘Variable’ column of the resulting IamDataFrame; and the reporting key to get() the data frame is <variable>:iamc.

base: (str)

Key for the quantity to convert.

select: (dict, optional)

Keyword arguments to

rename: (dict, optional)

Passed to convert_pyam().

replace: (dict, optional)

Passed to convert_pyam().

drop: (list of str, optional)

Dimensions to drop (→ convert_pyam).

unit: (str, optional)

Force output in these units (→ convert_pyam).

Additional entries are passed as keyword arguments to collapse(), which is then given as the collapse callback for convert_pyam().

collapse() formats the ‘Variable’ column of the IamDataFrame. The variable name replacements from the iamc variable names: section of the config file are applied to all variables.