Skip to content

Commit 9ef7323

Browse files
committed
Modify allowed extents in geo_coords check function to allow for bounds
1 parent 320d0f7 commit 9ef7323

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

climada/util/coordinates.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,17 @@
8888
def check_if_geo_coords(lat, lon):
8989
"""
9090
Check if latitude and longitude arrays are likely in geographic coordinates,
91-
testing if min/max values are within -180 to 180 for latitude and -360 to 360
91+
testing if min/max values are within -90 to 90 for latitude and -180 to 540
9292
for longitude.
9393
Returns True if lat/lon ranges are in the geographic coordinates range, otherwise False.
9494
"""
9595
lat = np.array(lat)
9696
lon = np.array(lon)
9797

98-
# Check if latitude is within -180 to 180 and longitude is within -360 to 360
98+
# Check if latitude is within -90 to 90 and longitude is within -180 to 540
9999
# and extent are smaller than 180 and 360 respectively
100100
if (
101-
lat.min() >= -180
102-
and lat.max() <= 180
103-
and lon.min() >= -360
104-
and lon.max() <= 360
101+
lat.min() >= -90 and lat.max() <= 90 and lon.min() >= -180 and lon.max() <= 540
105102
) and ((lat.max() - lat.min()) <= 180 and (lon.max() - lon.min()) <= 360):
106103
return True
107104
else:
@@ -823,9 +820,10 @@ def get_country_geometries(
823820
out = out[country_mask]
824821

825822
if extent:
826-
if extent[1] - extent[0] > 360:
823+
if not check_if_geo_coords(extent[2:], extent[:2]):
827824
raise ValueError(
828-
f"longitude extent range is greater than 360: {extent[0]} to {extent[1]}"
825+
"Coordinates are not geographic (i.e. in degrees). "
826+
"Please convert to a geographical coordinate system first."
829827
)
830828

831829
if extent[1] < extent[0]:

0 commit comments

Comments
 (0)