Skip to content

Commit d2f2997

Browse files
ChrisFairlessThomas Vogt
andauthored
Bugfix lon_bounds returning range > 360 degrees (#859)
* Bugfix coordinates.lon_bounds for edge case returning >360 range See issue #858 * lon_bounds: refactor --------- Co-authored-by: Thomas Vogt <[email protected]>
1 parent 199622a commit d2f2997

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

climada/util/coordinates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ def lon_bounds(lon, buffer=0.0):
200200
if lon_diff_max < 2:
201201
# since the largest gap is comparably small, enforce the [-180, 180] value range
202202
gap_max = lon_diff.size - 1
203+
lon_diff_max = lon_diff[gap_max]
203204
if lon_diff_max <= 2 * buffer:
204205
# avoid (-1, 359) and similar equivalent outputs for bounds covering the full circle
205206
lon_min, lon_max = (-180, 180)

climada/util/test/test_coordinates.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ def test_latlon_bounds(self):
265265
bounds = u_coord.latlon_bounds(lat, lon, buffer=1)
266266
self.assertEqual(bounds, (-180, -90, 180, 90))
267267

268+
# edge with values closer to the antimeridian than buffers and global coverage
269+
lon = np.concatenate([[-179.99], np.arange(-179.7, 179.9, 0.2), [179.99]])
270+
lat = np.zeros_like(lon)
271+
bounds = u_coord.latlon_bounds(lat, lon, buffer=0.1)
272+
self.assertEqual(bounds, (-180, -0.1, 180, 0.1))
273+
268274
def test_toggle_extent_bounds(self):
269275
"""Test the conversion between 'extent' and 'bounds'"""
270276
self.assertEqual(u_coord.toggle_extent_bounds((0, -1, 1, 3)), (0, 1, -1, 3))

0 commit comments

Comments
 (0)