Image Calibration (Bias, Dark, Flat Correction)

Start up AstroImageJ. There's more information at the AstroImageJ tutorials. You can find the journal paper on AstroImageJ here.

Put your bias frames in one directory, darks in another directory, flats in another directory, and science images in another directory. If there are data from multiple filters, segregate flats and science images in different filters to different directories (filters do not affect biases or darks, so there will just be one directory for each of these image types).

1. In AstroImageJ, click on the red and blue **DP** icon. Two windows should open---a "DP Coordinate Converter" window and a "CCD Data Processor" window.
2. In the "DP Coordinate Converter" window:
	* Select "Michigan State Univ Obs" from the Observatory ID drop-down menu.
	* In your web browser, look up your object on the SIMBAD website. Find the source's J2000 equatorial coordinates on the SIMBAD page. Back in AstroImageJ, type the coordinates in the boxes next to the SIMBAD icon (under the "J2000 Equatorial" label). Press Enter.
3. Check out your bias, darks, and flats to make sure they all look good. The simplest way to do this is to characterize them statistically.
	* A bias frame should have a mean value of 1481 counts and a standard deviation of ~5.7 counts.
	* A dark frame should have a bit higher counts than a bias frame, and a higher standard deviation. The longer the dark is exposed for, the more counts should be collected.
	* A flat frame should have a mean count value between 15,000 and 50,000 counts. Make sure it is not saturated (this will begin happening above 55,000 counts).
	* To actually measure statistics of a bunch of images in your directory, go the main AstroImageJ window/Menu, select the "Process" drop-down menu, and under that "Batch > Measure". You can then select a directory with images in it, and statistics will be provided for all images in that directory.
	* You can select what statistics are displayed by going to the "Analyze" drop-down menu in the main AstroImageJ window/Menu. Select "Set Measurements". I like to select
		+ 'Area' (how many pixel there are in an image);
		+ 'Standard Deviation' (the standard deviation of pixel values in the image, in units of counts);
		+ 'Min & Max gray value' (the minimum pixel value and maximum pixel value, in units of counts);
		+ 'Mean gray value' (the average pixel value);
		+ 'Median' (the median pixel value);
		+ 'Display label' (this will list the image name).
4. Delete any biases, darks, or flats that look flawed, based on your inspection in #3.
5. In the "CCD Data Processor" window, uncheck 'Enable' and 'Build' wherever it is checked on left side of window.
6. In the "CCD Data Processor" window, go to the 'View' menu and select "Show master calibration images".
7. In the "CCD Data Processor" window, let's create a **master (averaged) BIAS frame:**
	* Click 'Build' just below Bias Subtraction (do not select 'Enable').
	* Select 'ave' rather than 'med'.
	* Select the appropriate directory where your raw biases are stored, by clicking on the blue folder icon under the 'Directory' column, in the first row of the 'Bias Subtraction' subsection. Navigate to the relevant folder, and click 'Choose'.
	* Also click on the blue folder to the right, which is for "Filename/Pattern"; click on one of the files in the bias directory and then click 'Open'. Back in the "CCD Data Processor" window, make sure the number to the far right, under "Totals", corresponds to the number of biases in your directory.
	* In the following row, click on the blue folder icon and select the same directory as where the biases are stored; this is where the master bias will be saved.
	* To the right, give the image name that will be assigned to the combined bias (e.g., masterbias.fits).
	* Finally, click 'START' at the bottom of the "CCD Data Processor" window. A log file should pop up; if nothing went wrong, it should say the master bias was saved.
	* Check the master bias you've just created---it should look like the individual bias frames, but be slightly less noisy.
8. Next it is time to create a **master DARK:**
	* Activate the “Enable” option under “Bias Subtraction”.
	* Deactivate the "Build" option under "Bias Subtraction".
	* Select the “Build” option under "Dark Subtraction”.
	* Enable the “deBias” option under "Dark Subtraction”.
	* Select "ave" (not "med") under "Dark Subtraction”.
	* As you did when creating the master bias, use the blue folder icons to select the darks folder, and the darks filenames.
	* Click 'START' and make sure you didn't get any errors.
	* Check the master dark you've created---it should look similar to individual dark frames, but with slightly lower noise. It should also have much lower average counts, because the bias frame has been subtracted from it.
9. Now create a **master FLAT:**
	* Activate the “Enable” option under  “Bias Subtraction”.
	* Activate the “Enable” option under “Dark Subtraction”.
	* Activate the “scale" option under “Dark Subtraction”.
	* Deselect "Build" under "Dark Subtraction".
	* Keep "deBias" checked under "Dark Subtraction".
	* Activate the “Build” options under “Flat Division”.
	* Activate the ‘med’ option under “Flat Division”.
	* Select the appropriate flat directory and filenames using the blue folder icons. When you name the master flat, make sure you include the name of the filter.
	* Click 'START', and check for errors.
	* Look at your master flat. It should have an average value of 1 (because it has been normalized to have an average value of 1!). It should also have less (fractional) noise than an individual flat frame.
10. Repeat previous steps (the creation of the master flat) for additional filters, if you are working with more than one filter.
11. For making the **final images:**
	* Activate the “Enable” and "Sort Num" options under Filename Pattern Matching.
	* Select the “Enable” option under  “Bias Subtraction”.
	* Select the “Enable” , “scale” and ‘deBias’ options under  “Dark Subtraction”.
	* Select the “Enable” option under “Flat Division" and deselect "Build".
	* Activate the “General” option under “FITS Header Updates”.
	* Activate the “Enable” and "32" options (not "16"!) under "Save Calibrated Images”.
	* Click on the blue folder icon under 'Filename Pattern Matching' to select the raw\_data directory.
	* Make sure the selected master flat matches the filter of the raw data (under "Flat Division"), if you are dealing with more than one filter.
	* Under "Save Calibrated Images", give a sub-directory name in the Sub-dir window, specifying the filter of the data you are currently working on (if more than one).
	* Click 'START'. AstroImageJ should flash your science data at you, now bias-, dark-, and flat-corrected.
	* Look at the images. You want the nasty flat pattern (e.g., cross hatch pattern, dust donuts) to be gone from your science images. If there are still remnants of it, something probably went wrong, and you should try again or reach out to Laura or Lilia.
	* You'll want to look at the individual images of your science target, just to make sure none of them look terrible---say if the telescope moved and everything is just streaks. If some images are bad, you'll want to delete them before proceeding to photometry (please don't delete the originals; only cull copies in a directory where you are actively working on data reduction).
12. Repeat step #11 for other filters, if applicable.
13. Now you are ready to measure the light curve of your star with photometry!