diff --git a/esmvalcore/cmor/_fixes/cmip6/cnrm_cm6_1.py b/esmvalcore/cmor/_fixes/cmip6/cnrm_cm6_1.py index f2815d9ea5..4d634ef820 100644 --- a/esmvalcore/cmor/_fixes/cmip6/cnrm_cm6_1.py +++ b/esmvalcore/cmor/_fixes/cmip6/cnrm_cm6_1.py @@ -104,4 +104,17 @@ def fix_metadata(self, cubes): Cli = Cl + Clw = Cl + + +class O3(Cl): + """Fixes of ozone variable (mip: AERmon only).""" + + def fix_metadata(self, cubes): + for cube in cubes: + if "table_id" in cube.attributes: + if cube.attributes["table_id"] == "AERmon": + cubes = Cl.fix_metadata(self, cubes) + break + return cubes diff --git a/esmvalcore/cmor/_fixes/cmip6/cnrm_esm2_1.py b/esmvalcore/cmor/_fixes/cmip6/cnrm_esm2_1.py index 8eb9aafe6c..80082da49c 100644 --- a/esmvalcore/cmor/_fixes/cmip6/cnrm_esm2_1.py +++ b/esmvalcore/cmor/_fixes/cmip6/cnrm_esm2_1.py @@ -1,5 +1,6 @@ """Fixes for CNRM-ESM2-1 model.""" +from .cnrm_cm6_1 import O3 as BaseO3 # noqa: N811 from .cnrm_cm6_1 import Cl as BaseCl from .cnrm_cm6_1 import Clcalipso as BaseClcalipso from .cnrm_cm6_1 import Cli as BaseCli @@ -18,4 +19,7 @@ Clw = BaseClw +O3 = BaseO3 + + Omon = BaseOmon diff --git a/tests/integration/cmor/_fixes/cmip6/test_cnrm_cm6_1.py b/tests/integration/cmor/_fixes/cmip6/test_cnrm_cm6_1.py index 50785ef4e8..849a5140cf 100644 --- a/tests/integration/cmor/_fixes/cmip6/test_cnrm_cm6_1.py +++ b/tests/integration/cmor/_fixes/cmip6/test_cnrm_cm6_1.py @@ -5,6 +5,7 @@ import pytest from esmvalcore.cmor._fixes.cmip6.cnrm_cm6_1 import ( + O3, Cl, Clcalipso, Cli, @@ -154,3 +155,25 @@ def test_get_thetao_fix(): """Test getting of fix.""" fix = Fix.get_fixes("CMIP6", "CNRM-CM6-1", "Omon", "thetao") assert fix == [Omon(None), GenericFix(None)] + + +def test_o3_fix_metadata(test_data_path): + """Test fix for ``o3`` from mip: AERmon.""" + nc_path = test_data_path / "cnrm_cm6_1_cl.nc" + cubes = iris.load(str(nc_path)) + # change cl cube from test data to an o3 cube + # (reusing vertical hybrid coordinates for testing) + o3_cube = cubes.extract_cube("cloud_area_fraction_in_atmosphere_layer") + o3_cube.long_name = "Mole Fraction of O3" + o3_cube.standard_name = "mole_fraction_of_ozone_in_air" + o3_cube.units = "mol mol-1" + o3_cube.attributes["table_id"] = "AERmon" + o3_cube.var_name = "o3" + # test o3 fix_metadata + vardef = get_var_info("CMIP6", "AERmon", "o3") + fix = O3(vardef) + fixed_cubes = fix.fix_metadata(cubes) + # make sure the fixed cube has a coordinate "air_pressure" + cube = fixed_cubes.extract_cube("mole_fraction_of_ozone_in_air") + air_pressure_coord = cube.coord("air_pressure") + assert air_pressure_coord.points is not None