hfs_fit is an interactive graphic procedure for fitting simultaneously up to 9 velocity components of a spectral line with hyperfine structure.
It is a menu-driven program, and uses the PGplot Graphics Subroutine Library to display the spectral data, fit, and residual.
Example of a hfs_fit run:
$ hfs_fit nh311_thin.dat _____________________________________________ HfS_fit. HyperFine Spectra multicomponent fit Robert Estalella, 2015/06 _____________________________________________ ****** Use a terminal with at least 115 columns ****** Date: 2016/01/06 Time: 20:44:27Help is available, explaining the program options and parameters.
The spectrum to fit is read from an ASCII file with a pair of values (velocity, intensity) per line. Lines beginning with "#" or "!" are ignored. The file can be given as an argument to hfs_fit:
hfs_fit <source>.dat
The transition is selected among those stored in the file hfs_transitions.dat. This file has to be located in the working directory, or in the directory pointed at by the environment variable HFS_DIR. The first transition in the file is a single component at vLSR= 0, useful for fitting a single Gaussian line. Other transitions in the file include NH3 (1,1) and (2,2), N2H+(1–0), CN (1–0), and more transitions can be added easily to the file. Any transition not appearing in the file is assumed to be single.
An optional Hanning smoothing of the spectrum can be performed prior to fitting.
The four parameters fitted for each velocity component are
Δv, linewidth of the hyperfine components (deconvolved from the channel width);
vLSR, central velocity of the main component;
A(1 - e-τm), peak intensity of the main component (for lines wider than channel width), in the same units as the input spectra;
1 - e-τm, where tau_m is the optical depth of the main component.
with the additional constraints
0 < Δv,
0 < A(1 - e-τm),
0 < 1 - e-τm < 1.
The initial values for the fit are guessed from the intensity, position, and width of the data peak for the first component, and of the residual (data minus previous components) for the rest of components. The opacity is set arbitrarily to 0.7 (1 - e-τm = 0.5), or to an arbitrary low value (10-6) for a single Gaussian fit.
Alternatively, you can use the cursor to add or delete components. The position of a new component is set at the cursor position, its intensity is the intensity at the cursor position, and the FWHM is estimated around the cursor position.
Values for the initial search ranges are proposed, but they can be changed. Any of the parameters can be kept constant by setting its range to 0.
The fit is performed by sampling the parameter space of dimension 4×Ncomp (the number of components) using a Sobol pseudo-random sequence and finding the minimum residual rms. The parameter space is defined by a search range for each parameter, centered on the initial values (and taking into account the constraints given above).
The uncertainties in the parameters are found from the increase of residual rms with each parameter deviation.
See an example of fitting a NH3 (1, 1) spectrum with two velocity components: hfs_fit.log.
The synthesized spectrum is saved to an ASCII file <source>.synt The file has a header (lines beginning with "!") with the values of the parameters of the fitted spectrum for each velocity component. The file is readable by GREG. The file is overwritten for every new fit.
A plot showing the data, the components fitted, and the residual is saved in a file <source>.eps. The file is overwritten for every new fit. See an example (data in black, two velocity components in blue and red, residual in green, residual rms = 0.30):