Function adas.xxsple
def xxsple(xin, yin, xout, opt=0, log=False, drop_zero=False, return_info=False)-
Interpolates and extrapolates with cubic splines.
Parameters
xin:float- independent variable array.
yin:float- dependent variable array.
yxout:float- requested data array.
opt:int- control of interpolation/extrapolation
------------------------------------------------------- | opt | dy(1) ddy(1) | dy(n) ddy(n) |extrap'n| |-------|-----------------|------------------|--------| | < 0 | - 0.0 | - 0.0 | No | | 0 | - 0.0 | - 0.0 | Yes | | 1 | - 0.0 | -1.5 - | Yes | | 2 | 0.0 - | 1.0 - | Yes | | 3 | -0.5 - | -1.5 - | Yes | | 4 | 0.0 - | - 0.0 | Yes | | 5 | -4.5 - | -1.5 - | Yes | | 6 | +0.5 - | - 0.0 | Yes | | 7 | -3.5 - | - 0.0 | Yes | ------------------------------------------------------- log:bool- if log=True spline on log(xin) vs log(yin).
drop_zero:bool- if True do not include points with yin=0.0 in the evaluation.
return_info:bool- If True also return a dictionary of information on the transition. The default is False.
Returns
yout:float- splined point corresponding to xin array.
info:dict- extra information about the configuration
only return if return_info=True
'dy' : float array of derivatives at input knots 'extrap' : array True if point extrapolated 'interp' : array True if point interpolated
Notes
With opt < 0 no extrapolation takes place and returned yout values for xout outside the xin range are set to None.
Pure python translation of xxsple.for.
Version History
-
Martin O'Mullane, 14-07-2018
- First version
-
Martin O'Mullane, 14-08-2019
- Handle case when xout is a scalar.
-
Martin O'Mullane, 13-05-2022
- Add drop_zero option.
-
Martin O'Mullane, 05-10-2022
- Make returning the info dictionary optional.
- For no-extrapolation (opt<0) set the yout values for xout outside the xin range to be None/nan rather than 0.0.
Example
Example of function were transforming to log-space is essential.
>>> import adas as adas >>> xin=[1, 10, 100, 1000] >>> yin=[10.0, 20.0, 30.0, 40.0] >>> xout=[0.5, 10.0, 500.0] >>> yout, info = adas.xxsple(xin, yin, xout, log=True, return_info=True) >>> yout array([ 7.95020064, 20. , 36.80473467]) >>> info['extrap'] array([ True, False, False])Spline in linear space
>>> yout = adas.xxsple(xin, yin, xout) >>> yout array([ 9.42134318, 20. , -22.43944366])But care is required if no extrapolation is requested (opt<0)
>>> yout, info = adas.xxsple(xin, yin, xout, opt=-1) >>> yout array([ 0. , 20. , -22.43944366]) >>> yout, info = adas.xxsple(xin, yin, xout, log=True, opt=-1) >>> yout array([ 1. , 20. , 36.80473467])