=head1 NAME fitsio_subtract - WCS or pixel-based difference imaging software =head1 SYNOPSIS B I I I I I [B] =head1 DESCRIPTION B is a generic program for forming pixel or WCS-based difference images of the input FITS files, optionally using and creating confidence maps I, I . If present the catalogue FITS binary table files are used to define the list of stellar images to base the optimisation on, including overall flux scaling and further coordinate refinement. The software has options for doing a straightforward subtraction, with scaling derived from the flux ratio of matching stellar images in the two catalogue files, or from doing a full adaptive kernel matching subtraction. The (differential) astrometry can either be pixel-based ie. assuming both images are already aligned, or more generally uses the WCS information in the header images to derive and implement an internal differential coordinate transformation, which is further refined using a differential pixel-based algorithm basedon the catalogue x,y information. The differential background variation between the images can be optionally mapped out as part of the optimisation. Single or multi-extension input FITS images may be processed. The source catalogue FITS binary tables must match in number the extensions of the input image. Pixel matching, either WCS-based or X-Y grid-based, currently uses a simple bilinear interpolation scheme which we have in practice to gives excellent reliable results for this type of operation. Switchable adpative kernel plugins and alternative interpolation schemes have been incorporated as subroutines to test different image subraction methodologies. In addition to the inbuilt difference image algorithms, versions of the Alard and Lupton adaptive kernel algorithm (used by the Eurpoean SNe Consortium - http://supernovae.in2p3.fr/) have also been implemented for trialling. Refinements and further improvements from these comparisons have now been built into the native code, obviating the need for switchable plugins. =head1 BACKGROUND Image subtraction, or difference imaging, methods are used in several diverse branches of astronomy covering: transient event detection (eg. SNe, NEAs); variability monitoring in crowded stellar fields (eg. detection of transiting planets, stellar variability, microlensing); continuum subtraction for narrow-band imaging. The common problems for all these cases are: alignment of the different images; tracking and removing non-astronomical background changes; scaling the fluxes of objects to optimally match; and allowing for differences in effective seeing between the images. The main advantange of difference imaging is that it greatly simplifies subsequent analysis and can lead, for example, to much more accurate differential photometry. The main disadvantage is that it is difficult to accurately match images taken in different conditions. Adaptive kernel techniques (see Alard and Lupton 1998 ApJ 503 325 for more details) have gone a long way toward removing this limitation but their implementation and practical robust use is still an open question. Consequently we have written this image subtraction software package to test out these techniques and include full use of confidence maps, which are crucial for many applications. =head1 OPTIONS The following arguments are required: =over =item I Standard FITS images either single or multiextension are supported. These are comma separated with the convention that the second map is to be subtracted from the first and the level of the first retained (sky) or set to zero (zerosky). =item I Comma separated FITS binary table catalogue files matching the 2D images in type and order. These must be standard CASU-style catalogue files. If no catalogue files are available and just straightforward image subtraction is required the argument "nocats" should be used. =item I Use the implict WCS imformation in the files, or base the subtraction on the pixel locations as are. Note that if catalogues are supplied the differential pixel positions derived from the WCS are automatically updated using a 6 constant linear fit. =item I The file for the resulting difference image(s). This will use the WCS and other header information from map1 to define the structure and size of the output file. Map1 pixels lying outside of the range of map2 are set to the "average" sky level in map1. =item I There are 8 options which can be specified as a combination of: simple - adaptive, back - noback and sky - zerosky. I uses no adaptive kernel matching, whereas I does. Likewise the switch I causes differential background tracking and removal to take place, while I leaves the differential background alone. Finally, the switch I cause the output map sky to be set to zero, otherwise it is left at the average level on the input comparison frame. The most generally useful option is I which has a built in rationale to select the simplest (ie. lowest order) adaptive kernel solution that gives the best (in terms of mmse) results. For example, if the seeing is well-matched between the images this option may still choose to use the equivalent of the I methodology. The following arguments are optional: =item I Uses the confidence maps from I in the analysis where each input map has to have assigned its own confidence map (even if they are the same). The output confidence map is a simple combination of the two input image confidence maps renormalised to a median value of 100 before output. =back =head1 EXAMPLES Subtract r-band continuum image from H-alpha image without using confidence maps and using the catalogue files to help set the relative image scaling. Use no adaptive kernel matching and leave backgrounds untouched. fitsio_subtract halpha.fit,r-band.fit halpha_cat.fits,r-band_cat.fits \ wcs=y out.fit simple/noback/sky Subtract two g-band images with adaptive kernel matching enabled and with differential background removal enabled. Leave sky set to average level in comparison image and make use of confidence maps. fitsio_subtract gband1.fit,gband2.fit gband1_cat.fits,gband2_cat.fits \ wcs=y diff.fit adaptive/back/zerosky \ g_conf.fits,g_conf.fits g_conf_diff.fits Simple one-to-one subtraction using no scaling, background correction, wcs or confidence maps. fitsio_subtract gband1.fit,gband2.fit nocats wcs=n diff.fit \ simple/noback/sky =head1 AUTHOR Mike Irwin (mike@ast.cam.ac.uk) =cut