Skip to content

Commit

Permalink
Update CMIP5 EC-EARTH pr fix (#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
bouweandela authored Feb 19, 2025
1 parent 6a8406b commit 434e65e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions esmvalcore/cmor/_fixes/cmip5/ec_earth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Fixes for EC-Earth model."""

from collections.abc import Iterable

import iris
import numpy as np
from dask import array as da
Expand Down Expand Up @@ -132,7 +134,9 @@ def fix_metadata(self, cubes):
class Pr(Fix):
"""Fixes for pr."""

def fix_metadata(self, cubes):
def fix_metadata(
self, cubes: Iterable[iris.cube.Cube]
) -> iris.cube.CubeList:
"""Fix time coordinate.
Last file (2000-2009) has erroneously duplicated points
Expand Down Expand Up @@ -160,6 +164,8 @@ def fix_metadata(self, cubes):
else:
# erase erroneously copy-pasted points
select = np.unique(time_coord.points, return_index=True)[1]
new_list.append(cube[select])
new_cube = cube[select]
iris.util.promote_aux_coord_to_dim_coord(new_cube, "time")
new_list.append(new_cube)

return new_list
8 changes: 4 additions & 4 deletions tests/integration/cmor/_fixes/cmip5/test_ec_earth.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def setUp(self):
units="days since 1850-01-01",
)

correct_time_coord = AuxCoord(
correct_time_coord = DimCoord(
points=[1.0, 2.0, 3.0],
var_name="time",
standard_name="time",
Expand Down Expand Up @@ -216,7 +216,7 @@ def setUp(self):
self.correct_cube = CubeList(
[Cube(np.ones(3), var_name="pr", units="kg m-2 s-1")]
)
self.correct_cube[0].add_aux_coord(correct_time_coord, 0)
self.correct_cube[0].add_dim_coord(correct_time_coord, 0)

self.fix = Pr(None)

Expand All @@ -232,10 +232,10 @@ def test_pr_fix_metadata(self):
out_wrong_cube = self.fix.fix_metadata(self.wrong_cube)
out_correct_cube = self.fix.fix_metadata(self.correct_cube)

time = out_wrong_cube[0].coord("time")
time = out_wrong_cube[0].coord("time", dim_coords=True)
assert time == self.time_coord

time = out_correct_cube[0].coord("time")
time = out_correct_cube[0].coord("time", dim_coords=True)
assert time == self.time_coord

def test_pr_fix_metadata_no_time(self):
Expand Down

0 comments on commit 434e65e

Please sign in to comment.