Skip to content

Commit

Permalink
Added fixes for some 3D atmospheric variables of E3SM-1-1 (CMIP6) (#2620
Browse files Browse the repository at this point in the history
)
  • Loading branch information
schlunma authored Dec 18, 2024
1 parent 58934e5 commit 90d11a2
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
43 changes: 43 additions & 0 deletions esmvalcore/cmor/_fixes/cmip6/e3sm_1_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Fixes for E3SM-1-1 model."""

from iris.cube import Cube

from esmvalcore.cmor.fix import Fix
from esmvalcore.preprocessor._shared import get_array_module


def _mask_greater(cube: Cube, value: float) -> Cube:
"""Mask all data of cube which is greater than ``value``."""
npx = get_array_module(cube.core_data())
cube.data = npx.ma.masked_greater(cube.core_data(), value)
return cube


class Hus(Fix):
"""Fixes for ``hus``."""

def fix_data(self, cube: Cube) -> Cube:
"""Fix data.
Fix values that are not properly masked.
Parameters
----------
cube: iris.cube.Cube
Input cube.
Returns
-------
iris.cube.Cube
"""
return _mask_greater(cube, 1000.0)


Ta = Hus


Ua = Hus


Va = Hus
65 changes: 65 additions & 0 deletions tests/integration/cmor/_fixes/cmip6/test_e3sm_1_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Tests for the fixes of E3SM-1-1."""

import numpy as np
import pytest
from iris.cube import Cube

from esmvalcore.cmor._fixes.cmip6.e3sm_1_1 import Hus, Ta, Ua, Va
from esmvalcore.cmor._fixes.fix import GenericFix
from esmvalcore.cmor.fix import Fix
from tests import assert_array_equal


def test_get_hus_fix():
"""Test getting of fix."""
fix = Fix.get_fixes("CMIP6", "E3SM-1-1", "Amon", "hus")
assert fix == [Hus(None), GenericFix(None)]


def test_get_ta_fix():
"""Test getting of fix."""
fix = Fix.get_fixes("CMIP6", "E3SM-1-1", "Amon", "ta")
assert fix == [Ta(None), GenericFix(None)]


def test_get_ua_fix():
"""Test getting of fix."""
fix = Fix.get_fixes("CMIP6", "E3SM-1-1", "Amon", "ua")
assert fix == [Ua(None), GenericFix(None)]


def test_get_va_fix():
"""Test getting of fix."""
fix = Fix.get_fixes("CMIP6", "E3SM-1-1", "Amon", "va")
assert fix == [Va(None), GenericFix(None)]


@pytest.mark.parametrize("lazy", [True, False])
def test_hus_fix(lazy):
"""Test fix for ``hus``."""
cube = Cube([1.0, 1e35])
if lazy:
cube.data = cube.lazy_data()

fix = Hus(None)

fixed_cube = fix.fix_data(cube)

assert fixed_cube is cube
assert fixed_cube.has_lazy_data() is lazy
assert_array_equal(fixed_cube.data, np.ma.masked_invalid([1.0, np.nan]))


def test_ta_fix():
"""Test fix for ``ta``."""
assert Ta == Hus


def test_ua_fix():
"""Test fix for ``ua``."""
assert Ua == Hus


def test_va_fix():
"""Test fix for ``va``."""
assert Va == Hus

0 comments on commit 90d11a2

Please sign in to comment.