Spline Module#
Classes for interpolating 1D, 2D, and 3D data sets with cubic splines
- class bhpwave.spline.CubicSpline(x, f, bc='E(3)')[source]#
Bases:
objectA class for producing a cubic spline of a function \(f(x)\) given its values \(f_{i} = f(x_i)\) where \(x_i = x_0, x_1, \dots , x_N\) is a grid of \((N+1)\) uniformly-spaced points.
- Parameters:
x (1d-array[double]) – A uniformly-spaced grid of points
f (1d-array[double]) – Function values corresponding to the grid points x
bc (str (optional)) – Boundary value method. Valid options include “natural”, “not-a-knot”, “clamped”, and “E(3)”
- property coefficients#
The 2D array of spline coefficients with dimensions
(nx, 4). Data are ordered so that the element at index(i, mx)returns the same value ascoeffs(i, mx)- Return type:
3d-array[double]
- coeff(i, mx)[source]#
Returns the spline coefficients \(c_{i}^{(m_x)}\) defined by the spline \(f_{i}\)
\[f_{i}(x) = \sum_{m_x=0}^3 c_{i}^{(m_x)}(x-x_i)^{m_x}\]- Parameters:
i (int) – Coefficient for the domain \(x_i \leq x \leq x_{i+1}\)
mx (int) – Coefficient weighting \((x-x_i)^{m_x}\) in the spline series
- Return type:
double
- eval(x)[source]#
Evaluates the spline at the point x
- Parameters:
x (double) – dependent parameter
- Return type:
double
- deriv(x)[source]#
Evaluates the derivative of the spline at the point x
- Parameters:
x (double) – dependent parameter
- Return type:
double
- class bhpwave.spline.BicubicSpline(x, y, f, bc='E(3)')[source]#
Bases:
objectA class for producing a bicubic spline of a function \(f(x, y)\) given its values \(f_{ij} = f(x_i, y_j)\) where \(x_i = x_0, x_1, \dots , x_N\) is a grid of \((N+1)\) uniformly-spaced points and \(y_j = y_0, y_1, \dots , y_M\) is a grid of \((M+1)\) uniformly-spaced points. The input \(f_{ij}\) is therefore structured as a \((N+1) \times (M+1)\) matrix of function values
\[\begin{split}\begin{align*} f(x_i, y_j) &= \begin{pmatrix} f_{00} & f_{01} & \cdots & f_{0M} \\ f_{10} & f_{11} & \cdots & f_{1M} \\ \vdots & \vdots & \ddots & \vdots \\ f_{N0} & f_{N1} & \cdots & f_{NM} \end{pmatrix} \end{align*}\end{split}\]- Parameters:
x (1d-array[double]) – A uniformly-spaced grid of points
y (1d-array[double]) – A uniformly-spaced grid of points
f (2d-array[double]) – Function values corresponding to the grid points x, y
bc (str (optional)) – Boundary value method. Valid options include “natural”, “not-a-knot”, “clamped”, and “E(3)”
- eval(x, y)[source]#
Evaluates the spline at the point (x, y)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
- Return type:
double
- deriv_x(x, y)[source]#
Evaluates the partial derivative of the spline with respect to x at the point (x, y)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
- Return type:
double
- deriv_y(x, y)[source]#
Evaluates the partial derivative of the spline with respect to y at the point (x, y)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
- Return type:
double
- deriv_xx(x, y)[source]#
Evaluates the second partial derivative of the spline with respect to x at the point (x, y)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
- Return type:
double
- deriv_yy(x, y)[source]#
Evaluates the second partial derivative of the spline with respect to y at the point (x, y)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
- Return type:
double
- deriv_xy(x, y)[source]#
Evaluates the mixed partial derivative of the spline with respect to x and y at the point (x, y)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
- Return type:
double
- coeff(i, j, mx, my)[source]#
Returns the spline coefficients \(c_{ij}^{(m_x,m_y)}\) defined by the spline \(f_{ij}\)
\[f_{ij}(x, y) = \sum_{m_x=0}^3 \sum_{m_y=0}^3 c_{ij}^{(m_x,m_y)}(x-x_i)^{m_x}(y-y_j)^{m_y}\]- Parameters:
i (int) – Coefficient for the domain \(x_i \leq x \leq x_{i+1}\)
j (int) – Coefficient for the domain \(y_j \leq y \leq y_{j+1}\)
mx (int) – Coefficient weighting \((x-x_i)^{m_x}\) in the spline series
my (int) – Coefficient weighting \((y-y_j)^{m_y}\) in the spline series
- Return type:
double
- class bhpwave.spline.TricubicSpline(x, y, z, f, bc='E(3)')[source]#
Bases:
objectA class for producing a bicubic spline of a function \(f(x, y, z)\) given its values \(f_{ijk} = f(x_i, y_j, z_k)\) where \(x_i = x_0, x_1, \dots , x_N\) is a grid of \((N+1)\) uniformly-spaced points, \(y_j = y_0, y_1, \dots , y_M\) is a grid of \((M+1)\) uniformly-spaced points, and \(z_k = z_0, z_1, \dots , z_O\) is a grid of \((O+1)\) uniformly-spaced points. The input \(f_{ijk}\) is therefore structured as a \((N+1) \times (M+1) \times (O+1)\) tensor of function values
\[\begin{split}\begin{align*} f(x_i, y_j,z_k) &= \begin{pmatrix} f_{00k} & f_{01k} & \cdots & f_{0Mk} \\ f_{10k} & f_{11k} & \cdots & f_{1Mk} \\ \vdots & \vdots & \ddots & \vdots \\ f_{N0k} & f_{N1k} & \cdots & f_{NMk} \end{pmatrix} \end{align*}\end{split}\]where each entry is a vector of length \(O+1\) in the \(z\)-dimension
- Parameters:
x (1d-array[double]) – A uniformly-spaced grid of points
y (1d-array[double]) – A uniformly-spaced grid of points
z (1d-array[double]) – A uniformly-spaced grid of points
f (3d-array[double]) – Function values corresponding to the grid points x, y, z or pre-computed spline coefficients
bc (str (optional)) – Boundary value method. Valid options include “natural”, “not-a-knot”, “clamped”, and “E(3)”
- eval(x, y, z)[source]#
Evaluates the spline at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_x(x, y, z)[source]#
Evaluates the partial derivative of the spline with respect to x at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_y(x, y, z)[source]#
Evaluates the partial derivative of the spline with respect to y at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_z(x, y, z)[source]#
Evaluates the partial derivative of the spline with respect to z at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_xx(x, y, z)[source]#
Evaluates the second partial derivative of the spline with respect to x at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_yy(x, y, z)[source]#
Evaluates the second partial derivative of the spline with respect to y at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_zz(x, y, z)[source]#
Evaluates the second partial derivative of the spline with respect to z at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_xy(x, y, z)[source]#
Evaluates the mixed partial derivative of the spline with respect to x and y at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_xz(x, y, z)[source]#
Evaluates the mixed partial derivative of the spline with respect to x and z at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- deriv_yz(x, y, z)[source]#
Evaluates the mixed partial derivative of the spline with respect to y and z at the point (x, y, z)
- Parameters:
x (double) – dependent parameter
y (double) – dependent parameter
z (double) – dependent parameter
- Return type:
double
- coeff(i, j, k, mx, my, mz)[source]#
Returns the spline coefficients \(c_{ijk}^{(m_x,m_y,m_z)}\) defined by the spline \(f_{ijk}:math:\)
\[f_{ijk}(x, y, z) = \sum_{m_x=0}^3 \sum_{m_y=0}^3 \sum_{m_z=0}^3 c_{ijk}^{(m_x,m_y,m_z)}(x-x_i)^{m_x}(y-y_j)^{m_y}(z-z_k)^{m_z}\]- Parameters:
i (int) – Coefficient for the domain \(x_i \leq x \leq x_{i+1}\)
j (int) – Coefficient for the domain \(y_j \leq y \leq y_{j+1}\)
k (int) – Coefficient for the domain \(z_k \leq z \leq z_{k+1}\)
mx (int) – Coefficient weighting \((x-x_i)^{m_x}\) in the spline series
my (int) – Coefficient weighting \((y-y_j)^{m_y}\) in the spline series
mz (int) – Coefficient weighting \((z-z_k)^{m_z}\) in the spline series
- Return type:
double