Cosmic rays accumulate linearly in time. If you have exposures longer than five minutes, then you may need to clean out the cosmic rays. Note that this step is done after flat-fielding, but before any image shifting, registration, co-adding, etc.
   There are a variety of ways to remove cosmic rays. Particularly convenient for our purposes is the IRAF 'xzap' task. This lives in the stsdas.dimsum package. (If you are running your own private IRAF installation you will need to install STSDAS and Dimsum.) If you load that package you will not see xzap listed, but you can still edit the parameters and run the task in the usual way.
   The default parameters for xzap look like this:
I R A F
Image Reduction and Analysis Facility
PACKAGE = dimsum
TASK = xzap
inlist = Image(s) for cosmic ray cleaning
outlist = Output image(s)
(zboxsz = 5) Box size for zapping
(nsigma = 5.) Number of sky sigma for zapping threshold
(nnegsig= 0.) Number of sky sigma for negative zapping
(nrings = 0) Number of pixels to flag as buffer around CRs
(nobjsig= 2.) Number of sky sigma for object identification
(skyfilt= 15) Median filter size for local sky evaluation
(skysubs= 1) Block averaging factor before median filtering
(ngrowob= 0) Number of pixels to flag as buffer around obje
(statsec= ) Image section to use for computing sky sigma
(deletem= no) Delete CR mask after execution?
(cleanpl= yes) Delete other working .pl masks after execution?
(cleanim= yes) Delete working images after execution?
(verbose= yes) Verbose output?
(unzap = no) Unzap using objects from OBJmask files?
(checkli= yes) Check min and max pix values before filtering?
(zmin = -32768.) Minimum data value for fmedian
(zmax = 32767.) Minimum data value for fmedian
(inimgli= )
(outimgl= )
(statlis= )
(mode = al)
You should change "deletem" to "yes". Other than this, the only parameters
you will need to adjust are "inlist", "outlist", "zboxsz", "nsigma", and
"statsec".
   Each image to be cleaned must be done separately. Begin by examining the image in the image display. Make sure you are zoomed in far enough that you are seeing all the pixels; you may need to use the panner to move around because the image will not all fit in the display window. You are looking for a region, not very near the edge of the image, if possible, that that contains nothing-- no sources, no cosmic rays, only blank sky and ordinary statistical noise. A region of about 10,000 pixels (e.g., 100 x 100) will do nicely. Make a note of the pixel coordinates of the lower left and upper right corners, and use a text editor to make a file containing these coordinates in IRAF image section format. For example, suppose you are cleaning n1021.fits, and you have decided that the rectangular region with the lower left corner at (200,500) and upper right corner at (299,599) will be your sky section. Then the file n1021.skysec (or whatever name you like) should contain the single line
[200:299,500:599]If you are cleaning multiple images of the same object, you should try to pick the sky sections in the same general region.
   Next, edit the task parameters. Set the "inlist" to the image name. (Don't use a list to clean a batch of images in one pass.) Set the "outlist" to something appropriate. Some people like to label their zapped images with an initial "z" (zn1021.fits); others like to put a "z" or a "cl" (cleaned) at the end (n1021cl.fits). Try 7 for the box size, and leave the nsigma threshhold at 5. Finally, the "statsec" should be the name of the file containing the sky section for this image, preceded by an @ sign. (You can also simply type the image section into this slot; but if you have it in a file you automatically have a record of what you did.) Run the task.
   Now this is the important part. You have to do a careful examination of the cleaned image to make sure that the cosmic rays---and only the cosmic rays---have been removed. Display the original and cleaned images in different image buffers, with the same z1 and z2 parameters, and blink them. Zoom in and move around the images, and look at what has been changed. If xzap has done too little or too much cleaning, you will have to adjust the "zboxsz" and "nsigma" parameters and try again. These are the sorts of things you do not want to see: