parallel_fit_dask#

astropy.modeling.fitting.parallel_fit_dask(*, model, fitter, data, data_unit=None, weights=None, mask=None, fitting_axes=None, world=None, chunk_n_max=None, diagnostics=None, diagnostics_path=None, diagnostics_callable=None, scheduler=None, fitter_kwargs=None, preserve_native_chunks=False, equivalencies=None)[source]#

Fit a model in parallel to an N-dimensional dataset.

Axes in the N-dimensional dataset are considered to be either ‘fitting axes’ or ‘iterating axes’. As a specific example, if fitting a spectral cube with two celestial and one spectral axis, then if fitting a 1D model to each spectrum in the cube, the spectral axis would be a fitting axis and the celestial axes would be iterating axes.

Parameters:
modelastropy.modeling.Model

The model to fit, specifying the initial parameter values. The shape of the parameters should be broadcastable to the shape of the iterating axes.

fitterastropy.modeling.fitting.Fitter

The fitter to use in the fitting process.

datanumpy.ndarray or dask.array.core.Array

The N-dimensional data to fit.

data_unitsastropy.units.Unit

Units for the data array, for when the data array is not a Quantity instance.

weightsnumpy.ndarray, dask.array.core.Array or astropy.nddata.NDUncertainty

The weights to use in the fitting. See the documentation for specific fitters for more information about the meaning of weights. If passed as a NDUncertainty object it will be converted to a StdDevUncertainty and then passed to the fitter as 1 over that.

masknumpy.ndarray

A boolean mask to be applied to the data.

fitting_axesint or tuple

The axes to keep for the fitting (other axes will be sliced/iterated over)

worldNone or tuple or APE-14-WCS

This can be specified either as a tuple of world coordinates for each fitting axis, or as WCS for the whole cube. If specified as a tuple, the values in the tuple can be either 1D arrays, or can be given as N-dimensional arrays with shape broadcastable to the data shape. If specified as a WCS, the WCS can have any dimensionality so long as it matches the data. If not specified, the fitting is carried out in pixel coordinates.

chunk_n_maxint

Maximum number of fits to include in a chunk. If this is made too large, then the workload will not be split properly over processes, and if it is too small it may be inefficient. If not specified, this will default to 500.

diagnostics{ None | ‘error’ | ‘error+warn’ | ‘all’ }, optional

Whether to output diagnostic information for fits. This can be either None (nothing), 'error' (output information for fits that raised exceptions), or 'all' (output information for all fits).

diagnostics_pathstr, optional

If diagnostics is not None, this should be the path to a folder in which a folder will be made for each fit that is output.

diagnostics_callablecallable()

By default, any warnings or errors are output to diagnostics_path. However, you can also specify a callable that can e.g. make a plot or write out information in a custom format. The callable should take the following arguments: the path to the subfolder of diagnostics_path for the specific index being fit, a list of the coordinates passed to the fitter, the data array, the weights array (or None if no weights are being used), the model that was fit (or None if the fit errored), and a dictionary of other keyword arguments passed to the fitter.

schedulerstr, optional

If not specified, a local multi-processing scheduler will be used. If 'default', whatever is the current default scheduler will be used. You can also set this to anything that would be passed to array.compute(scheduler=...)

fitter_kwargsNone or dict

Keyword arguments to pass to the fitting when it is called.

preserve_native_chunksbool, optional

If True, the native data chunks will be used, although an error will be raised if this chunk size does not include the whole fitting axes.