Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix lon_bounds returning range > 360 degrees #859

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions climada/util/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions climada/util/test/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading