Basic Usage
Fit a spectrum with the default BIC model selection:
from gaussFitSpec import fit_spectrum, plot_fit, read_spectrum
velocity, spectrum, spectrum_err = read_spectrum("examples/example_spectra.txt")
result = fit_spectrum(
velocity,
spectrum,
spectrum_err,
name="spectra1",
method="bic",
max_components=8,
)
print(result.components)
result.to_csv("examples/example_components.csv")
plot_fit(
velocity,
spectrum,
spectrum_err,
result,
output_file="examples/example_fit.png",
)
Fitting Options
Use min_fwhm and max_fwhm to constrain component widths:
result = fit_spectrum(
velocity,
spectrum,
spectrum_err,
min_fwhm=2.0,
max_fwhm=40.0,
)
Fit Result
The returned SpectrumFitResult contains:
componentsA pandas DataFrame with one row per Gaussian component.
best_modelThe total fitted Gaussian model evaluated on the input velocity grid.
individual_componentsA 2D array containing each Gaussian component evaluated on the input velocity grid.
residualspectrum - best_model.methodThe selected model-selection method.
n_componentsThe number of selected Gaussian components.
fit_statisticsA dictionary with values such as
chi2,reduced_chi2,aic, andbic.
Component Table
The component table includes:
name
component_index
amplitude
amplitude_err
velocity
velocity_err
fwhm
fwhm_err