Skip to content

LineFit reference

from WaLSAlib import LineFit exposes the WaLSA_LineFit callable. linefit is a root-level alias. Inputs and outputs are explained in the workflow.

LineFit

Complete source signature
LineFit(spectra, fit_func='asymmetric_voigt', num_iterations=10, save_fitted_spectra=False, date_identifier=None, refwavelength=None, smoothing_window=3, wavelengths=None, element=None, pixel=None, window_size=4, plot_result=False, alpha_init=0.3, red_asymmetry=True, return_vlos_intensity=True, write_csv=False, adaptive_window=True, per_line_window_size=None, init_centres_nm=None, use_coarse_centers: bool=False, close_pairs: list[tuple[int, int]] | None=None, reversal_lines: list[int] | None=None, coarse_search_half_win: int=120, coarse_smooth: int=3, coarse_peak_distance: int=2, coarse_height_rel: float=0.05, coarse_valley_pad_bins: int=0, max_center_shift_nm: float=0.015, reversal_window_floor: int=20, silent: bool=False, DEBUG_PRINT=False, reversal_valley_depth_rel: float=0.1, reversal_peak_min_rel: float=0.16, reversal_peak_balance_rel: float=0.2, reversal_weak_valley_depth_rel: float=0.05, reversal_weak_peak_min_rel: float=0.12, reversal_weak_balance_rel: float=0.15, reversal_weak_sep_min_bins: int=10, per_line_min_halfwin=None, per_line_max_halfwin=None, allow_shrink_below_base: bool=False, max_expand_bins: int=6, max_expand_factor: float=1.3, depth_min_for_expand: float=0.03, frac_for_width: float=0.35, reject_expand_if_secondary_peak: bool=True, secondary_peak_rel: float=0.35, emission_rel_min: float=0.03, emission_frac_for_width: float=0.2, emission_margin_bins: int=8, emission_min_width_bins: int=8, emission_expand_bins: int=6, emission_expand_factor: float=1.6, huge_emission_rel_thr: float=0.35, huge_emission_force_max: bool=True)
Parameter Default Annotation / meaning
spectra Required One spectrum or stack; wavelength is the last dimension.
fit_func 'asymmetric_voigt' Model name: voigt or asymmetric_voigt.
num_iterations 10 Maximum fitting/refinement iterations.
save_fitted_spectra False Collect fitted segments; FITS writing also needs write_csv=True.
date_identifier None Filename token; uses data when omitted during CSV writing.
refwavelength None One reference wavelength in nm per line.
smoothing_window 3 Boxcar width in spectral samples.
wavelengths None Wavelength axis in nm.
element None One label per line.
pixel None Sample-row selection; unprocessed rows retain NaN outputs.
window_size 4 Baseline spectral half-window in bins.
plot_result False Plot diagnostics for the selected spectrum.
alpha_init 0.3 Initial asymmetry parameter.
red_asymmetry True Apply (1 + alpha) width scaling to the red wing when true, otherwise the blue wing.
return_vlos_intensity True Return velocity and intensity arrays when true.
write_csv False Write parameters in the current working directory.
adaptive_window True Enable adaptive selection of each first-iteration fit window.
per_line_window_size None One baseline half-window in bins per line.
init_centres_nm None Initial line-centre estimates in nm.
use_coarse_centers False bool — Use close-pair-aware coarse initial localisation.
close_pairs None list[tuple[int, int]] | None — Zero-based pairs of requested line indices.
reversal_lines None list[int] | None — Zero-based indices to examine for split cores.
coarse_search_half_win 120 int — Half-width of the coarse search interval in bins.
coarse_smooth 3 int — Coarse localisation smoothing width in bins.
coarse_peak_distance 2 int — Minimum coarse peak separation in bins.
coarse_height_rel 0.05 float — Relative peak-height threshold in coarse localisation.
coarse_valley_pad_bins 0 int — Padding at the valley dividing close-pair ownership.
max_center_shift_nm 0.015 float — Initial local search limit from reference, in nm.
reversal_window_floor 20 int — Half-window floor used for declared reversal candidates.
silent False bool — Suppress routine progress output.
DEBUG_PRINT False Enable implementation diagnostic printing.
reversal_valley_depth_rel 0.1 float — Strong reversal minimum relative valley depth.
reversal_peak_min_rel 0.16 float — Strong reversal minimum relative peak strength.
reversal_peak_balance_rel 0.2 float — Strong reversal minimum weaker/stronger peak ratio.
reversal_weak_valley_depth_rel 0.05 float — Weak reversal minimum relative valley depth.
reversal_weak_peak_min_rel 0.12 float — Weak reversal minimum relative peak strength.
reversal_weak_balance_rel 0.15 float — Weak reversal minimum peak-balance ratio.
reversal_weak_sep_min_bins 10 int — Weak reversal minimum peak spacing in bins.
per_line_min_halfwin None Minimum allowed half-windows in bins.
per_line_max_halfwin None Maximum allowed half-windows in bins.
allow_shrink_below_base False bool — Permit adaptive shrinkage below the baseline half-window.
max_expand_bins 6 int — Maximum ordinary adaptive expansion beyond baseline, in bins.
max_expand_factor 1.3 float — Multiplicative cap on ordinary adaptive expansion.
depth_min_for_expand 0.03 float — Minimum local depression for width-based expansion.
frac_for_width 0.35 float — Depression fraction used in estimating absorption width.
reject_expand_if_secondary_peak True bool — Guard against expansion toward a secondary peak.
secondary_peak_rel 0.35 float — Relative strength defining a secondary peak for the guard.
emission_rel_min 0.03 float — Minimum local emission-proxy strength for expansion.
emission_frac_for_width 0.2 float — Emission-proxy fraction used for width estimation.
emission_margin_bins 8 int — Additional margin for emission-proxy width, in bins.
emission_min_width_bins 8 int — Minimum emission-proxy width in bins.
emission_expand_bins 6 int — Additive emission-driven expansion cap, in bins.
emission_expand_factor 1.6 float — Multiplicative emission-driven expansion cap.
huge_emission_rel_thr 0.35 float — Relative metric threshold for the rare reversal override.
huge_emission_force_max True bool — Allow the override to force the maximum window.

View implementation · Parameters and defaults generated from this checkout.

Returns (velocity, intensity) when return_vlos_intensity=True (the default), otherwise None. Both returned arrays have the full input sample count and one column per line. See output semantics for nearest-bin intensity, row selection, and file side effects.

Symmetric Voigt profile

from WaLSAlib.linefit.WaLSA_LineFit import voigt
Complete source signature
voigt(x, A0, A, x0, sigma, gamma)
Parameter Default Annotation / meaning
x Required Wavelength coordinates in nm.
A0 Required Baseline in normalised inverted intensity space.
A Required Profile amplitude in inverted intensity space.
x0 Required Profile centre in nm.
sigma Required Gaussian width parameter in the built-in profile.
gamma Required Lorentzian width parameter in the built-in profile.

View implementation · Parameters and defaults generated from this checkout.

Evaluates the symmetric profile in inverted spectrum space. Use fit_func="voigt" to select this model through LineFit.

Asymmetric Voigt profile

from WaLSAlib.linefit.WaLSA_LineFit import asymmetric_voigt
Complete source signature
asymmetric_voigt(x, A0, A, x0, sigma_blue, gamma_blue, alpha, red_asymmetry=True)
Parameter Default Annotation / meaning
x Required Wavelength coordinates in nm.
A0 Required Baseline in normalised inverted intensity space.
A Required Profile amplitude in inverted intensity space.
x0 Required Profile centre in nm.
sigma_blue Required Base blue-wing Gaussian width parameter.
gamma_blue Required Base blue-wing Lorentzian width parameter.
alpha Required Wing asymmetry factor.
red_asymmetry True Apply (1 + alpha) width scaling to the red wing when true, otherwise the blue wing.

View implementation · Parameters and defaults generated from this checkout.

Uses separate effective wing broadening controlled by alpha and red_asymmetry. It is the default family selected by fit_func="asymmetric_voigt".

Coarse centre localisation

Complete source signature
coarse_centers_closepair_safe(wl, I, lambda0_nm, search_half_win=120, smooth=3, close_pairs=None, peak_distance=2, height_rel=0.05, valley_pad_bins=0)
Parameter Default Annotation / meaning
wl Required Wavelength samples in nm.
I Required Input intensity spectrum.
lambda0_nm Required Expected line centres in nm.
search_half_win 120 Search half-width in bins.
smooth 3 Smoothing width in bins.
close_pairs None Zero-based pairs of requested line indices.
peak_distance 2 Minimum peak spacing in bins.
height_rel 0.05 Relative peak-height threshold.
valley_pad_bins 0 Valley ownership padding in bins.

View implementation · Parameters and defaults generated from this checkout.

Returns centre estimates in nm and their nearest wavelength indices. close_pairs contains zero-based line-index pairs. This is a lower-level helper; the public fitter invokes it through its coarse-centre controls.