xarray.Dataset.pr.add_aggregates_variables

xarray.Dataset.pr.add_aggregates_variables#

Dataset.pr.add_aggregates_variables(gas_baskets: dict[str, list[str] | dict[str, float | str | list[str] | dict[str, str | list[str]]]], tolerance: float | None = 0.01, skipna: bool | None = True, min_count: int | None = 1) Dataset#

Creates or fills gas baskets

No sanity check on what you aggregate, so you could aggregate CH4 and CO2 to N2O

If a gas basket is present the aggregate data are merged to check if aggregated and existing data agree within the given tolerance.

Parameters:
gas_baskets: dict

dict with the following format:

gas_baskets = {
    "new_variable1": {
        'sources': [source_values],
        'tolerance': <non-default tolerance> (optional),
        'filter': <filter in pr.loc style> (optional),
    },
    "new_value": [source_values], # simplified format for coord2
    ...
}
example:
gas_baskets = {
    'FGASES (AR4GWP100)': ['SF6', 'NF3', 'HFCS (AR4GWP100)', 'PFCS (AR4GWP100)'],
    'KYOTOGHG (AR4GWP100)': {
        'sources': ['CO2', 'CH4', 'N2O', 'FGASES (AR4GWP100)'],
        'filter': {'area (ISO3)': ['COL']},
        'tolerance': 0.015,
    },
}
tolerance:

non-default tolerance for merging (default = 0.01 (1%))

skipna: bool, optional

If True (default), skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).

min_count: int (default None, but set to 1 if skipna=True)

The minimal number of non-NA values in a sum that is necessary for a non-NA result. This only has an effect if skipna=True. As an example: you sum data for a region for a certain sector, gas and year. If skipna=False, all countries in the region need to have non-NA data for that sector, gas, year combination. If skipna=True and min_count=1 then one country with non-NA data is enough for a non-NA result. All NA values will be treated as zero. If min_count=0 all NA values will be treated as zero also if there is no single non-NA value in the data that is to be summed.

Returns:
xr.Dataset

Input with aggregated gas baskets added