fit_model_to_spectrum#

jdaviz.configs.default.plugins.model_fitting.fitting_backend.fit_model_to_spectrum(spectrum, component_list, expression, run_fitter=False, window=None, n_cpu=None)[source]#

Fits a CompoundModel to a Spectrum1D instance.

If the input spectrum represents a spectral cube, then fits the model to every spaxel in the cube, using a multiprocessor pool running in parallel (if n_cpu is larger than 1).

Parameters:
spectrumSpectrum1D

The spectrum to be fitted.

component_listlist

Spectral model subcomponents stored in a list. Their 'name' attribute must be unique. Each subcomponent should be an initialized object from Model.

expressionstr

The arithmetic expression that combines together the model subcomponents. The subcomponents are referred via their 'name' attribute.

run_fitterbool

This is currently being ignored for 3D fits. When False (the default), the function composes the compound model and returns it without fitting.

windowNone or SpectralRegion

See specutils.fitting.fit_lines().

n_cpuNone or int

This is only used for spectral cube fitting. Number of cores to use for multiprocessing. Using all the cores at once is not recommended. If None, it will use max cores minus one. Set this to 1 for debugging.

Returns:
output_modelCompoundModel or list

The model resulting from the fit. In the case of a 1D input spectrum, a single model instance is returned. In case of a 3D spectral cube input, instead o model instances for every spaxel, a list with 2D arrays, each one storing fitted parameter values for all spaxels, is returned.

output_spectrumSpectrum1D

The realization of the fitted model as a spectrum. The spectrum will be 1D or 3D depending on the shape of input spectrum.