MCPcopy Index your code
hub / github.com/pydata/xarray / curvefit

Method curvefit

xarray/core/dataarray.py:6524–6694  ·  view source on GitHub ↗

Curve fitting optimization for arbitrary functions. Wraps :py:func:`scipy.optimize.curve_fit` with :py:func:`~xarray.apply_ufunc`. Parameters ---------- coords : Hashable, DataArray, or sequence of DataArray or Hashable Independent coordinate(s)

(
        self,
        coords: str | DataArray | Iterable[str | DataArray],
        func: Callable[..., Any],
        reduce_dims: Dims = None,
        skipna: bool = True,
        p0: Mapping[str, float | DataArray] | None = None,
        bounds: Mapping[str, tuple[float | DataArray, float | DataArray]] | None = None,
        param_names: Sequence[str] | None = None,
        errors: ErrorOptions = "raise",
        kwargs: dict[str, Any] | None = None,
    )

Source from the content-addressed store, hash-verified

6522 return ds[self.name]
6523
6524 def curvefit(
6525 self,
6526 coords: str | DataArray | Iterable[str | DataArray],
6527 func: Callable[..., Any],
6528 reduce_dims: Dims = None,
6529 skipna: bool = True,
6530 p0: Mapping[str, float | DataArray] | None = None,
6531 bounds: Mapping[str, tuple[float | DataArray, float | DataArray]] | None = None,
6532 param_names: Sequence[str] | None = None,
6533 errors: ErrorOptions = "raise",
6534 kwargs: dict[str, Any] | None = None,
6535 ) -> Dataset:
6536 """
6537 Curve fitting optimization for arbitrary functions.
6538
6539 Wraps :py:func:`scipy.optimize.curve_fit` with :py:func:`~xarray.apply_ufunc`.
6540
6541 Parameters
6542 ----------
6543 coords : Hashable, DataArray, or sequence of DataArray or Hashable
6544 Independent coordinate(s) over which to perform the curve fitting. Must share
6545 at least one dimension with the calling object. When fitting multi-dimensional
6546 functions, supply `coords` as a sequence in the same order as arguments in
6547 `func`. To fit along existing dimensions of the calling object, `coords` can
6548 also be specified as a str or sequence of strs.
6549 func : callable
6550 User specified function in the form `f(x, *params)` which returns a numpy
6551 array of length `len(x)`. `params` are the fittable parameters which are optimized
6552 by scipy curve_fit. `x` can also be specified as a sequence containing multiple
6553 coordinates, e.g. `f((x0, x1), *params)`.
6554 reduce_dims : str, Iterable of Hashable or None, optional
6555 Additional dimension(s) over which to aggregate while fitting. For example,
6556 calling `ds.curvefit(coords='time', reduce_dims=['lat', 'lon'], ...)` will
6557 aggregate all lat and lon points and fit the specified function along the
6558 time dimension.
6559 skipna : bool, default: True
6560 Whether to skip missing values when fitting. Default is True.
6561 p0 : dict-like or None, optional
6562 Optional dictionary of parameter names to initial guesses passed to the
6563 `curve_fit` `p0` arg. If the values are DataArrays, they will be appropriately
6564 broadcast to the coordinates of the array. If none or only some parameters are
6565 passed, the rest will be assigned initial values following the default scipy
6566 behavior.
6567 bounds : dict-like, optional
6568 Optional dictionary of parameter names to tuples of bounding values passed to the
6569 `curve_fit` `bounds` arg. If any of the bounds are DataArrays, they will be
6570 appropriately broadcast to the coordinates of the array. If none or only some
6571 parameters are passed, the rest will be unbounded following the default scipy
6572 behavior.
6573 param_names : sequence of Hashable or None, optional
6574 Sequence of names for the fittable parameters of `func`. If not supplied,
6575 this will be automatically determined by arguments of `func`. `param_names`
6576 should be manually supplied when fitting a function that takes a variable
6577 number of parameters.
6578 errors : {"raise", "ignore"}, default: "raise"
6579 If 'raise', any errors from the `scipy.optimize_curve_fit` optimization will
6580 raise an exception. If 'ignore', the coefficients and covariances for the
6581 coordinates where the fitting failed will be NaN.

Calls 1

_to_temp_datasetMethod · 0.95