[SciPy-Dev] Mass 1D interpolation, advice

Jonathan Stickel jjstickel at gmail.com
Wed Apr 15 10:33:17 EDT 2015


On 4/14/15 16:12 , Matthew Brett wrote:
> Hi,
>
> In brain imaging (my world) - we need to do 1D interpolation of large
> datasets, specifically, we have data in the order of (X, Y) = (200,
> 4000), where we are interpolating at the same ~200 X locations for
> each of the 4000 rows.
>
> We need to do this with extrapolation at the boundaries, so I think we
> can't use scipy.interpolate.interp1d which is otherwise well suited
> for the task.
>
> scipy.interpolate.InterpolatedUnivariateSpline does deal with
> extrapolation, but only works with vectors.
>
> I think, in order to make speed reasonable, I will need to loop over
> the rows in compiled code.
>
> My questions are:
>
> a) how easy would it be to try and link some external Cython code
> against the fitpack code in scipy?
> b) if that is not easy, what can I do that will also be of most use to
> other scipy users?
>
> Cheers,
>
> Matthew

I am not sure if I understand your problem statement. Most interpolation 
problems are posed as:  given data (x,y), determine yp at xp, where xp 
are different from x. This is fine for cases where you have a single y 
and possibly multiple sets xp. I had case awhile ago where I had a 
single xp and multiple y (at the same x). In this case, the problem 
statement is:  given known locations x and interpolant locations xp, 
what are the values for yp (corresponding to xp) given y (corresponding 
to xp). To solve this problem efficiently, I wrote the code I posted here:

http://scipy-central.org/item/21/1/simple-piecewise-polynomial-interpolation

Although it is not true spline interpolation (rather a simpler local 
polynomial interpolation), it is reasonably fast and accurate. 
Extrapolation is allowed. However, I later found that 
scipy.interpolate.splrep/splev are so fast that they could be used 
instead with equivalent speed for my problem. By comparison, 
scipy.interpolate.interp1d is quite slow.

HTH,
Jonathan



More information about the SciPy-Dev mailing list