Example of how to use B-splines for interpolation
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
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
Andrew Straw wrote:
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.
Thanks for the patch. I'm doing something a little simpler now (the clip method).
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.
I'm not getting any errors for x being integers in the code you gave, perhaps you mean that when the new array to evaluate over is an array of integers we get errors, which is true and has been fixed. -Travis
participants (2)
-
Andrew Straw -
Travis Oliphant