Utility functions
- climate_assessment.utils.columns_to_basic(df)
Takes a pyam.IamDataFrame and only keeps the basic columns [“model”, “scenario”, “region”, “variable”, “unit”, “year”, “value”], discarding potential other input columns ([“exclude”, “meta”, “subannual”, “version”]).
- Parameters
df (
pyam.IamDataFrame
) – The input data to be formatted.- Returns
The input data with only the remaining basic columns.
- Return type
pyam.IamDataFrame
- climate_assessment.utils.require_var_allyears(df, vars)
Filter out the scenarios that, for a set of variables, do not report all required years. This is currently hard-coded to be decadal from 2020 to 2100.
- Parameters
df (
pyam.IamDataFrame
) – The input data to be checked and filtered.- Returns
The output data with only scenarios that have full-century information for all necessary variables.
- Return type
pyam.IamDataFrame
- climate_assessment.utils.convert_units_to_co2_equiv(df, metric)
Converts the units of gases reported in kt into Mt CO2 equivalent per year
Uses GWP100 values from either (by default) AR5 or AR4 IPCC reports.
- Parameters
df (
pyam.IamDataFrame
) – The input dataframe whose units need to be converted.metric (str) – The name of the conversion metric to use. This will usually be AR<4/5/6>GWP100.
- Returns
The input data with units converted.
- Return type
pyam.IamDataFrame
- climate_assessment.utils.convert_co2_equiv_to_kt_gas(df, var_filter, metric='AR6GWP100')
Convert units from CO2 equivalent to kt of gas.
- Parameters
df (
pyam.IamDataFrame
) – The input data to be converted.var_filter (list[str], str) – Filter to use to pick the variables to convert
metric (str) – The name of the conversion metric to use. This will usually be AR<4/5/6>GWP100.
- Returns
The input data with units converted.
- Return type
pyam.IamDataFrame
- climate_assessment.utils.add_gwp100_kyoto_wrapper(df, prefixes=['', 'AR6 climate diagnostics|Harmonized|', 'AR6 climate diagnostics|Infilled|'], gwps=['AR5GWP100', 'AR6GWP100'])
Add Kyoto GWP100 emissions
- Parameters
df (
pyam.IamDataFrame
) –pyam.IamDataFrame
containing emissions from which the GWP sum should be createdprefixes (list[str]) – List of prefixes to use for the aggregation
gwps (list[str]) – GWPs to use for aggregation
- Returns
Input emissions plus the Kyoto GWP100 equivalents
- Return type
pyam.IamDataFrame
- climate_assessment.utils.parallel_progress_bar(tqdm_bar)
Context manage to patch joblib so it shows a progress bar with tqdm
Shoutout to https://stackoverflow.com/a/58936697 for the original implementation of this code
- climate_assessment.utils.split_df(df, **filter_options)
This function splits the dataframe into model/scenario sets that fulfill the filter condition and those that don’t.
- Parameters
df (
pyam.IamDataFrame
) – Input scenario data- Returns
to_return_1 (
pyam.IamDataFrame
) – Scenarios that fulfill the condition.to_return_2 (
pyam.IamDataFrame
) – Scenarios that do not fulfill the condition.
- climate_assessment.utils._perform_operation(df, var_1, var_2, out_variable, op, raise_if_mismatch=True)
Helper function that is called in
_diff_variables()
and_add_variables()
, instead of silicone.multiple_infillers.infill_composite_values, because silicone.multiple_infillers.infill_composite_values does not check whether all components are included.
- climate_assessment.utils._diff_variables(df, var_1, var_2, out_variable, raise_if_mismatch=True)
Calculates the difference between two variables, and adds this new variable to the dataframe.
- Parameters
df (
pyam.IamDataFrame
) – Input scenario datavar_1 (str) – First variable in operation
var_2 (str) – Second variable in operation
out_variable (str) – What to call the new variable
- Returns
Dataframe with added difference variable
- Return type
pyam.IamDataFrame
- climate_assessment.utils._add_variables(df, var_1, var_2, out_variable, raise_if_mismatch=True)
Calculates the sum of two variables, and adds this as a new variable to the dataframe.
- Parameters
df (
pyam.IamDataFrame
) – Input scenario datavar_1 (str) – First variable in operation
var_2 (str) – Second variable in operation
out_variable (str) – What to call the new variable
- Returns
Dataframe with added sum variable
- Return type
pyam.IamDataFrame