diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 2eb66e7..631f05f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,7 @@ master Added ~~~~~ +- (`#24 `_) Ability to specify temperature thresholds, peak percentiles and percentiles in :func:`climate_assessment.climate.climate_assessment` - (`#15 `_) Fix packaging issues and add installation instructions - (`#6 `_) Added example run notebooks and tests thereof - (`#1 `_) Added :func:`climate_assessment.cli.run_workflow` diff --git a/src/climate_assessment/climate/__init__.py b/src/climate_assessment/climate/__init__.py index b91e261..495e5e5 100644 --- a/src/climate_assessment/climate/__init__.py +++ b/src/climate_assessment/climate/__init__.py @@ -43,10 +43,30 @@ def climate_assessment( fair_extra_config=None, co2_and_non_co2_warming=False, prefix="AR6 climate diagnostics", + temp_thresholds=(1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0), + peak_percentiles=(5, 10, 17, 25, 33, 50, 66, 67, 75, 83, 90, 95), + percentiles=( + 5, + 10, + 1 / 6 * 100, + 17, + 25, + 33, + 50, + 66, + 67, + 75, + 83, + 5 / 6 * 100, + 90, + 95, + ), ): """ Run the climate assessment + TODO: re-write all of these docs + Parameters ---------- df : :class:`pyam.IamDataFrame` @@ -203,6 +223,9 @@ def save_pyam_style_meta_table(outpath, meta_table): outdir=outdir, test_run=test_run, co2_and_non_co2_warming=co2_and_non_co2_warming, + temp_thresholds=temp_thresholds, + peak_percentiles=peak_percentiles, + percentiles=percentiles, ) LOGGER.info( @@ -286,6 +309,24 @@ def run_and_post_process( test_run, save_raw_output, co2_and_non_co2_warming, + temp_thresholds=(1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0), + peak_percentiles=(5, 10, 17, 25, 33, 50, 66, 67, 75, 83, 90, 95), + percentiles=( + 5, + 10, + 1 / 6 * 100, + 17, + 25, + 33, + 50, + 66, + 67, + 75, + 83, + 5 / 6 * 100, + 90, + 95, + ), ): """ Run the climate models probabilistically @@ -325,6 +366,16 @@ def run_and_post_process( co2_and_non_co2_warming : bool Include assessment of CO2 and non-CO2 warming? + temp_thresholds : tuple[float] + Temperature thresholds for which exceedance probabilities are + calculated + + peak_percentiles : tuple[float] + Percentiles at which peak warming is calculated + + percentiles : tuple[float] + Percentiles to report in the output for timeseries + Returns ------- @@ -414,6 +465,9 @@ def run_and_post_process( historical_warming=historical_warming, historical_warming_reference_period=historical_warming_reference_period, historical_warming_evaluation_period=historical_warming_evaluation_period, + temp_thresholds=temp_thresholds, + peak_percentiles=peak_percentiles, + percentiles=percentiles, ) diff --git a/tests/integration/test_climate_integration.py b/tests/integration/test_climate_integration.py new file mode 100644 index 0000000..1932a2e --- /dev/null +++ b/tests/integration/test_climate_integration.py @@ -0,0 +1,77 @@ +import os.path + +import pyam + +from climate_assessment.climate import climate_assessment + + +def test_climate_assessment_percentiles( + fair_slim_configs_filepath, + fair_common_configs_filepath, + tmpdir, + test_data_dir, +): + temp_thresholds_1 = (1.5, 2.0) + temp_thresholds_2 = (1.5, 1.6, 1.7) + + peak_percentiles_1 = (5, 10) + peak_percentiles_2 = (5, 50, 95) + + percentiles_1 = (17, 83) + percentiles_2 = (25, 50, 75) + + df = pyam.IamDataFrame( + os.path.join( + test_data_dir, + "workflow-fair", + "ex2_harmonized_infilled.csv", + ) + ) + df = df.filter(model=df.model[0]) + + common_kwargs = dict( + df=df, + key_string="test_climate_assessment_percentiles", + outdir=tmpdir, + model="fair", + num_cfgs=30, + probabilistic_file=fair_slim_configs_filepath, + fair_extra_config=fair_common_configs_filepath, + test_run=True, + ) + + res_1 = climate_assessment( + **common_kwargs, + temp_thresholds=temp_thresholds_1, + peak_percentiles=peak_percentiles_1, + percentiles=percentiles_1, + ) + + res_2 = climate_assessment( + **common_kwargs, + temp_thresholds=temp_thresholds_2, + peak_percentiles=peak_percentiles_2, + percentiles=percentiles_2, + ) + + for thresholds, peak_percentiles, percentiles, res in ( + (temp_thresholds_1, peak_percentiles_1, percentiles_1, res_1), + (temp_thresholds_2, peak_percentiles_2, percentiles_2, res_2), + ): + for t in thresholds: + assert f"Exceedance Probability {t:.1f}C (FaIRv1.6.2)" in res.meta + + for pp in peak_percentiles: + if pp == 50: + pp_s = "median" + else: + pp_s = f"p{pp:.0f}" + + assert f"{pp_s} peak warming (FaIRv1.6.2)" in res.meta + assert f"{pp_s} year of peak warming (FaIRv1.6.2)" in res.meta + + for p in percentiles: + assert ( + f"AR6 climate diagnostics|Surface Temperature (GSAT)|FaIRv1.6.2|{p:.1f}th Percentile" + in res.variable + )