-
Notifications
You must be signed in to change notification settings - Fork 14
Add a diagnostic to compute cloud radiative effects #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lewisjared
merged 12 commits into
Climate-REF:main
from
bouweandela:add-esmvaltool-cloud-radiative-effects
May 8, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c513b1
Add an ESMValTool metric to compute climatologies and zonal mean prof…
bouweandela b955596
Add test
bouweandela 01fd30e
Add changelog entry
bouweandela f6e2ff8
Remove output bundle
bouweandela 6c40387
Add observational data
bouweandela 067e845
Merge branch 'main' into add-esmvaltool-cloud-radiative-effects
bouweandela 03920bb
Merge branch 'main' of github.com:Climate-REF/climate-ref into add-es…
bouweandela 11bc0ff
Small improvements
bouweandela 9fe70ac
Sort variables
bouweandela 631e768
Merge branch 'main' of github.com:Climate-REF/climate-ref into add-es…
bouweandela 8bd357b
Add regression test data
bouweandela ccaeae7
Merge branch 'main' into add-esmvaltool-cloud-radiative-effects
lewisjared File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Added an ESMValTool metric to compute climatologies and zonal mean profiles of | ||
| cloud radiative effects. |
12 changes: 12 additions & 0 deletions
12
packages/climate-ref-esmvaltool/src/climate_ref_esmvaltool/dataset_registry/data.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
.../climate-ref-esmvaltool/src/climate_ref_esmvaltool/diagnostics/cloud_radiative_effects.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import pandas | ||
|
|
||
| from climate_ref_core.constraints import ( | ||
| AddSupplementaryDataset, | ||
| RequireContiguousTimerange, | ||
| RequireFacets, | ||
| RequireOverlappingTimerange, | ||
| ) | ||
| from climate_ref_core.datasets import FacetFilter, SourceDatasetType | ||
| from climate_ref_core.diagnostics import DataRequirement | ||
| from climate_ref_esmvaltool.diagnostics.base import ESMValToolDiagnostic | ||
| from climate_ref_esmvaltool.recipe import dataframe_to_recipe | ||
| from climate_ref_esmvaltool.types import Recipe | ||
|
|
||
|
|
||
| class CloudRadiativeEffects(ESMValToolDiagnostic): | ||
| """ | ||
| Plot climatologies and zonal mean profiles of cloud radiative effects (sw + lw) for a dataset. | ||
| """ | ||
|
|
||
| name = "Climatologies and zonal mean profiles of cloud radiative effects" | ||
| slug = "cloud-radiative-effects" | ||
| base_recipe = "ref/recipe_ref_cre.yml" | ||
|
|
||
| # TODO: These facets are needed to pass metric bundle validation, | ||
| # in the integration test, but this diagnostic does not produce a metric. | ||
| # Should they be removed? | ||
| facets = ("model", "metric") | ||
|
|
||
| variables = ( | ||
| "rlut", | ||
| "rlutcs", | ||
| "rsut", | ||
| "rsutcs", | ||
| ) | ||
| data_requirements = ( | ||
| DataRequirement( | ||
| source_type=SourceDatasetType.CMIP6, | ||
| filters=( | ||
| FacetFilter( | ||
| facets={ | ||
| "variable_id": variables, | ||
| "experiment_id": ("historical",), | ||
| } | ||
| ), | ||
| ), | ||
| group_by=("source_id", "member_id", "grid_label"), | ||
| constraints=( | ||
| RequireFacets("variable_id", variables), | ||
| RequireContiguousTimerange(group_by=("instance_id",)), | ||
| RequireOverlappingTimerange(group_by=("instance_id",)), | ||
| AddSupplementaryDataset.from_defaults("areacella", SourceDatasetType.CMIP6), | ||
| ), | ||
| ), | ||
| # TODO: Use CERES-EBAF, ESACCI-CLOUD, and ISCCP-FH from obs4MIPs once available. | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def update_recipe(recipe: Recipe, input_files: pandas.DataFrame) -> None: | ||
| """Update the recipe.""" | ||
| recipe_variables = dataframe_to_recipe(input_files) | ||
| recipe_variables = {k: v for k, v in recipe_variables.items() if k != "areacella"} | ||
|
|
||
| # Select a timerange covered by all datasets. | ||
| start_times, end_times = [], [] | ||
| for variable in recipe_variables.values(): | ||
| for dataset in variable["additional_datasets"]: | ||
| start, end = dataset["timerange"].split("/") | ||
| start_times.append(start) | ||
| end_times.append(end) | ||
| start_time = max(start_times) | ||
| start_time = max(start_time, "20010101T000000") # Earliest observational dataset availability | ||
| timerange = f"{start_time}/{min(end_times)}" | ||
|
|
||
| datasets = recipe_variables["rsut"]["additional_datasets"] | ||
| for dataset in datasets: | ||
| dataset.pop("timerange") | ||
| recipe["datasets"] = datasets | ||
| recipe["timerange_for_models"] = timerange | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
...es/climate-ref-esmvaltool/tests/unit/diagnostics/input_files_cloud_radiative_effects.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| { | ||
| "start_time":{ | ||
| "4":"1850-01-16T12:00:00.000", | ||
| "3":"1850-01-16T12:00:00.000", | ||
| "2":"1850-01-16T12:00:00.000", | ||
| "1":"1850-01-16T12:00:00.000" | ||
| }, | ||
| "end_time":{ | ||
| "4":"2014-12-16T12:00:00.000", | ||
| "3":"2014-12-16T12:00:00.000", | ||
| "2":"2014-12-16T12:00:00.000", | ||
| "1":"2014-12-16T12:00:00.000" | ||
| }, | ||
| "path":{ | ||
| "4":"\/work\/bd0854\/DATA\/ESMValTool2\/CMIP6_DKRZ\/CMIP\/CSIRO\/ACCESS-ESM1-5\/historical\/r1i1p1f1\/Amon\/rsut\/gn\/v20191115\/rsut_Amon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_185001-201412.nc", | ||
| "3":"\/work\/bd0854\/DATA\/ESMValTool2\/CMIP6_DKRZ\/CMIP\/CSIRO\/ACCESS-ESM1-5\/historical\/r1i1p1f1\/Amon\/rsutcs\/gn\/v20191115\/rsutcs_Amon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_185001-201412.nc", | ||
| "2":"\/work\/bd0854\/DATA\/ESMValTool2\/CMIP6_DKRZ\/CMIP\/CSIRO\/ACCESS-ESM1-5\/historical\/r1i1p1f1\/Amon\/rlutcs\/gn\/v20191115\/rlutcs_Amon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_185001-201412.nc", | ||
| "1":"\/work\/bd0854\/DATA\/ESMValTool2\/CMIP6_DKRZ\/CMIP\/CSIRO\/ACCESS-ESM1-5\/historical\/r1i1p1f1\/Amon\/rlut\/gn\/v20191115\/rlut_Amon_ACCESS-ESM1-5_historical_r1i1p1f1_gn_185001-201412.nc" | ||
| }, | ||
| "activity_id":{ | ||
| "4":"CMIP", | ||
| "3":"CMIP", | ||
| "2":"CMIP", | ||
| "1":"CMIP" | ||
| }, | ||
| "branch_method":{ | ||
| "4":"standard", | ||
| "3":"standard", | ||
| "2":"standard", | ||
| "1":"standard" | ||
| }, | ||
| "branch_time_in_child":{ | ||
| "4":0.0, | ||
| "3":0.0, | ||
| "2":0.0, | ||
| "1":0.0 | ||
| }, | ||
| "branch_time_in_parent":{ | ||
| "4":21915.0, | ||
| "3":21915.0, | ||
| "2":21915.0, | ||
| "1":21915.0 | ||
| }, | ||
| "experiment":{ | ||
| "4":"all-forcing simulation of the recent past", | ||
| "3":"all-forcing simulation of the recent past", | ||
| "2":"all-forcing simulation of the recent past", | ||
| "1":"all-forcing simulation of the recent past" | ||
| }, | ||
| "experiment_id":{ | ||
| "4":"historical", | ||
| "3":"historical", | ||
| "2":"historical", | ||
| "1":"historical" | ||
| }, | ||
| "frequency":{ | ||
| "4":"mon", | ||
| "3":"mon", | ||
| "2":"mon", | ||
| "1":"mon" | ||
| }, | ||
| "grid":{ | ||
| "4":"native atmosphere N96 grid (145x192 latxlon)", | ||
| "3":"native atmosphere N96 grid (145x192 latxlon)", | ||
| "2":"native atmosphere N96 grid (145x192 latxlon)", | ||
| "1":"native atmosphere N96 grid (145x192 latxlon)" | ||
| }, | ||
| "grid_label":{ | ||
| "4":"gn", | ||
| "3":"gn", | ||
| "2":"gn", | ||
| "1":"gn" | ||
| }, | ||
| "institution_id":{ | ||
| "4":"CSIRO", | ||
| "3":"CSIRO", | ||
| "2":"CSIRO", | ||
| "1":"CSIRO" | ||
| }, | ||
| "nominal_resolution":{ | ||
| "4":"250 km", | ||
| "3":"250 km", | ||
| "2":"250 km", | ||
| "1":"250 km" | ||
| }, | ||
| "parent_activity_id":{ | ||
| "4":"CMIP", | ||
| "3":"CMIP", | ||
| "2":"CMIP", | ||
| "1":"CMIP" | ||
| }, | ||
| "parent_experiment_id":{ | ||
| "4":"piControl", | ||
| "3":"piControl", | ||
| "2":"piControl", | ||
| "1":"piControl" | ||
| }, | ||
| "parent_source_id":{ | ||
| "4":"ACCESS-ESM1-5", | ||
| "3":"ACCESS-ESM1-5", | ||
| "2":"ACCESS-ESM1-5", | ||
| "1":"ACCESS-ESM1-5" | ||
| }, | ||
| "parent_time_units":{ | ||
| "4":"days since 0101-1-1", | ||
| "3":"days since 0101-1-1", | ||
| "2":"days since 0101-1-1", | ||
| "1":"days since 0101-1-1" | ||
| }, | ||
| "parent_variant_label":{ | ||
| "4":"r1i1p1f1", | ||
| "3":"r1i1p1f1", | ||
| "2":"r1i1p1f1", | ||
| "1":"r1i1p1f1" | ||
| }, | ||
| "product":{ | ||
| "4":"model-output", | ||
| "3":"model-output", | ||
| "2":"model-output", | ||
| "1":"model-output" | ||
| }, | ||
| "realm":{ | ||
| "4":"atmos", | ||
| "3":"atmos", | ||
| "2":"atmos", | ||
| "1":"atmos" | ||
| }, | ||
| "source_id":{ | ||
| "4":"ACCESS-ESM1-5", | ||
| "3":"ACCESS-ESM1-5", | ||
| "2":"ACCESS-ESM1-5", | ||
| "1":"ACCESS-ESM1-5" | ||
| }, | ||
| "source_type":{ | ||
| "4":"AOGCM", | ||
| "3":"AOGCM", | ||
| "2":"AOGCM", | ||
| "1":"AOGCM" | ||
| }, | ||
| "sub_experiment":{ | ||
| "4":"none", | ||
| "3":"none", | ||
| "2":"none", | ||
| "1":"none" | ||
| }, | ||
| "sub_experiment_id":{ | ||
| "4":"none", | ||
| "3":"none", | ||
| "2":"none", | ||
| "1":"none" | ||
| }, | ||
| "table_id":{ | ||
| "4":"Amon", | ||
| "3":"Amon", | ||
| "2":"Amon", | ||
| "1":"Amon" | ||
| }, | ||
| "variable_id":{ | ||
| "4":"rsut", | ||
| "3":"rsutcs", | ||
| "2":"rlutcs", | ||
| "1":"rlut" | ||
| }, | ||
| "variant_label":{ | ||
| "4":"r1i1p1f1", | ||
| "3":"r1i1p1f1", | ||
| "2":"r1i1p1f1", | ||
| "1":"r1i1p1f1" | ||
| }, | ||
| "member_id":{ | ||
| "4":"r1i1p1f1", | ||
| "3":"r1i1p1f1", | ||
| "2":"r1i1p1f1", | ||
| "1":"r1i1p1f1" | ||
| }, | ||
| "standard_name":{ | ||
| "4":"toa_outgoing_shortwave_flux", | ||
| "3":"toa_outgoing_shortwave_flux_assuming_clear_sky", | ||
| "2":"toa_outgoing_longwave_flux_assuming_clear_sky", | ||
| "1":"toa_outgoing_longwave_flux" | ||
| }, | ||
| "long_name":{ | ||
| "4":"TOA Outgoing Shortwave Radiation", | ||
| "3":"TOA Outgoing Clear-Sky Shortwave Radiation", | ||
| "2":"TOA Outgoing Clear-Sky Longwave Radiation", | ||
| "1":"TOA Outgoing Longwave Radiation" | ||
| }, | ||
| "units":{ | ||
| "4":"W m-2", | ||
| "3":"W m-2", | ||
| "2":"W m-2", | ||
| "1":"W m-2" | ||
| }, | ||
| "vertical_levels":{ | ||
| "4":1, | ||
| "3":1, | ||
| "2":1, | ||
| "1":1 | ||
| }, | ||
| "init_year":{ | ||
| "4":null, | ||
| "3":null, | ||
| "2":null, | ||
| "1":null | ||
| }, | ||
| "version":{ | ||
| "4":"v20191115", | ||
| "3":"v20191115", | ||
| "2":"v20191115", | ||
| "1":"v20191115" | ||
| }, | ||
| "instance_id":{ | ||
| "4":"CMIP6.CMIP.CSIRO.ACCESS-ESM1-5.historical.r1i1p1f1.Amon.rsut.gn.v20191115", | ||
| "3":"CMIP6.CMIP.CSIRO.ACCESS-ESM1-5.historical.r1i1p1f1.Amon.rsutcs.gn.v20191115", | ||
| "2":"CMIP6.CMIP.CSIRO.ACCESS-ESM1-5.historical.r1i1p1f1.Amon.rlutcs.gn.v20191115", | ||
| "1":"CMIP6.CMIP.CSIRO.ACCESS-ESM1-5.historical.r1i1p1f1.Amon.rlut.gn.v20191115" | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
packages/climate-ref-esmvaltool/tests/unit/diagnostics/test_cloud_radiative_effects.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pandas | ||
| from climate_ref_esmvaltool.diagnostics import CloudRadiativeEffects | ||
| from climate_ref_esmvaltool.recipe import load_recipe | ||
|
|
||
|
|
||
| def test_update_recipe(): | ||
| # Insert the following code in CloudRadiativeEffects.update_recipe to | ||
| # save an example input dataframe: | ||
| # input_files.to_json(Path("input_files_cloud_radiative_effects.json"), indent=4, date_format="iso") | ||
| input_files = pandas.read_json(Path(__file__).parent / "input_files_cloud_radiative_effects.json") | ||
| recipe = load_recipe("ref/recipe_ref_cre.yml") | ||
| CloudRadiativeEffects().update_recipe(recipe, input_files) | ||
| assert recipe["datasets"] == [ | ||
| { | ||
| "activity": "CMIP", | ||
| "dataset": "ACCESS-ESM1-5", | ||
| "ensemble": "r1i1p1f1", | ||
| "exp": "historical", | ||
| "grid": "gn", | ||
| "institute": "CSIRO", | ||
| "mip": "Amon", | ||
| "project": "CMIP6", | ||
| }, | ||
| ] | ||
| assert recipe["timerange_for_models"] == "20010101T000000/20141216T120000" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #280