Pyam (compat.pyam)#

Package documentation

genno.compat.pyam.computations.as_pyam(scenario, quantity, rename={}, collapse: Callable | None = None, replace={}, drop: 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.

Parameters:

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

Raises:

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(obj, path: str | PathLike) None[source]#

Write obj` to the file at path.

If obj 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: DataFrame, unit=None) DataFrame[source]#

Convert magnitudes and units of df to unit in str.

Raises:

ValueError – if there is more than one unit.

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

Collapse columns into the IAMC columns of df.

genno.compat.pyam.util.drop(df: DataFrame, columns: Collection[str] | str) DataFrame[source]#

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

Configuration#

compat.pyam adds a iamc: configuration file section.

pyam.iamc(info)#

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 computations.select().

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.