Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 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,7 +2233,12 @@ 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)
close_enough = np.allclose(pre_wrap_delta, post_wrap_delta)
if close_enough:
split_cell_indices = np.array(())
else:
split_cell_indices, _ = np.where(pre_wrap_delta !=
post_wrap_delta)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marqh You could simply refactor this to be the following ...

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)
    # Re-calaulate the extended minimum.
    indices = inside_indices[split_cell_indices]
    cells = bounds[indices]
    ....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that looks neater

if split_cell_indices.size:
# Recalculate the extended minimum.
indices = inside_indices[split_cell_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