Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/anemoi/transform/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ def nearest_grid_points(
target_latitudes: NDArray[Any],
target_longitudes: NDArray[Any],
max_distance: float = None,
num_neighbours_to_return: int = 1,
) -> NDArray[Any]:
"""Find the nearest grid points from source to target coordinates.

Expand All @@ -606,7 +607,8 @@ def nearest_grid_points(
max_distance: float, optional
Maximum distance between nearest point and point to interpolate. Defaults to None.
For example, 1e-3 is 1 km.

num_neighbours_to_return : int, optional
Number of nearest neighbours to return. Defaults to 1.
Returns
-------
NDArray[Any]
Expand All @@ -620,7 +622,9 @@ def nearest_grid_points(
target_xyz = latlon_to_xyz(target_latitudes, target_longitudes)
target_points = np.array(target_xyz).transpose()
if max_distance is None:
_, indices = cKDTree(source_points).query(target_points, k=1)
_, indices = cKDTree(source_points).query(target_points, k=num_neighbours_to_return)
else:
_, indices = cKDTree(source_points).query(target_points, k=1, distance_upper_bound=max_distance)
_, indices = cKDTree(source_points).query(
target_points, k=num_neighbours_to_return, distance_upper_bound=max_distance
)
return indices
Loading