Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from climate_ref_core.datasets import ExecutionDatasetCollection, FacetFilter, SourceDatasetType
from climate_ref_core.diagnostics import DataRequirement
from climate_ref_core.esgf import CMIP6Request, CMIP7Request
from climate_ref_core.metric_values.typing import FileDefinition
from climate_ref_core.metric_values.typing import FileDefinition, SeriesDefinition
from climate_ref_core.pycmec.metric import CMECMetric, MetricCV
from climate_ref_core.pycmec.output import CMECOutput
from climate_ref_core.testing import TestCase, TestDataSpecification
Expand All @@ -32,7 +32,7 @@ class TransientClimateResponseEmissions(ESMValToolDiagnostic):

name = "Transient Climate Response to Cumulative CO2 Emissions"
slug = "transient-climate-response-emissions"
base_recipe = "recipe_tcre.yml"
base_recipe = "ref/recipe_ref_tcre.yml"

variables = (
"tas",
Expand Down Expand Up @@ -78,46 +78,58 @@ class TransientClimateResponseEmissions(ESMValToolDiagnostic):
DataRequirement(
source_type=SourceDatasetType.CMIP7,
filters=(
FacetFilter(
facets={
"branded_variable": (
"fco2antt_tavg-u-hxy-u",
"tas_tavg-h2m-hxy-u",
),
"experiment_id": "esm-1pctCO2",
"frequency": "mon",
"region": "glb",
},
),
FacetFilter(
facets={
"branded_variable": "tas_tavg-h2m-hxy-u",
"experiment_id": "esm-piControl",
"experiment_id": "esm-flat10",
"frequency": "mon",
"region": "glb",
},
),
),
group_by=("source_id", "variant_label", "grid_label"),
constraints=(
AddParentDataset.from_defaults(SourceDatasetType.CMIP7),
AddSupplementaryDataset(
supplementary_facets={
"branded_variable": "fco2antt_tavg-u-hxy-u",
"experiment_id": "esm-flat10",
"frequency": "mon",
"region": "glb",
},
matching_facets=(
"source_id",
"variant_label",
"grid_label",
),
optional_matching_facets=("version",),
),
RequireContiguousTimerange(group_by=("instance_id",)),
RequireFacets("experiment_id", ("esm-1pctCO2", "esm-piControl")),
RequireFacets("variable_id", variables),
RequireFacets("variable_id", ("tas", "fco2antt")),
AddSupplementaryDataset.from_defaults("areacella", SourceDatasetType.CMIP7),
),
),
),
)
facets = ("grid_label", "member_id", "variant_label", "source_id", "region", "metric")
# TODO: the ESMValTool diagnostic script does not save the data for the timeseries.
series = tuple()
series = (
SeriesDefinition(
file_pattern="tcre/calculate/{source_id}.nc",
dimensions={
"statistic": "global annual mean anomaly of tas vs cumulative fco2antt",
},
values_name="tas",
index_name="cumulative_fco2antt",
attributes=[],
),
)
files = (
FileDefinition(
file_pattern="plots/tcre/calculate_tcre/*.png",
file_pattern="plots/tcre/calculate/*.png",
dimensions={"statistic": "tcre"},
),
FileDefinition(
file_pattern="work/tcre/calculate_tcre/tcre.nc",
file_pattern="work/tcre/calculate/tcre.nc",
dimensions={"metric": "tcre"},
),
)
Expand Down Expand Up @@ -147,7 +159,7 @@ class TransientClimateResponseEmissions(ESMValToolDiagnostic):
CMIP7Request(
slug="cmip7",
facets={
"experiment_id": ["esm-1pctCO2", "esm-piControl"],
"experiment_id": ["esm-flat10", "esm-piControl"],
"source_id": "MPI-ESM1-2-LR",
"variable_id": ["areacella", "fco2antt", "tas"],
"branded_variable": [
Expand All @@ -173,31 +185,35 @@ def update_recipe(
) -> None:
"""Update the recipe."""
# Prepare updated datasets section in recipe. It contains three
# datasets, "tas" and "fco2antt" for the "esm-1pctCO2" and just "tas"
# for the "esm-piControl" experiment.
# datasets, "tas" and "fco2antt" for a scenario with steady CO2
# increase (i.e., "esm-flat10" for CMIP7 and "esm-1pctCO2" for CMIP6)
# and just "tas" for the "esm-piControl" experiment.
cmip_source = get_cmip_source_type(input_files)
df = input_files[cmip_source]
tas_esm_1pctCO2, tas_esm_piControl = get_child_and_parent_dataset(
if cmip_source == SourceDatasetType.CMIP6:
exp_duration_in_years = 65
else:
exp_duration_in_years = 110
tas_co2_increase, tas_esm_piControl = get_child_and_parent_dataset(
df[df.variable_id == "tas"],
parent_experiment="esm-piControl",
child_duration_in_years=65,
child_duration_in_years=exp_duration_in_years,
parent_offset_in_years=0,
parent_duration_in_years=65,
parent_duration_in_years=exp_duration_in_years,
)
recipe_variables = dataframe_to_recipe(df[df.variable_id == "fco2antt"])

fco2antt_esm_1pctCO2 = next(
ds for ds in recipe_variables["fco2antt"]["additional_datasets"] if ds["exp"] == "esm-1pctCO2"
)
fco2antt_esm_1pctCO2["timerange"] = tas_esm_1pctCO2["timerange"]
fco2antt_esm_1pctCO2["timerange"] = tas_co2_increase["timerange"]

recipe["diagnostics"]["tcre"]["variables"] = {
"tas_esm-1pctCO2": {
"short_name": "tas",
"tas": {
"preprocessor": "global_annual_mean_anomaly",
"additional_datasets": [tas_esm_1pctCO2],
"additional_datasets": [tas_co2_increase],
},
"tas_esm-piControl": {
"tas_control": {
"short_name": "tas",
"preprocessor": "global_annual_mean_anomaly",
"additional_datasets": [tas_esm_piControl],
Expand All @@ -207,18 +223,21 @@ def update_recipe(
"additional_datasets": [fco2antt_esm_1pctCO2],
},
}
recipe["diagnostics"].pop("barplot")

# Update descriptions.
dataset = tas_esm_1pctCO2["dataset"]
ensemble = tas_esm_1pctCO2["ensemble"]
settings = recipe["diagnostics"]["tcre"]["scripts"]["calculate_tcre"]
settings["caption"] = (
settings["caption"].replace("MPI-ESM1-2-LR", dataset).replace("r1i1p1f1", ensemble)
)
settings["pyplot_kwargs"]["title"] = (
settings["pyplot_kwargs"]["title"].replace("MPI-ESM1-2-LR", dataset).replace("r1i1p1f1", ensemble)
)
# For CMIP6, some special settings are necessary because the esm-flat10
# experiment does not exist
if cmip_source == SourceDatasetType.CMIP6:
diag_settings = recipe["diagnostics"]["tcre"]["scripts"]["calculate"]
diag_settings["calc_tcre_period"] = [45, 65]
diag_settings["caption"] = (
"Global annual mean near-surface air temperature anomaly ΔT vs. "
"global annual cumulative CO2 emissions E of the emission-driven "
"1% CO2 increase per year experiment. The transient climate "
"response to cumulative CO2 Emissions (TCRE) is defined as the "
"20-year average ΔT centered at the time where cumulative CO2 "
"emissions E reach 1000 PgC (i.e., after 55 years)."
)
diag_settings["exp_target"] = "esm-1pctCO2"

@staticmethod
def format_result(
Expand All @@ -228,7 +247,7 @@ def format_result(
output_args: OutputBundleArgs,
) -> tuple[CMECMetric, CMECOutput]:
"""Format the result."""
tcre_ds = xarray.open_dataset(result_dir / "work" / "tcre" / "calculate_tcre" / "tcre.nc")
tcre_ds = xarray.open_dataset(result_dir / "work" / "tcre" / "calculate" / "tcre.nc")
tcre = float(fillvalues_to_nan(tcre_ds["tcre"].values)[0])

# Update the diagnostic bundle arguments with the computed diagnostics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def get_child_and_parent_dataset(
return [child_dataset, parent_dataset]


_ESMVALTOOL_COMMIT = "dead90ca848d3892ed90785b3940909d58d27780"
_ESMVALTOOL_COMMIT = "12cb5309bd64ca4189bc0ef63bcf25e82664e45f"
_ESMVALTOOL_VERSION = f"2.14.0.dev65+g{_ESMVALTOOL_COMMIT[:9]}"
_ESMVALTOOL_URL = f"git+https://github.com/ESMValGroup/ESMValTool.git@{_ESMVALTOOL_COMMIT}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ recipe_calculate_gwl_exceedance_stats.yml 9f28304b85f7043fb76eb29ee84da46e0849
recipe_ecs.yml 0cc57034fcb64e32015b4ff949ece5df8cdb8c6f493618b50ceded119fb37918
recipe_seaice_sensitivity.yml 07270818ebf04a58713dc989720cc9ace77f28d42b1ea189c3bdaf22f5d64577
recipe_tcr.yml 35f9ef035a4e71aff5cac5dd26c49da2162fc00291bf3b0bd16b661b7b2f606b
recipe_tcre.yml 48fc9e3baf541bbcef7491853ea3a774053771dca33352b41466425faeaa38af
recipe_zec.yml b0af7f789b7610ab3f29a6617124aa40c40866ead958204fc199eaf82863de51
ref/recipe_enso_basicclimatology.yml 9ea7deb7ee668e39ac44618b96496d898bd82285c22dcee4fce4695e0c9fa82b
ref/recipe_enso_characteristics.yml 34c2518b138068ac96d212910b979d54a8fcedee2c0089b5acd56a42c41dc3e4
ref/recipe_ref_annual_cycle_region.yml 88e0c2f07a76c4de4276547badcc74091516e03840eddb1f0e62469c67a0a86d
ref/recipe_ref_cre.yml 4375f262479c3b3e1b348b71080a6d758e195bda76516a591182045a3a29aa32
ref/recipe_ref_fire.yml 2ad82effaca4e742d8abe6a0aa07bb46e1e92ef0d2d240760f7623b0ba045926
ref/recipe_ref_ozone.yml 388aaf01721c0856ab7143b47b9d2f1efeaaae4ef57e11572c1e133b49aad0a6
ref/recipe_ref_ozone.yml 09ded4946ecd762ba000916c9f8618120a2e6269930427ae5129da466165f3e5
ref/recipe_ref_sea_ice_area_basic.yml 7d01a8527880663ca28284772f83a8356d9972fb4f022a4000e50a56ce044b09
ref/recipe_ref_scatterplot.yml b99d1736e16256d161847b025811d7088ad9f892d4887fb009fa99c4079135a0
ref/recipe_ref_tcre.yml 85bd9ffc42a4eb70dc7e3d984f0f7c1085232ac8dd977d04d58b27a982254ebd
ref/recipe_ref_timeseries_region.yml deee4403ea25867401e163f6c9d7fcc4fee09d3088009007fcad6a29d01247a8
ref/recipe_ref_trend_regions.yml 18fe246a51474bd12172ab1ba141efac999a247de7774822f77ae6ef144645fe
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,6 @@ documentation:
- schlund_manuel
references:
- sanderson24gmd
domains:
- global
realms:
- atmos
themes:
- carbon
- bgphys
datasets_target_exp:
- project: CMIP6
dataset: MPI-ESM1-2-LR
ensemble: r1i1p1f1
grid: gn
timerange: 1850/1914
datasets_control_exp:
- project: CMIP6
dataset: MPI-ESM1-2-LR
ensemble: r1i1p1f1
grid: gn
timerange: 1850/1914
preprocessors:
global_annual_mean_anomaly:
custom_order: true
Expand All @@ -53,8 +34,7 @@ preprocessors:
diagnostics:
tcre:
variables:
tas_esm-1pctCO2:
short_name: tas
tas:
preprocessor: global_annual_mean_anomaly
additional_datasets:
- project: CMIP6
Expand All @@ -66,7 +46,7 @@ diagnostics:
grid: gn
mip: Amon
timerange: 1850/1914
tas_esm-piControl:
tas_control:
short_name: tas
preprocessor: global_annual_mean_anomaly
additional_datasets:
Expand All @@ -92,20 +72,18 @@ diagnostics:
mip: Amon
timerange: 1850/1914
scripts:
calculate_tcre:
calculate:
script: climate_metrics/tcre.py
calc_tcre_period:
- 45
- 65
caption: "Global annual mean near-surface air temperature anomaly \u0394T\
\ vs.\nglobal annual cumulative CO2 emissions E of the emission-driven 1%\n\
CO2 increase per year experiment for model MPI-ESM1-2-LR (ensemble\nmember\
\ r1i1p1f1). The transient climate response to cumulative CO2\nEmissions\
\ (TCRE) is defined as the 20-year average \u0394T centered at\nthe time\
\ where cumulative CO2 emissions E reach 1000 PgC.\n"
exp_target: esm-1pctCO2
legend_kwargs: false
\ vs. global annual cumulative CO2 emissions E of the emission-driven 1%\
\ CO2 increase per year experiment. The transient climate response to cumulative\
\ CO2 Emissions (TCRE) is defined as the 20-year average \u0394T centered\
\ at the time where cumulative CO2 emissions E reach 1000 PgC (i.e., after\
\ 55 years)."
pyplot_kwargs:
title: MPI-ESM1-2-LR (ensemble member r1i1p1f1)
xlabel: E [PgC]
ylabel: "\u0394T [K]"
calc_tcre_period:
- 45
- 65
exp_target: esm-1pctCO2
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ cmip6_gn_r1i1p1f1_MPI-ESM1-2-LR:
- CMIP6.C4MIP CDRMIP.MPI-M.MPI-ESM1-2-LR.esm-1pctCO2.r1i1p1f1.Amon.tas.gn.v20190815
- CMIP6.CMIP.MPI-M.MPI-ESM1-2-LR.1pctCO2.r1i1p1f1.fx.areacella.gn.v20190710
- CMIP6.CMIP.MPI-M.MPI-ESM1-2-LR.esm-piControl.r1i1p1f1.Amon.tas.gn.v20190815
cmip7_gn_MPI-ESM1-2-LR_r1i1p1f1:
cmip7:
- CMIP7.C4MIP CDRMIP.MPI-M.MPI-ESM1-2-LR.esm-1pctCO2.r1i1p1f1.glb.mon.fco2antt.tavg-u-hxy-u.gn.v20190815
- CMIP7.C4MIP CDRMIP.MPI-M.MPI-ESM1-2-LR.esm-1pctCO2.r1i1p1f1.glb.mon.tas.tavg-h2m-hxy-u.gn.v20190815
- CMIP7.CMIP.MPI-M.MPI-ESM1-2-LR.1pctCO2.r1i1p1f1.glb.fx.areacella.ti-u-hxy-u.gn.v20190710
- CMIP7.CMIP.MPI-M.MPI-ESM1-2-LR.esm-piControl.r1i1p1f1.glb.mon.tas.tavg-h2m-hxy-u.gn.v20190815
Loading