Closed MaximilianHoffmann closed 4 years ago
I don't mind keeping the issue here: the code base is evolving a lot so stackoverflow might be premature. A few elements to answer your question:
itp=interpolator(...)
and then evaluate with interpolate(itp, points)
. Different structures will have different options (like cubic, linear, extrapolate one way or another) and will have a different numba type so we can generate efficient code for all subcases. There is no preexisting limit to what we can do here so feel free to open feature requests and we'll see how they fit in the code overhaul. In particular, using fill_values
instead of extrapolation shouldn't be a big deal but one could incorporate other extrapolation modes. But right now the answer to your question is "no it's not supported".interp
is a function whose behaviour is supposed to correspond to scipy.interpn with the linear options. Except there are subtle differences like the fact that scipy seems to consider image coordinates by default (interp(x,y, A_yx)
) which seems plain wrong to me. Now I am not quite sure as to the best approach here: whether to copy scipy functionality or ignore it and maybe remove the interp
functionmlininterp
has a more consistent API and is probably here to stayThanks for your answer.
I am interested in the library mainly, because I was looking for a fast alternative to scipy for interpolating image volumes.
Especially I want to rotate volumes , which leads to a lot of extrapolation in the current version, this is why I am interested in the fill_values
option
Hi @MaximilianHoffmann . We now have options to extrapolate: you can do eval_linear(grid, x, point, options.NEAREST)
or eval_linear(grid, x, point, options.CONSTANT)
(which fills outside values with 0). There are more details in the README file. Is it what you needed ?
Perfect, this is what I needed. Thanks a lot
Hi @albop ,
Thanks for the excellent package! I've a quick question:
When I do eval_linear(grid, x, point, options.CONSTANT)
with grid = (np.linspace(0,1,10), np.linspace(0,1,10))
, it returns an error with the following traceback:
File "testing_eval_linear.py", line 46, in <module>
ans1 = eval_linear(grid1, values, points, xto.CONSTANT) # 10000 vector
File "/usr/local/lib/python3.7/site-packages/numba/dispatcher.py", line 376, in _compile_for_args
error_rewrite(e, 'typing')
File "/usr/local/lib/python3.7/site-packages/numba/dispatcher.py", line 343, in error_rewrite
reraise(type(e), e, None)
File "/usr/local/lib/python3.7/site-packages/numba/six.py", line 658, in reraise
raise value.with_traceback(tb)
numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function _eval_linear at 0x116b89620>) with argument(s) of type(s): (tuple(array(float64, 1d, C) x 2), array(float64, 2d, C), array(float64, 2d, C), instance.jitclass.c_CONSTANT#116c21860<>)
*parameterized
while with grid = UCGrid((0, 1.0, 10), (0.0, 1.0, 10))
, it just works perfectly fine.
here is the code from the readme:
import numpy as np
from interpolation.splines import UCGrid, CGrid, nodes
f = lambda x,y: np.sin(np.sqrt(x**2+y**2+0.00001))/np.sqrt(x**2+y**2+0.00001)
grid = UCGrid((-1.0, 1.0, 10), (-1.0, 1.0, 10))
gp = nodes(grid) # 100x2 matrix
values = f(gp[:,0], gp[:,1]).reshape((10,10))
from interpolation.splines import eval_linear
from interpolation.splines import extrap_options as xto
points = np.random.random((100,2))*3-1
grid1 = (np.linspace(0,1,10), np.linspace(0,1,10))
ans1 = eval_linear(grid1, values, points, xto.CONSTANT) # This line gives an error
grid2 = UCGrid((0, 1.0, 10), (0.0, 1.0, 10))
ans2 = eval_linear(grid2, values, points, xto.CONSTANT) # This works fine
Is the extrapolation utility only available with grids defined in tuple of tuples format and not tuple of arrays? Thanks a lot :)
it shouldn't be the case. Let me check
On Mon, Sep 30, 2019 at 5:20 PM Praful Gupta notifications@github.com wrote:
Hi @albop https://github.com/albop ,
Thanks for the excellent package! I've a quick question:
When I do eval_linear(grid, x, point, options.CONSTANT) with grid = (np.linspace(0,1,10), np.linspace(0,1,10)), it returns an error with the following traceback: ` File "testing_eval_linear.py", line 46, in ans1 = eval_linear(grid1, values, points, xto.CONSTANT) # 10000 vector File "/usr/local/lib/python3.7/site-packages/numba/dispatcher.py", line 376, in _compile_for_args error_rewrite(e, 'typing') File "/usr/local/lib/python3.7/site-packages/numba/dispatcher.py", line 343, in error_rewrite reraise(type(e), e, None) File "/usr/local/lib/python3.7/site-packages/numba/six.py", line 658, in reraise raise value.with_traceback(tb) numba.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) Invalid use of Function(<function _eval_linear at 0x116b89620>) with argument(s) of type(s): (tuple(array(float64, 1d, C) x 2), array(float64, 2d, C), array(float64, 2d, C), instance.jitclass.c_CONSTANT#116c21860<>)
- parameterized`
while with grid = UCGrid((0, 1.0, 10), (0.0, 1.0, 10)), it just works perfectly fine.
here is the code from the readme:
import numpy as np
from interpolation.splines import UCGrid, CGrid, nodes
f = lambda x,y: np.sin(np.sqrt(x2+y2+0.00001))/np.sqrt(x2+y2+0.00001)
grid = UCGrid((-1.0, 1.0, 10), (-1.0, 1.0, 10))
gp = nodes(grid) # 100x2 matrix
values = f(gp[:,0], gp[:,1]).reshape((10,10))
from interpolation.splines import eval_linear from interpolation.splines import extrap_options as xto points = np.random.random((100,2))*3-1
grid1 = (np.linspace(0,1,10), np.linspace(0,1,10)) ans1 = eval_linear(grid1, values, points, xto.CONSTANT) # This line gives an error
grid2 = UCGrid((0, 1.0, 10), (0.0, 1.0, 10)) ans2 = eval_linear(grid2, values, points, xto.CONSTANT) # This works fine
Is the extrapolation utility only available with grids defined in tuple of tuples format and not tuple of arrays? Thanks a lot :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/EconForge/interpolation.py/issues/28?email_source=notifications&email_token=AACDSKOXNWAG2ITDKHXQCBTQMIKLXA5CNFSM4FUHAS62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD76AZNQ#issuecomment-536612022, or mute the thread https://github.com/notifications/unsubscribe-auth/AACDSKIMOZ7A4FCVKZH26ZTQMIKLXANCNFSM4FUHAS6Q .
@guptapraful : I think I fixed the problem in master. Would you mind checking whether it gives reasonable results ?
Hi @albop, It works perfectly now! Thanks!
especially, what happens outside of the regular grid, can I switch extrapolation off and define a fill value == 0 ?
Sorry. that this is no real issue. Happy to migrate it to stackoverflow or so