diff --git a/.github/workflows/install-from-pypi.yml b/.github/workflows/install-from-pypi.yml index c758b93299..c60675c013 100644 --- a/.github/workflows/install-from-pypi.yml +++ b/.github/workflows/install-from-pypi.yml @@ -15,7 +15,7 @@ name: Install from PyPi # runs on a push on main and at the end of every day on: - # triggering on push without branch name will run tests everytime + # triggering on push without branch name will run tests every time # there is a push on any branch # turn it on only if needed push: @@ -36,7 +36,7 @@ jobs: matrix: python-version: ["3.7", "3.8", "3.9", "3.10"] # fail-fast set to False allows all other tests - # in the worflow to run regardless of any fail + # in the workflow to run regardless of any fail fail-fast: false name: Linux Python ${{ matrix.python-version }} steps: diff --git a/esmvalcore/cmor/_fixes/obs4mips/airs_2_1.py b/esmvalcore/cmor/_fixes/obs4mips/airs_2_1.py new file mode 100644 index 0000000000..93ca03eaa6 --- /dev/null +++ b/esmvalcore/cmor/_fixes/obs4mips/airs_2_1.py @@ -0,0 +1,35 @@ +"""Fixes for obs4MIPs dataset AIRS-2-1.""" +from iris.exceptions import CoordinateNotFoundError + +from ..fix import Fix + + +class AllVars(Fix): + """Common fixes to all vars.""" + + def fix_metadata(self, cubes): + """ + Fix metadata. + + Change unit of coordinate plev from hPa to Pa. + + Parameters + ---------- + cubes: iris.cube.CubeList + Input cubes. + + Returns + ------- + iris.cube.CubeList + Fixed cubes. + + """ + for cube in cubes: + try: + plev = cube.coord('air_pressure') + except CoordinateNotFoundError: + continue + else: + if plev.points[0] > 10000.0: + plev.units = 'Pa' + return cubes diff --git a/tests/integration/cmor/_fixes/obs4mips/test_airs_2_1.py b/tests/integration/cmor/_fixes/obs4mips/test_airs_2_1.py new file mode 100644 index 0000000000..4ac2ce7f26 --- /dev/null +++ b/tests/integration/cmor/_fixes/obs4mips/test_airs_2_1.py @@ -0,0 +1,77 @@ +"""Test AIRS-2-1 fixes.""" +import numpy as np +from iris.coords import DimCoord +from iris.cube import Cube, CubeList + +from esmvalcore.cmor._fixes.obs4mips.airs_2_1 import AllVars +from esmvalcore.cmor.fix import Fix + + +def get_air_pressure_coord(points, units): + """Get ``air_pressure`` coordinate.""" + return DimCoord(points, var_name='plev', standard_name='air_pressure', + long_name='pressure', units=units) + + +def test_get_allvars_fix(): + """Test getting of fix.""" + fix = Fix.get_fixes('obs4MIPs', 'AIRS-2-1', 'Amon', 'cl') + assert fix == [AllVars(None)] + + +def test_allvars_fix_no_air_pressure(): + """Test fix for all variables.""" + cubes = CubeList([Cube(0.0, var_name='cl')]) + fix = AllVars(None) + out_cubes = fix.fix_metadata(cubes.copy()) + + assert len(out_cubes) == 1 + assert out_cubes[0] == cubes[0] + + +def test_allvars_fix_correct_air_pressure_pa(): + """Test fix for all variables.""" + air_pressure_coord = get_air_pressure_coord([100000.0, 80000.0], 'Pa') + cube = Cube([0.0, 1.0], var_name='cl', + dim_coords_and_dims=[(air_pressure_coord, 0)]) + cubes = CubeList([cube]) + fix = AllVars(None) + out_cubes = fix.fix_metadata(cubes.copy()) + + assert len(out_cubes) == 1 + assert out_cubes[0] == cubes[0] + assert out_cubes[0].coord('air_pressure').units == 'Pa' + np.testing.assert_allclose(out_cubes[0].coord('air_pressure').points, + [100000.0, 80000.0]) + + +def test_allvars_fix_correct_air_pressure_hpa(): + """Test fix for all variables.""" + air_pressure_coord = get_air_pressure_coord([1000.0, 800.0], 'hPa') + cube = Cube([0.0, 1.0], var_name='cl', + dim_coords_and_dims=[(air_pressure_coord, 0)]) + cubes = CubeList([cube]) + fix = AllVars(None) + out_cubes = fix.fix_metadata(cubes.copy()) + + assert len(out_cubes) == 1 + assert out_cubes[0] == cubes[0] + assert out_cubes[0].coord('air_pressure').units == 'hPa' + np.testing.assert_allclose(out_cubes[0].coord('air_pressure').points, + [1000.0, 800.0]) + + +def test_allvars_fix_incorrect_air_pressure(): + """Test fix for all variables.""" + air_pressure_coord = get_air_pressure_coord([100000.0, 80000.0], 'hPa') + cube = Cube([0.0, 1.0], var_name='cl', + dim_coords_and_dims=[(air_pressure_coord, 0)]) + cubes = CubeList([cube]) + fix = AllVars(None) + out_cubes = fix.fix_metadata(cubes.copy()) + + assert len(out_cubes) == 1 + assert out_cubes[0] != cubes[0] + assert out_cubes[0].coord('air_pressure').units == 'Pa' + np.testing.assert_allclose(out_cubes[0].coord('air_pressure').points, + [100000.0, 80000.0])