Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/install-from-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
35 changes: 35 additions & 0 deletions esmvalcore/cmor/_fixes/obs4mips/airs_2_1.py
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions tests/integration/cmor/_fixes/obs4mips/test_airs_2_1.py
Original file line number Diff line number Diff line change
@@ -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])