Skip to content

Commit

Permalink
fixing done as suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
zfan001 committed Sep 7, 2021
1 parent d629f8a commit 4e1d387
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions improver/regrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 1 addition & 1 deletion improver/utilities/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions improver_tests/utilities/test_spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"""
Expand All @@ -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):
Expand Down

0 comments on commit 4e1d387

Please sign in to comment.