Skip to content

Commit

Permalink
Fix nearest neighbor index errors/Remove SciPy upper limit (#2475)
Browse files Browse the repository at this point in the history
* Add fix, remove SciPy upper limit

* Add changelog
  • Loading branch information
JaydenR2305 committed Jan 23, 2024
1 parent d23a9a1 commit 45e6f56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog/2475.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed ``_nearest_neighbor_interpolator`` method in `~plasmapy.plasma.grids` to interpolate quantities array instead of producing an intermediate index.
11 changes: 4 additions & 7 deletions plasmapy/plasma/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1393,9 +1393,9 @@ def _nearest_neighbor_interpolator(self):
"""

indgrid = np.arange(self.grid.shape[0])

return interp.NearestNDInterpolator(self.grid.to(u.m).value, indgrid)
return interp.NearestNDInterpolator(
self.grid.to(u.m).value, self._interp_quantities
)

@modify_docstring(prepend=AbstractGrid.nearest_neighbor_interpolator.__doc__)
def nearest_neighbor_interpolator(
Expand All @@ -1418,10 +1418,6 @@ def nearest_neighbor_interpolator(
pts1 = self.pts1.to(u.m).value
pts2 = self.pts2.to(u.m).value

i = self._nearest_neighbor_interpolator(pos)

vals = self._interp_quantities[i, :]

mask_particle_off = (
(pos[:, 0] < pts0.min())
| (pos[:, 0] > pts0.max())
Expand All @@ -1431,6 +1427,7 @@ def nearest_neighbor_interpolator(
| (pos[:, 2] > pts2.max())
)

vals = self._nearest_neighbor_interpolator(pos)
vals[mask_particle_off] = np.nan

output = [vals[:, arg] * self._interp_units[arg] for arg in range(len(args))]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies = [
"pandas >= 1.3.0",
"pytest >= 7.0.1",
"requests >= 2.27.1",
"scipy >= 1.7.0, < 1.12.0",
"scipy >= 1.7.0",
"tqdm >= 4.60.0",
"voila >= 0.5.0",
"wrapt >= 1.12.1",
Expand Down

0 comments on commit 45e6f56

Please sign in to comment.