Skip to content

Commit a325e2d

Browse files
authored
Issue #1188 Update the numba_celltree package (#1189)
Fixes #1188 # Description In the numba_celltree package a change has been made that changes the behavior of the locate_points method. In structured grids the behavior is that when a point lies on the left or bottom edge it is considered to be in the cell. When the point lies on the right or top edge its considered outside of the cell This kind of logic doesn't work for unstructured grids because the orientation of the cell can be anything. However there are unit tests that do assume that this applies for unstructured grids as well. And those are the tests that are failing right now. To solve this the bahavior has changed such that when a point lies on a cell edge its is considered to be in the cell. This also applies to structred grids. This was # Checklist <!--- Before requesting review, please go through this checklist: --> - [ ] Links to correct issue - [ ] Update changelog, if changes affect users - [ ] PR title starts with ``Issue #nr``, e.g. ``Issue #737`` - [ ] Unit tests were added - [ ] **If feature added**: Added/extended example
1 parent d327617 commit a325e2d

4 files changed

Lines changed: 34 additions & 28 deletions

File tree

imod/select/points.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def points_in_bounds(da, **points):
112112
da_x = da.coords[key]
113113
_, xmin, xmax = imod.util.spatial.coord_reference(da_x)
114114
# Inplace bitwise operator
115-
in_bounds &= (x >= xmin) & (x < xmax)
115+
in_bounds &= (x >= xmin) & (x <= xmax)
116116

117117
return in_bounds
118118

imod/tests/test_select/test_select_points.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def test_in_bounds(test_da_nonequidistant, test_uda):
7878
actual = imod.select.points_in_bounds(case, x=x, y=y)
7979
assert (expected == actual).all()
8080

81-
# Upper exclusive
81+
# Upper inclusive
8282
x = 4.0
8383
y = 3.0
84-
expected = np.array([False])
84+
expected = np.array([True])
8585
actual = imod.select.points_in_bounds(case, x=x, y=y)
8686
assert (expected == actual).all()
8787

@@ -107,11 +107,12 @@ def test_get_indices__nonequidistant(test_da_nonequidistant):
107107
actual = imod.select.points_indices(test_da_nonequidistant, x=x, y=y)
108108
assert expected == xy_indices(actual)
109109

110-
# Upper exclusive
110+
# Upper inclusive
111111
x = 4.0
112112
y = 2.5
113-
with pytest.raises(ValueError):
114-
actual = imod.select.points_indices(test_da_nonequidistant, x=x, y=y)
113+
expected = (np.array([0]), np.array([4]))
114+
actual = imod.select.points_indices(test_da_nonequidistant, x=x, y=y)
115+
assert expected == xy_indices(actual)
115116

116117
# Arrays
117118
x = [3.0, 0.0]
@@ -123,11 +124,15 @@ def test_get_indices__nonequidistant(test_da_nonequidistant):
123124
assert (rr_e == rr_a).all()
124125
assert (cc_e == cc_a).all()
125126

126-
# Arrays; upper exclusive
127+
# Arrays; upper inclusive
127128
x = [4.0, 0.0]
128129
y = [2.5, 0.0]
129-
with pytest.raises(ValueError):
130+
rr_e, cc_e = (np.array([0, 2]), np.array([4, 0]))
131+
rr_a, cc_a = xy_indices(
130132
imod.select.points_indices(test_da_nonequidistant, x=x, y=y)
133+
)
134+
assert (rr_e == rr_a).all()
135+
assert (cc_e == cc_a).all()
131136

132137

133138
def test_get_indices__equidistant(test_da):
@@ -141,22 +146,24 @@ def test_get_indices__equidistant(test_da):
141146
def test_get_indices__unstructured(test_uda):
142147
x = 3.0
143148
y = 2.5
144-
expected = np.array([3])
149+
expected = np.array([2])
145150
indices = imod.select.points_indices(test_uda, x=x, y=y)
146151
actual = indices["mesh2d_nFaces"].values
147152
assert expected == actual
148153

149-
# Upper exclusive
154+
# Upper inclusive
150155
x = 4.0
151156
y = 2.5
152-
with pytest.raises(ValueError):
153-
actual = imod.select.points_indices(test_uda, x=x, y=y)
157+
expected = np.array([3])
158+
indices = imod.select.points_indices(test_uda, x=x, y=y)
159+
actual = indices["mesh2d_nFaces"].values
160+
assert expected == actual
154161

155162

156163
def test_get_values__unstructured(test_uda):
157164
x = 3.0
158165
y = 2.5
159-
expected = np.array([3])
166+
expected = np.array([2])
160167
indices = imod.select.points_values(test_uda, x=x, y=y)
161168
actual = indices["mesh2d_nFaces"].values
162169
assert expected == actual

pixi.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ matplotlib = "*"
6868
mypy = "*"
6969
netcdf4 = "*"
7070
numba = ">=0.50"
71-
numba_celltree = "<0.2" # The 0.2 version breaks the following test: test_in_bounds, test_get_indices__unstructured, test_get_values__unstructured
7271
numpy = "*"
7372
pandamesh = "*"
7473
pandas = "*"

0 commit comments

Comments
 (0)