[SciPy-user] Example of how to use B-splines for interpolation

Andrew Straw strawman at astraw.com
Sun Jan 29 15:42:07 CST 2006


Hi Travis,

Thanks for your work on this--it's very useful to me.

I found 2 issues. I'm including a test and a potential fix for the first
issue, which seems to be an end-point problem. Under some circumstances,
the endpoints aren't properly detected. I didn't attempt to comprehend
everything going on in this function, but the patch I made apparently
works. Please review it and apply it if it's acceptable.

The second issue is that the x array cannot be integers (a TypeError
gets raised). There doesn't seem to be any good reason for this (why
can't splines exist over integers?), so I submit that it's also a bug.
Unfortunately, that didn't look as easy for me to fix, so I leave it for
now.

Cheers!
Andrew

Travis Oliphant wrote:

> This example needs the SVN version of scipy (or you need to get the
> cspline1d_eval function out of SVN):
>
> I sent a smaller image hoping it would make it to the list...
>
> Example;
>
> from numpy import r_, sin
> from scipy.signal import cspline1d, cspline1d_eval
>
> x = r_[0:10]
> dx = x[1]-x[0]
> newx = r_[-3:13:0.1]  # notice outside the original domain
> y = sin(x)
> cj = cspline1d(y)
> newy = cspline1d_eval(cj, newx, dx=dx,x0=x[0])
>
> from pylab import plot
> plot(newx, newy, x, y, 'o')
>
>
> Have fun,
>
> -Travis
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: spline.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
Url : http://www.scipy.net/pipermail/scipy-user/attachments/20060129/63e08825/spline.bin


More information about the SciPy-user mailing list