Spectral line analysis tools

by Jane on October 2, 2009

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?

{ 34 comments… read them below or add one }

1 Adam Ginsburg October 2, 2009 at 3:53 pm

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.

Reply

2 Kelle October 2, 2009 at 4:02 pm

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).

Reply

3 Eilat October 2, 2009 at 8:10 pm

Someone told me something about a “gandalf”

Reply

4 Mike October 2, 2009 at 8:20 pm

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,

http://fuse.pha.jhu.edu/analysis/sw/

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…

Reply

5 Jane October 2, 2009 at 8:24 pm

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

Reply

6 Kelle October 3, 2009 at 12:31 am

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.

Reply

7 Eilat October 3, 2009 at 11:52 am

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.

Reply

8 Marc October 24, 2009 at 7:04 am

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.

Marc

Reply

9 ES.E November 2, 2009 at 3:22 pm

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.

Reply

10 Wayne S November 12, 2009 at 2:29 pm

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.

Reply

11 Neil November 23, 2009 at 5:34 pm

I keep my Python research code here:

http://www.bitbucket.org/nhmc/pyserpens

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.

Reply

12 Gene Avrett December 11, 2009 at 3:51 pm

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.

Reply

13 Randall Smith December 11, 2009 at 5:20 pm

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.

–Randall

Reply

14 Vinay Kashyap December 11, 2009 at 5:47 pm

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.

Reply

15 Eric Bubar December 13, 2009 at 12:47 pm

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.

Reply

16 Tolga Guver December 14, 2009 at 5:24 pm

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.

Reply

17 Fred Walter December 15, 2009 at 8:04 pm

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.

Reply

18 Tim van K. December 16, 2009 at 3:48 am

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.

Reply

19 Anca Constantin December 17, 2009 at 11:00 am

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.

Reply

20 Pierre December 21, 2009 at 6:09 am

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:
http://astro.u-strasbg.fr/~ocvirk/
drop me a line if youre interested, Ill keep you up to date with the latest developments.

Reply

21 George Jacoby January 27, 2010 at 8:40 am

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.

Reply

22 Yang January 5, 2013 at 12:29 pm

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!

23 George Jacoby January 20, 2013 at 9:26 am

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:

nonlinear
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.

Regards,
Frank Valdes

24 Mark Westmoquette April 8, 2010 at 9:49 am

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.

Reply

25 Adam Ginsburg August 12, 2010 at 9:18 am

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.

Reply

26 Ben Weiner August 12, 2010 at 1:41 pm

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.

Reply

27 Kelle May 27, 2011 at 8:13 am

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.”
http://adsabs.harvard.edu/abs/2011PASP..123..638M

Reply

28 Robert M. Elowitz July 31, 2011 at 5:34 pm

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.

http://www.stsci.edu/resources/software_hardware/specview

Reply

29 Adam Ginsburg September 13, 2011 at 4:01 pm

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.

Reply

30 Karen Leighly July 28, 2012 at 1:54 pm

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.,:
http://cxc.cfa.harvard.edu/sherpa/ahelp/absorptiongaussian.html

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”.

Reply

31 Emanuela January 20, 2013 at 2:56 am

How about STARLIGHT? It’s publicly available and you can use different fitting libraries.
http://www.starlight.ufsc.br/index.php?section=1

Reply

32 Tina June 30, 2013 at 11:57 pm

Hi

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.

Reply

33 Kelle July 1, 2013 at 9:42 am

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.

34 Tina July 1, 2013 at 10:23 am

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.

Leave a Comment

Previous post:

Next post: