Skip to content

Commit

Permalink
faster min-distance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Aug 30, 2024
1 parent d6e3304 commit 941bbf6
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/anemoi/datasets/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,15 @@ def cutout_mask(
xyx = latlon_to_xyz(lats, lons)
lam_points = np.array(xyx).transpose()

# Use a KDTree to find the nearest points
kdtree = KDTree(lam_points)

distances, indices = kdtree.query(global_points, k=neighbours)

if min_distance_km is not None:
min_distance = min_distance_km / 6371.0
else:
distances, _ = KDTree(global_points).query(global_points, k=2)
min_distance = np.min(distances[:, 1])

# Use a KDTree to find the nearest points
distances, indices = KDTree(lam_points).query(global_points, k=neighbours)

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

# Centre of the Earth
Expand Down Expand Up @@ -291,8 +289,7 @@ def thinning_mask(
points = np.array(xyx).transpose()

# Use a KDTree to find the nearest points
kdtree = KDTree(points)
_, indices = kdtree.query(global_points, k=1)
_, indices = KDTree(points).query(global_points, k=1)

return np.array([i for i in indices])

Expand Down

0 comments on commit 941bbf6

Please sign in to comment.