Skip to main content
`Ctrl`+`K`

# 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, fit_info=False)

  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:
    model `astropy.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.

    fitter `astropy.modeling.fitting.Fitter`

      The fitter to use in the fitting process.

    data `numpy.ndarray` or `dask.array.core.Array`

      The N-dimensional data to fit.

    data_units `astropy.units.Unit`

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

    weights `numpy.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.

    mask `numpy.ndarray`

      A boolean mask to be applied to the data.

    fitting_axes `python:int` or `python:tuple`

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

    world `None` or `python: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_max `python:int`

      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{ `python: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_path `python:str`, 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_callable `python:callable()`

      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.

    scheduler `python:str`, 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_kwargs `python:None` or `python:dict`

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

    preserve_native_chunks bool, 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.

    equivalencies `python:list` of `python:tuple`

      Any equivalencies to take into account in unit conversions

    fit_info bool or `python:str` or python:iterable, optional

      Option to control whether fit information set on the `.fit_info` attribute of the fitters for individual fits should be concatenated and set on the `.fit_info` on the input fitter object. The options are as follows:

      - `False`: don’t set `.fit_info` on the fitter

      - `True`: set `.fit_info` on the fitter with all available information

          from individual fits

      - An iterable of strings: only save the specific attributes mentioned in the iterable

      If not `False`, the `.fit_info` attribute on the fitter will be set to a `FitInfoArrayContainer` object which can be used to query the fit information for individual fits. Otherwise, `.fit_info` will be left unchanged.