[SciPy-Dev] Linear extrapolation in univariate spline

Andrea Arteaga andyspiros at gmail.com
Mon Oct 23 07:40:59 EDT 2017


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.UnivariateSpline.html#scipy.interpolate.UnivariateSpline
[2] https://en.wikipedia.org/wiki/Spline_interpolation#Example
[3]
https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/splev.f#L97-L113
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20171023/127f03f3/attachment.html>


More information about the SciPy-Dev mailing list