Can scipy's RegularGridInterpolator return both values and gradients with a single call?
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5
--
Chapters
00:00 Question
02:53 Accepted answer (Score 1)
03:57 Thank you
--
Full question
https://stackoverflow.com/questions/3905...
Question links:
https://docs.scipy.org/doc/scipy-0.16.0/...
https://docs.scipy.org/doc/scipy-0.16.0/...
[image]: https://i.stack.imgur.com/n61ss.png
Accepted answer links:
https://github.com/JohannesBuchner/regul...
https://en.wikipedia.org/wiki/Trilinear_...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #scipy #interpolation #gradient #linearinterpolation
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5
--
Chapters
00:00 Question
02:53 Accepted answer (Score 1)
03:57 Thank you
--
Full question
https://stackoverflow.com/questions/3905...
Question links:
https://docs.scipy.org/doc/scipy-0.16.0/...
https://docs.scipy.org/doc/scipy-0.16.0/...
[image]: https://i.stack.imgur.com/n61ss.png
Accepted answer links:
https://github.com/JohannesBuchner/regul...
https://en.wikipedia.org/wiki/Trilinear_...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #scipy #interpolation #gradient #linearinterpolation
#avk47
ACCEPTED ANSWER
Score 1
No.
Here is what scipy.interpolate.RegularGridInterpolator does under the hood:
class CartesianGrid(object):
"""
Linear Multivariate Cartesian Grid interpolation in arbitrary dimensions
This is a regular grid with equal spacing.
"""
def __init__(self, limits, values):
self.values = values
self.limits = limits
def __call__(self, *coords):
# transform coords into pixel values
coords = numpy.asarray(coords)
coords = [(c - lo) * (n - 1) / (hi - lo) for (lo, hi), c, n in zip(self.limits, coords, self.values.shape)]
return scipy.ndimage.map_coordinates(self.values, coords,
cval=numpy.nan, order=1)
https://github.com/JohannesBuchner/regulargrid/blob/master/regulargrid/cartesiangrid.py
It uses scipy.ndimage.map_coordinates to do the linear interpolation.
coords contains the location in pixel coordinates. You should be able to use these weights, and the lower and upper values at each dimension to figure out how steep the interpolation rises.
However, the gradient also depends on the values of the corner points.
You can find the math here: https://en.wikipedia.org/wiki/Trilinear_interpolation