2 Provides some UnivariateSpline child classes for alternative interpolation
6 from numpy
import log
, exp
, e
7 import scipy
.interpolate
as SI
9 class eSpline(SI
.UnivariateSpline
):
11 Spline in Y log scale (with fized e base). Simple prototype class.
14 def __init__(self
, x
, y
, w
=None, bbox
=[None, None], k
=3, s
=None):
16 For a description of the parameters see UnivariateSpline class.
20 SI
.UnivariateSpline
.__init
__(self
, x
=x
, y
=y_
, s
=s
, k
=k
, bbox
=bbox
, w
=w
)
22 def __call__(self
, x
, nu
=None):
23 res
= SI
.UnivariateSpline
.__call
__(self
, x
, nu
)
27 class aSpline(SI
.UnivariateSpline
):
29 Base class for splines calculated in a generic coordinate system.
31 def __init__(self
, x
, y
, fun
, inv
, both
=False,
32 w
=None, bbox
=[None, None], k
=3, s
=None):
34 Besised the starndard UnivariateSpline parameters we have:
35 @fun: the function to be applied to the input data 'y' and 'x'
36 @inv: the inverse function to be applied to the returned data
37 @both: if the transformation should be applied to both axes or only Y
47 SI
.UnivariateSpline
.__init
__(self
, x
=x_
, y
=y_
, s
=s
, k
=k
,
50 def __call__(self
, x
, nu
=None):
52 Same parameters as UnivariateSpline.
58 res
= SI
.UnivariateSpline
.__call
__(self
, x_
, nu
)
59 return self
.__inv
(res
)
62 class eeSpline(aSpline
):
64 Exponential spline: a spline calculated in log scale.
67 def __init__(self
, x
, y
, base
=e
, w
=None, bbox
=[None, None], k
=3, s
=None):
69 Besides usual UnivariateSpline parameters a 'base' for the exponetial
70 transformation can be specified.
74 # Workaround for bad interpolation with s=0
75 if s
== 0: s
= len(x
)*1e-6
77 aSpline
.__init
__(self
, x
=x
, y
=y
, both
=False,
78 fun
= lambda x
: log(x
)/log(self
.base
),
79 inv
= lambda x
: self
.base
**x
,
80 s
=s
, k
=k
, bbox
=bbox
, w
=w
)