Fitting workflow¶
Prepare spectra and references¶
Supply spectra as (n_wavelength,) or (n_samples, n_wavelength), a matching wavelength axis in nm, and one reference wavelength and label per line. A sample is one spectrum, for example at one time or spatial position. LineFit fits each row independently. The reference wavelength for each line defines its zero-velocity position.
import numpy as np
from WaLSAlib import LineFit
velocity, intensity = LineFit(
spectra,
wavelengths=wavelengths_nm,
refwavelength=rest_wavelengths_nm,
element=line_labels,
)
spectra contains the intensity samples, wavelengths_nm their wavelength coordinates, rest_wavelengths_nm one reference wavelength per line, and line_labels the corresponding names. The spectral fitting example provides these arrays from the supplied data.
Inspect finite values, wavelength order, sampling, continuum behaviour, and rest-wavelength conventions before fitting. Use np.array(spectra, dtype=float, copy=True) to protect the original data from internal interpolation of non-finite samples.
Choose a model¶
fit_func="asymmetric_voigt" is the default. alpha_init seeds asymmetry and red_asymmetry selects the wing to which the (1 + alpha) width scaling is applied. fit_func="voigt" selects the symmetric model. The public profile helpers are available from WaLSAlib.linefit.WaLSA_LineFit for explicit use.
Use the simplest profile adequate for the scientific measurement, and inspect systematic residuals and line-centre behaviour on representative observations. Custom callables must match the fitter's expected parameter structure; the two built-in models are the supported starting point.
Set centre and window controls¶
window_size sets a baseline half-window in spectral samples. per_line_window_size supplies a baseline for every line. The first-iteration adaptive logic can adjust that baseline subject to per-line minimum and maximum half-windows and expansion caps.
Use use_coarse_centers=True when coarse localisation is appropriate; declare close pairs and reversal candidates explicitly using zero-based line indices. Read windows, blends, and reversals before tuning these settings.
Inspect a small selection¶
Select one sample row with pixel and set plot_result=True to display its diagnostic plot. Check a small subset before processing a long sequence. num_iterations is the iteration limit; the routine can stop earlier on convergence. Set silent=True to suppress routine progress printing.
Check profiles, fitting intervals, centre shifts, and comparison measurements. Record questionable samples in a validity mask.
Process and save¶
The default return_vlos_intensity=True returns two float32 arrays. Optional CSV and fitted-spectrum FITS outputs are described in outputs. Keep a record of all settings and the ordering of samples and lines.
For the exact signature and defaults, see the LineFit reference.