Skip to content

Commit d6e3304

Browse files
committed
faster min-distance calculation
1 parent 5e78201 commit d6e3304

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/anemoi/datasets/grids.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def cutout_mask(
151151
):
152152
"""Return a mask for the points in [global_lats, global_lons] that are inside of [lats, lons]"""
153153
from scipy.spatial import KDTree
154-
from scipy.spatial import distance_matrix
155154

156155
# TODO: transform min_distance from lat/lon to xyz
157156

@@ -198,9 +197,8 @@ def cutout_mask(
198197
if min_distance_km is not None:
199198
min_distance = min_distance_km / 6371.0
200199
else:
201-
min_distance = 0
202-
dm = distance_matrix(global_points, global_points)
203-
min_distance = np.min(dm[dm > 0])
200+
distances, _ = KDTree(global_points).query(global_points, k=2)
201+
min_distance = np.min(distances[:, 1])
204202

205203
LOG.debug(f"cutout_mask using min_distance = {min_distance * 6371.0} km")
206204

0 commit comments

Comments
 (0)