Skip to content

openscm_calibration.scmdata_utils#

scmdata utility functions

Functions:

Name Description
scmrun_as_dict

Group an input into a dictionary with keys

scmrun_as_dict #

scmrun_as_dict(
    inp: BaseScmRun,
    groups: Iterable[str],
    separator: str = "_",
) -> dict[str, BaseScmRun]

Group an input into a dictionary with keys

Parameters:

Name Type Description Default
inp BaseScmRun

Data to group

required
groups Iterable[str]

Metadata keys to use to make the groups

required
separator str

Separator for metadata values when making the keys

'_'

Returns:

Type Description
dict[str, BaseScmRun]

Grouped inp

Source code in src/openscm_calibration/scmdata_utils.py
def scmrun_as_dict(
    inp: scmdata.run.BaseScmRun, groups: Iterable[str], separator: str = "_"
) -> dict[str, scmdata.run.BaseScmRun]:
    """
    Group an input into a dictionary with keys

    Parameters
    ----------
    inp
        Data to group

    groups
        Metadata keys to use to make the groups

    separator
        Separator for metadata values when making the keys

    Returns
    -------
    :
        Grouped `inp`
    """
    res = {}
    for inp_g in inp.groupby(groups):
        key = str(separator.join([str(inp_g.get_unique_meta(g, True)) for g in groups]))
        res[key] = inp_g

    return res