Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numerical tolerance #1641

Merged
merged 2 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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: 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)
Copy link
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
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


# 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