Skip to content

Commit 15d1d7f

Browse files
authored
fix(gridintersect): relax cell boundary checks with np.isclose (#2173)
Check np.isclose instead of exact equality in find_position_in_array() to allow for floating point error after round-trip coordinate transformation — if a coordinate passes the fuzzy check, clamp it to the cell boundary
1 parent dc35b09 commit 15d1d7f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

flopy/utils/gridintersect.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,13 +2246,17 @@ def find_position_in_array(arr, x):
22462246
"""
22472247
jpos = []
22482248

2249-
if x == arr[-1]:
2249+
if np.isclose(x, arr[-1]):
22502250
return len(arr) - 2
22512251

2252-
if x < min(arr[0], arr[-1]):
2253-
return None
2252+
xmin = min(arr[0], arr[-1])
2253+
xmax = max(arr[0], arr[-1])
22542254

2255-
if x > max(arr[0], arr[-1]):
2255+
if np.isclose(x, xmin):
2256+
x = xmin
2257+
if np.isclose(x, xmax):
2258+
x = xmax
2259+
if not (xmin <= x <= xmax):
22562260
return None
22572261

22582262
# go through each position

0 commit comments

Comments
 (0)