Tutorials
- In my tutorials, I first explain what I am doing, then show the format of what you should type( these are preceded by cl>) and then give an example. At the end, there will be a full example for easy modification. Reminder- there may be steps that need to be completed between the typed parts.

- Aligning Images
- Editing Images
- Sky Subtraction
- Smoothing Images





Aligning Images


1. Display each image in a different frame

     cl> disp <imagename> <frame #(1-4)>
     example - disp n69461AOR.phot.1.fits 1

     (note-one image should be your reference image and all the others will be aligned to it.)


2. Pick three or four reference points using the green circle(just click where you want the circle) so that each point can be easily spotted in each image.


3. Now, use imexam to write the coordinates of each ref point to a text file.

     cl> imexam <imagename> keep+ logfile=<newtextfile.txt>
     example - n69461AOR.phot.1.fits keep+ logfile=6946a.txt

     now go back to the ds9 and type 'a' after pointing the cursor on each ref point. When done, hit 'q' to return to the terminal. Do this for each file making sure to hit the points in the same order.


4. The important information in these new text files will be the first two columns of numbers. they are the xcor and ycor for each star. Delete all the extra info. you need to combine the info into one text file. the first two columns should be the coordniates from the reference image. the format is
     xref yref xcor ycor
     xref yref xcor ycor

     ...and so on depending on how many ref point and images you have. shortcut...copy the coordinates from the second text file <ctrl> <c> and paste onto the first using <ctrl> <shift> <v> to paste in column form. save the new file as something other than your original logfiles.

     example - 6946c.txt


5. Use geomap to create another txt file to use in geotran. First, use imheader to find the parameters of the reference image

     cl> imhead <imagename>
     example- imhead n69461AOR.phot.4.fits

     the info you need will be in the first pair of [ , ].

cl> geomap <filewithallcoor> <newtextfile.txt>1 <first parameter> 1 <second paramter>
example - geomap 6946c.txt 6946map.txt 1 1799 1 1211

     hit q in the pop up IRAF window, showing the propsed transformation to return to the terminal.

6. Using geotran


geotran <imagename> <newimagename.fits> <newtext.txt> <filewithallcoords>
example - n69461AOR.phot.4.fits 6946_4_new.fits 6946map.txt 6946c.txt

The newly aligned image is the newimage.fits example - 6946_4_new.fits


7. Subtract sky from each image(tutorial available)


Composite of all examples-

cl> disp n1377_v03.1.1_dr.fits 1 zr- zs- z1=0.1 z2=10
disp n1377_v03.1.4_dr.fits 2 zr- zs- z1=0.1 z2=10
imexam n1377_v03.1.1_dr.fits keep+ logfile=n1377a.txt
imexam n1377_v03.1.4_dr.fits keep+ logfile=n1377b.txt
n n1377a.txt &
n n1377b.txt &
imhead n1377_v03.1.1_dr.fits
geomap n1377c.txt n1377map.txt 1 1002 1 482
geotran n1377_v03.1.4_dr.fits n1377_4.fits n1377map.txt n1377c.txt
disp n1377_4.fits 2 zr- zs- z1=0.1 z2=10





Editing Images

1. Display the appropriate image you want to edit and the corresponding colormap withing ds9(not from the command line so you can use wcs coordinates).

  (note-At this time, make sure that the wcs coordinates are the same in both image and colormap, its much easier if they are)


2. Load(or create) source regions so that you know how much of the image you should edit. You dont want to waste time editing stuff you dont need to.


3. Set regions around the sources you want to delete on the colormap.

  Save these regions as a wcs coordinate system region( Region->File Coordinate System->WCS) so if you need to do more than one image of the same source, you don't have to start from scratch.

  Load the regions on to your image that you want to edit.

  Now save them as an image region( Region->File Coordinate System->Image) so that you can load them within imedit.


4. To ensure you can peek 'inside' the galaxy, you need to adjust the scale withing 'display'. Find the approximate sky value on the image(a value on an area where there appear to be no objects).

    cl> epar display

    inside epar display, set
          (zrange = no)display full image intensity range
          (zmask = no) sample mask
          (z1 = approx sky value) minimum greylevel to be displayed
          (z2 = a few above z1) maximum greylevel to be displayed

   hit <ctrl> <D> to exit epar


5. Now you can edit the image with imedit.

  cl> imedit <image to be edited> <new edited image name.fits>
   example - imedit n1291_v03.1.2_dr n1291_4.5.edit.fits

  (note-Make sure to include .fits at the end of your new image name because it will create something different if you don't.)


6.
  -There are several ways to delete objects within imedit. Put the cursor either around or on top of the object and hit the appropriate command.
  -The commands I most comonly use are-
   'a' sky replacement (rectangle) (note-you hit a on two corners diagonal from each other on a rectange around the object)
   'b' sky replacement (aperture) (note-hit command on center of theobject. you can adjust the size of the radius of the aperature by hitting <+> to make it larger or <-> to make it smaller.
   'c' column interpolation (rectangle)
   'l' line interpolation (rectangle)
   'u' undo last change (note-probably the most important one to remember because you can only undo your last change)
   '?' print help (note-there are lots more commands here)
   'q' quit and save changes (note-if you use this, you don't need to save your image manually--thats nice)
   'Q' without saving changes


Composite of all examples-

epar display
imedit n1291_v03.1.2_dr n1291_4.5.edit.fits
(note-There's not a lot of typing envolved in this task. Most of the work is done within imedit.)





Sky Subtraction

1. Display each image.


2. Define various star/galaxy/etc-free (sky) apertures ("regions").

 Use the green circles to define about 4 or 5 sky regions (you don't need to do source regions). To get a region, simply click and drag the cursor until you have the appropriate size apperature.


3. Save the apertures to a file (Region -> save).


4. Edit the file to remove all "image;" and the line that starts with "global" and the line below that.
   crow-1-> n <region file .reg> &
   example - n n1377_1.bg.reg &
   example - n n1377_4.bg.reg &

5. Start up IRAF (in xterm) and get inside the xray and xspatial packages.

   crow-2-> xgterm -sb &
   crow-1-> cl
   cl> xray
  xr> xspatial


6. Now you can use imcnts to get counts per pixels. Imcnts expects you to want to find both a sky and source count, but since we only need the sky, you can do two images at once.

   xs > imcnts <first image name .fits> <first sky region .reg> <second image name .fits> <second sky region .reg> <new file .tab>
   example - imcnts n1377_1.fits n1377_1.bg.reg n1377_4.fits n1377_4.bg.reg n1377.tab


7. Compute the average sky counts/pixel with a program or manually. Its a good idea to check if the numbers you are getting are correct. Go to your image, and run the cursor around a sky region. hopefully, the values you see will be somewhat close to the value you calculated.


8. Subtract your value from the image

   xs > imarith <first image name .fits> - <calculated value> <new image name .fits>
   example - imarith n1377_1.fits - 0.01 n1377_1_new.fits


Composite of all examples-

 n n1377_1.bg.reg &
 n n1377_4.bg.reg &
 xgterm -sb &
 cl
 xray
 xspatial
 imcnts n1377_1.fits n1377_1.bg.reg n1377_4.fits n1377_4.bg.reg n1377.tab
 imarith n1377_1.fits - 0.01 n1377_1_new.fits






Smoothing Images


1. Subract off the sky values. See the sky subtraction tutorial

  cl> imarith <original image.fits> <new sky subtracted image.fits>
   example - imarith /data/sings/irac/n4594_aor1_v03.1.4 - 7.296 /data/sings/irac/n4594_aor1_v03.1.4_skysub.fits

2. Select the portion of the image that has actual values. In other words, cut out those pixels that are beyond the mosaic edges yet still register (x,y) values in DS9.

  cl> imcopy <sky subtracted image.fits>[x-min:x-max,y-min:y-max] <new cutout image.fits>
   example - imcopy /data/sings/irac/n4594_aor1_v03.1.4_skysub.fits[30:1394,39:1010] data/sings/irac/n4594_aor1_v03.1.4_skysub_cutout.fits

3. The next comand is to smooth the image. For this example, I am using a model file. to use a different kind of smooth function, type help imsmooth for more instructions.

  cl> imsmooth <cutout image.fits> <new smoothed image.imh> function=<function type> model_file=<function file location> clobber+
   example -imsmooth /data/sings/irac/n4594_aor1_v03.1.4_skysub_cutout /data/sings/irac/n4594_8.0_conv24.imh function=file model_file="/data/sings/psfs/irac_c4_to_mips_24_75K.fits" clobber+


Composite of all examples-

 imarith /data/sings/irac/n4594_aor1_v03.1.4 - 7.296 /data/sings/irac/n4594_aor1_v03.1.4_skysub.fits
 imcopy /data/sings/irac/n4594_aor1_v03.1.4_skysub.fits[30:1394,39:1010] data/sings/irac/n4594_aor1_v03.1.4_skysub_cutout.fits
 imsmooth /data/sings/irac/n4594_aor1_v03.1.4_skysub_cutout /data/sings/irac/n4594_8.0_conv24.imh function=file model_file="/data/sings/psfs/irac_c4_to_mips_24_75K.fits" clobber+