Skip to content

Commit 0e416d8

Browse files
clean up equality fix
1 parent 294a0d7 commit 0e416d8

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* Copying a cube would previously ignore any attached class:`iris.coords.CellMeasure`.
2+
These are now copied over.

lib/iris/analysis/__init__.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def matches_any(self, predicate):
186186
return any(self.matches(predicate))
187187

188188

189-
def coord_comparison(*cubes, object_type="coord"):
189+
def coord_comparison(*cubes, object_get=None):
190190
"""
191191
Convenience function to help compare coordinates on one or more cubes
192192
by their metadata.
@@ -240,14 +240,12 @@ def coord_comparison(*cubes, object_type="coord"):
240240
print('All equal coordinates: ', result['equal'])
241241
242242
"""
243-
if object_type == "coord":
244-
all_coords = [cube.coords() for cube in cubes]
245-
elif object_type == "cell measure":
246-
all_coords = [cube.cell_measures() for cube in cubes]
247-
elif object_type == "ancillary variable":
248-
all_coords = [cube.ancillary_variables() for cube in cubes]
249-
else:
250-
raise Exception
243+
if object_get is None:
244+
from iris.cube import Cube
245+
246+
object_get = Cube.coords
247+
248+
all_coords = [object_get(cube) for cube in cubes]
251249
grouped_coords = []
252250

253251
# set of coordinates id()s of coordinates which have been processed
@@ -341,31 +339,15 @@ def diff_shape_fn(cube, coord):
341339
# dimension on their respective cubes
342340
# (None -> group describes a different dimension)
343341
def diff_data_dim_fn(cube, coord):
344-
if object_type == "coord":
345-
return cube.coord_dims(coord) != first_cube.coord_dims(
346-
first_coord
347-
)
348-
elif object_type == "cell measure":
349-
return cube.cell_measure_dims(
350-
coord
351-
) != first_cube.cell_measure_dims(first_coord)
352-
elif object_type == "ancillary variable":
353-
return cube.ancillary_variable_dims(
354-
coord
355-
) != first_cube.ancillary_variable_dims(first_coord)
342+
return coord.cube_dims(cube) != first_coord.cube_dims(first_cube)
356343

357344
if coord_group.matches_any(diff_data_dim_fn):
358345
different_data_dimension.add(coord_group)
359346

360347
# get all coordinate groups which don't describe a dimension
361348
# (None -> doesn't describe a dimension)
362349
def no_data_dim_fn(cube, coord):
363-
if object_type == "coord":
364-
return cube.coord_dims(coord) == ()
365-
elif object_type == "cell measure":
366-
return cube.cell_measure_dims(coord) == ()
367-
elif object_type == "ancillary variable":
368-
return cube.ancillary_variable_dims(coord) == ()
350+
return coord.cube_dims(cube) == ()
369351

370352
if coord_group.matches_all(no_data_dim_fn):
371353
no_data_dimension.add(coord_group)

lib/iris/cube.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,7 +3576,7 @@ def __eq__(self, other):
35763576

35773577
if result:
35783578
coord_comparison = iris.analysis.coord_comparison(
3579-
self, other, object_type="cell measure",
3579+
self, other, object_get=Cube.cell_measures,
35803580
)
35813581
# if there are any cell measures which are not equal
35823582
result = not (
@@ -3586,7 +3586,7 @@ def __eq__(self, other):
35863586

35873587
if result:
35883588
coord_comparison = iris.analysis.coord_comparison(
3589-
self, other, object_type="ancillary variable",
3589+
self, other, object_get=Cube.ancillary_variables,
35903590
)
35913591
# if there are any ancillary variables which are not equal
35923592
result = not (

0 commit comments

Comments
 (0)