Amateur astronomers have increasingly better access to affordable spectrographs they can use with their telescope to take spectra of objects in the night sky. This opens up a whole new domain for citizen science. But to do real science, it helps to understand exactly how the data are gathered.
For most amateurs, their spectrograph might come with some canned software that is for all intents and purposes a black box that you put the CCD images from the spectrograph in one end and get one-dimensional spectra out the other with no hint of what happens in-between. One goal of this tutorial is to de-mystify that process and make amateurs as confortable with reducing spectra as they are with reducing CCD images or photometry. The other goal is to dymystify the reduction of spectra and unchain the enthusiastic amateur from their black-box to let them understand and take more control of how their data is reduced.
Many of the basic principles of CCD image reduction also apply to the reduction of spectra. The CCD is broken up into pixels. Each pixel can be thought as a mini-detector of light with its own calibration properties. In order to calibrate the pixel we need to know how much noise it would have gathered without the light falling on it and how it responds relative to the other pixels around it.
The Dark frame is used to tell how much noise there is in the pixel. The Flat frame is used to calibrate its relative response to other pixels.In spectroscopy the Dark is an important calibration. And we will apply the dark in very much the same way you would use a Dark frame for normal CCD imaging. The Dark will be subtracted from the spectrum to remove the background noise in each pixel.
The Flat plays a different roll in spectroscopy. The Flat is not directly divided into the CCD frame containing the spectra. Instead it is extracted identically to the spectra and modeled with a low-order polynomial. That polynomial of the extraction from the Flat is divided into the data. It is also important to understand that unless you are doing spectral photometry (not a recommended project for most amateurs) that the Flat is a completely unnecessary step in reducing spectra. If you only plan to measure the Doppler shifts of features or changes in them relative to the continuum, then the flat-field calibration, while it might make the spectra more presentable, is not needed.
In spectroscopy there is one additional calibration that is not done in normal CCD imaging. To analyze your spectrum you will need to map the row number on your CCD to wavelength. This is done with a wavelength calibration, also called a Comparison spectrum. The Comparison is reduced the same way as the spectrum of your target star and then you identify known features in the Comparison to map the CCD row number to the wavelength in both the Comparison and your target spectrum.
There is a FREE software package that you will need to complete this tutorial. Please download them and install DS9 on your computer before you begin.
SAOImage DS9 - http://hea-www.harvard.edu/RD/ds9/
You will also need a way to plot and display the graph a list of XY points. The could be done in Excel, gnuplot or another plotting package you are familiar with.
In addition to software you will need to download the following four FITS files that you will need to follow along with the tutorial.
Start up DS9 and open up the file spectrum.fit using the "Open" option under the "File" menu.
To make the spectrum easier to see go under the "Zoom" menu and zoom the image so that it can fit on your screen. Also go to the "Sclae" menu and select "Log" to display the brightness as a logrithmic scale. You should see something similar to the picture below.
The Projection region tool in DS9 can be used to make one-dimensional (1D) extractions out of the two-dimensional (2D) CCD images. Select the Projection tool from the "Regions" menu in DS9 as shown below.
Click and drag the mouse across the spectrum.fit image and it will leave behind a green line that traces out the projection that is extracted and graphed in a small secondary window that pops up. Draw your projection region so that it goes across one order of the spectrum. You can expand the width of the box by "grabbing" the dot at the center with your mouse and pulling it. See below for an example.
Another more precise way to determine the location of the projection region is to double click on it and pop-up the projection control box. In that window you can set the coordinates of the end-points of the projection and its thickness. This will come in very handy when we want to extract exactly the same pixels from the Dark, Flat, and Comp that we extracted from the spectrum.
If you want to follow along endter the numbers shown in the box below into your projection region control box AND click "Apply."
Select the projection region graph window and while in that window select "Save As" from the "File" menu. For the purpose of this tutorial we will save the 1D extraction from spectrum.fit as spectrum.txt.
Next follow steps 1 through 3 to extract the same set of pixels from the Dark (dark.fit), Flat (flat.fit), and Comparison (comp.fit) that you extracted from spectrum.fit. IT IS CRITICAL that the extractions of the Dark and Comparison have the same parameters (see the screenshot of the window in step #2) that you used for spectrum.fit. You want to make sure that the first pixel in each extraction refers to the same pixel on the CCD in the spectrum, Dark, and Comparison images.
Below are the extractions from each image that I got. You can compare these with your files to make sure that you are on the right track.
The next step should be familiar to those of you who have done a lot of CCD imaging or photometry. The spectrum.txt extraction still contains the "dark current" for the CCD pixels. We need to subtract that using the dark.txt extraction.
To do this just load spectrum.txt and dark.txt into a spreadsheet program (i.e. Microsoft Excel) and subtract the values in dark.txt from the cooresponding rows in spectrum.txt. Save this file as spectrum.darksub.txt. An example of the result is below.
The dark has already been subtracted from the Flat and Comparison provided in this tutorial. This demonstrates and excellent point. If the software you use to take the CCD images with your spectrograph allows you to subtract a dark from your spectrum.fits, then you can go ahead and apply the dark that way. That will yeild exactly the same results as the procedure that we have followed here.
This step is completely optional. As explained before, you do not need to flat-field your spectrum unless you need to do an flux calibration (which is not necessary for most measurements).
If you were doing normal CCD image reductions you would divide the Flat image (that is also dark subtracted) directly into your object image at this point. With spectroscopy we do not divide flat.txt directly into spectrum.darksub.txt. Doing that directly could increase the noise in your reduced spectrum by up to a factor of 1.4.
Instead you should fit a low-order polynomial to flat.txt as a function of CCD row in the extraction. How you fit this function is up to you. If I was doing this, I would use the "fit" function in gnuplot. But you could just as easilly read it into Microsoft Excel and fit a polynomial to it. When you do that, it is worthwhile to check (and fine tune) the fit of your ploynomial by plotting it with the flat.txt data and seeing how well it matches.
For this flat, a best fit of a sixth order polynomial yeilds the equation: f(x) = (3922.31) + (11.1949)*x + (0.0328195)*x^2 + (-7.287e-5)*x^3 + (6.3027e-8)*x^4 + (-2.5858e-11)*x^5 + (3.9247e-15)*x^6
The values in this function have to be normalized before you do anything with it. If you divide the unmornalized function above into your numbers in spectrum.darksub.txt, it will make all your y-axis values ridiculously small. There are many ways to normalize a function like this. What I'll do here is take the value of flat.txt at the mid point (around column 1009) and divide that into the function (f(x)). The normalization value for this example is 16579.
Once you have the ploynomial fit, comput its value in each row and divide that number into spectrum.darksub.txt and produce the file spectrum.flat.txt. The you can check you own results against the file linked below.
The data used in this example is flawed to illustrate a point. It shows that flattening a spectrum might not be helpful. Not that the dip in the flat between column 500 and 1000 is not fit by the polynomial. This means that dip (which is probably due to contamination on the CCD, i.e. ice crystals condensing) is not removed from the spectrum by flattening. However, notice that the flat might be helpful for identifying these "dents" in the spectrum that are instrumental rather than in your observed source. When you start measuring your spectrum you are going to have to keep this in mind: which features in it are instrumental effects.
For this part you are going to need to plot the text file of XY points that you extracted from your 2D image. We are going to assume that you know how to use the package you select to read in and plot the points in a text file.
Open up and plot comp.txt. You should produce a graph similar to the screenshot shown below. This is a typical Mercury-Argon spectrum that the Barber Observatory uses to calibrate our spectra.
You may find it useful to zoom in on a part of the graph to see the coordinate of the peak of each emission line. OR alternatively you can find the peak by examining the numbers you are plotting. Your next task is to identify the lines in this spectrum and measure their line centers (in CCD row number). The spectrum below has been annotated with the wavelengths of each line.
It may take some practice with your spectrograph and comparison source to learn how to identify the lines in your comparison spectrum. But once you have done it well once the comparison spectrum will only shift around on the CCD, it will not change too much.
Here is a table of the expected wavelengths and CCD column where they appear for the example in this tutorial:
Fit a function to the pairs of rows you measured and known wavelengths. Normally a second or third order polynomial fit is sufficient. Now you know which row number corresponds to which wavelength. A linear fit to the data in the table above gives: (wave) = 746.503 + 0.03259 (pixel)
You can use this function in a spreadsheet to change the row numbers in spectrum.darksub.txt into wavelengths. An example of the finished file (spectrum.final.txt) is here.
You now have a text file which contains XY points for your spectrum where X is the wavelength and Y is the relative flux. Most programs for measuring spectra will accept a spectrum in that form. Now you can start doing science!
To recap, this tutorial is intended to cover only the basics of what needs to be done to a CCD image from your spectrograph in order to get it ready to do science. You will probably find this procedure too cumbersome and interactive to do it with each and every one of your spectra but it should help you understand the flow and method enough to write your own software or start using the canned software that came with your spectrograph more effectively. Hopefully there is also value in understanding how to do it yourself bare-knuckled if you had to.
Last Modified: April 26, 2021