Stacking Process

After reducing, calibrating, and performing photometry on data, we are finally able to stack. Stacking, in short, consists of aligning and literally stacking images of like fields on top of one another to increase flux and depth.

The file stack.txt contains an overview of the steps involved in stacking, for quick reference later. I will explain here, in greater detail, the procedures.

Correct for Airmass and Setup Files for Aligning the images
1. Add the new image's *.mag.1 to the file called image.list (or generate a brand new one). For each galaxy/filter combination the location of the center.mag.1 file will indicate the beginning of a new galaxy/filter/ set of individual *.mag.1 files:

galaxies/BK03N/wiro/center.mag.1
galaxies/BK03N/wiro/V/a052_apr22232012.mag.1
galaxies/BK03N/wiro/V/a053_apr22232012.mag.1

2. Run the code align.pro. This program creates a file called "scale.cl" which has IRAF scripts to scale the images for the appropriate airmass. Copy and paste into an IRAF terminal for the directory /data/stack/. This program also create *.txt files in the "galaxies/GALAXY/TELESCOPE/FILTER/ directory with the center and image pixel values of all 5 stars from the photometry steps. These pixel values will be used by an IRAF task to shift each image to that of the center image.


Align Images
The following steps will align your images around the center image you chose.
The following steps will align your images around the center image you chose.
1. Change to the galaxies/GALAXY/TELESCOPE/FILTER/ direcotry.
2. Enter into a terminal: ls *.txt > ToCoordinates.list
3. Enter into iraf: geomap @ToCoordinates.list Coordinates.list 1 xpix 1 ypix ; where x/ypix are the size of your image. Hit "q" in the Textronic window to cycle through all the images. IMPORTANT!! Watch carefully as the Textronic window cycles through the images. The small plus signs should stay in relatively the same place, and the grid of lines should remain basically horizontal and vertical. If the grid becomes askew (you'll know), or if the plus signs suddenly move around, something's wrong. It usually means that you accidentally hit spacebar on the wrong star during phot, or you spacebar'd the stars in the wrong order. Go back and redo those photometry steps.
4. Enter: ls /data/photometry/GALAXY/TELESCOPE/FILTER/*A.fit > ToAlign.list. Obviously, update this line for whatever field/filter with which you're working.
5. Enter: cp ToAlign.list Aligned.list. Open up Aligned.list and add "A" at the end of all file names. All names should have an "S" at the end of them; this stands for scaled and "A" is for aligned.
6. Enter into iraf: geotran @ToAlign.list @Aligned.list Coordinates.list @ToCoordinates.list.
14. Go through the newly aligned images by entering "prevu @Aligned.list" (prevu.cl can be found in my photometry section) into iraf. Press spacebar to cycle through the images. If you place a region circle on a star, you will be able to check if the images are truly aligned. If the star moves around, the alignment failed.
Summary of Lines to Enter:
see stack.txt at the beginning of this page.

Stack Images
To stack the images, all you need to do is combine them using imcombine, using certain parameters. The most important of these is hsigma. Normally, the default hsigma works fine. However, every once in awhile you'll get a field whose stack looks very streaky or grainy. If this is the case, remake the stack with increasingly higher values of hsigma, beginning at 3 and going up in increments of 0.1. Keep going up until the streaking/graininess disappears. You can be pretty liberal with this; continue going higher until you're absolutely sure all streaking and graininess are gone. NOTE: There was one case I ran into where, instead of increasing hsigma, I had to increase lsigma. This should rarely, if ever, happen, but if higher and higher hsigmas don't seem to be working, perhaps consider trying to tweak lsigma. Also, once you reach a good hsigma value the image will not change significatly.

Here's the imcombine command to enter into iraf (leave out the hsigma parameter at first):
  • imcombine @Aligned.list stack.fit combine=average reject=avsigclip weight=@weighting.bin lthresh=INDEF hthresh=INDEF hsigma=3.2
  • Repeat the above alignment and stacking steps for the other filters

    Add WCS Coordinates to Header
    This final task adds WCS coordinates to the headers of the images. Unlike alignment and stacking, you only need to do this set of steps once (i.e., once for each galaxy).

    1. Load the "gasp" package in iraf. This can be found in "stsdas" followed by "analysis."
    2. Open all .txt files (i.e., "FAVORITE EDITOR" *.txt &). Clicking through these, you'll notice that the first two columns are always the same, while the second two columns differ for each file. These columns are coordinates of the stars you chose for photometry: the first two columns are the coordinates of the center image, and the second two columns are the coordinates of each specific image. Keep these open.
    3. Load stack.fit into frame 1 of ds9 (i.e., disp stack.fit 1), and load the corresponding DSS image in frame 2 (i.e., disp ../../../fields/dss/w19[0] 2). Remember to use [0] when displaying the DSS images. NOTE: !!!Your stack.fit should be flipped to match the dss image!!! The dss image is orientated North-up, East-left; the standard convention. If you flip the dss image to match the stack.fits image your image will not be orientated correctly. Fiddle with the zoom on each image until you can blink the images and be able to map, by eye, a star from your stack to the corresponding star in the DSS image.
    4. You now need to examine the DSS image and mark the stars that correspond to the stars used in photometry. To do this, type "imexam logfile=dss.txt keep+". This prepares a file called "dss.txt" that will record each keystroke within imexam. Look at the first two columns of a .txt file (they should still be open). For each pair of coordinates, find the star to which they point in your stack image, press "tab" to move to the DSS image, and press "a" on the corresponding DSS image star. Do this for all five stars, then quit out of imexam. NOTE: Because the DSS image is somewhat offset from your stacked image, if one of your stars is somewhat close to the edge, it will be out of the frame in the DSS image. You DO NOT need to go back and do everything. This step merely lines up the two images, and using the five stars you used before is done strictly out of convenience. So just choose another star. But REMEMBER which star it is, because in a step below, you will have to enter its coordinates (by using phot on the star IN THE IMAGE YOU USED AS THE CENTER) in a file.
    5. Enter the following into iraf, remembering to update the DSS image. This will create a file called dss.coords:

  • xyeq iminfo=yes image=../../../fields/dss/w19[0] xy=dss.txt pix_center=iraf xcol=1 ycol=2 nskip=2 orig=yes new=no ra_h=yes ra_f=%h dec_f=%h > dss.coords

    6. You must now create a new file, called ccmap.in. Into this file you will paste four columns: the first two columns will be the first two columns of any .txt file; and the second two columns will be the RA and DEC columns of dss.coords. No columns headers are needed; only five lines of text, one per star. After doing this, you can close dss.coords, ccmap.in, and all .txt files. NOTE: If you had to use a different star in step 4, use phot on your center image to get its coordinates, and put these in the proper place in your ccmap.in table. Note that you only need to replace the X and Y coordinates of the star; you can still use the RA and DEC in dss.coords. (For example, if your second star was out of frame and you replaced it, the first two columns in the second row will be the X and Y coordinates of your new star.)
    7. Last step. Enter into iraf:
  • ccmap input=ccmap.in database=ccmap.database images=stack.fit lngunits=hours latunits=degrees results=ccmap.out update=yes interactive=no
  • change directory to the other filters in this galaxy and enter into iraf:
  • ccmap input=../"DIRECTORY YOU CREATED ccmap.in"/ccmap.in database=ccmap.database images=stack.fit lngunits=hours latunits=degrees results=ccmap.out update=yes interactive=no

    IMPORTANT!! Each of those lines will display some text in the iraf window. Towards the bottom of this text, in a section entitled "Coordinate mapping parameters," there will be a line that enumerates the pixel scale ("X and Y scale"). MAKE SURE IT'S CLOSE TO the pixscale you expect (0.523"/pix for WIRO). It doesn't need to be exact, but if it's off by, say, 0.004 or more, it should warrant examination of your steps to see if anything went wrong.

    8. Ok, I lied, one more step. But this one's trivial. Update your reduction status web page for your collaborators to enjoy.
    Summary of Lines to Enter:
    found in stack.txt in the beginning of this page.