-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added fixes for some 3D atmospheric variables of E3SM-1-1 (CMIP6) (#2620
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |