Skip to content

Commit 5a7d7d2

Browse files
adding checks to index_search to validate bcoord between 0 and 1
1 parent e77866f commit 5a7d7d2

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

parcels/_index_search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def _search_time_index(field: Field, time: datetime):
6767
if field.data.time.data[ti] != field.data.time.data[ti + 1]
6868
else 0
6969
)
70+
if tau < 0 or tau > 1: # TODO only for debugging; test can go?
71+
raise ValueError(f"Time {time} is out of bounds for field time data {field.data.time.data}.")
7072
return tau, ti
7173

7274

parcels/xgrid.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ def _search_1d_array(
399399
return 0, 0.0
400400
i = np.argmin(arr <= x) - 1
401401
bcoord = (x - arr[i]) / (arr[i + 1] - arr[i])
402+
if bcoord < 0 or bcoord > 1: # TODO only for debugging; test can go?
403+
raise ValueError(f"Position {x} is out of bounds for array {arr}.")
402404
return i, bcoord
403405

404406

0 commit comments

Comments
 (0)