template_match

specutils.analysis.template_match(observed_spectrum, spectral_templates, redshift=None, resample_method='flux_conserving', extrapolation_treatment='truncate')[source]

Find which spectral templates is the best fit to an observed spectrum by computing the chi-squared. If two template_spectra have the same chi2, the first template is returned.

Parameters:
observed_spectrumSpectrum1D

The observed spectrum.

spectral_templatesSpectrum1D or SpectrumCollection or list

That will give a single Spectrum1D when iterated over. The template spectra, which will be resampled, normalized, and compared to the observed spectrum, where the smallest chi2 and normalized template spectrum will be returned.

redshift‘float’, int, list, tuple, ‘numpy.array`

If the user knows the redshift they want to apply to the spectrum/spectra within spectral_templates, then this float or int value redshift can be applied to each template before attempting the match. Or, alternatively, an iterable with redshift values to be applied to each template, before computation of the corresponding chi2 value, can be passed via this same parameter. For each template, the redshift value that results in the smallest chi2 is used.

resample_methodstring

Three resample options: flux_conserving, linear_interpolated, and spline_interpolated. Anything else does not resample the spectrum.

extrapolation_treatmentstring

Three options for what to do if the template spectrum and observed spectrum have regions that do not overlap: nan_fill and zero_fill to fill the non-overlapping bins, or truncate to remove the non-overlapping bins. Passed to the resampler, defaults to truncate.

Returns:
normalized_template_spectrumSpectrum1D

The template spectrum that has been normalized and resampled to the observed spectrum’s spectral axis.

redshiftNone or float

The value of the redshift that provides the smallest chi2.

smallest_chi_indexint

The index of the spectrum with the smallest chi2 in spectral templates.

chi2_minfloat

The chi2 of the flux of the observed_spectrum and the flux of the normalized template spectrum.

chi2_listlist

A list with all chi2 values found for each template spectrum.