Skip to content

Commit a27f3d4

Browse files
author
marqh
committed
numerical tolerance
1 parent d50e039 commit a27f3d4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/iris/cube.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,6 @@ def _intersect(self, name_or_coord, minimum, maximum,
21132113
if modulus is None:
21142114
raise ValueError('coordinate units with no modulus are not yet'
21152115
' supported')
2116-
21172116
subsets, points, bounds = self._intersect_modulus(coord,
21182117
minimum, maximum,
21192118
min_inclusive,
@@ -2234,7 +2233,12 @@ def _intersect_modulus(self, coord, minimum, maximum, min_inclusive,
22342233
# and call the new bounds = the new points + the difference.
22352234
pre_wrap_delta = np.diff(coord.bounds[inside_indices])
22362235
post_wrap_delta = np.diff(bounds[inside_indices])
2237-
split_cell_indices, _ = np.where(pre_wrap_delta != post_wrap_delta)
2236+
close_enough = np.allclose(pre_wrap_delta, post_wrap_delta)
2237+
if close_enough:
2238+
split_cell_indices = np.array(())
2239+
else:
2240+
split_cell_indices, _ = np.where(pre_wrap_delta != \
2241+
post_wrap_delta)
22382242
if split_cell_indices.size:
22392243
# Recalculate the extended minimum.
22402244
indices = inside_indices[split_cell_indices]

lib/iris/tests/unit/cube/test_Cube.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,14 @@ def test_decrementing_wrapped(self):
10511051
self.assertEqual(result.data[0, 0, 0], 350)
10521052
self.assertEqual(result.data[0, 0, -1], 10)
10531053

1054+
def test_numerical_tolerance(self):
1055+
# test the tolerance on the coordinate value is not causing a
1056+
# modulus wrapping
1057+
cube = create_cube(28.5, 68.5, bounds=True)
1058+
result = cube.intersection(longitude=(27.74, 68.61))
1059+
self.assertAlmostEqual(result.coord('longitude').points[0], 28.5)
1060+
self.assertAlmostEqual(result.coord('longitude').points[-1], 67.5)
1061+
10541062

10551063
def unrolled_cube():
10561064
data = np.arange(5, dtype='f4')

0 commit comments

Comments
 (0)