xarray_coarsened_polyfit
- PlasmaCalcs.tools.xarray_tools.xarray_sci.xarray_coarsened_polyfit(array, coord, degree, window_len, *, dim_coarse='window', keep_coord='middle', assign_coarse_coords=True, boundary=UNSET, side=UNSET, stride=UNSET, fill_value=UNSET, keep_attrs=UNSET, **kw_polyfit)
returns result of coarsening array, then polyfitting along the fine dimension, in each window.
E.g., make windows of length 10 along ‘t’, then polyfit each window along ‘t’,then concat the results from each window, along dim_coarse (default: ‘window’).- coord: str
- coordinate to polyfit along.
- degree: int
- degree of polynomial to fit.
- window_len: int or None
- length of window to coarsen over.None –> polyfit without coarsening; equivalent to window_len = len(array.coords[coord])
- dim_coarse: str, default ‘window’
- name of coarse dimension; the i’th value here corresponds to the i’th window.
- keep_coord: False or str in (‘left’, ‘right’, ‘middle’)
- along the dim_coarse dimension, also provide some of the original coord values.‘left’ –> provide the left-most value in each window.‘middle’ –> provide the middle value in each window.‘right’ –> provide the right-most value in each window.False –> don’t provide any of the original coord values.if not False, result will swap dims such that coord is a dimension instead of dim_coarse.
- assign_coarse_coords: bool or coords
- coords to assign along the dim_coarse dimension.True –> use np.arange.False –> don’t assign coords.
- boundary, side: UNSET or value
- if provided (not UNSET), pass this value to coarsen().
- stride, fill_value, keep_attrs: UNSET or value
- if provided (not UNSET), pass this value to construct().
additional **kw are passed to polyfit.Docs for xr.DataArray.polyfit copied below:——————————————-Least squares polynomial fit.This replicates the behaviour ofnumpy.polyfitbut differs by skippinginvalid values whenskipna = True.Parameters———-- dimHashable
- Coordinate along which to fit the polynomials.
- degint
- Degree of the fitting polynomial.
- skipnabool or None, optional
- If True, removes all invalid values before fitting each 1D slices of the array.Default is True if data is stored in a dask.array or if there is anyinvalid values, False otherwise.
- rcondfloat or None, optional
- Relative condition number to the fit.
- wHashable, array-like or None, optional
- Weights to apply to the y-coordinate of the sample points.Can be an array-like object or the name of a coordinate in the dataset.
- fullbool, default: False
- Whether to return the residuals, matrix rank and singular values in additionto the coefficients.
- covbool or “unscaled”, default: False
- Whether to return to the covariance matrix in addition to the coefficients.The matrix is not scaled if
cov='unscaled'.
Returns——-- polyfit_resultsDataset
- A single dataset which contains:polyfit_coefficientsThe coefficients of the best fit.polyfit_residualsThe residuals of the least-square computation (only included if
full=True).When the matrix rank is deficient, np.nan is returned.[dim]_matrix_rankThe effective rank of the scaled Vandermonde coefficient matrix (only included iffull=True)[dim]_singular_valueThe singular values of the scaled Vandermonde coefficient matrix (only included iffull=True)polyfit_covarianceThe covariance matrix of the polynomial coefficient estimates (only included iffull=Falseandcov=True)
See Also——–numpy.polyfitnumpy.polyvalxarray.polyvalDataArray.curvefit