Skip to content

Commit

Permalink
Merge pull request #1641 from marqh/intersectionBug
Browse files Browse the repository at this point in the history
numerical tolerance
  • Loading branch information
bjlittle committed Apr 22, 2015
2 parents d50e039 + c881ec8 commit f77170e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,6 @@ def _intersect(self, name_or_coord, minimum, maximum,
if modulus is None:
raise ValueError('coordinate units with no modulus are not yet'
' supported')

subsets, points, bounds = self._intersect_modulus(coord,
minimum, maximum,
min_inclusive,
Expand Down Expand Up @@ -2234,8 +2233,11 @@ def _intersect_modulus(self, coord, minimum, maximum, min_inclusive,
# and call the new bounds = the new points + the difference.
pre_wrap_delta = np.diff(coord.bounds[inside_indices])
post_wrap_delta = np.diff(bounds[inside_indices])
split_cell_indices, _ = np.where(pre_wrap_delta != post_wrap_delta)
if split_cell_indices.size:
close_enough = np.allclose(pre_wrap_delta, post_wrap_delta)
if not close_enough:
split_cell_indices, _ = np.where(pre_wrap_delta !=
post_wrap_delta)

# Recalculate the extended minimum.
indices = inside_indices[split_cell_indices]
cells = bounds[indices]
Expand Down
8 changes: 8 additions & 0 deletions lib/iris/tests/unit/cube/test_Cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,14 @@ def test_decrementing_wrapped(self):
self.assertEqual(result.data[0, 0, 0], 350)
self.assertEqual(result.data[0, 0, -1], 10)

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


def unrolled_cube():
data = np.arange(5, dtype='f4')
Expand Down

0 comments on commit f77170e

Please sign in to comment.