Linear extrapolation in univariate spline
![](https://secure.gravatar.com/avatar/2094e3540201216badc3c0e707183d7a.jpg?s=120&d=mm&r=g)
Dear SciPy devs, The UnivariateSpline class [1] allows to pass a parameter `ext` to control the behavior of the interpolant outside of the input data range, i.e, for the cases where an extrapolation is required. The four available modes are to perform actual k-degree extrapolation, to return 0, to do constant extrapolation or to fail. These modes are insufficient for my needs. What I would actually need is a linear extrapolation. By definition of the "natural" cubic spline [2], the second derivative will be zero at both ends of the domain. This has the physical meaning of modeling exactly the shape of a ruler bent in such a way to touch a set of points. Before the first point and after the last one, the rules will be straight. This is the kind of extrapolation I would need. I would like to ask if that feature has not been implemented for a good reason, if there are any plans on implementing it and if I can do something. I started to look at the code to see if I could easily implement this mode. In any case I will need some guidance with it. Another thing I should ask is whether there is already a way to specify custom extrapolation modes (e.g. by passing a python function). I think I found the place in the SciPy code where the extrapolation modes are handled, in the `splev.f` file [3]. It does not look too difficult to add a `e .eq. 4` case, which handles linear extrapolation. But I don't know how to access the slopes at both ends of the domain. Thanks and best Andrea Arteaga [1] https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.Univa... [2] https://en.wikipedia.org/wiki/Spline_interpolation#Example [3] https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/splev.f...
participants (1)
-
Andrea Arteaga