alfa(1)

๐Ÿ“ฆ
version 2.2 ยท 2 versions
  • 2.2 ยท debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 2.1 ยท ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

Bestie, this is the alfa(1) man page ๐Ÿ’–, the manual for alfa, so let's get into it ๐ŸŒธ

โœจ NAME โœจ

alfa - automated line fitting algorithm ๐Ÿฆ‹

๐Ÿ’… SYNOPSIS ๐Ÿ’…

alfa [OPTION] [VALUE]... [FILE]

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

okay so alfa rapidly fits emission line spectra โœจ, and it's giving genetic algorithm energy because it uses one to optimise the fitting parameters ๐Ÿงฌ. It's meant to be totally automated ๐Ÿซถ, but even though the defaults slay in lots of situations, getting a good fit to your observed spectrum might need a few tweaks to the input parameters ๐Ÿ’…. It's optimised for optical spectra, but it can be applied to any wavelength range too, as long as you give it a suitable line catalogue ๐ŸŒธ.

alfa reads one dimensional spectra in either plain text or FITS format ๐Ÿ“–. Plain text input should have 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 ๐Ÿ“.

๐ŸŽ€ OPTIONS ๐ŸŽ€

  • -b, --bad-data [REAL] โ€” If every value in a spectrum is below the number you give, alfa won't fit it ๐Ÿ™ˆ. Most useful for not wasting time on low signal regions of data cubes ๐Ÿ’€.
  • --citation โ€” Prints the bibliographic details of the paper to cite if you use alfa in your research ๐Ÿ“š.
  • -cl, --clobber โ€” By default alfa refuses to overwrite any pre-existing output file ๐Ÿšซ. Specify this option and it'll overwrite the output file instead ๐Ÿ’ฅ.
  • --collapse โ€” Sums all spectra in multi-dimensional FITS files into one single spectrum โž•. Spectra whose peak value is below any value you give with the --bad-data option get excluded ๐Ÿ—‘๏ธ. --collapse has no effect on 1D data ๐Ÿ™….
  • -cw, --continuum-window [INTEGER] โ€” alfa's continuum fitting takes the 25th percentile of flux values in a moving window as the representative continuum level ๐Ÿ“Š. This option sets the size of that window ๐ŸชŸ. The value must be an odd integer. Default: 101
  • -dl, --detection-limit [REAL] โ€” Sets the factor by which a line's flux must exceed the locally estimated noise level before it counts as a detection ๐Ÿ”. Default: 3.0
  • -el, --exclude-line [REAL] โ€” When reading in the line catalogues, any wavelengths you give with this option get ignored ๐Ÿ™…โ€โ™€๏ธ. For example, if H alpha were saturated, you could exclude it from the fit with --exclude-line 6562.77 ๐ŸŒŸ. You can exclude as many lines as you want by repeating the option with the wavelengths you need ๐Ÿ”.
  • -fc, --flux-column [INTEGER] โ€” When reading FITS tables, this option picks which table column holds the flux values ๐Ÿช„. For any other file type it does nothing. Default: 2
  • -g, --generations [INTEGER] โ€” The number of generations used in the genetic algorithm ๐Ÿงฌ. Default: 500
  • -n, --normalise [VALUE] โ€” Normalises to Hb=100, assuming that F(Hb)=VALUE ๐Ÿ’ซ. If VALUE is zero, no normalisation happens ๐Ÿ™ƒ. If you don't specify this option, fluxes get normalised using the measured value of Hb if it was detected, and left unnormalised otherwise ๐Ÿคทโ€โ™€๏ธ.
  • -nc, --no-continuum โ€” If the spectrum you're fitting is already continuum subtracted, set this option to skip alfa's continuum fitting โญ๏ธ.
  • -o, --output-dir [DIRECTORY] โ€” The directory where the output files go ๐Ÿ“. Default: current working directory.
  • -of, --output-format [VALUE] โ€” The format of the output files ๐ŸŽจ. Valid values are text, csv, fits, latex. If you're using alfa alongside neat, plain text and fits formats can currently be read in ๐Ÿซถ. Default: text
  • -pr, --pressure [REAL] โ€” The fraction of the population retained from each generation ๐ŸŒŠ. The product of the pressure and the population size should be an integer ๐Ÿ”ข. Default: 0.3
  • -ps, --populationsize [INTEGER] โ€” The size of the population used in the genetic algorithm ๐Ÿ‘ฏ. Default: 30
  • -rb, --rebin [INTEGER] โ€” Rebins the input spectrum by the factor you specify ๐Ÿงฑ. Super useful for high resolution spectra where the line profiles are kinematic rather than instrumental ๐ŸŒˆ. This option is currently only implemented for 1d spectra ๐Ÿšง.
  • -rg, --resolution-guess [VALUE] โ€” Your initial guess for the resolution [lambda/delta lambda] ๐Ÿ”ญ. Default: estimated using the sampling of the input spectrum, assuming that it is Nyquist sampled ๐ŸŽฏ.
  • -rtol1, --resolution-tolerance-1 [VALUE] โ€” How much variation in resolution is allowed in the first pass ๐ŸŽข. Default: equal to 0.9 x resolution guess.
  • -rtol2, --resolution-tolerance-2 [VALUE] โ€” How much variation in resolution is allowed in the second pass ๐ŸŽข. Default: 500.
  • -skyc, --sky-catalogue; -sc, --strong-catalogue; -dc, --deep-catalogue [FILENAME] โ€” These point to the line catalogues used for removing sky lines, estimating velocity and resolution, and the full line fitting ๐Ÿ“œ. The default catalogues live in /usr/share/alfa ๐Ÿก. Want your own catalogue? Each line needs to be 85 characters wide, with a wavelength in the first column ๐Ÿ“. alfa doesn't use the rest of the characters, but they get transferred to the output files, so, like in the supplied catalogues, you can use them for line transition data ๐Ÿ’…. To use the default catalogues but skip some lines, use the --exclude-line option ๐Ÿ™Œ.
  • -ss, --subtract-sky โ€” Fits and subtracts night sky emission lines before fitting the nebular emission lines ๐ŸŒŒ.
  • -ul, --upper-limits โ€” Writes out upper limits for every line searched for and not detected ๐Ÿ”ป. The upper limit is the detection limit (default 3, set by --detection-limit) multiplied by the uncertainty ๐Ÿงฎ. With FITS output this option gets ignored, since all upper limits are written out anyway and marked with negative flux values โš ๏ธ. If the FITS file is later analysed with neat, those negative values are simply ignored ๐Ÿซง.
  • -vg, --velocity-guess [VALUE] โ€” Your initial guess for the velocity of the object [km/s] ๐Ÿš€. Default: 0.
  • -vtol1, --velocity-tolerance-1 [VALUE] โ€” How much variation in velocity is allowed in the first pass of the fitting ๐ŸŒ€. Default: 900km/s
  • -vtol2, --velocity-tolerance-2 [VALUE] โ€” How much variation in velocity is allowed in the second pass of the fitting ๐ŸŒ€. Default: 60km/s
  • -wc, --wavelength-column [INTEGER] โ€” When reading FITS tables, this option picks which table column holds the wavelength values ๐ŸŒŸ. For any other file type it does nothing. Default: 1
  • -ws, --wavelength-scaling [VALUE] โ€” alfa checks the units in FITS file headers to set the wavelength scale, and assumes Angstroms if there's no keyword ๐Ÿ“. If your input spectrum isn't in Angstroms, use this option to set the value that wavelengths get multiplied by to convert them to A ๐Ÿ”. For example, -ws 10.0 would apply if your spectra have wavelengths in nm ๐Ÿญ.

part 2 picks up with ALGORITHM next ๐Ÿฆ‹

๐Ÿ“ INPUT FILES ๐Ÿ“

okay so alfa can read two kinds of files, bestie: plain text files or FITS format files ๐Ÿ’– For plain text, the file needs a wavelength and a flux, and the wavelength has to be in the same units as the line catalogues (the default catalogues use Angstroms โœจ). FITS files get read through the CFITSIO library, so any FITS-compliant file should be fine... but ngl, a surprisingly large fraction of FITS files don't follow the standard ๐Ÿ’€ So if things go wrong, try using fitsverify to check your file ๐Ÿ™ˆ

The FITS file can have one, two or three dimensions. Two dimensions means it's treated as Row-Stacked Spectra (RSS) format ๐ŸŒธ Three dimensions means it's treated as a data cube, with two axes for spatial dimensions and a third axis for the spectral dimension ๐Ÿฆ‹

If you don't want to fit the whole dataset, you can choose the range of pixels on each axis by appending the filename with [startx:endx,starty:endy] ๐ŸŽ€ This is a CFITSIO feature, and the format is described at https://heasarc.gsfc.nasa.gov/docs/software/fitsio/c/c_user/node97.html. Lowkey important: alfa doesn't read the section coordinates itself, so the output file numbering starts from 1 on each axis no matter where the image section actually started ๐Ÿ™ƒ The next release of alfa will have improved support for image sections ๐Ÿ‘‘


๐Ÿ’พ OUTPUT FILES ๐Ÿ’พ

alfa can spit out plain text, csv, latex or FITS format ๐Ÿงš FITS is the default and the recommended one โœจ In future releases, output formats other than FITS will be deprecated and eventually removed, so FITS is the main character era ๐Ÿ’…

When you go with plain text, csv or latex, alfa makes two files: a fit file and a line list file. With FITS you get a single file with three extensions. One is for the fit, one is for the linelist, and the third holds the Hbeta flux, number of lines detected, the radial velocity and the average resolution over the spectrum ๐ŸŒˆ Output filenames are based on the input filename, with the extensions below ๐Ÿซถ

The fit file (_fit.txt, _fit.csv, _fit.tex) or extension (.fits)

The fit file holds the best fitting synthesised spectrum ๐Ÿ’œ It has seven columns: wavelength, input spectrum, fitted spectrum, original after continuum subtraction, estimated continuum, fluxes of sky lines, and residuals. So to see the fitted spectrum, you need to plot columns 1 and 3 ๐Ÿฆ‹ In gnuplot, you can compare the input and fitted spectra with this command:

plot 'filename_fit' w l, 'filename_fit' using 1:3 w l

The lines file (_lines.txt, _lines.csv, _lines.tex) or extension (.fits)

This file has four columns with the parameters of the fitted lines: observed wavelength, rest wavelength, flux, and the uncertainty estimated from the residuals ๐Ÿ”ฅ neat can read this file directly, and neat is the one that determines abundances for photoionised nebulae ๐ŸŒŒ If you request latex format, the file also includes atomic data details that aren't available in the other formats yet ๐Ÿ“š

For RSS files and data cubes, alfa currently makes output for each pixel ๐Ÿ˜ญ So for a large data cube, you could end up with tens of thousands of files in your output directory ๐Ÿ’€ A routine to combine these outputs into image maps is coming in a future release of alfa ๐ŸŽ€


๐Ÿง  USAGE NOTES ๐Ÿง 

alfa's default parameters are supposed to work in most cases, but sometimes it won't converge on the correct wavelength solution ๐Ÿ˜ค It starts by searching for velocities in the range +/-900km/s, which is huge for Galactic objects. So running the code with --resolution-tolerance-1 100 or so might improve your results ๐Ÿ’–

The genetic parameters (population size, number of generations, pressure) are likely to be suitable for most cases. There's no algorithm known yet for optimising these parameters in a genetic algorithm, so changing them is pure 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 โœจ

๐Ÿšจ Error codes ๐Ÿšจ

If alfa runs into an error, it will return one of these 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

๐Ÿ”— SEE ALSO ๐Ÿ”—

neat ๐Ÿ’…


๐Ÿ› BUGS ๐Ÿ›

If you're reporting a bug, please say which version of alfa you were using, and include the input and any output files produced if possible ๐Ÿ™

๐Ÿ‘ฉโ€๐Ÿ’ป AUTHOR ๐Ÿ‘ฉโ€๐Ÿ’ป

Roger Wesson ๐ŸŒธ


And that's the whole page, bestie! ๐Ÿ’– Version 1.0 from 26 Aug 2016, slaying the man page game forever ๐Ÿ’…๐ŸŽ€โœจ

๐Ÿ“ฆ where this page comes from