Least squares polynomial fit. This replicates the behaviour of `numpy.polyfit` but differs by skipping invalid values when `skipna = True`. Parameters ---------- obj : Dataset or DataArray Object to perform the polyfit on dim : hashable Coordinate along
(
obj,
dim: Hashable,
deg: int,
skipna: bool | None = None,
rcond: np.floating[Any] | float | None = None,
w: Hashable | Any = None,
full: bool = False,
cov: bool | Literal["unscaled"] = False,
)
| 99 | |
| 100 | |
| 101 | def polyfit( |
| 102 | obj, |
| 103 | dim: Hashable, |
| 104 | deg: int, |
| 105 | skipna: bool | None = None, |
| 106 | rcond: np.floating[Any] | float | None = None, |
| 107 | w: Hashable | Any = None, |
| 108 | full: bool = False, |
| 109 | cov: bool | Literal["unscaled"] = False, |
| 110 | ): |
| 111 | """ |
| 112 | Least squares polynomial fit. |
| 113 | |
| 114 | This replicates the behaviour of `numpy.polyfit` but differs by skipping |
| 115 | invalid values when `skipna = True`. |
| 116 | |
| 117 | Parameters |
| 118 | ---------- |
| 119 | obj : Dataset or DataArray |
| 120 | Object to perform the polyfit on |
| 121 | dim : hashable |
| 122 | Coordinate along which to fit the polynomials. |
| 123 | deg : int |
| 124 | Degree of the fitting polynomial. |
| 125 | skipna : bool or None, optional |
| 126 | If True, removes all invalid values before fitting each 1D slices of the array. |
| 127 | Default is True if data is stored in a dask.array or if there is any |
| 128 | invalid values, False otherwise. |
| 129 | rcond : float or None, optional |
| 130 | Relative condition number to the fit. |
| 131 | w : hashable or Any, optional |
| 132 | Weights to apply to the y-coordinate of the sample points. |
| 133 | Can be an array-like object or the name of a coordinate in the dataset. |
| 134 | full : bool, default: False |
| 135 | Whether to return the residuals, matrix rank and singular values in addition |
| 136 | to the coefficients. |
| 137 | cov : bool or "unscaled", default: False |
| 138 | Whether to return to the covariance matrix in addition to the coefficients. |
| 139 | The matrix is not scaled if `cov='unscaled'`. |
| 140 | |
| 141 | Returns |
| 142 | ------- |
| 143 | Dataset |
| 144 | A single dataset which contains (for each "var" in the input dataset): |
| 145 | |
| 146 | [var]_polyfit_coefficients |
| 147 | The coefficients of the best fit for each variable in this dataset. |
| 148 | [var]_polyfit_residuals |
| 149 | The residuals of the least-square computation for each variable (only included if `full=True`) |
| 150 | When the matrix rank is deficient, np.nan is returned. |
| 151 | [dim]_matrix_rank |
| 152 | The effective rank of the scaled Vandermonde coefficient matrix (only included if `full=True`) |
| 153 | The rank is computed ignoring the NaN values that might be skipped. |
| 154 | [dim]_singular_values |
| 155 | The singular values of the scaled Vandermonde coefficient matrix (only included if `full=True`) |
| 156 | [var]_polyfit_covariance |
| 157 | The covariance matrix of the polynomial coefficient estimates (only included if `full=False` and `cov=True`) |
| 158 |
nothing calls this directly
no test coverage detected
searching dependent graphs…