Skip to content

Commit 2a893e0

Browse files
Fixing index_search to support particles exactly at right side
1 parent ced1413 commit 2a893e0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/parcels/_core/index_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _search_1d_array(
4444
# TODO v4: We probably rework this to deal with 0D arrays before this point (as we already know field dimensionality)
4545
if len(arr) < 2:
4646
return np.zeros(shape=x.shape, dtype=np.int32), np.zeros_like(x)
47-
index = np.searchsorted(arr, x, side="right") - 1
47+
index = np.clip(np.searchsorted(arr, x, side="right") - 1, 0, len(arr) - 2)
4848
# Use broadcasting to avoid repeated array access
4949
arr_index = arr[index]
5050
arr_next = arr[np.clip(index + 1, 1, len(arr) - 1)] # Ensure we don't go out of bounds
@@ -57,7 +57,7 @@ def _search_1d_array(
5757
# bcoord = (x - arr[index]) / dx
5858

5959
index = np.where(x < arr[0], LEFT_OUT_OF_BOUNDS, index)
60-
index = np.where(x >= arr[-1], RIGHT_OUT_OF_BOUNDS, index)
60+
index = np.where(x > arr[-1], RIGHT_OUT_OF_BOUNDS, index)
6161

6262
return np.atleast_1d(index), np.atleast_1d(bcoord)
6363

0 commit comments

Comments
 (0)