bundles / scipy latest / scipy / interpolate / _fitpack_py / splprep
function
scipy.interpolate._fitpack_py:splprep
Signature
def splprep ( x , w = None , u = None , ub = None , ue = None , k = 3 , task = 0 , s = None , t = None , full_output = 0 , nest = None , per = 0 , quiet = 1 ) Summary
Find the B-spline representation of an N-D curve.
Extended Summary
Given a list of N rank-1 arrays, x, which represent a curve in N-dimensional space parametrized by u, find a smooth approximating spline curve g(u). Uses the FORTRAN routine parcur from FITPACK.
Parameters
x: array_likeA list of sample vector arrays representing the curve.
w: array_like, optionalStrictly positive rank-1 array of weights the same length as
x[0]. The weights are used in computing the weighted least-squares spline fit. If the errors in thexvalues have standard-deviation given by the vector d, thenwshould be 1/d. Default isones(len(x[0])).u: array_like, optionalAn array of parameter values. If not given, these values are calculated automatically as
M = len(x[0]), wherev[0] = 0
v[i] = v[i-1] + distance(
x[i],x[i-1])u[i] = v[i] / v[M-1]
ub, ue: int, optionalThe end-points of the parameters interval. Defaults to u[0] and u[-1].
k: int, optionalDegree of the spline. Cubic splines are recommended. Even values of
kshould be avoided especially with a small s-value.1 <= k <= 5, default is 3.task: int, optionalIf task==0 (default), find t and c for a given smoothing factor, s. If task==1, find t and c for another value of the smoothing factor, s. There must have been a previous call with task=0 or task=1 for the same set of data. If task=-1 find the weighted least square spline for a given set of knots, t.
s: float, optionalA smoothing condition. The amount of smoothness is determined by satisfying the conditions:
sum((w * (y - g))**2,axis=0) <= s, where g(x) is the smoothed interpolation of (x,y). The user can usesto control the trade-off between closeness and smoothness of fit. Largersmeans more smoothing while smaller values ofsindicate less smoothing. Recommended values ofsdepend on the weights, w. If the weights represent the inverse of the standard-deviation of y, then a goodsvalue should be found in the range(m-sqrt(2*m),m+sqrt(2*m)), where m is the number of data points in x, y, and w.t: array, optionalThe knots needed for
task=-1. There must be at least2*k+2knots.full_output: int, optionalIf non-zero, then return optional outputs.
nest: int, optionalAn over-estimate of the total number of knots of the spline to help in determining the storage space. By default nest=m/2. Always large enough is nest=m+k+1.
per: int, optionalIf non-zero, data points are considered periodic with period
x[m-1] - x[0]and a smooth periodic spline approximation is returned. Values ofy[m-1]andw[m-1]are not used.quiet: int, optionalNon-zero to suppress messages.
Returns
tck: tupleA tuple,
(t,c,k)containing the vector of knots, the B-spline coefficients, and the degree of the spline.u: arrayAn array of the values of the parameter.
fp: floatThe weighted sum of squared residuals of the spline approximation.
ier: intAn integer flag about splrep success. Success is indicated if ier<=0. If ier in [1,2,3] an error occurred but was not raised. Otherwise an error is raised.
msg: strA message corresponding to the integer flag, ier.
Notes
See splev for evaluation of the spline and its derivatives. The number of dimensions N must be smaller than 11.
The number of coefficients in the c array is k+1 less than the number of knots, len(t). This is in contrast with splrep, which zero-pads the array of coefficients to have the same length as the array of knots. These additional coefficients are ignored by evaluation routines, splev and BSpline.
Array API Standard Support
splprep is not in-scope for support of Python Array API Standard compatible backends other than NumPy.
See dev-arrayapi for more information.
Examples
Generate a discretization of a limacon curve in the polar coordinates:import numpy as np phi = np.linspace(0, 2.*np.pi, 40) r = 0.5 + np.cos(phi) # polar coords x, y = r * np.cos(phi), r * np.sin(phi) # convert to cartesian✓
from scipy.interpolate import splprep, splev tck, u = splprep([x, y], s=0) new_points = splev(u, tck)✓
import matplotlib.pyplot as plt fig, ax = plt.subplots()✓
ax.plot(x, y, 'ro') ax.plot(new_points[0], new_points[1], 'r-')✗
plt.show()
✓
See also
- BSpline
- BivariateSpline
- UnivariateSpline
- bisplev
- bisplrep
- make_interp_spline
- spalde
- splev
- splint
- splrep
- sproot
Aliases
-
scipy.interpolate.splprep