[SciPy-Dev] Mass 1D interpolation, advice

Matthew Brett matthew.brett at gmail.com
Wed Apr 15 13:57:28 EDT 2015


Hi,

On Wed, Apr 15, 2015 at 7:33 AM, Jonathan Stickel <jjstickel at gmail.com> wrote:
> 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).

Sorry not to be clear; that is my case too.  (1D x, xp, ND y, yp).

> To solve this problem
> efficiently, I wrote the code I posted here:
>
> http://scipy-central.org/item/21/1/simple-piecewise-polynomial-interpolation

Thanks for the pointer.

> 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.

Just to check - you looping over vectors in y, and using splrep/splev
on each vector?

Cheers,

Matthew



More information about the SciPy-Dev mailing list