Skip to content

Fix oh for model: EC-Earth3-AerChem mip: AERMonZ #2634

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
merged 11 commits into from
Jan 16, 2025
35 changes: 35 additions & 0 deletions esmvalcore/cmor/_fixes/cmip6/ec_earth3_aerchem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Fixes for EC-Earth3-AerChem model."""

from ..fix import Fix


class Oh(Fix):
"""Fixes for oh."""

def fix_metadata(self, cubes):
"""Fix standard name for ps.

Fix standard_name for Surface Air Pressure (ps).
See discussion in
https://github.com/ESMValGroup/ESMValCore/issues/2613
Cube has two coordinates called air_pressure: an AuxCoord ps
and a DerivedCoord that is 4D and derived using formula terms,
we are setting the former's standard_name to "surface_air_pressure".

Parameters
----------
cubes : iris.cube.CubeList
Input cubes.

Returns
-------
iris.cube.CubeList
"""
cube = self.get_cube_from_list(cubes)

for cube in cubes:
for coord in cube.coords():
if coord.var_name == "ps":
coord.standard_name = "surface_air_pressure"

return cubes
41 changes: 41 additions & 0 deletions tests/integration/cmor/_fixes/cmip6/test_ec_earth3_aerchem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Tests for EC-Earth3-AerChem model."""

import iris
import pytest

from esmvalcore.cmor._fixes.cmip6.ec_earth3_aerchem import Oh
from esmvalcore.cmor.fix import Fix
from esmvalcore.cmor.table import get_var_info


@pytest.fixture
def oh_cubes():
air_pressure_coord = iris.coords.DimCoord(
[1000.09, 600.6, 200.0],
bounds=[[1200.00001, 800], [800, 400.8], [400.8, 1.9]],
var_name="ps",
standard_name="air_pressure",
units="pa",
)
oh_cube = iris.cube.Cube(
[0.0, 1.0, 2.0],
var_name="oh",
dim_coords_and_dims=[(air_pressure_coord, 0)],
)
return iris.cube.CubeList([oh_cube])


def test_get_oh_fix():
"""Test getting of fix."""
fix = Fix.get_fixes("CMIP6", "EC-Earth3-AerChem", "AERmonZ", "oh")
assert Oh(None) in fix


def test_oh_fix_metadata(oh_cubes):
"""Test ``fix_metadata`` for ``oh``."""
vardef = get_var_info("CMIP6", "AERmonZ", "oh")
fix = Oh(vardef)
fixed_cubes = fix.fix_metadata(oh_cubes)
for coord in fixed_cubes[0].coords():
if coord.var_name == "ps":
assert coord.standard_name == "surface_air_pressure"