I played with a package that uses linear scipy.interpolate.interp1d to create a history function for ode solver in scipy described here.
The corresponding bit of code looks something like this:
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])
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
Where g is some function that returns an array of values ββthat are solutions for a set of differential equations, and tc is the current time.
This seems pleasant to me because a new interpolator object does not need to be re-created every time I want to update value ranges (which happens at every explicit time step during the simulation). This interpolator update method works well under scipy v 0.11.0. However, after upgrading to v 0.12.0, I ran into problems. I see that the new interpolator now includes an _y array, which seems to be just another copy of the original. Is it safe and / or reasonable to just update _y as above? Is there an easier and more pythonic way to resolve this issue, which I hope will be more reliable for future updates in scipy? Again, in v 0.11 everything works well, and the expected results are produced, and in v 0.12 I get a IndexError when _y referenced , because it is not updated in my function, but y itself is.
Any help / pointers would be appreciated!
source share