[SciPy-User] interpolate.interp1d: can't figure out what I'm doing wrong

Ralf Gommers ralf.gommers@googlemail....
Fri Aug 19 03:47:20 CDT 2011


On Fri, Aug 19, 2011 at 5:32 AM, David Perlman <dperlman@wisc.edu> wrote:

> Well at least I got it to give me a different error message.  I thought it
> might not like the generator instead of list, so I converted to list first.
>  Now I get this error:
>
> old time range: [0.0, 200.00000298023224, 400.00000596046448,
> 600.00000894069672]
> new time range: [0, 100.0, 200.0, 300.0, 400.0, 500.0, 600.0]
> Traceback (most recent call last):
>  File "/home/perlman/bin/pretty_fmri.py", line 840, in <module>
>    main()
>  File "/home/perlman/bin/pretty_fmri.py", line 130, in main
>    dataProcessor.interpolate()
>  File "/home/perlman/bin/pretty_fmri.py", line 249, in interpolate
>     self.interpolateddata=f(list(xnew))
>  File
> "/usr/local/Python/Versions/2.6.5/lib/python2.6/site-packages/scipy/interpolate/interpolate.py",
> line 362, in __call__
>    y_new[out_of_bounds] = self.fill_value
> IndexError: invalid index
>
>
>
> On Aug 18, 2011, at 10:16 PM, David Perlman wrote:
>
> > I am absolutely sure that my x_new range doesn't go outside my original
> x, and yet it is giving me an error saying that it is:
> > old time range: [0.0, 200.00000298023224, 400.00000596046448,
> 600.00000894069672]
> > new time range: [0, 100.0, 200.0, 300.0, 400.0, 500.0, 600.0]
> > Traceback (most recent call last):
> >  File "/home/perlman/bin/pretty_fmri.py", line 840, in <module>
> >    main()
> >  File "/home/perlman/bin/pretty_fmri.py", line 130, in main
> >    dataProcessor.interpolate()
> >  File "/home/perlman/bin/pretty_fmri.py", line 249, in interpolate
> >    self.interpolateddata=f(xnew)
> >  File
> "/usr/local/Python/Versions/2.6.5/lib/python2.6/site-packages/scipy/interpolate/interpolate.py",
> line 333, in __call__
> >    out_of_bounds = self._check_bounds(x_new)
> >  File
> "/usr/local/Python/Versions/2.6.5/lib/python2.6/site-packages/scipy/interpolate/interpolate.py",
> line 391, in _check_bounds
> >    raise ValueError("A value in x_new is above the interpolation "
> > ValueError: A value in x_new is above the interpolation range.
> >
> >
> > Here is the snippet of code where this is going wrong:
> >    oldNum=numpy.shape(self.data)[0]
> >    endTime=(oldNum-1)*oldTR
> >    x=numpy.linspace(0, endTime, oldNum)
> >    if self.opts.verbose: print "old time range:", list(x)
> >    f=scipy.interpolate.interp1d(x, self.data, self.opts.interp, 0)
> >    # make the new time points
> >    xnew=self.crange(0, endTime, newTR)
> >    if self.opts.verbose: print "new time range:", list(xnew)
> >    self.interpolateddata=f(xnew)
> >
>

Can you create a self-contained example that illustrates the problem?

Ralf

>
> > You can see from that, that there is no code between the displayed ranges
> and the calling of the interpolator.  So I am at a loss for how to figure
> out what's going on here!
> >
> > Any help would be greatly appreciated.  I have been looking into this for
> a while, even to the point of looking at the source code for the interp1d
> function.  :-/
> >
> > --
> > -dave----------------------------------------------------------------
> > "Let us work without theorizing... 'tis the only way to make life
> endurable."
> > - Voltaire, Candide, Chapter 30
> >
>
> --
> -dave----------------------------------------------------------------
> "Let us work without theorizing... 'tis the only way to make life
> endurable."
> - Voltaire, Candide, Chapter 30
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20110819/62aa0025/attachment-0001.html 


More information about the SciPy-User mailing list