Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ master

Added
~~~~~
- (`#24 <https://github.com/iiasa/climate-assessment/pull/24>`_) Ability to specify temperature thresholds, peak percentiles and percentiles in :func:`climate_assessment.climate.climate_assessment`
- (`#15 <https://github.com/iiasa/climate-assessment/pull/15>`_) Fix packaging issues and add installation instructions
- (`#6 <https://github.com/iiasa/climate-assessment/pull/6>`_) Added example run notebooks and tests thereof
- (`#1 <https://github.com/iiasa/climate-assessment/pull/1>`_) Added :func:`climate_assessment.cli.run_workflow`
Expand Down
54 changes: 54 additions & 0 deletions src/climate_assessment/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
-------

Expand Down Expand Up @@ -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,
)


Expand Down
77 changes: 77 additions & 0 deletions tests/integration/test_climate_integration.py
Original file line number Diff line number Diff line change
@@ -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
)