Skip to content
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

Added ICON fixes for hfls and hfss #2360

Merged
merged 4 commits into from
Mar 5, 2024
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: 4 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@
"affiliation": "BSC, Spain",
"name": "Martin-Martinez, Eneko",
"orcid": "0000-0002-9213-7818"
},
{
"affiliation": "DLR, Germany",
"name": "Cammarano, Diego"
}
],
"description": "ESMValCore: A community tool for pre-processing data from Earth system models in CMIP and running analysis scripts.",
Expand Down
4 changes: 4 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ authors:
family-names: Martin-Martinez
given-names: Eneko
orcid: "https://orcid.org/0000-0002-9213-7818"
-
affiliation: "DLR, Germany"
family-names: Cammarano
given-names: Diego

cff-version: 1.2.0
date-released: 2023-12-19
Expand Down
9 changes: 9 additions & 0 deletions esmvalcore/cmor/_fixes/icon/_base_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,12 @@ def _set_range_in_0_360(lon_coord):
lon_coord.points = (lon_coord.core_points() + 360.0) % 360.0
if lon_coord.has_bounds():
lon_coord.bounds = (lon_coord.core_bounds() + 360.0) % 360.0


class NegateData(IconFix):
"""Base fix to negate data."""

def fix_data(self, cube):
"""Fix data."""
cube.data = -cube.core_data()
return cube
8 changes: 7 additions & 1 deletion esmvalcore/cmor/_fixes/icon/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from esmvalcore.iris_helpers import add_leading_dim_to_cube, date2num

from ._base_fixes import IconFix
from ._base_fixes import IconFix, NegateData

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -512,3 +512,9 @@ def fix_metadata(self, cubes):
)
cube.var_name = self.vardef.short_name
return CubeList([cube])


Hfls = NegateData


Hfss = NegateData
71 changes: 70 additions & 1 deletion tests/integration/cmor/_fixes/icon/test_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import esmvalcore.cmor._fixes.icon.icon
from esmvalcore.cmor._fixes.fix import GenericFix
from esmvalcore.cmor._fixes.icon._base_fixes import IconFix
from esmvalcore.cmor._fixes.icon.icon import AllVars, Clwvi
from esmvalcore.cmor._fixes.icon.icon import AllVars, Clwvi, Hfls, Hfss
from esmvalcore.cmor.fix import Fix
from esmvalcore.cmor.table import CoordinateInfo, get_var_info
from esmvalcore.config import CFG
Expand Down Expand Up @@ -147,6 +147,15 @@ def fix_metadata(cubes, mip, short_name, session=None):
return cubes


def fix_data(cube, mip, short_name, session=None):
"""Fix data of cube."""
fix = get_fix(mip, short_name, session=session)
cube = fix.fix_data(cube)
fix = get_allvars_fix(mip, short_name, session=session)
cube = fix.fix_data(cube)
return cube


def check_ta_metadata(cubes):
"""Check ta metadata."""
assert len(cubes) == 1
Expand Down Expand Up @@ -2209,3 +2218,63 @@ def test_fix_height_alt16(bounds, simple_unstructured_cube):
np.testing.assert_allclose(alt16.bounds, expected_bnds)
else:
assert alt16.bounds is None


# Test hfls (for extra fix)


def test_get_hfls_fix():
"""Test getting of fix."""
fix = Fix.get_fixes('ICON', 'ICON', 'Amon', 'hfls')
assert fix == [Hfls(None), AllVars(None), GenericFix(None)]


def test_hfls_fix(cubes_regular_grid):
"""Test fix."""
cubes = CubeList([cubes_regular_grid[0].copy()])
cubes[0].var_name = 'hfls'
cubes[0].units = 'W m-2'

fixed_cubes = fix_metadata(cubes, 'Amon', 'hfls')

assert len(fixed_cubes) == 1
cube = fixed_cubes[0]
assert cube.var_name == 'hfls'
assert cube.standard_name == 'surface_upward_latent_heat_flux'
assert cube.long_name == 'Surface Upward Latent Heat Flux'
assert cube.units == 'W m-2'
assert cube.attributes['positive'] == 'up'

fixed_cube = fix_data(cube, 'Amon', 'hfls')

np.testing.assert_allclose(fixed_cube.data, [[[0.0, -1.0], [-2.0, -3.0]]])


# Test hfss (for extra fix)


def test_get_hfss_fix():
"""Test getting of fix."""
fix = Fix.get_fixes('ICON', 'ICON', 'Amon', 'hfss')
assert fix == [Hfss(None), AllVars(None), GenericFix(None)]


def test_hfss_fix(cubes_regular_grid):
"""Test fix."""
cubes = CubeList([cubes_regular_grid[0].copy()])
cubes[0].var_name = 'hfss'
cubes[0].units = 'W m-2'

fixed_cubes = fix_metadata(cubes, 'Amon', 'hfss')

assert len(fixed_cubes) == 1
cube = fixed_cubes[0]
assert cube.var_name == 'hfss'
assert cube.standard_name == 'surface_upward_sensible_heat_flux'
assert cube.long_name == 'Surface Upward Sensible Heat Flux'
assert cube.units == 'W m-2'
assert cube.attributes['positive'] == 'up'

fixed_cube = fix_data(cube, 'Amon', 'hfss')

np.testing.assert_allclose(fixed_cube.data, [[[0.0, -1.0], [-2.0, -3.0]]])
Loading