Making a Twilight Flat Field Frame


As before, begin by copying the raw data over from the archive into a working directory:

me> cp /data/mega1/Archive/rawdata/data/ARCHMEGACAM/2005.0630/skyflat*.fits .

Check that none of the twilight flats have exposure times below 0.05 sec, and that none of the twilight flats are close to saturation with pixel values close to 64,000. Frames satisfying either of these two conditions must not be used.

me> imhead skyflat.*.fits[im1] long+ | grep EXPTIME
me> mscstat skyflat.*.fits

This would also be a good time to double-check the commlog.ps file to make sure the weather was good enough to construct reliable flats. Moderate cloud cover will make twilight flats useless. However, if only very thin cirrus is present, it is *possible* to get good flatfields -- we tried this successfully during the 2007 June Megacam run. Clear skies are definitely strongly recommended however.

After deleting any bad frames, overscan correct, trim, and zero-subtract the twilight flats as follows:

me> ccdproc skyflat*.fits overscan+ trim+ zerocor+ zero="Zero.fits"
me> addbpm skyflat*.fits bpmaskdir = "megacam$Badpix/"
me> ccdproc skyflat*.fits fixpix+

Correct for throughput errors that arise for frames having exposure times below 1.0 second

me> imhead skyflat*.fits[im1] | grep EXPTIME # to check if shutcorr is needed
me> shutcorr skyflat*.fits corrfile="megacam$shut20050605m.fits"

Mask out bright stars, if they are present (inspect)

me> nproto
np> set masktype = pl
np> ls skyflat.*.fits > om.twiflat.list
np> vi om.twiflat.list # (to change ".fits" --> "om" on all lines)
np> objmask.ngrow=3
np> objmask.hsigma=10
np> objmask skyflat.*.fits objmasks = "@om.twiflat.list" ldetect-

It is possible for u', g', and r' frames to use objmask.hsigma=5; this is not advisable for exposures having obvious fringing however.

Some updating of the headers will then be required to assign the OBJMASK keywords in all the extensions to the .pl files just created

np> mscstat skyflat*.fits fields="image" format- > fixpix_skyflat
np> cp fixpix_skyflat fixpix_skyflat2
np> vi fixpix_skyflat2
:1,$ s/]/.pl/
:1,$ s/.fits./om\//
:wq
np> !paste fixpix_skyflat fixpix_skyflat2 | awk '{printf "hedit %s BPM %s add+ update+ verify- delete-\n",$1, $2}' > hedit.macro
np> cl < hedit.macro
np> fixpix @fixpix_skyflat BPM
np> bye

Next, check to ensure that the text file called 'subsets' contains only single-letter designations for filters in the second column. For example, the entries for the u' filter in this file ought to look like the following, with only a single-character designation for the filter in the second column (other filters would be represented similarly):

'gblk,u' u
'u,gblk' u
'u' u

Visually inspect at least one of the masks to make sure they're correct. Then combine them with flatcombine as follows. flatcombine is smart enough to segregate the data by wavelength, so you need not do this multiple times:

me> flatcombine skyflat*.fits output = "Flat" reject="sigclip" combine="average"

This procedure ought to be iterated once so that relatively faint objects in flattened twilight flats can be masked; the resulting masks can then be applied to the original twilight exposures and an improved twilight flat generated. This can be tested by flattening individual skyflats.

Check that the twilight flat is named Flatu.fits instead of, e.g., Flatu,gblk.fits. Rename it appropriately if necessary. This should not be needed if the subsets file is set up before running flatcombine. If necessary, Change the image header to get rid of the gblk ( this example for filter="g")

me> msccmd "hedit $input FILTER g update+ verify- add- del-" Flatg.fits

Once you're satisfied that the flat is good, delete all the dreg skyflat files from the current directory and the Raw/ subdirectory.

me> del skyflat*.fits; del Raw/skyflat*.fits
me> !"rm" -r skyflat*om

Last modified November 2, 2007.