From cd332744bf7b8a738bbe92aa77c0f4e5625ddbfc Mon Sep 17 00:00:00 2001 From: Bouwe Andela Date: Mon, 16 Feb 2026 17:00:16 +0100 Subject: [PATCH] Fix fire diagnostic CMIP7 data selection and recipe writing --- changelog/540.fix.md | 1 + .../diagnostics/climate_drivers_for_fire.py | 70 ++++++-------- .../recipe_climate_drivers_for_fire_cmip6.yml | 94 +++++++++++++++++-- 3 files changed, 116 insertions(+), 49 deletions(-) create mode 100644 changelog/540.fix.md diff --git a/changelog/540.fix.md b/changelog/540.fix.md new file mode 100644 index 000000000..4fc07bdca --- /dev/null +++ b/changelog/540.fix.md @@ -0,0 +1 @@ +Fixed fire diagnostic CMIP7 data selection and recipe writing. diff --git a/packages/climate-ref-esmvaltool/src/climate_ref_esmvaltool/diagnostics/climate_drivers_for_fire.py b/packages/climate-ref-esmvaltool/src/climate_ref_esmvaltool/diagnostics/climate_drivers_for_fire.py index 44161532f..169b41de4 100644 --- a/packages/climate-ref-esmvaltool/src/climate_ref_esmvaltool/diagnostics/climate_drivers_for_fire.py +++ b/packages/climate-ref-esmvaltool/src/climate_ref_esmvaltool/diagnostics/climate_drivers_for_fire.py @@ -99,6 +99,7 @@ class ClimateDriversForFire(ESMValToolDiagnostic): "branded_variable": ( "cVeg_tavg-u-hxy-lnd", "treeFrac_tavg-u-hxy-u", + "vegFrac_tavg-u-hxy-u", ), "experiment_id": "historical", "frequency": "mon", @@ -106,15 +107,6 @@ class ClimateDriversForFire(ESMValToolDiagnostic): "realm": "land", } ), - FacetFilter( - { - "branded_variable": "vegFrac_tavg-u-hxy-u", - "experiment_id": "historical", - "frequency": "mon", - "region": "glb", - "realm": "land", - } - ), ), group_by=("source_id", "variant_label", "grid_label"), constraints=( @@ -125,16 +117,16 @@ class ClimateDriversForFire(ESMValToolDiagnostic): ), AddSupplementaryDataset.from_defaults("sftlf", SourceDatasetType.CMIP7), RequireFacets( - "variable_id", + "branded_variable", ( - "cVeg", - "hurs", - "pr", - "tas", - "tasmax", - "sftlf", - "treeFrac", - "vegFrac", + "cVeg_tavg-u-hxy-lnd", + "hurs_tavg-h2m-hxy-u", + "pr_tavg-u-hxy-u", + "sftlf_ti-u-hxy-u", + "tas_tavg-h2m-hxy-u", + "tas_tmaxavg-h2m-hxy-u", + "treeFrac_tavg-u-hxy-u", + "vegFrac_tavg-u-hxy-u", ), ), ), @@ -234,27 +226,27 @@ def update_recipe( """Update the recipe.""" cmip_source = get_cmip_source_type(input_files) recipe_variables = dataframe_to_recipe(input_files[cmip_source]) + recipe.pop("datasets") + for diagnostic in recipe["diagnostics"].values(): + for variable_group, variable in diagnostic.get("variables", {}).items(): + cmip6_short_name = variable.get("short_name", variable_group) + if cmip_source == SourceDatasetType.CMIP7 and cmip6_short_name == "tasmax": + short_name = "tas" + else: + short_name = cmip6_short_name + variable["short_name"] = short_name + variable["start_year"] = 2013 + variable["end_year"] = 2014 + datasets = recipe_variables[short_name]["additional_datasets"] + for dataset in datasets: + dataset.pop("timerange", None) + if cmip_source == SourceDatasetType.CMIP7 and short_name == "tas": + # Separate the two "tas" datasets into "tas" and "tasmax". + if cmip6_short_name == "tasmax": + datasets = [d for d in datasets if d["branding_suffix"] == "tmaxavg-h2m-hxy-u"] + else: + datasets = [d for d in datasets if d["branding_suffix"] == "tavg-h2m-hxy-u"] - if cmip_source == SourceDatasetType.CMIP7: - # CMIP7: use per-variable additional_datasets to preserve correct branding_suffix - recipe["datasets"] = [] - for diagnostic in recipe["diagnostics"].values(): - for var_name, variable in diagnostic.get("variables", {}).items(): - short_name = variable.get("short_name", var_name) - if short_name in recipe_variables: - datasets = recipe_variables[short_name]["additional_datasets"] - for ds in datasets: - ds.pop("mip", None) - ds.pop("timerange", None) - ds["start_year"] = 2013 - ds["end_year"] = 2014 - variable["additional_datasets"] = datasets - else: - dataset = recipe_variables["cVeg"]["additional_datasets"][0] - dataset.pop("mip") - dataset.pop("timerange") - dataset["start_year"] = 2013 - dataset["end_year"] = 2014 - recipe["datasets"] = [dataset] + variable["additional_datasets"] = datasets recipe["diagnostics"]["fire_evaluation"]["scripts"]["fire_evaluation"]["remove_confire_files"] = True diff --git a/packages/climate-ref-esmvaltool/tests/unit/diagnostics/recipes/recipe_climate_drivers_for_fire_cmip6.yml b/packages/climate-ref-esmvaltool/tests/unit/diagnostics/recipes/recipe_climate_drivers_for_fire_cmip6.yml index 3fa32c46e..49b7e0636 100644 --- a/packages/climate-ref-esmvaltool/tests/unit/diagnostics/recipes/recipe_climate_drivers_for_fire_cmip6.yml +++ b/packages/climate-ref-esmvaltool/tests/unit/diagnostics/recipes/recipe_climate_drivers_for_fire_cmip6.yml @@ -12,16 +12,6 @@ documentation: - kelley_douglas maintainer: - lenhardt_julien -datasets: -- project: CMIP6 - activity: CMIP - dataset: ACCESS-ESM1-5 - ensemble: r1i1p1f1 - institute: CSIRO - exp: historical - grid: gn - start_year: 2013 - end_year: 2014 preprocessors: preproc: regrid: @@ -44,24 +34,108 @@ diagnostics: pr: mip: Amon preprocessor: preproc + short_name: pr + start_year: 2013 + end_year: 2014 + additional_datasets: + - project: CMIP6 + activity: CMIP + dataset: ACCESS-ESM1-5 + ensemble: r1i1p1f1 + institute: CSIRO + exp: historical + grid: gn + mip: Amon tasmax: mip: Amon preprocessor: preproc + short_name: tasmax + start_year: 2013 + end_year: 2014 + additional_datasets: + - project: CMIP6 + activity: CMIP + dataset: ACCESS-ESM1-5 + ensemble: r1i1p1f1 + institute: CSIRO + exp: historical + grid: gn + mip: Amon treeFrac: mip: Lmon preprocessor: preproc_fraction + short_name: treeFrac + start_year: 2013 + end_year: 2014 + additional_datasets: + - project: CMIP6 + activity: CMIP + dataset: ACCESS-ESM1-5 + ensemble: r1i1p1f1 + institute: CSIRO + exp: historical + grid: gn + mip: Lmon vegFrac: mip: Emon preprocessor: preproc_fraction + short_name: vegFrac + start_year: 2013 + end_year: 2014 + additional_datasets: + - project: CMIP6 + activity: CMIP + dataset: ACCESS-ESM1-5 + ensemble: r1i1p1f1 + institute: CSIRO + exp: historical + grid: gn + mip: Emon cVeg: mip: Lmon preprocessor: preproc + short_name: cVeg + start_year: 2013 + end_year: 2014 + additional_datasets: + - project: CMIP6 + activity: CMIP + dataset: ACCESS-ESM1-5 + ensemble: r1i1p1f1 + institute: CSIRO + exp: historical + grid: gn + mip: Lmon tas: mip: Amon preprocessor: preproc + short_name: tas + start_year: 2013 + end_year: 2014 + additional_datasets: + - project: CMIP6 + activity: CMIP + dataset: ACCESS-ESM1-5 + ensemble: r1i1p1f1 + institute: CSIRO + exp: historical + grid: gn + mip: Amon hurs: mip: Amon preprocessor: preproc + short_name: hurs + start_year: 2013 + end_year: 2014 + additional_datasets: + - project: CMIP6 + activity: CMIP + dataset: ACCESS-ESM1-5 + ensemble: r1i1p1f1 + institute: CSIRO + exp: historical + grid: gn + mip: Amon scripts: fire_evaluation: script: fire/fire_diagnostic.py