Skip to content

Commit 434e65e

Browse files
authored
Update CMIP5 EC-EARTH pr fix (#2666)
1 parent 6a8406b commit 434e65e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

esmvalcore/cmor/_fixes/cmip5/ec_earth.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Fixes for EC-Earth model."""
22

3+
from collections.abc import Iterable
4+
35
import iris
46
import numpy as np
57
from dask import array as da
@@ -132,7 +134,9 @@ def fix_metadata(self, cubes):
132134
class Pr(Fix):
133135
"""Fixes for pr."""
134136

135-
def fix_metadata(self, cubes):
137+
def fix_metadata(
138+
self, cubes: Iterable[iris.cube.Cube]
139+
) -> iris.cube.CubeList:
136140
"""Fix time coordinate.
137141
138142
Last file (2000-2009) has erroneously duplicated points
@@ -160,6 +164,8 @@ def fix_metadata(self, cubes):
160164
else:
161165
# erase erroneously copy-pasted points
162166
select = np.unique(time_coord.points, return_index=True)[1]
163-
new_list.append(cube[select])
167+
new_cube = cube[select]
168+
iris.util.promote_aux_coord_to_dim_coord(new_cube, "time")
169+
new_list.append(new_cube)
164170

165171
return new_list

tests/integration/cmor/_fixes/cmip5/test_ec_earth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def setUp(self):
187187
units="days since 1850-01-01",
188188
)
189189

190-
correct_time_coord = AuxCoord(
190+
correct_time_coord = DimCoord(
191191
points=[1.0, 2.0, 3.0],
192192
var_name="time",
193193
standard_name="time",
@@ -216,7 +216,7 @@ def setUp(self):
216216
self.correct_cube = CubeList(
217217
[Cube(np.ones(3), var_name="pr", units="kg m-2 s-1")]
218218
)
219-
self.correct_cube[0].add_aux_coord(correct_time_coord, 0)
219+
self.correct_cube[0].add_dim_coord(correct_time_coord, 0)
220220

221221
self.fix = Pr(None)
222222

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

235-
time = out_wrong_cube[0].coord("time")
235+
time = out_wrong_cube[0].coord("time", dim_coords=True)
236236
assert time == self.time_coord
237237

238-
time = out_correct_cube[0].coord("time")
238+
time = out_correct_cube[0].coord("time", dim_coords=True)
239239
assert time == self.time_coord
240240

241241
def test_pr_fix_metadata_no_time(self):

0 commit comments

Comments
 (0)