alfa(1) | alfa man page | alfa(1) |
alfa - automated line fitting algorithm
alfa [OPTION] [VALUE]... [FILE]
alfa rapidly fits emission line spectra, using a genetic algorithm to optimise fitting parameters. It is intended to be entirely automated, but while the default values should work well in many situations, a good fit to your observed spectrum may require some adjustments to the input parameters. It is optimised for optical spectra, but can be applied to any wavelength range if a suitable line catalogue is provided.
alfa reads one dimensional spectra in either plain text or FITS format. Plain text input should consist of two columns, giving wavelength and flux. It can also read data cubes and row-stacked spectra in FITS format. Results are written out in plain text, to files containing the fit (total fit, continuum-subtracted original, continuum, sky lines and residuals), and the line flux measurements.
alfa works in three stages. First, it estimates and subtracts the continuum. Second, it estimates the resolution of the spectra and the velocity of the object. And third, it fits the emission lines. These stages work as follows:
alfa estimates the continuum using a percentile filter, taking the 25th percentile in a moving window 101 pixels wide. Currently these values are hard-coded, but will be user-configurable in a future release. Regions such as the Balmer and Paschen jumps may be poorly fitted by this method if the spectral resolution is low and the continuum gradient is changing fast. Broad stellar emission lines and telluric absorption features may also not be well fitted by this method. Inspection of the fitted continuum is recommended.
If no relevant command line options are specified, alfa begins by assuming that the velocity of the object is zero, and that the spectrum is Nyquist-sampled. It then carries out a fit on a subset of strong lines, using the genetic algorithm described below, to obtain an overall estimate for the velocity and the resolution. If necessary, the initial guesses can be specified with the -vg and -rg options described above, and the parameter space for the fine tuning can be specified with -vtol1 and -rtol1.
With the continuum subtracted and the resolution and velocity estimated, alfa divides the spectrum up into chunks 440 pixels wide, with 20 pixels at either end overlapping with adjacent chunks. Then the genetic algorithm fits all lines from the deep catalogue that fall within the central 400 pixels, with the overlap regions providing the full line profile for lines close to the edge of the chunk. The initial guess for the resolution and velocity are taken from the global estimate for the first chunk, and from the preceding chunk's fine tuned value for all succeeding chunks.
With the parameters optimised in each chunk, uncertainties are estimated using the root mean square of the residuals in a 20 pixel window, exlucing the two largest residuals to mitigate against overestimated uncertainties in the neighbourhood of bad pixels or strong lines.
alfa can read either plain text files or FITS format files. For plain text, the file should contain a wavelength and a flux, with the wavelength in the same units as the line catalogues (the default catalogues have wavelengths in Angstroms). FITS files are read using the CFITSIO library, so any FITS-compliant file should be fine. However, a surprisingly large fraction of all FITS files do not comply with the standard, so in case of problems, trying using fitsverify to check your FITS file.
The FITS file can have one, two or three dimensions. If it has two, it is assumed to be in Row-Stacked Spectra (RSS) format, while if it has three, it is assumed to be a data cube with two axes representing spatial dimensions and the third representing the spectral dimension.
If you don't want to fit the whole dataset, you can specify the range of pixels on each axis that you want alfa to read in by appending the filename with [startx:endx,starty:endy]. This functionality is part of the CFITSIO library, and the format is described at https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node97.html. alfa itself does not read in the coordinates of the section, and so the output file numbering starts from 1 on each axis regardless of where the image section actually started. The next release of alfa will have improved support for image sections.
alfa can produce output in plain text, csv, latex or FITS format. FITS is the default and recommended format; in future releases, output formats other than FITS will be deprecated and eventually removed.
When producing plain text, csv or latex output, alfa will produce two files, a fit file and a line list file. When producing FITS format, a single file is created, with three extensions, for the fit, the linelist, and a third extension containing the Hbeta flux, number of lines detected, the radial velocity and average resolution over the spectrum. Output filenames are based on the input filename, with the extensions noted below.
The fit file contains the best fitting synthesised spectrum.
It contains seven columns, representing the wavelength, the input
spectrum, the fitted spectrum, the original after continuum subtraction,
the estimated continuum, the fluxes of sky lines, and the residuals.
Thus, to see the fitted spectrum, you need to plot columns 1 and 3 of
this file. In gnuplot, one can compare the input and fitted spectra
using this command:
plot 'filename_fit' w l, 'filename_fit' using 1:3 w l
This file contains four columns with parameters of the fitted lines - the observed wavelength, the rest wavelength, the flux, and the uncertainty estimated from the residuals. This file can be read directly by neat, which determines abundances for photoionised nebulae. If latex format is requested, the file additionally contains atomic data details not currently available in the other formats.
For RSS files and data cubes, alfa currently produces output for each pixel. Thus, for a large data cube you may end up with tens of thousands of files in the output directory. A routine to combine these outputs into image maps will be provided in a future release of alfa.
alfa's default parameters are supposed to work in most cases, but sometimes you might find that it does not converge on the correct wavelength solution. It searches initially for velocities in the range +/-900km/s, which is very large for Galactic objects. So, running the code with --resolution-tolerance-1 100. or so may improve your results.
The genetic parameters (population size, number of generations, pressure) are likely to be suitable for most cases. There is no algorithm yet known for optimising these parameters in a genetic algorithm, so changing them requires trial and error. In spectra of regions with lots of emission lines, such as 4000-4500 Angstrom, increasing the number of generations can result in a better fit.
If alfa encounters an error it will return one of the following status codes:
100 incomplete or invalid command line option
101 input file does not exist
102 output directory does not exist
103 error opening FITS file
104 no axes found in input file
105 too many axes found in input file
106 error reading FITS keywords
107 error writing FITS output
108 no line catalogue file specified
109 line catalogue not found
200 all fluxes below baddata limit
201 no known emission lines in wavelength range
202 failed to estimate velocity and resolution - no lines found
neat
If reporting a bug, please state which version of alfa you were using, and include input and any output files produced if possible.
Roger Wesson
26 Aug 2016 | 1.0 |