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

hari jayaram harijay at gmail.com
Thu Sep 29 17:24:22 EDT 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(
http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.splrep.html)
 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

>x.shape
(2339,)


> 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
'numpy.ndarray'>
Traceback (most recent call last):
  File "ReadAndSplitInput.py", line 50, in <module>
    plot_for_well(well_id)
  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
    idim,m=x.shape
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
appreciated.

Thanks a lot for your help
Hari

#################
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,
min(xvals),max(xvals),type(xs),type(ys)
    tck =interpolate.splprep(x=ys)
    xcalc = linspace(min(xvals),max(xvals),len(xvals))
    ycalc = interpolate.splev(xcalc,tck)
    ax = plt.subplot(111)
    ax.set_yscale('log')
    ax.plot(xvals,yvals,"o",xcalc,ycalc)
    plt.show()

Python particulars:
hari at 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__
'1.3.0'
>>> scipy.__version__
'0.7.0'
-------------- 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