Spectral line analysis tools

This is an embarrassing post, but I’m going to forge ahead.  Time was, we used IRAF and we hated it, but what else was there?  Now, there are many choices, lots of them buggy and badly documented, some of them superb.

Say I have a one-dimensional, flux-calibrated, wavelength-calibrated spectrum.  (So, all the hard work of calibration is already done.) I want to measure equivalent widths, fluxes, and wavelengths of lines, interactively and then non-interactively.  What software packages can people can recommend?

35 comments… add one
  • Adam Ginsburg Oct 2, 2009 @ 15:53

    Unfortunately, I’m in the same boat – everyone I’ve asked uses their own homegrown routines. There are automated routines in IRAF – which I still use without hating any more – but nothing satisfying. SPLAT (http://star-www.dur.ac.uk/~pdraper/splat/index.html) works in principle, but I haven’t managed to use it effectively. Personally, I’ve mostly switched over to using homegrown routines as well – I have my own gaussfitter in python (http://code.google.com/p/agpy/source/browse/trunk/gaussfitter.py) and have had to write my own methods depending on the spectral range & instrument to do the fitting and output useful info. If you’re doing radio work, CLASS is OK for gaussian fitting too.

  • Kelle Oct 2, 2009 @ 16:02

    I’ve run into this before and have always just ended up using IRAF…especially if you want interactivity. I use the primitive logging capabilities of splot.

    For measuring spectral indices, I use my own IDL routines….which I would be happy to share if people were interested. They are the result of many years of tweaking and improving and, as a result, if I might say so myself, are quite nice and flexible. They do not, however, have any GUI-based interactivity nor do they measure EWs…only flux ratios (aka spectral indices).

  • Eilat Oct 2, 2009 @ 20:10

    Someone told me something about a “gandalf”

  • Mike Oct 2, 2009 @ 20:20

    I have one written for Spextool data but never made it robust enough to release to the general public.

    There is a GUI written for the FUSE spacecraft that does EWs and line fluxes, etc. It can be found at,


    It is the ltools package and the routine is line_eqwidth. It isn’t bad, but I like my widgets better, hence why I wrote my own. It will get fixed someday…

  • Jane Oct 2, 2009 @ 20:24

    Ah, you mean this Gandalf. That’s all fancy 2D stuff.

  • Kelle Oct 3, 2009 @ 0:31

    Over on FB, Avril and Ben have suggested the DIPSO program in Starlink…which is apparently a British thing: http://www.starlink.rl.ac.uk/star/docs/sun50.htx/sun50.html
    It’s byline is “a friendly spectrum analysis program” but it looks like it might be all command line and it’s not clear it’s any better than IRAF…but I could be wrong.

  • Eilat Oct 3, 2009 @ 11:52

    Yes, I did mean that gandalf (my prev. comment was sent by iphone), but apparently it works just fine on 1D stuff. My colleague Kevin Schawinski at Yale uses it on sdss spectra. they illustrate its use here
    ive never used it, but it seems very cool.

  • Marc Oct 24, 2009 @ 7:04

    Hi there just a note for anyone interested in Gandalf. Please do drop me an e-mail if you download it, so that I can keep you up to date if I upgrade it, or worse find a small bug in it.


  • ES.E Nov 2, 2009 @ 15:22

    I have been using Starlink’s Dipso for many years and it is completely satisfactory for 1D analysis of spectra; very much user-friendly as compared with iraf. It includes a robust Emission Line Fitting package. Mostly interactive, but you can run it from a command file input. I recommend it.

  • Wayne S Nov 12, 2009 @ 14:29

    To go along with Adam’s comment, after digging through CLASS (radio reduction software) and seeing how different routines perform the same calculation differently I resorted to taking baselines spectra and previously determined line windows and computing everything in IDL. Conveniently, I was only fitting one line per spectrum. Basically, I determined the 0th, 1st, and 2nd moments of the spectrum. For the first and second moments, use only data 3-sigma above the baseline. These will give you the area, line center, and the width. These can then be used as starting parameters for fitting a Gaussian. If you are using IDL you can use Craig Markwardt’s MPFITPEAK. The nice thing about this rather than using CLASS was the fact I could define what parameters a valid fit could have. Since the results using these two methods should match fairly closely you can double check your numbers.

  • Neil Nov 23, 2009 @ 17:34

    I keep my Python research code here:


    It has a couple of modules for finding and fitting absorption lines. (findline.py, spec.py and fit.py). It’s not too user friendly at the moment, but feel free to try it out.

  • Gene Avrett Dec 11, 2009 @ 15:51

    See my website for some lecture notes on the atmospheric modeling aspect of spectral line analysis, as well as a description of the Pandora computer program I use to calculate a spectrum from given atmospheric parameters.

  • Randall Smith Dec 11, 2009 @ 17:20

    You could take a look at Profit

    It was an attempt to develop a spectral line fitting program with the same ease-of-use of saoimage/ds9. I won’t say we succeeded (I think we set a high bar trying to be as good as ds9), and unfortunately development has stalled as both developers moved on, but it is still usable.


  • Vinay Kashyap Dec 11, 2009 @ 17:47

    See also PINTofALE, at http://hea-www.harvard.edu/PINTofALE/

    Designed for analysis of high-resolution EUV/X-ray stellar gratings spectra. There is a gui line-fitting program called fitlines() that’s pretty flexible and robust, if I may say so myself.

  • Eric Bubar Dec 13, 2009 @ 12:47

    I like to use SPECTRE from Chris Sneden. It requires Supermongo to work, but its excellent for getting out equivalent widths interactively. For automated extraction of equivalent widths, I’ve tried to bend DAOSPEC from Peter Stetson to my will, but haven’t gotten it working to my satisfaction yet. Those would be my two choices.

  • Tolga Guver Dec 14, 2009 @ 17:24

    You can try SHERPA (from : http://cxc.harvard.edu/sherpa3.4/) it is an older version and basically written to analyze Chandra X-ray spectroscopic data. But it also accepts ASCII files, so you can fit any sort of data (optionally with errorbars) with a broad selection of features and models (Gaussian, Lorentz, etc. together with all other typical X-ray spectral and general mathematical models, and finally if you need your own models). It also supports all sorts of chi2 minimization techniques, confidence contour plots etc. The newer version of the software also supports Python and S-lang you you can easily write complicated scripts as well, but the older one is much easier to use, for interactive analysis.

  • Fred Walter Dec 15, 2009 @ 20:04

    ICUR, an IDL-based interactive spectroscopic package I started writing nearly 30 years ago, still works (though parts of it need to be updated).

    See the ICUR download page. Documentation is in this pdf file.

  • Tim van K. Dec 16, 2009 @ 3:48

    I would go for CLASS. It is a bit of a steeper learning curve, but Class 90 can do a lot of fitting and a lot of moments easily. I have been using it in the submm for years now, even converting starlink produced spectra to class. One big advantage of class that i found cumbersome in IDL routine is its ability to easily do spectral line maps with variable fits of different baseline orders.

  • Anca Constantin Dec 17, 2009 @ 11:00

    I didn’t see here any mention of G. Kriss’ SPECFIT, IRAF again [included in the stsdas group, under contrib.spfitpkg package], but it’s been pretty good to me. And, definitely much more versatile than SPLOT. The help file was sufficient for me when I first tried it, and a brief description can be found in the 1994, PASP Conf. Series, Vol. 61, p. 437.

  • Pierre Dec 21, 2009 @ 6:09

    Hi all,
    in the same line of work as Gandalf, there is STECKMAP, which I wrote during my PhD and I am still using and upgrading, along with a number of believers. You can check it out here:
    drop me a line if youre interested, Ill keep you up to date with the latest developments.

  • George Jacoby Jan 27, 2010 @ 8:40

    Okay, I’ll admit to being the original author of SPLOT and most of the ONEDSPEC package in IRAF. I find it both thrilling and shocking that most people (including myself) use these tools “as is” 25 years after I wrote them. (Note that Frank Valdes has provided many improvements and additions over the years.) My intent here is to encourage users to send suggestions to IRAF support at NOAO. Many improvements can be made relatively quickly and easily (e.g., a true database output from SPLOT). Although the resources at NOAO for IRAF are currently very limited, once improvements are made, the entire community benefits.

    • Yang Jan 5, 2013 @ 12:29

      Dear George, Where can I send my suggestions to SPLOT? It seems SPLOT can only accept spectra fits file with wavelength encoded in the header. But some sometimes the wavelength is not regularly sampled, so we need one column/line to represent wavelength and the other to represent the flux. Thank you!

    • George Jacoby Jan 20, 2013 @ 9:26

      Frank Valdes of the IRAF group responds to the query from Yang …

      SPLOT, and all IRAF spectroscopy tasks for that matter, do support a sampled WCS (provided the number of points is not extremely large). Getting this format is best done with RSPECTEXT. This takes a text file with wavelength and flux pairs and produces the image format you mention. One of the parameters in this task should be set as “dtype=nonlinear”. As the help page notes:

      Store the wavelength values in the image header as a lookup
      table. The flux values are not resampled. The wavelength
      values need not be evenly sampled.

      You could also dig through the help on “specwcs” for an example and discussion.

      Many years ago I did work to have IRAF spectral tools understand spectra in tables, which were starting to be more common. This work never was finished due to resources requiring me to move on to other things. However, there is a plan to complete this this year (but you know how plans are).

      BTW, as George notes you can also use RSPECTEXT (or SINTERP) to fit the wavelength points by a WCS function and then interpolate the points to produce the image format where the pixels are flux and wavelengths are described by the function in the header. Normally interpolation errors are not really as bad as people worry about. It mostly becomes bad if the data are marginally sampled and there are strong spikes (both emission and absorption) which cause interpolators to ring.

      Frank Valdes

  • Mark Westmoquette Apr 8, 2010 @ 9:49

    Just to add another alternative to the already fairly extensive list discussed above, I’ve been using PAN (Peak ANalysis). This is an IDL-based general-purpose curve-fitting utility with a graphical user interface, based on Craig Markwardt’s MPFIT. PAN can be used to fit any of its in-built functions (straight line, Gaussian, Lorentzian, etc.) or you can create custom functions to fit your data (e.g. Ha+[NII]). There is no limit to the number of functions to which you can fit simultaneously but more functions result in more computation time.

    PAN is particularly useful for IFU/MOS data since:
    1. It has the ability to read in multiple spectra at once in an array format, and fit one initial guess to these spectra automatically. This is ideal for IFS data with potentially hundreds of spectra.
    2. The spectrum+fit, the residuals and the numerical results are displayed on-screen for each spectrum, meaning you can view and review the fit for each spectrum in a very visual manner.
    3. The initial parameter guesses (amplitude, position and width) can be specified visually with the mouse. PAN was written such that the amount of typing done by the user is minimized.

  • Adam Ginsburg Aug 12, 2010 @ 9:18

    Returning to this page 10 months after the fact…. it’s still kind of surprising to me that every instrument and every group seems to use their own code. As far as I can tell from discussions with locals, IRAF is the only program that’s nice about fitting Voigt profiles, particularly blended ones. Most of the codes listed above “could be used” to do any given task, provided a lot of additional work is put in at the front to incorporate the types of fitting you want to do. Since spectra are essentially the same once reduced, it seems like there should be one major spectral line tool similar to DS9 for imaging. I’m not volunteering to do that… but at the very least, a list of spectral line tools should be maintained. I’ll start a wiki page for it.

  • Ben Weiner Aug 12, 2010 @ 13:41

    Happy spectra are all alike; every unhappy spectrum is unhappy in its own way. Although 1-D spectra are the same basic data structure, different regimes have substantially different systematics – baseline stability, blendedness, whether you care about the damping wings, and so on. Further, some people want to dink around with the initial guesses and use a GUI to adjust the fit, some people want to fit 100,000 lines and have it not take all day, and so on.

    I fit lines in optical spectra with a Fortran program that uses Levenberg-Marquardt non-linear least squares to fit a Gaussian or Voigt (or multiple lines), with simple automated construction of the initial guesses (important for an iterative routine). One should be able to do the same thing with MPFIT in IDL, less clunkily but slower. I use a subroutine written long ago by my advisor that does a very accurate fast approximation of a Voigt function and its derivatives. Email me if you want a copy of this subroutine.

  • Kelle May 27, 2011 @ 8:13

    another one: SpecPro
    “an interactive IDL program for viewing and analyzing astronomical spectra…SpecPro’s interactive design lets the user simultaneously view spectroscopic, photometric, and imaging data, allowing for rapid object classification and redshift determination.”

  • Robert M. Elowitz Jul 31, 2011 @ 17:34

    I use a program called SpecView from the Space Telescope Science Institute. It can fit basic models such as Gaussian, Lorentzian, and Voigt profiles to spectral lines. It also has other models such as blackbody, powerlaw fits, etc. You can overplot line ids on your spectrum. It runs under MS Windows and has a descent GUI interface. You can get SpecView at the following website. One nice feature with SpecView is that it can import spectra in the form of ascii files. There only has to be some very basic header lines in the ascii file, which is described in the SpecView documentation.


  • Adam Ginsburg Sep 13, 2011 @ 16:01

    More than a year later…

    Jordan Mirocha and I have been developing a python-based spectrosopic analysis toolkit. It’s available at pyspeckit.bitbucket.org. It fits profiles interactively or via “clever” guessing. It can fit gaussian, lorentzian, and voigt profiles (built in). It can also do model-grid based fitting and has an NH3 inversion fitter written at the moment. It deals well with unit conversions and can read and write a variety of different file types. It has some interactive data cube capabilities, but those aren’t particularly well refined at the moment. It can link to the SPLATALOGUE radio line database to overplot line locations and has a small optical line database built in.

    The big advantages are that it’s designed to be extensible: i.e., you can write your own model function and plug it into the code without having to write any of the overhead stuff (e.g., x-axis units, residual calculations, annotations, etc.).

    As Ben pointed out, unhappy spectra can be unhappy in a lot of different ways. PySpecKit is designed to deal with happy spectra, but can deal with flagged data and can be used to subtract baselines.

    Finally, because it’s pure python, it is slow for batch-processing large spectra. I’d like to incorporate a fortran implementation of MPFIT if possible, but that’s low on the priority list for now.

  • Karen Leighly Jul 28, 2012 @ 13:54

    We have now had to get rid of our Sun machines (no security patches available), and so I am left trying to run Specfit on an ancient Mac Power-PC and one ancient laptop. (It crashes while trying to converge on Linux and Intel Macs – a well known problem, at least among the people I’ve talked with, and I’ve also corresponded with the software’s author about this issue).

    I’ve tried to shift to Sherpa, but it doesn’t have the functionality I need – specifically, I need to fit emission and absorption templates. Sherpa will fit an emission template, but they seem to have some unusual understanding of absorption lines, e.g.,:

    Anyway, does anybody have any suggestion for software that can do what I need? e.g., the Specfit commands I am trying to reproduce are “continuum” and “absline”.

  • Emanuela Jan 20, 2013 @ 2:56

    How about STARLIGHT? It’s publicly available and you can use different fitting libraries.

  • Tina Jun 30, 2013 @ 23:57


    Not sure if this really fits here but I’ve been trying to get flux uncertainties for my Spitzer IRS high resolution data. The data has been calibrated. None of the programs, like SMART or such, are useful with high resolution data so I normally get error messages. I also do not have several observations for an object in a night since these objects are variables and hence have a high fluxes. I know a little IRAF but not sure if there is anything I can use to get these uncertainties. Any help is appreciated. Thanks.

    • Kelle Jul 1, 2013 @ 9:42

      Tina, I forwarded your query to the Spitzer Help Desk: help@spitzer.caltech.edu & http://ssc.spitzer.caltech.edu/spitzerhelpdesk/.

      I’m pretty sure the flux uncertainties were calculated when the data was reduced. I suspect they are in your data files and you just need a little help figuring out how to get at ’em.

    • Tina Jul 1, 2013 @ 10:23

      Hi Kelle
      I think I might not have used the right word to describe the data by using calibrated. We received the “raw” (i.e. right off the telescope) data and I reduced it (i.e. background subtracted, bad pixel removal with IRSCLEAN, defringed with IRSFRINGE, and trimmed the data). So the Spitzer help desk most likely can’t help with this inquiry since it is home-grown routines and some of their programs (IRSCLEAN and IRSFRINGE). Thanks for contacting the help desk, though I would have contacted them myself however I was told that it won’t be of any help since they didn’t reduce the data but I did. I hope this makes my problem a bit clearer.
      The main problem I seem to have is that it is high resolution data and only one observation during a night with several weeks between those. People I have talked to either don’t use Spitzer data or never dealt with the high resolution data in the case of Mira variables.

  • Emil Rivera-Thorsen Dec 3, 2014 @ 6:54

    Adam Ginsburg, for Voigt profile fitting, there is a specialized package called VPfit developed by Robert Carswell and John Webb that is specialized in multiple blending Voigt profiles overmultiple transitions and can tie, freeze different parameters, it is very capable. But the UI is… Well, I am happy that Joe Liske made the external VPfit gui called VPguess, which makes interactive work with VPfit if not a breeze, then at least doable example.
    But when it comes to fitting voigt profiles in terms of (N, b, z) over multiple transitions, VPfit is the best I’ve seen by a long shot.

    [VPfit]: http://www.ast.cam.ac.uk/~rfc/vpfit.html
    [VPguess]: http://www.eso.org/~jliske/vpguess/
    [example]: http://www.eso.org/~jliske/vpguess/example.html

Leave a Reply

Your email address will not be published. Required fields are marked *