diff --git a/improver/regrid/grid.py b/improver/regrid/grid.py index 81bd7b7f77..5a2ed9d28d 100644 --- a/improver/regrid/grid.py +++ b/improver/regrid/grid.py @@ -66,8 +66,8 @@ def calculate_input_grid_spacing(cube_in: Cube) -> Tuple[float, float]: raise ValueError("Input grid is not on a latitude/longitude system") # calculate grid spacing - lon_spacing = calculate_grid_spacing(cube_in, "degree", axis="x", rtol=7.0e-5) - lat_spacing = calculate_grid_spacing(cube_in, "degree", axis="y", rtol=7.0e-5) + lon_spacing = calculate_grid_spacing(cube_in, "degree", axis="x", rtol=3.0e-5) + lat_spacing = calculate_grid_spacing(cube_in, "degree", axis="y", rtol=3.0e-5) if lon_spacing < 0 or lat_spacing < 0: raise ValueError("Input grid coordinates are not ascending.") diff --git a/improver/utilities/spatial.py b/improver/utilities/spatial.py index c960976858..81f1b597c8 100644 --- a/improver/utilities/spatial.py +++ b/improver/utilities/spatial.py @@ -77,7 +77,7 @@ def check_if_grid_is_equal_area( def calculate_grid_spacing( - cube: Cube, units: Union[Unit, str], axis: str = "x", rtol: float = 1.0e-6 + cube: Cube, units: Union[Unit, str], axis: str = "x", rtol: float = 1.0e-5 ) -> float: """ Returns the grid spacing of a given spatial axis diff --git a/improver_tests/utilities/test_spatial.py b/improver_tests/utilities/test_spatial.py index d27da93a14..de7c18e25f 100644 --- a/improver_tests/utilities/test_spatial.py +++ b/improver_tests/utilities/test_spatial.py @@ -228,7 +228,7 @@ def setUp(self): 10.0, 20.00001, ] - self.longitude_points_2 = [ + self.longitude_points_thirds = [ 160.0, 160.33333, 160.66667, @@ -237,8 +237,8 @@ def setUp(self): ] self.rtol = 1.0e-5 self.expected = 10.0 - self.expected_2 = 0.33333 - self.rtol_2 = 3.0e-5 + self.expected_thirds = 0.33333 + self.rtol_thirds = 3.0e-5 def test_lat_lon_equal_spacing(self): """Test grid spacing outputs with lat-lon grid with tolerance""" @@ -262,18 +262,22 @@ def test_lat_lon_not_equal_spacing(self): with self.assertRaisesRegex(ValueError, msg): calculate_grid_spacing(self.lat_lon_cube, "degrees", rtol=self.rtol) - def test_lat_lon_equal_spacing_recurring_decimal_spacing(self): - """Test grid spacing outputs with lat-lon grid with tolerance""" - self.lat_lon_cube.coord("longitude").points = self.longitude_points_2 + def test_lat_lon_equal_spacing_recurring_decimal_spacing_fails(self): + """Test grid spacing with lat-lon grid with with 1/3 degree + intervals with tolerance of 1.0e-5""" + self.lat_lon_cube.coord("longitude").points = self.longitude_points_thirds msg = "Coordinate longitude points are not equally spaced" with self.assertRaisesRegex(ValueError, msg): calculate_grid_spacing(self.lat_lon_cube, "degrees", rtol=self.rtol) def test_lat_lon_equal_spacing_recurring_decimal_spacing_2(self): - """Test grid spacing outputs with lat-lon grid with tolerance 3.0e-5""" - self.lat_lon_cube.coord("longitude").points = self.longitude_points_2 - result = calculate_grid_spacing(self.lat_lon_cube, "degrees", rtol=self.rtol_2) - self.assertAlmostEqual(result, self.expected_2, places=5) + """Test grid spacing outputs with lat-lon grid with 1/3 degree + intervals with tolerance of 3.0e-5""" + self.lat_lon_cube.coord("longitude").points = self.longitude_points_thirds + result = calculate_grid_spacing( + self.lat_lon_cube, "degrees", rtol=self.rtol_thirds + ) + self.assertAlmostEqual(result, self.expected_thirds, places=5) class Test_convert_distance_into_number_of_grid_cells(IrisTest):