Skip to content

Commit 2a1f9b1

Browse files
committed
Check for geo coords in match_coordinates
1 parent cb1e718 commit 2a1f9b1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

climada/util/coordinates.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,15 @@ def match_coordinates(
11251125

11261126
# assign remaining coordinates to their geographically nearest neighbor
11271127
if threshold > 0 and exact_assign_idx.size != coords_view.size:
1128+
# check that coords are geographic before proceeding to nearest neighbor search
1129+
if not (
1130+
check_if_geo_coords(coords[:, 0], coords[:, 1])
1131+
and check_if_geo_coords(coords_to_assign[:, 0], coords_to_assign[:, 1])
1132+
):
1133+
raise ValueError(
1134+
"Input lat and lon coordinates are not geographic "
1135+
"or have total extents > 180° for lat or > 360° for lon."
1136+
)
11281137
not_assigned_idx_mask = assigned_idx == -1
11291138
assigned_idx[not_assigned_idx_mask] = nearest_neighbor_funcs[distance](
11301139
coords_to_assign, coords[not_assigned_idx_mask], threshold, **kwargs

0 commit comments

Comments
 (0)