Skip to content

Commit 657b612

Browse files
committed
Add function to test if lat and lon are in geographic coords
1 parent 5f092ab commit 657b612

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

climada/util/coordinates.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@
7979
"""Distance threshold in km for coordinate assignment. Nearest neighbors with greater distances
8080
are not considered."""
8181

82+
def check_if_geo_coords(lat, lon):
83+
"""
84+
Check if latitude and longitude arrays are likely in geographic coordinates,
85+
testing if min/max values are within -90 to 180 for latitude and -180 to 360
86+
for longitude.
87+
Returns True if lat/lon ranges are in the geographic coordinates range, otherwise False.
88+
"""
89+
lat = np.array(lat)
90+
lon = np.array(lon)
91+
92+
# Check if latitude is within -90 to 180 and longitude is within -180 to 360
93+
# and extent are smaller than 180 and 360 respectively
94+
if ((lat.min() >= -90 and lat.max() <= 180 and lon.min() >= -180 and lon.max() <= 360)
95+
and (lat.max() - lat.min() <= 180 and lon.max() - lon.min() <= 360)):
96+
return True
97+
else:
98+
return False
99+
82100
def latlon_to_geosph_vector(lat, lon, rad=False, basis=False):
83101
"""Convert lat/lon coodinates to radial vectors (on geosphere)
84102

0 commit comments

Comments
 (0)