diff --git a/climada/util/coordinates.py b/climada/util/coordinates.py index 09a22f84f..741b40586 100644 --- a/climada/util/coordinates.py +++ b/climada/util/coordinates.py @@ -200,6 +200,7 @@ def lon_bounds(lon, buffer=0.0): if lon_diff_max < 2: # since the largest gap is comparably small, enforce the [-180, 180] value range gap_max = lon_diff.size - 1 + lon_diff_max = lon_diff[gap_max] if lon_diff_max <= 2 * buffer: # avoid (-1, 359) and similar equivalent outputs for bounds covering the full circle lon_min, lon_max = (-180, 180) diff --git a/climada/util/test/test_coordinates.py b/climada/util/test/test_coordinates.py index 5903c2f1c..15b8b9119 100644 --- a/climada/util/test/test_coordinates.py +++ b/climada/util/test/test_coordinates.py @@ -265,6 +265,12 @@ def test_latlon_bounds(self): bounds = u_coord.latlon_bounds(lat, lon, buffer=1) self.assertEqual(bounds, (-180, -90, 180, 90)) + # edge with values closer to the antimeridian than buffers and global coverage + lon = np.concatenate([[-179.99], np.arange(-179.7, 179.9, 0.2), [179.99]]) + lat = np.zeros_like(lon) + bounds = u_coord.latlon_bounds(lat, lon, buffer=0.1) + self.assertEqual(bounds, (-180, -0.1, 180, 0.1)) + def test_toggle_extent_bounds(self): """Test the conversion between 'extent' and 'bounds'""" self.assertEqual(u_coord.toggle_extent_bounds((0, -1, 1, 3)), (0, 1, -1, 3))