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

David Perlman dperlman@wisc....
Thu Aug 18 22:32:08 CDT 2011


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)
> 
> 
> 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



More information about the SciPy-User mailing list