PlasmaCalcs.tools.xarray_tools.xarray_sci.xarray_curve_fit
- PlasmaCalcs.tools.xarray_tools.xarray_sci.xarray_curve_fit(array, f, dim, *, stddev=True, promote_dims_if_needed=True, pnames=None, pbounds=None, bounds=UNSET, **kw_curve_fit)
- scipy.optimize.curve_fit(f, xdata=array[dim], ydata=array).Except, iterate over all other dims in array.E.g. arr.curve_fit(‘t’, f) for arr with ‘t’ and ‘fluid’ dims–> result reduces ‘t’ dim but retains ‘fluid’ dim.
- f: callable like f(x, param1, param2, …)
- function to fit.
- stddev: bool
- whether to include data_var ‘stddev’ telling standard deviation of the fit.
- promote_dims_if_needed: bool
- whether to promote non-dimension coords to dimensions.if False, raise DimensionKeyError if any relevant coord is not already a dimension.
- pnames: None or list of str
- names of params. If provided, ‘param’ coord will be assigned these names.
- pbounds: list of [None, callable, or 2-tuple of value, None, or callable]
- bounds for each parameter. Provide
pboundsorbounds, but not both.Each bound can be:callable –> call as bound(array, dim) (after doing array.pc.ensure_dims(dim)).None –> use (-np.inf, np.inf).2-tuple –> (lower, upper).callable –> use lower(array, dim) / upper(array, dim)None –> use -np.inf / np.inf. - bounds: UNSET or (list of lower bounds, list of upper bounds)
- bounds, formatted as expected by scipy curve_fit.Provide
pboundsorbounds, but not both.
additional kwargs go to scipy.optimize.curve_fit.returns xarray.Dataset with data_vars: