Makee: Matching Spectra Levels with "spim2"

Abstract:
This page describes a method of matching or equalizing continuum levels between orders and exposures using "spim2".


Gathering Together All Observations

It is recommended that you start by creating a new directory for each object you are combining, and copy all the individual Flux-###.fits and Err-###.fits reduced spectrum files to this new directory. If you have conflicting observation numbers from different observing runs, it is easiest to just add 900 or 800 to some of the observation numbers and rename the Flux-###.fits and Err-###.fits files.

Step 1: Copy individual reduced spectrum files to a new directory for your object.


Equalizing Observations and Overlapping Orders

In order to use a program like   combine   to average together many exposures, the spectra must be "equalized" such that every wavelength point is a measure of the same value. That is, the continuum levels of all overlapping orders must all match within the level of the noise.

Usually, one would hope that flux calibration of the spectral response using a standard star would do this for us, however, accurate flux calibration of echelle spectra is often difficult or impossible. There are particular problems with the response function across orders of the Keck HIRES instrument in that this function appears to be dependent upon telescope elevation, although the source and nature of this effect has not been well investigated.


Approximate Template Spectrum Strategy

If you had a complete continuous one dimensional spectrum of your source, you could use this template to ``flux calibrate'' each order of each individual observation by scaling the orders to match the template. Unless you've observed your object previously with Keck, you probably do not have a high enough S/N spectrum to use as a template. However, you can use your current HIRES data to create an approximate template spectrum.

The advantage to making an ``approximate'' spectrum first (rather than going directly to your final spectrum) is that you can do such things as throw out large chunks of data, add directly observations with similiar setup angles, and even interpolate or extrapolate parts of the spectra.

Step 2: Use opim to add together individual observations.
Example:
opim add Flux-015 Flux-016 a.fits
opim ade Err-015 Err-016 ae.fits
opim add Flux-143 Flux-144 a.fits
opim ade Err-143 Err-144 ae.fits

(Note: Later programs will recognize (filename)e.fits as the error spectrum to (filename).fits .)

(Note: it may be a good idea to write small script files which execute your commands. That way, you can see later what commands you executed and you can re-create your procedure later, if necessary.)


Using spim2 to View 2-D Spectra

The program spim2 is a PGPLOT plotting program which uses the "pgdisp" window to allow the user to interactively view multiple 2-D spectrum files order by order and show the overlapping portion of spectra from adjacent orders.

Step 3:
Example: spim2 a b

The program reads in ae.fits and be.fits as the error spectra. The primary order of the primary spectrum is shown in white, the secondary spectrum (primary order) is shown in red, data from adjacent orders are shown in a multitude of colors. The primary order of the primary error spectrum is shown as a white dotted line. You can control many features of the display (similiar to   xplot  ) -- hit the ``?'' key for a list of key command options. For example, use ``b'' to rebin the data, use ``x'' to change how much of the adjacent orders are shown, use the ``+'' and ``-'' keys to flip through the echelle orders, use the left-mouse-button to control the horizontal plot limits, and use ``w'' to show the whole plot range.


Matching Adjacent Orders

Next, you need to match the ends of adjacent orders to the same level. You will do this one spectrum at a time. To view just the primary spectrum hit the ``0'' key (toggle). (The second spectrum will be used to help scale the orders.)

Now you may want to go through the spectrum and delete any obvious cosmic rays or bad portions of the spectrum which may mess up the order overlap scaling. You can do this by hitting ``m'' twice while moving the cursor. The data will be set to zero, and the error to -1.0; these data points will be ignored.

Next, use ``S'' to compute a re-scaling solution to line up the echelle orders. Enter the primary and secondary image numbers (i.e. ``1,2'') (this is NOT the observation number.) Enter ``2'' to rescale each increasing row (or echelle order number), and then a reference row (i.e.``1''). (Note: spim2 scales each successive row to the previous row, this may cause a runaway scaling effect, which is probably unavoidable.).

Next, you will see a set of scaling factors vs. row number. You can fix bad points manually by entering ``1''. Enter ``9'' to apply the rescaling factors to your spectrum. View your spectrum, you can manually scale a row by using the ``$'' key command.

Repeat the last few steps for the secondary spectrum. Make the secondary spectrum the primary spectrum by the ``6'' key command. Use ``S'' again, but this time enter ``2,1'' instead of ``1,2''.

Go through both spectrum and clip off the ends that do not match using ``m''. You can be fairly bold, remember that you are only making a template spectrum at this stage.

Scale the two observations to match each other using the ``M'' key. Enter 1,2 or 2,1. Fit a polynomial by entering 1 and a polynomial order and then rescale the data and return to the main menu by entering 3. Use the ``0'' to view both spectra. The two spectra and all their orders should now be at the same level (within the noise). Check to see how well the data match and mask any bad regions.

Exit spim2 by hitting "ESC" and save the changed data.


Creating the Continuous, One-dimensional Template Spectrum

You can now use   combine   to create the template spectrum.

Step 4:
Example: combine a b of=temp -loglin disp=2.1

(Note: In this example, the spectrum is created with a log-linear scale such that each pixel is 2.1 km/s wide.) Use   xplot   to view the template spectrum and its error. This spectrum will look essentially the same as the final result, but to combine the data properly, we must scale each order of each observation to this template and then combine all the re-scaled individual observations.


Scaling Individual Observations and Orders to Template

Before scaling the individual observations, change the filenames so as not to get them to confused with the original reduced spectra files. The data in these new filenames will be scaled and modified. (NOTE: You should have copies of the originals in another directory.)

Step 5:
Example:
mv Flux-015.fits F-015.fits
mv Flux-016.fits F-016.fits
mv Err-015.fits E-015.fits
mv Err-016.fits E-016.fits

(NOTE: The programs will understand that the file ``E-015.fits'' is the error file for ``F-015.fits''.) Run spim2 with each of the individual observations and the (big) one-dimensional template spectrum.

Step 6:
Example: spim2 F-015 big=template

The template spectrum will appear in blue in the plot window (but it may be scaled off the plot). For the low S/N orders, you may want to increase the binning. Use the ``g'' key to divide the template by the 2-D spectrum for the row (echelle order) displayed. (Note, You will asked for a "min_reject" value which is a level below which pixels are ignored expressed as a fraction of the median level before division, suggested value is 0.05.) Choose a region (``w'' for whole range) and choose a polynomial order. Use ``o'' to select a different polynomial order. Use ``m'' and ``w'' to multiply the whole row of the 2-D spectrum by the fit. You can fit another polynomial to division, or quit (``q''). Repeat this process for each row (echelle order). You can speed up this process using the ``v'' key command, which will divide the data, fit an 8th order polynomial, multiply, and return to the main menu.


Under construction...






Back to makee home page.