finesse.utilities.polyfit module
Functions for fitting polynomials.
- finesse.utilities.polyfit.polyfit2d(x, y, z, kx, ky, *, order=None, weights=None)[source]
Two dimensional polynomial fitting by least squares. Fits the functional form f(x,y) = z.
Parameters
- x, y: array-like, 1d
x and y coordinates.
- z: np.ndarray, 2d
Surface to fit.
- kx, ky: int
Polynomial order in x and y, respectively.
- order: int or None
If None, all coefficients up to maxiumum kx, ky, ie. up to and including x^kx*y^ky, are considered. If int, coefficients up to a maximum of kx+ky <= order are considered.
- weight: array_like, 2d
Weighting to use for fit. Same dimenstions as z
Returns
Return parameters from np.linalg.lstsq.
- soln: np.ndarray
Array of polynomial coefficients.
- residuals: np.ndarray
residuals
- rank: int
rank
- s: np.ndarray
s
Notes
Resultant fit can be evaluated with
polyfit2d_eval().Based on code from: https://stackoverflow.com/questions/33964913/equivalent-of-polyfit-for-a-2d-polynomial-in-python
- finesse.utilities.polyfit.polyfit2d_eval(x, y, soln, kx, ky)[source]
Evaluate polynomial fit from
polyfit2d()Parameters
- x, y: array-like, 1d
x and y coordinates.
- soln: np.ndarray
Array of polynomial coefficients.
- kx, ky: int
Polynomial order in x and y, respectively.
- finesse.utilities.polyfit.polyfit2d_index(kx, a, b)[source]
Returns index of polynomial from the result of
polyfit2d()for \(x^{a} y^{b}\).Parameters
- kxint
X polynomial order computed
- a, bint
x and y polynomial order
- finesse.utilities.polyfit.polyfit2d_indices(kx, ky)[source]
Get indicies of polynomials returned by
polyfit2d().Parameters
- kx, ky: int
Polynomial order in x and y, respectively.
Returns
- indicesarray_like
Array of x^a y^b powers