From 77c1f960d8036326cf62fc3b2ce0a1e281668675 Mon Sep 17 00:00:00 2001 From: cpelley Date: Wed, 19 Oct 2016 11:02:34 +0100 Subject: [PATCH 1/3] TEST: Intolerant area weighted float comparison failure --- ..._area_weighted_rectilinear_src_and_grid.py | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/iris/tests/unit/experimental/regrid/test_regrid_area_weighted_rectilinear_src_and_grid.py b/lib/iris/tests/unit/experimental/regrid/test_regrid_area_weighted_rectilinear_src_and_grid.py index 16a63f4d6a..53c7932ee0 100644 --- a/lib/iris/tests/unit/experimental/regrid/test_regrid_area_weighted_rectilinear_src_and_grid.py +++ b/lib/iris/tests/unit/experimental/regrid/test_regrid_area_weighted_rectilinear_src_and_grid.py @@ -1,4 +1,4 @@ -# (C) British Crown Copyright 2014 - 2015, Met Office +# (C) British Crown Copyright 2014 - 2016, Met Office # # This file is part of Iris. # @@ -150,5 +150,32 @@ def test_scalar_with_overlap_above_mdtol(self): self.assertEqual(ma.count_masked(res.data), 1) +class TestWrapAround(tests.IrisTest): + def test_float_tolerant_equality(self): + # Ensure that floating point numbers are treated appropriately when + # introducing precision difference from wrap_around. + source = Cube([[1]]) + bounds = np.array([[-91, 0]], dtype='float') + points = bounds.mean(axis=1) + lon_coord = DimCoord(points, bounds=bounds, standard_name='longitude') + 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') + 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') + 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])) + + if __name__ == '__main__': tests.main() From fb51730365a77893eb9fa2be1ec665d3ed591e40 Mon Sep 17 00:00:00 2001 From: cpelley Date: Wed, 19 Oct 2016 11:36:47 +0100 Subject: [PATCH 2/3] BUG: Tolerance regrid within_bounds --- lib/iris/experimental/regrid.py | 4 ++-- ...regrid_area_weighted_rectilinear_src_and_grid.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/iris/experimental/regrid.py b/lib/iris/experimental/regrid.py index c6123da4f5..06cc8b956e 100644 --- a/lib/iris/experimental/regrid.py +++ b/lib/iris/experimental/regrid.py @@ -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: diff --git a/lib/iris/tests/unit/experimental/regrid/test_regrid_area_weighted_rectilinear_src_and_grid.py b/lib/iris/tests/unit/experimental/regrid/test_regrid_area_weighted_rectilinear_src_and_grid.py index 53c7932ee0..addacbdbf6 100644 --- a/lib/iris/tests/unit/experimental/regrid/test_regrid_area_weighted_rectilinear_src_and_grid.py +++ b/lib/iris/tests/unit/experimental/regrid/test_regrid_area_weighted_rectilinear_src_and_grid.py @@ -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__': From 37415317892c98616239c055d4b3a4869dd9d2b4 Mon Sep 17 00:00:00 2001 From: cpelley Date: Wed, 19 Oct 2016 11:37:37 +0100 Subject: [PATCH 3/3] MAINT: Failing unrelated pep8 --- lib/iris/coord_systems.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/iris/coord_systems.py b/lib/iris/coord_systems.py index 1d23225940..51a95f4506 100644 --- a/lib/iris/coord_systems.py +++ b/lib/iris/coord_systems.py @@ -914,11 +914,11 @@ def __repr__(self): return ("LambertAzimuthalEqualArea(latitude_of_projection_origin={!r}," " longitude_of_projection_origin={!r}, false_easting={!r}," " false_northing={!r}, ellipsoid={!r})").format( - self.latitude_of_projection_origin, - self.longitude_of_projection_origin, - self.false_easting, - self.false_northing, - self.ellipsoid) + self.latitude_of_projection_origin, + self.longitude_of_projection_origin, + self.false_easting, + self.false_northing, + self.ellipsoid) def as_cartopy_crs(self): if self.ellipsoid is not None: