[SciPy-User] trusting splprep
elliot
offonoffoffonoff at gmail.com
Mon Jul 25 14:56:39 EDT 2011
backstory:
I am working on an optical raytracing program written in python.
Currently, I am reworking the face that uses a spline approximation of
a profile. Specifically, moving from a second order to third order.
The evaluating of the spline is done in c code that I intend to write,
and so in exploring what exactly the output of splprep means, and how
to construct the curve in question from tck, I discovered that I need
to know how to use splprep better.
question:
How can I be sure that my spline approximation is sufficiently
accurate? In ray tracing, a slight inaccuracy in the derivative of
the interpolation could have a large effect. My use of splprep is
awkward, so i am looking for some advice.
for instance, just trying a simple example:
#####
>>>x = range(0,6)
>>>y = [c**3 for c in x]
>>>tck,uout = scipy.interpolate.splprep([x,y],s=.000005,k=3)
>>>t = numpy.linspace(0,1,6) #evenly spaced parameters, should correspond to x
>>> xy = scipy.interpolate.splev(t,tck)
>>> print xy[0] #should be same as x
array([ 0.10119217, 2.81103321, 3.959404 , 3.90686522,
3.85308141,
4.99999962]
# !! x went backwards as parameter progressed: graph is not a function
>>> inty = [c**3 for c in xy[0]]
#differance between interpolated y's and cubes of interpolated x's
>>> numpy.array(xy[1])-numpy.array(inty)
array([ -6.36532821e-04, 2.50019069e+00, -1.25009170e+01,
1.53618385e+01, 4.31465996e+01, 2.89434607e-05])
####
Now, this is pretty large error considering that this is a cubic
spline on a simple cubic function. This should be pretty accurate, if
not exact, but an order of magnitude off just isn't right. changing
the smoothness from .00005 to 5 doesn't make a difference.
So, how do I use splprep correctly. And, does anyone have any
pointers regarding ensuring a certain level of accuracy in the
results, or at least raising an error if the spline is not accurate
enough.
thanks,
Elliot
More information about the SciPy-User
mailing list