[SciPy-User] scipy 0.11.0 to 0.12.0 changes scipy.interpolate.interp1d, breaks constantly updated interpolator

Ralf Gommers ralf.gommers@gmail....
Sat Jul 20 09:59:42 CDT 2013


On Fri, Jul 5, 2013 at 10:46 PM, Benjamin Evans <b.evans@yale.edu> wrote:

> Hello all,
>
> I have been playing around with a package that uses a linear
> scipy.interpolate.interp1d to create a history function for the ode solver
> in scipy, described here<http://zulko.wordpress.com/2013/03/01/delay-differential-equations-easy-with-python/>
> .
>
> The relevant bit of code goes something like
>
> def update(self, ti, Y):
>         """ Add one new (ti, yi) to the interpolator """
>         self.itpr.x = np.hstack([self.itpr.x,  [ti]])
>         yi = np.array([Y]).T
>         self.itpr.y = np.hstack([self.itpr.y,  yi])
>         self.itpr.fill_value = Y
>
> Where "self.itpr" is initialized in __init__:
>
> def __init__(self, g, tc=0):
>     """ g(t) = expression of Y(t) for t<tc """
>
>     self.g = g
>     self.tc = tc
>     # We must fill the interpolator with 2 points minimum
>     self.itpr = scipy.interpolate.interp1d(
>         np.array([tc-1, tc]),  # X
>         np.array([self.g(tc), self.g(tc)]).T,  # Y
>         kind='linear',  bounds_error=False,
>         fill_value = self.g(tc))
>
> Where g is some function that returns an array of values that are
> solutions to a set of differential equations and tc is the current time.
>
> This seems nice to me because a new interpolator object doesn't have to be
> re-created every time I want to update the ranges of values (which happens
> at each explicit time step during a simulation).  This method of updating
> the interpolator works well under scipy v 0.11.0.  However, after updating
> to v 0.12.0 I ran into issues.  I see that the new interpolator now
> includes an array _y<https://github.com/scipy/scipy/blob/master/scipy/interpolate/interpolate.py#L390>.
> Is it safe and/or sane to just update _y as outlined above as well?  Is
> there a simpler, more pythonic way to address this that would hopefully be
> more robust to future updates in scipy?  Again, in v 0.11 everything works
> well and expected results are produced, and in v 0.12 I get an IndexError when
> _y is referenced<https://github.com/scipy/scipy/blob/master/scipy/interpolate/interpolate.py#L409>as it isn't updated in my function while y itself is.
>
> Any help/pointers would be appreciated!
>

There's a ticket with discussion here:
https://github.com/scipy/scipy/issues/2621

Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130720/e259b856/attachment.html 


More information about the SciPy-User mailing list