Spline module for smooth interpolation in one and two dimensions
Class: FloatSpline - 1D cubic spline
listOfXYPairs is a sequence (of length N) of sequences containing
two floating point elements listing (x, y) data points.
Alternatively, the x and y data points can be input separately:
where vectorOfX and vectorOfY are cdsVector.CDSVector_double
instances with the x and y values, respectively; x and y values
are matched by offset to generate the corresponding (x, y) pairs.
Regardless of the constructor used, the x values do not have to lie
on a regular grid.
By default the data is assumed non-periodic. Periodic data can be
specified as follows:
In this case, an additional point is added to listOfXYPairs at
(x, y), where
x = 2 * listOfXYPairs[N-1] - listOfXYPairs[N-2]
y = listOfXYPairs
Also, the slope at the first and final points are set to match.
The same result is obtained by using the alternative constructor:
FloatSpline(vectorOfX, vectorOfY, True)
__call__(x) - return the interpolated value at (x).
deriv(x) - return derivative wrt x at x.
secondDeriv(x) - return the second derivative wrt x at x.
size() - return the number of input x,y data pairs.
Interpolated y values are obtained using the __call__() method.
spline = FloatSpline( [(0,1), (1,2), (2,3)] )
will return the value 1.5.
Class: FloatSpline2D - 2D bicubic interpolation
from spline import FloatSpline2D, PERIODIC_NOT
FloatSpline2D(xList, yList, zList, periodic=PERIODIC_NOT)
xList and yList contain x and y values of grid points. These values
should be monotonically increasing, but do not need to be equally
spaced. zList is a row-major list of data on this grid. For example,
if xList=[x0, x1, x2] and yList=[y0, y1, y2], then
zList = [z00, z01, z02,
z10, z11, z12,
z20, z21, z22]
where zij is associated to coordinate values (xi, yj).
The optional periodic argument is a bit field specifying whether the x
or y dimensions contain periodic data. Valid values are PERIODIC_NOT,
PERIODIC_X and PERIODIC_Y. If a dimension is marked as periodic, the
corresponding dimension in zList should be one less. Thus, in the above
example, if PERIODIC_X is set, it is assumed that z0j=z2j and values
z20, z21, z22 should be omitted from zList. Similarly, if PERIODIC_Y is
set, values z02, z12, z22 should be omitted. First derivatives are also
matched in case of periodicity.
Note that, unlike the 1D case, the spline coefficients are not taken
from a global fit. This is possible, but not yet implemented.
__call__(x, y) - return the interpolated value at (x, y).
derivs(x, y) - return derivatives wrt x and y at (x, y) in a tuple (dx, dy).
Interpolated z values are obtained using the __call__() method.
x=[1, 2, 3]
spline2d = spline.FloatSpline2D(x, y, z)
will return the value 5.032. Specification of periodicity in both
x and y dimensions:
another_spline2d = spline.FloatSpline2D(x, y, z, spline.PERIODIC_X|spline.PERIODIC_Y)
(x, y, and z are different from the previous non-periodic example).
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 4.0.2
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
|PERIODIC_NOT = 0|
PERIODIC_X = 1
PERIODIC_Y = 2