Roy Gal's Notes on SExtractor

SExtractor is a very useful package for photometering images, but it has a number of quirks. There are also details that require attention when it is used on images output by MultiDrizzle. I describe some issues I have encountered, and potential solutions. Many authors have discussed some of these, but rarely if ever all in one place. Thanks to Alexie Leauthaud, Jason Rhodes, Emmanuel Bertin and others for discussing some of these issues with me. Some ideas were also taken from GOODS papers and Benitez et al. 2004.

What should the value of GAIN be set to for MultiDrizzled ACS images? It should be CCDGAIN * exposure_time. Thus, if your ACS images were taken with a CCDGAIN=1, and you have MultiDrizzled 4 exposures of 1000s each, you should set

GAIN 4000.0
You can also check the EXPTIME and CCDGAIN header keywords in your output science image (from MultiDrizzle), and set GAIN in the Sextractor config file to EXPTIME * CCDGAIN.

Running in Dual Image or Pseudo-Dual-Image Mode
SExtractor is capable of detecting objects in one image, while performing photometry on another. This method is called Dual Image Mode, and is especially useful if you construct an ultradeep detection image that combines data in multiple filters (or epochs), and you then measure object magnitudes in a single filter. With this technique, all your objects in all filters can have the same photometry areas, apertures, etc., appropriate for measuring colors, for instance.

To use SExtractor this way, you will probably need:

An important caveat is that these images must all have the same size and cover the same area!


IMPORTANT NOTE REGARDING WEIGHT AND RMS MAPS
Although the mathematical relationship between a weight map and an rms map is simply
weight = 1/(rms^2)
SExtractor does NOT treat these two map types by just converting one to the other using this relation! Instead, it does the following:

Thus, if you have an output weight map from MultiDrizzle, you should convert it to an RMS map!
This can be done easily in IRAF:
cl> imcalc weightmap.fits rmsmap.fits "1/sqrt(im1)" pixtype=double


In your Sextractor configuration file you would then include:

WEIGHT_IMAGE 	detect_rms.fits,measure_rms.fits
WEIGHT_TYPE	MAP_RMS,MAP_RMS
WEIGHT_GAIN	N,N
and execute
% sex -c configfile detection.fits,measure.fits
Or, if you are using an effective exposure time map corresponding to your measurement image:
WEIGHT_IMAGE 	detect_rms.fits,measure_expmap.fits
WEIGHT_TYPE	MAP_RMS,MAP_WEIGHT
WEIGHT_GAIN	N,Y
For images generated with MultiDrizzle, the weight map is output by specifying ERR for final_wht_type. The exposure map can be output by specifying EXP for final_wht_type.

You may also want to run in Pseudo-Dual-Image mode, where the detection and measurement images are the same, but the weight maps used can be different. This is useful, for instance, if you want to detect objects relying on a weight map, but measure them using an exposure time map as a gain map. In this case, you would set

WEIGHT_IMAGE 	detect_weight.fits,detect_expmap.fits
WEIGHT_TYPE	MAP_WEIGHT,MAP_WEIGHT
WEIGHT_GAIN	N,Y
and execute
% sex -c configfile detection.fits,detection.fits

Correcting for correlate noise when using MultiDrizzle images

Regardless of how you run SExtractor, the errors will be incorrect if the images have been MultiDrizzle'd. For details on this, see Casertano et al. 2000. If you have run MultiDrizzle with pixfrac p and scale s, then you should calculate a correction factor

sqrt(F_A) = (s/p)(1-(s/3p)) if s<p
sqrt(F_A) = 1 - p/(3s)      if s>p
NOTE: Here, s is the multiplicative factor applied to the original image pixel scale. For ACS, if your output drizzled image has 0.03" pixels, then s=0.6.
For instance, for HAGGLES, p=0.9 and s=0.6, so √FA=0.51852.
This correction factor needs to be applied to the background noise estimate generated by SExtractor (output to the screen at runtime as the RMS), and therefore to the flux and magnitude errors that are output.
For objects that have Flag=0, the flux error is given by
FLUX_ERR = sqrt( (A*sig^2) + F/g)
where A is the object area, sig is the background RMS, F is the total flux, and g is the gain. NOTE: The value of g is CCDGAIN * total_exposure_time. Unfortunately, even though we know the gain, and we can get the flux from SExtractor, there is no SExtractor output parameter that gives you the total area of an object! So, we have to dissect FLUX_ERR to apply the correction:
A*sig^2 = FLUX_ERR^2 - FLUX/GAIN
FLUX_ERR_CORRECT = sqrt( ((A*sig^2)/F_A) + FLUX/GAIN )
MAG_ERR_CORRECT = FLUX_ERR_CORRECT/FLUX * 2.5/ln(10)
Note that F_A is only an approximation, and if you are using a gain map, then the GAIN is not really a constant either!

SIMPLIFICATION: Simply setting
Err_correct = Err_initial / √FA
yields results very close to the complete derivation.

Making a Flag Image

You can make a complex flag image that uses different values to denote different exposure levels. The below example just sets a binary flag value for areas that are very underexposed (flag=1 if bad).

cl> median ACSJ160449+432050_F814W_wht.fits med_foo.fits 7 7 boundary=nearest
Examine the image, and find the data value below which you wish to flag (say, 500).
cl> stsdas
cl> toolbox
cl> imgtools
cl> imcalc med_foo.fits flag_foo.fits "if im1 .lt. 500. then 1 else 0"
cl> boxcar flag_foo.fits box_foo.fits 7 7  boundary=nearest
cl imcalc box_foo.fits ACSJ160449+432050_F814W_flag.fits "if im1 .gt. 0.2 then 1 else 0" pixtype=int
It is important to set the output pixel type to "int" in the last step - SExtractor expects flag images to contain only integers.