CCD Reduction

Getting Started -- Changing the Default File Type
Combining Bias Images
Combining Dark Frames
Combining Flats
Arithmetic Operations with imarith Reducing CCD Images Using imarith
CCD Reduction with ccdproc Changing Fits Headers
Using ccdproc
A Note on Errors

Getting Started -- Changing the Default File Type

Once you have taken all of your images and have transferred them to your computer, you will have to reduce them in order to get rid of background noise due to bias, dark, and flats. But first, you will need to set IRAF to handle fits files as default. Otherwise you will have to use the rfits command (See UNM Tutorial). In order to change the default, type in these steps:

show imtype IRAF will print the type of image that is set as the default. It will probably print "imh" the first time you try this.
set imtype="fits,noinherit" This will set the default image type to fits files. When you process images, IRAF will automatically spit out a fits file.

Be sure to execute these commands at the cl prompt, or else it will not work correctly.

If you want IRAF to always have fits files set as the default, you can alter your login file.

  1. In the Unix command window, move into your iraf directory.
  2. Type ls. There will be a file called "login.cl". Open it in emacs by entering emacs login.cl &
  3. Look for the section, # Uncomment and edit to change the defaults. Underneath, on the last row, will be the parameter for image type.
  4. Change the last row to read set imtype = "fits,noinherit". Be sure to delete the "#" sign, or else this will not work.
  5. Press Ctrl+x Ctrl+s to save, then Ctrl+x Ctrl+c to exit.
  6. Open up iraf and check the image type. It will print "fits,noinherit".

To display images, enter:
display filename frame The file you have chosen will be displayed in the DS9 window. The frame parameter is a number which indicates which frame you want the image to pop up in. This way, you can have multiple images open. (See the DS9 Guide for more information.) If you don't enter a number, IRAF will prompt you for one. If you're not concerned about having more than one image open at a time, just choose "1" each time.

Combining Bias Images

In order to combine your bias images, you will have to use the task zerocombine. The first thing you should do is move into the appropriate directory. When you open IRAF, you are located in your iraf directory. Inside the IRAF command window, you can use Unix commands to navigate to other folders. Use the cd command to move to different folders until you find the location of your bias frames. If you ever have to refer to a certain image that is not in the current directory, you will have to specify the path. (../ is often useful).

You now have to open the correct packages to run zerocombine. Enter imred, and then ccdred and you will be set.

Now, set the following parameters by typing epar zerocombine:

input You can set this in the parameters, or IRAF will automatically prompt you for a list of files to combine. (To create lists, see the UNM Tutorial)
You can also choose a series of images (ex: bias1, bias2, bias3, etc) by typing in the characters your images start with, then star (ex: bias*). It is a good idea to think ahead when creating filenames so that you won't have to make lists.
output IRAF will not prompt you to name the output file, so you will have to set it in the parameters. Luckily, IRAF will not write over files with the same name, so if you accidentally forget to change it, don't worry!
A quick, easy way to fix this is to enter output=filename when you enter the command. That way, you will not always have to return to the parameter listing each time you run zerocombine.
combine="average"
reject="minmax"
ccdtype="none" This is very important
Zerocombine will look for images with IMAGETYP=zero in the fits header. However, images from Brackett Observatory do not contain an IMAGETYP header, so unless you set ccdtype to "none", zerocombine will not work on your images. Alternatively, you can create an IMAGETYP parameter for your bias images and set it to "zero". See Changing Fits Headers in the CCD Reduction with ccdproc section.
Ctrl+d exits the edit parameters section

Don't worry about the other parameters. They will already be set to appropriate values.

The next thing you should do is run zerocombine. IRAF will prompt you for the files to combine. If you entered these filenames in the parameters section, they will be shown in parentheses. If you want these filenames to be used, just press enter. Otherwise, just type in the files you want. IRAF will then list the files that are being combined, and a few statistics on them. Once it is done, the command prompt will appear again. Type ls and you should be able to see the new image.

To run zerocombine without being prompted, you can enter:

zerocombine input

Combining Dark Frames

For combining dark images, use the task darkcombine. This can be accessed by entering imred and then ccdred from the cl prompt.

Check the parameter settings by entering epar darkcombing at the prompt:

combine="average"
reject="minmax"
ccdtype="dark" IRAF will look for IMAGETYP=dark in the fits header or else it will not process the images.
If you have changed the fits headers (See Changing Fits Headers), you can leave this parameter alone. If your fits headers are not labeled correctly, just change this parameter to "none".
process="no" If processing is turned on, then the task ccdproc will be called on to subtract bias frames from your dark.
If you are going to be using ccdproc later, this setting should definitely be turned off, or else the bias will be subtracted from your dark image a second time.
It is up to you whether or not you want the output dark to be bias subtracted or not. Keep in mind that ccdproc will subtract the bias from all of your dark frames and then save the subtracted image over the original. You will have to edit the parameter listing for ccdproc in order to select the bias frame. (See Ccdproc)
scale="none" The default will be set to scale by exposure time.
If you have images from Brackett Observatory, the fits headers will contain the exposure time. Images taken with V++ at Table Mountain will not. If you want your dark current to be scaled by exposure time, you will have to edit the fits header. (See Changing Fits Headers)
If you decide to scale the dark by exposure time, you will have to have the bias subtracted. (You can do this by turning the "process" option on.) Otherwise, the bias will end up being scaled, too. Once again, keep in mind that running ccdproc with the resultant darks will cause the bias to be subtracted again; you have to be very careful.

Once you have the parameters editted, you can enter:

darkcombine input output=output
at the prompt. A list of the images being combined will be shown, along with some statistics.

Combining Flats

To combine flat images, use the task flatcombine. This can be opened from the same package as zerocombine. From the cl prompt, just enter imred and then ccdred. Once again, be sure that you are located in the appropriate directory to access your files. If you are not, you will have to indicate a path in order to get to them.

Next, edit the parameters by entering epar flatcombine:

input You don't have to indicate a list of input files. IRAF will automatically prompt you.
An easy way to bypass the prompt is to enter the names of the files you want to combine when you enter the command, like so: flatcombine filenames*
output IRAF will not prompt you for an output filename when you enter the command. However, you can enter output=filename when you enter the command to prevent having to alter the parameter listing every time.
ccdtype="none" IRAF will look for images with IMAGETYP=flat in the fits header unless you change this option to "none".
Alternatively, you can edit the fits headers and leave this setting to "flat". (See Changing Fits Headers)
combine="median" The median option is good for combining flats, because it eliminates large counts from bright early evening/early morning stars.
reject="none" This controls the reject algorithm for processing the images. However, "none" is a good option because you can be sure that a median is being taken for every pixel.
scale="mode" For flats, scaling will help even out any effects of non-uniform light. Light from twilight or dawn is fairly even, but it is still a good precaution. You will definitely need to use the scaling option if you are using screen or dome flats.
Ctrl+d exits the edit parameters section

Don't worry about the other parameters. They will already be set to appropriate values.

Now you can enter flatcombine and IRAF will prompt you for input files. If you entered these filenames in the parameters section, they will be shown in parentheses. If you want these filenames to be used, just press enter. Otherwise, just type in the files you want. IRAF will then list the files that are being combined, and a few statistics on them. Once it is done, the command prompt will appear again. Type ls and you should be able to see the new image.

To run imcombine without being prompted, just enter:

imcombine input output=output


Now you need to divide your averaged flats by the mean number of counts for the whole image. This will create a normalized flat. When you divide your raw image by the normalized flat, it is equivalent to dividing it by the combined flats and multiplying by the mean.

To find the mean value for your flats, enter imstat filename. IRAF will print statistics for the image. (You can also run the command on a list of images.) Note the MEAN values.

Next use imarith to divide the averaged flats by their mean values.

Arithmetic Operations with imarith

The imarith task can be run from the cl prompt, and consequently can be opened from any other package. Do not worry about adjusting the parameters for imarith, because IRAF will prompt you for the appropriate parameters.

Enter imarith to receive the following prompts:

Operand image or numerical constant: enter a list of images or a single image that you want to modify
Operator (+|-|*|/|min|max): pick which operation you want to perform.
Operand image or numerical constant: Enter the filename or path for the image you want to use to reduce the raw image.
If you are working with bias, enter the bias filename; with flats, enter the flat filename. If you are creating a normalized flat, enter the mean value.
Resultant image: Enter the filename you want the reduced image to be given
If you are reducing multiple images at once, there is an easy way to add prefixes to each filename on the list. For example, if you want add the letter z to the beginning of each modified file, enter z//filenames. In general, whatever was entered in the first prompt should be entered behind the z// in this last prompt.


To run imarith without having to be prompted, enter:

imarith operand1 operator operand2 result

You can enter any number of the parameters. You will be prompted for the parameters that aren't entered.

Reducing CCD Images Using imarith

When you are ready to reduce your CCD images completely:

  1. Subtract your averaged bias frame from your images.
  2. Subtract your dark frame from your images. Be sure that the exposure times are the same. (If you are using a dark frame that has not been bias subtracted, you can skip the first step.)
  3. Divide the resultant images by the normalized flat frames.

CCD Reduction with ccdproc

The task ccdproc can be accessed by opening the packages imred and then ccdred. You can use this command to process images without having to use multiple steps with imarith. First create your averaged bias and flat frames. Before you can run ccdproc, you will have to create and set an IMAGETYP parameter for your frames. Like zerocombine, ccdproc will only work with certain image types, but you can not turn this feature off.

Changing Fits Headers

There are four possibilities for the IMAGETYP header: zero, flat, object, and comp. To create and change this header, you will use the task ccdhedit, which can be accessed from the same packages as ccdproc. Be sure that you are in the correct directory, or that you know the path to the images you want to modify. Enter ccdhedit to receive the following prompts:

CCD images: You can choose one or more images to edit.
Image header parameter: Enter IMAGETYP
Parameter value: Enter one of the four image types that you want for the selected images


A shortcut for editing images:

hedit filename parameter=value add+

where filename are the images you want to edit, parameter is the part of the header you want to edit (ex:IMAGETYP), and value is how you want to set the parameter (ex:object)

Here are some other useful commands for playing with fits headers:

imhead filename prints a short version of the fits header
imhead filename l+ prints the full fits header
ccdlist filenames prints short version of fits header for all of the selected images

If you intend to use ccdproc for dark subtraction, all of your images will have to have an exposure time in the fits header so that ccdproc can scale the dark frame. (If you don't, an error will come up and it won't work.) There is no way to turn this off. If you are using images from Table Mountain, you will have to add the exposure times. Create a parameter called EXPTIME. For the value, write the exposure time in scientific notation. (For example, a 30 second image will have EXPTIME=3.000e+001 in the fits header.)

Using ccdproc

Make sure that you have opened the packages imred and ccdred

Enter epar ccdproc to set the following parameters:

images Enter the images you want to correct. IRAF will prompt you for this parameter anyway.
output You will not be prompted for the output filename, and if nothing is entered IRAF will overwrite the original file. If you want to keep your backup, be sure to enter an output filename.
If you are reducing multiple images at once, there is an easy way to add prefixes to each filename on the list. For example, if you want add the letter z to the beginning of each modified file, enter z//filenames. In general, whatever was entered in the first prompt should be entered behind the z// in this last prompt.
oversca="no" The CCD chip from Brackett and Table Mountain do not have overscan sections, so make sure that this property of ccdproc is turned off
zerocor="yes" Turns bias correction feature on
darkcor="no" Images from Brackett are often Autodarked, so you don't need to worry about dark correction. If you are using images from Table Mountain, and you have measurable dark current, you might want to turn this feature on.
flatcor="yes" Turns flat correction feature on
Be sure that the other correction types are set to "no"
zero enter the path or filename for the averaged bias frame
dark enter the path or filename for the combined, non bias-subtracted, dark image
flat enter the path or filename for the combined (not normalized!!) flat frame
Ctrl+d exits the edit parameters section

Ccdproc will not prompt you for anything besides the input files. It is best to run epar ccdproc anytime you wish to run ccdproc to be sure everything is set up right.

To run ccdproc without being prompted, enter:

ccdproc filenames


When reducing several groups of images, another way to utilize the parameters is to turn bias, dark, and flat correction on, but leave the parameters where you would normally enter the filenames empty. (Just type "" at the parameter.) Then, when you enter the command for ccdproc, you can add flat=flatname dark=darkname flat=flatname. This way, you don't have to open the parameter file all the time.

When ccdproc starts running (assuming you have bias, dark, and flat correction on), the following will occur:
  1. The bias frame will be subtracted from the image
  2. The bias frame will be subtracted from the dark
  3. The dark frame will be subtracted from the image
  4. The bias frame will be subtracted from the flat
  5. The dark frame will be subtracted from the flat
  6. The image will be divided by the flat (and normalized)
  7. The next image will be processed by subtracting the bias, then dark, then dividing and normalizing by the flat. This happens until all of the images are processed.
You have to be careful of several things: the dark and flat images must be raw. You should not run images that have already been bias or dark subtracted through ccdproc. Ccdproc will also alter some of the images in this process. (You can look in the long version of the fits header to see if the image has been altered. If it has, there will be a note saying that it was processed with ccdproc, with the date and time. A record of what occured in ccdproc will be deposited in the folder where it occured. You can also look there for more details.)

If you are processing with the dark, all of your images must have exposure times. Ccdproc will scale them, and if exposure times are not present, an error will occur.

It is easy to mess up on small details when reducing images. Be careful, and once you have determined a process (whether using imarith or ccdproc or both), stick to it.

A Note on Errors

"ERROR:segmentation violation" is an all-purpose error. It is possible that you have accidentally entered a filename that doesn't exist. Check your path, directories, and spelling to be sure that you have entered a valid filename.

Another cause for this error may be due to Unix's case-sensitive nature. If the images you are trying to combine are titled *.FIT, you will have to change them to *.fit. IRAF will not process them otherwise.

If you are using lists, check what is inside. If there is an object which is not an image file, there is your problem. (Be careful when using * to select images for a list. You might accidentally include something you did not intend to.)

If you get, "* is not an image or a number", you probably have not entered a valid filename. Check to be sure you did not mispell or point to an incorrect directory.

If you get a "no images to combine" error, it may be due to the IMAGETYP parameter in the fits files. If you are trying to run zerocombine or ccdproc, check that the IMAGETYP is set correctly or set ccdtype equal to "none" in the parameters for zerocombine.

This error will also occur when you have not set the default image type to "fits,noinherit". Go to the cl prompt and enter show imtype to be sure that you have fits files set as default.

If you get, "Warning: Cannot open image", you have entered an incorrect filename or path. Check for spelling and correct path.