mdreg.fit_pixels#
- mdreg.fit_pixels(ydata, model=None, p0=None, xdata=None, func_init=<function _func_init>, parallel=True, progress_bar=True, path=None, bounds=(-inf, inf), memdim=2, **kwargs)[source]#
Fit a model pixel-wise
- Parameters:
ydata (numpy.ndarray | zarr.Array) – 2D or 3D array of signal intensities
model (function) – Model function to fit to the data (required). Model functions need to have one argument xdata followed by the free parameters of the model. The return value is the signal at each value of xdata.
p0 (array) – Initial guess for the model parameters (required)
xdata (array-like) – Independent variables for the model. If this is not provided, an index array is used.
func_init (function) – Function to initialize the model parameters. It must take xdata and ydata as arguments, followed by p0 (see below). It returns estimates for the free model parameters as a tuple.
parallel (bool) – Option to perform fitting in parallel. Default is True.
progress_bar (bool) – Option to display a progress bar. This option is ignored when parallel = True. Default is True.
path (str, optional) – Path on disk where to save the results. If no path is provided, the results are not saved to disk. Defaults to None.
memdim (int) – Number of array dimensions to be held in memory at any one time. Possible values for memdim range from 0 (pixel-by-pixel processing) to ydata.ndim-1 (process the whole array at once). With memdim=1, data are loaded and processed row-by-row, with memdim=2 the are processed slice-by-slice, and so on. Default is 2.
bounds (tuple) – Bounds for the model parameters, in the format required by scipy.curve_fit. Note the initial value p0 needs to be contained in the bounds.
**kwargs (Any additional arguments accepted by scipy.curve_fit().)
- Returns:
fit (numpy.ndarray | zarr.Array) – The fitted signal model with the same dimensions as arr.
pars (numpy.ndarray | zarr.Array) – The parameters of the fitted signal model with dimensions (x,y,n) or (x,y,z,n), where n is the number of free parameters of the signal model.