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

Benjamin Evans b.evans@yale....
Fri Jul 5 15:46:33 CDT 2013

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

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

Ben Evans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130705/8b9a92b6/attachment.html 

More information about the SciPy-User mailing list