[SciPy-User] newbie help: splprep to get spline interpolation of 2d signal : ValueError from code but not in command line example

hari jayaram harijay@gmail....
Thu Sep 29 16:24:22 CDT 2011

I am rather new to scipy and numpy. I am using a numpy version 1.3.0 and
scipy version 0.3.0 on Ubuntu 64 bit box with python version 2.6.5

# Section My test case

I can get the following commands based on the documentation(
 to work in the python shell.

import numpy
from numpy import *
from scipy import interpolate

x = linspace(20,81,2339)
y = sin(x)
tck = interpolate.splrep(x, y)

In this case the interpolation has succeeded without error
However to troubleshoot my function if I try on the command line


> my_idim, my_m = x.s
>>> my_idim, my_m = x.shape
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack

#Section : My actual program

Now in my actual program I get an error from the fitpack routine which seems
to suggest it does not like the x and y data I am feeding the splprep
function. The shapes are identical to the test example above. Although the
signal is like a very wonky sigmoidal signal that I want to interpolate.

The error I get is from line 191 in the fitpack.py .

# Printed x shape , y shape , x dtype , y dtype , x type , y type
(2339,) (2339,) float64 float64 20.04 84.86 <type 'numpy.ndarray'> <type
Traceback (most recent call last):
  File "ReadAndSplitInput.py", line 50, in <module>
  File "ReadAndSplitInput.py", line 35, in plot_for_well
    tck =interpolate.splprep(xs,ys)
  File "/usr/lib/python2.6/dist-packages/scipy/interpolate/fitpack.py", line
191, in splprep
ValueError: need more than 1 value to unpack

I get the same ValueError in the example I adapted from the docs ( as I
mentioned in section I)
Any suggestions in troubleshooting whats happening will be greatly

Thanks a lot for your help

Here is my function:
def plot_for_well(well_id):
    xvals = []
    yvals = []
    for vals in mega_data_dict[well_id]:
        xvals.append("%0.2f" % float(vals[0]))
        yvals.append("%0.2f" % (float(vals[1])))
    xs = array(xvals , numpy.dtype('f8'))
    ys = array(yvals, numpy.dtype('f8'))
    print xs.shape, ys.shape,xs.dtype,ys.dtype,
    tck =interpolate.splprep(x=ys)
    xcalc = linspace(min(xvals),max(xvals),len(xvals))
    ycalc = interpolate.splev(xcalc,tck)
    ax = plt.subplot(111)

Python particulars:
hari@hari:~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> numpy.__version__
>>> scipy.__version__
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20110929/e6260a0e/attachment.html 

More information about the SciPy-User mailing list