Skip to content

Commit

Permalink
fix "pick search radius" not recognized if 1D brute-force queries are…
Browse files Browse the repository at this point in the history
… used
  • Loading branch information
raphaelquast committed Jun 13, 2024
1 parent de375f6 commit cc1b23f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions eomaps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,18 @@ def query(self, x, k=1, d=None, pick_relative_to_closest=True):
i = None
# take care of 1D coordinates and 2D data
if self._m._data_manager.x0_1D is not None:

dx = np.abs(self._m._data_manager.x0_1D - x[0])
dy = np.abs(self._m._data_manager.y0_1D - x[1])

if k > 1 and pick_relative_to_closest is True:
ix = np.argmin(np.abs(self._m._data_manager.x0_1D - x[0]))
iy = np.argmin(np.abs(self._m._data_manager.y0_1D - x[1]))
# mask datapoints outside the "search_radius"
dx, dy = dx[dx < d], dy[dy < d]
if len(dx) == 0 or len(dy) == 0:
return None

Check warning on line 481 in eomaps/helpers.py

View check run for this annotation

Codecov / codecov/patch

eomaps/helpers.py#L481

Added line #L481 was not covered by tests

ix = np.argmin(dx)
iy = np.argmin(dy)
# query again (starting from the closest point)
return self.query(
(self._m._data_manager.x0_1D[ix], self._m._data_manager.y0_1D[iy]),
Expand All @@ -481,14 +490,14 @@ def query(self, x, k=1, d=None, pick_relative_to_closest=True):
pick_relative_to_closest=False,
)
else:

# perform a brute-force search for 1D coords
ix = np.argpartition(
np.abs(self._m._data_manager.x0_1D - x[0]), range(k)
)[:k]
iy = np.argpartition(
np.abs(self._m._data_manager.y0_1D - x[1]), range(k)
)[:k]
ix = np.argpartition(dx, range(k))[:k]
iy = np.argpartition(dy, range(k))[:k]

# mask datapoints outside the "search_radius"
ix, iy = ix[dx[ix] < d], iy[dy[iy] < d]
if len(ix) == 0 or len(iy) == 0:
return None

Check warning on line 500 in eomaps/helpers.py

View check run for this annotation

Codecov / codecov/patch

eomaps/helpers.py#L500

Added line #L500 was not covered by tests

if k > 1:
# select a circle within the kxk rectangle
Expand Down

0 comments on commit cc1b23f

Please sign in to comment.