Skip to content

Commit

Permalink
BUG: Tolerance regrid within_bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
cpelley committed Oct 19, 2016
1 parent 45054fa commit 2a45d7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/iris/experimental/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def _within_bounds(src_bounds, tgt_bounds, orderswap=False):
extremes of the source bounds.
"""
min_bound = np.min(src_bounds)
max_bound = np.max(src_bounds)
min_bound = np.min(src_bounds) - 1e-14
max_bound = np.max(src_bounds) + 1e-14

# Swap upper-lower is necessary.
if orderswap is True:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,31 @@ def test_float_tolerant_equality(self):
# Ensure that floating point numbers are treated appropriately when
# introducing precision difference from wrap_around.
source = Cube([[1]])
cs = GeogCS(6371229)

bounds = np.array([[-91, 0]], dtype='float')
points = bounds.mean(axis=1)
lon_coord = DimCoord(points, bounds=bounds, standard_name='longitude')
lon_coord = DimCoord(points, bounds=bounds, standard_name='longitude',
units='degrees', coord_system=cs)
source.add_aux_coord(lon_coord, 1)

bounds = np.array([[-90, 90]], dtype='float')
points = bounds.mean(axis=1)
lat_coord = DimCoord(points, bounds=bounds, standard_name='latitude')
lat_coord = DimCoord(points, bounds=bounds, standard_name='latitude',
units='degrees', coord_system=cs)
source.add_aux_coord(lat_coord, 0)

grid = Cube([[0]])
bounds = np.array([[270, 360]], dtype='float')
points = bounds.mean(axis=1)
lon_coord = DimCoord(points, bounds=bounds, standard_name='longitude')
lon_coord = DimCoord(points, bounds=bounds, standard_name='longitude',
units='degrees', coord_system=cs)
grid.add_aux_coord(lon_coord, 1)
grid.add_aux_coord(lat_coord, 0)

res = regrid(source, grid)
# The result should be equal to the source data and NOT be masked.
self.assertMaskedArrayEqual(res.data, np.array([1.0]))
self.assertArrayEqual(res.data, np.array([1.0]))


if __name__ == '__main__':
Expand Down

0 comments on commit 2a45d7c

Please sign in to comment.