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: strcoordinate to polyfit along.degree: intdegree of polynomial to fit.window_len: int or Nonelength 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 coordscoords to assign along the dim_coarse dimension.True –> use np.arange.False –> don’t assign coords.boundary, side: UNSET or valueif provided (not UNSET), pass this value to coarsen().stride, fill_value, keep_attrs: UNSET or valueif 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———-dim : HashableCoordinate along which to fit the polynomials.deg : intDegree of the fitting polynomial.skipna : bool or None, optionalIf 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.rcond : float or None, optionalRelative condition number to the fit.w : Hashable, array-like or None, optionalWeights 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.full : bool, default: FalseWhether to return the residuals, matrix rank and singular values in additionto the coefficients.cov : bool or “unscaled”, default: FalseWhether to return to the covariance matrix in addition to the coefficients.The matrix is not scaled ifcov='unscaled'.Returns——-polyfit_results : DatasetA single dataset which contains:polyfit_coefficientsThe coefficients of the best fit.polyfit_residualsThe residuals of the least-square computation (only included iffull=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