scijit.interpolate.SmoothSphereBivariateSpline

scijit.interpolate.SmoothSphereBivariateSpline(theta, phi, r, w=array([], dtype=float64), s=0.0, eps=1e-16)

Build a smoothing spline on a sphere.

Parameters:
theta1-D float64 ndarray, length m

Colatitudes of the data points, each in [0, pi].

phi1-D float64 ndarray, length m

Longitudes, each in [0, 2*pi].

r1-D float64 ndarray, length m

Values at those points.

w1-D array_like of float, optional

Weights, length m, each >= 0. None and a ZERO-LENGTH array both mean unit weights.

sfloat, optional

Smoothing factor. Default 0.0.

epsfloat, optional

Rank-determination threshold, strictly between 0 and 1. Default 1e-16. It CHANGES THE COEFFICIENTS on rank-deficient data and is not cosmetic; see Notes.

Attributes:
tx, ty1-D float64 ndarray

Knot vectors in colatitude and longitude.

c1-D float64 ndarray

Coefficients in FITPACK’s flat bivariate layout.

kx, kyint

Both 3. The routine is BICUBIC ONLY.

fpfloat

Weighted sum of squared residuals, also returned by get_residual().

ierint

FITPACK status: 0 smoothing achieved, -1 interpolating, -2 least-squares polynomial. Any other value has already raised, so this is 0, -1 or -2 on every instance that exists.

Methods

eval_grid(t, p, dtheta, dphi)

Grid evaluation, the equivalent of spl(theta, phi).

ev(ti, pi_, dtheta, dphi), ev_one(t, p, dtheta, dphi),

partial_derivative(t, p, dtheta, dphi), get_knots(), get_coeffs(),

get_residual()

Returns:
spl_SmoothSphereBivariateSpline

A jitclass instance carrying the attributes and methods below.

Raises:
ValueError

theta outside [0, pi], phi outside [0, 2*pi], a negative weight, s < 0, eps outside (0, 1), mismatched lengths, and every FITPACK status outside {0, -1, -2}.

See also

scipy.interpolate.SmoothSphereBivariateSpline

The scipy class this mirrors.

Notes

  • spl(t, p) runs eval_grid, scipy’s grid=True default, for every pair of scalars and arrays, so two scalars give a (1, 1) grid. ev(ti, pi_) is scipy’s grid=False and ev_one(t, p) the single-point scalar spelling, both reached by name.

  • .partial_derivative(dtheta, dphi) returns a new object in scipy; here it evaluates on a grid directly.

  • ev_one returns a SCALAR where scipy’s spl.ev(t, p) on scalars returns a length-1 array.

  • No .integral: FITPACK offers no dblint equivalent over a spherical patch, and scipy has none either.

Defaults work in both worlds. SmoothSphereBivariateSpline is a plain @njit factory, not the jitclass itself, so SmoothSphereBivariateSpline(theta, phi, r) compiles and runs inside @njit as well as from Python. The class it returns, _SmoothSphereBivariateSpline, takes every argument explicitly, because a jitclass constructor’s defaults are Python-only.

Accuracy against scipy.interpolate.SmoothSphereBivariateSpline on scipy 1.18.0, 150 scattered points, max absolute difference: knots, coefficients, fp, grid values and .ev all exactly 0.0 at s = 0.5, 1.0 and 5.0, and for every dtheta/dphi pair. Reproduced on a second 150-point fixture. This is the one bivariate class whose smoothing fits agreed on every fixture tried; the other three can place knots differently – see their docstrings.

prange-safe: yes.

Examples

>>> import numpy as np
>>> from numba import njit
>>> from scijit.interpolate import SmoothSphereBivariateSpline
>>> rng = np.random.default_rng(1)
>>> theta = rng.uniform(0.2, np.pi - 0.2, 150)
>>> phi = rng.uniform(0, 2 * np.pi, 150)
>>> r = np.sin(theta) * np.cos(phi) + 2.0
>>> spl = SmoothSphereBivariateSpline(theta, phi, r, s=0.5)     # fit once
>>> spl.ier
0
>>> float(np.round(spl(1.5, 1.0)[0, 0], 6))     # spl(theta, phi) is the grid form; [0, 0] takes the point
2.462142

Inside compiled code, the largest value over a coarse query grid:

>>> @njit
... def gridmax(spl):
...     return np.max(spl(np.linspace(0.5, 2.5, 5), np.linspace(0.5, 5.5, 5)))
>>> float(np.round(gridmax(spl), 6))
2.776181