Aligning and stacking images - anjavdl/PHY517_AST443 GitHub Wiki

Often, we want to ``co-add'' images to create an image with higher signal-to-noise, or align images in different bands to make a color image. In both cases, we need to resample the original images to a new, common pixel grid, meaning that the mapping between (x,y) and `(RA,Dec)` needs to be the same. Note that in general, this cannot be done simply with re-indexing the pixel coordinates, rather, flux from the original pixels needs to be redistributed over several new pixels.

For any alignment or stacking of images, you first need to add the astrometric solution to the image headers, i.e. run astrometry.net.

SWarp

Combining images (single-filter case)

Resampling images can be done with swarp. The easiest case is to combine a list of images (taken of the same object, in the same filter); this is as easy as:

swarp *.fits

where *.fits should expand to a list of the images that you want to co-add. This will output a coadded image coadd.fits and a weight file coadd.weight.fits, where the latter is a map of how many input images contributed to an output pixel.

SWarp works with a configuration file, which can be edited, or keywords can be changed on-the-fly on the command line, just as in Source Extractor. For example, to change the name of the output images, you can call it as:

swarp *.fits -IMAGEOUT_NAME custom_name.fits -WEIGHTOUT_NAME custom_name.weight.fits

By default, SWarp will perform a median-coadd, i.e. a given output pixel is the median of the input pixels. The keyword to change this behavior is COMBINE_TYPE. Consult the manual to see alternative options. Also note that if you have created a bad pixel map, SWarp can use this when co-adding (i.e. ignore pixels with zero weight in the combination).

Running Source Extractor on combined images

You will probably want to run Source Extractor on the combined image. For best results, you need to tell Source Extractor the effective exposure of each pixel, which you can do with the weight map that SWarp created (by default, coadd.weight.fits). For example, the call to Source Extractor would be:

sex coadd.fits -WEIGHT_IMAGE coadd.weight.fits -WEIGHT_TYPE MAP_WEIGHT

You can then filter the resulting catalog by the Source Extractor extraction FLAGS.

Aligning images (multiple-bands case)

To resample, but not coadd images, turn off coadding with the COMBINE keyword:

swarp *fits -COMBINE N

which will create a resampled image for every input image, with the same name, but the ending .resamp.fits (instead of .fits). For example, if you have taken images of an object in multiple bands (e.g. BVR), you would run all of them through swarp in one call, as above; this ensure that they are all pixel-matched. You would then combine all the B-band images to a coadded B-band image, all the V-band images to a coadded V-band image, and all the V-band images to a coadded V-band image (in this step, the pixels should not be resampled again, but simply combined pixel-by-pixel, you can do this in swarp with RESAMPLE N or in python). The coadded BVR images are then pixel-matched, which will make it easy to make color images in ds9, or in python.

Python package

Instead of using SWarp, you can use the reproject package in python.