Skip to content

Commit

Permalink
Correct incorrect time bounds in EMAC data (#2621)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Schlund <32543114+schlunma@users.noreply.github.com>
  • Loading branch information
FranziskaWinterstein and schlunma authored Jan 9, 2025
1 parent bd617f5 commit b0b2799
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
31 changes: 17 additions & 14 deletions doc/quickstart/find_data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,20 +380,23 @@ For some variables, extra facets are necessary; otherwise ESMValCore cannot
read them properly.
Supported keys for extra facets are:

==================== ====================================== =================================
Key Description Default value if not specified
==================== ====================================== =================================
``channel`` Channel in which the desired variable No default (needs to be specified
is stored in extra facets or recipe if
default DRS is used)
``postproc_flag`` Postprocessing flag of the data ``''`` (empty string)
``raw_name`` Variable name of the variable in the CMOR variable name of the
raw input file corresponding variable
``raw_units`` Units of the variable in the raw If specified, the value given by
input file the ``units`` attribute in the
raw input file; otherwise
``unknown``
==================== ====================================== =================================
===================== ====================================== =================================
Key Description Default value if not specified
===================== ====================================== =================================
``channel`` Channel in which the desired variable No default (needs to be specified
is stored in extra facets or recipe if
default DRS is used)
``postproc_flag`` Postprocessing flag of the data ``''`` (empty string)
``raw_name`` Variable name of the variable in the CMOR variable name of the
raw input file corresponding variable
``raw_units`` Units of the variable in the raw If specified, the value given by
input file the ``units`` attribute in the
raw input file; otherwise
``unknown``
``reset_time_bounds`` Boolean if time bounds are deleted, ``False``
and automatically recalculated by
iris
===================== ====================================== =================================

.. note::

Expand Down
4 changes: 4 additions & 0 deletions esmvalcore/cmor/_fixes/emac/emac.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def fix_metadata(self, cubes):
cube = self.get_cube(cubes)

# Fix time, latitude, and longitude coordinates
if cube.coords("time") and self.extra_facets.get(
"reset_time_bounds", False
):
cube.coord("time").bounds = None
self.fix_regular_time(cube)
self.fix_regular_lat(cube)
self.fix_regular_lon(cube)
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/cmor/_fixes/emac/test_emac.py
Original file line number Diff line number Diff line change
Expand Up @@ -2806,3 +2806,22 @@ def test_fix_invalid_units():
assert "positive" not in cube.attributes

np.testing.assert_allclose(cube.data, 1.0)


# Test fix invalid time bounds


def test_fix_time_bounds(cubes_2d):
"""Test fix."""
cubes_2d[0].var_name = "tsurf"
cubes_2d[0].units = "K"
cubes_2d[0].coord("time").bounds = [0.0, 0.5]

fix = get_allvars_fix("Amon", "ts")
fix.extra_facets["reset_time_bounds"] = True

fixed_cubes = fix.fix_metadata(cubes_2d)

cube = fixed_cubes[0]

assert not cube.coord("time").has_bounds()

0 comments on commit b0b2799

Please sign in to comment.