22 from __future__
import absolute_import, division, print_function
24 __all__ = [
"SnapPsfMatchConfigDF",
"SnapPsfMatchConfigAL",
"SnapPsfMatchConfig",
"SnapPsfMatchTask"]
27 from .psfMatch
import PsfMatchConfigDF, PsfMatchConfigAL
28 from .imagePsfMatch
import ImagePsfMatchTask, ImagePsfMatchConfig
32 """Delta-function Psf-matching config optimized for snap subtraction""" 35 PsfMatchConfigDF.setDefaults(self)
47 """Sum-of-Gaussian (Alard-Lupton) Psf-matching config optimized for snap subtraction""" 50 PsfMatchConfigAL.setDefaults(self)
59 kernel = pexConfig.ConfigChoiceField(
62 AL=SnapPsfMatchConfigAL,
63 DF=SnapPsfMatchConfigDF
68 doWarping = pexConfig.Field(
70 doc=
"Warp the snaps?",
75 ImagePsfMatchConfig.setDefaults(self)
78 self.
kernel.active.spatialKernelOrder = 0
81 self.
kernel.active.fitForBackground =
False 84 self.
kernel.active.kernelSize = 7
87 self.
kernel.active.spatialKernelClipping =
False 99 \anchor SnapPsfMatchTask_ 101 \brief Image-based Psf-matching of two subsequent snaps from the same visit 103 \section ip_diffim_snappsfmatch_Contents Contents 105 - \ref ip_diffim_snappsfmatch_Purpose 106 - \ref ip_diffim_snappsfmatch_Initialize 107 - \ref ip_diffim_snappsfmatch_IO 108 - \ref ip_diffim_snappsfmatch_Config 109 - \ref ip_diffim_snappsfmatch_Metadata 110 - \ref ip_diffim_snappsfmatch_Debug 111 - \ref ip_diffim_snappsfmatch_Example 113 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 115 \section ip_diffim_snappsfmatch_Purpose Description 117 \copybrief SnapPsfMatchTask 119 This Task differs from ImagePsfMatchTask in that it matches two Exposures assuming that the images have 120 been acquired very closely in time. Under this assumption, the astrometric misalignments and/or 121 relative distortions should be within a pixel, and the Psf-shapes should be very similar. As a 122 consequence, the default configurations for this class assume a very simple solution. 124 . The spatial variation in the kernel (SnapPsfMatchConfig.spatialKernelOrder) is assumed to be zero 126 . With no spatial variation, we turn of the spatial clipping loops (SnapPsfMatchConfig.spatialKernelClipping) 128 . The differential background is _not_ fit for (SnapPsfMatchConfig.fitForBackground) 130 . The kernel is expected to be appx. a delta function, and has a small size (SnapPsfMatchConfig.kernelSize) 132 The sub-configurations for the Alard-Lupton (SnapPsfMatchConfigAL) and delta-function (SnapPsfMatchConfigDF) 133 bases also are designed to generate a small, simple kernel. 135 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 137 \section ip_diffim_snappsfmatch_Initialize Task initialization 139 Initialization is the same as base class ImagePsfMatch.__init__, with the difference being that the Task's 140 ConfigClass is SnapPsfMatchConfig. 142 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 144 \section ip_diffim_snappsfmatch_IO Invoking the Task 146 The Task is only configured to have a subtractExposures method, which in turn calls 147 ImagePsfMatchTask.subtractExposures. 149 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 151 \section ip_diffim_snappsfmatch_Config Configuration parameters 153 See \ref SnapPsfMatchConfig, which uses either \ref SnapPsfMatchConfigDF and \ref SnapPsfMatchConfigAL 154 as its active configuration. 156 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 158 \section ip_diffim_snappsfmatch_Metadata Quantities set in Metadata 160 See \ref ip_diffim_psfmatch_Metadata "PsfMatchTask" 162 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 164 \section ip_diffim_snappsfmatch_Debug Debug variables 166 The \link lsst.pipe.base.cmdLineTask.CmdLineTask command line task\endlink interface supports a 167 flag \c -d/--debug to import \b debug.py from your \c PYTHONPATH. The relevant contents of debug.py 168 for this Task include: 174 di = lsstDebug.getInfo(name) 175 if name == "lsst.ip.diffim.psfMatch": 176 di.display = True # enable debug output 177 di.maskTransparency = 80 # ds9 mask transparency 178 di.displayCandidates = True # show all the candidates and residuals 179 di.displayKernelBasis = False # show kernel basis functions 180 di.displayKernelMosaic = True # show kernel realized across the image 181 di.plotKernelSpatialModel = False # show coefficients of spatial model 182 di.showBadCandidates = True # show the bad candidates (red) along with good (green) 183 elif name == "lsst.ip.diffim.imagePsfMatch": 184 di.display = True # enable debug output 185 di.maskTransparency = 30 # ds9 mask transparency 186 di.displayTemplate = True # show full (remapped) template 187 di.displaySciIm = True # show science image to match to 188 di.displaySpatialCells = True # show spatial cells 189 di.displayDiffIm = True # show difference image 190 di.showBadCandidates = True # show the bad candidates (red) along with good (green) 191 elif name == "lsst.ip.diffim.diaCatalogSourceSelector": 192 di.display = False # enable debug output 193 di.maskTransparency = 30 # ds9 mask transparency 194 di.displayExposure = True # show exposure with candidates indicated 195 di.pauseAtEnd = False # pause when done 197 lsstDebug.Info = DebugInfo 201 Note that if you want addional logging info, you may add to your scripts: 203 import lsst.log.utils as logUtils 204 logUtils.traceSetAt("ip.diffim", 4) 207 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 209 \section ip_diffim_snappsfmatch_Example A complete example of using SnapPsfMatchTask 211 This code is snapPsfMatchTask.py in the examples directory, and can be run as \em e.g. 213 examples/snapPsfMatchTask.py 214 examples/snapPsfMatchTask.py --debug 215 examples/snapPsfMatchTask.py --debug --template /path/to/templateExp.fits --science /path/to/scienceExp.fits 218 \dontinclude snapPsfMatchTask.py 219 First, create a subclass of SnapPsfMatchTask that accepts two exposures. Ideally these exposures would have 220 been taken back-to-back, such that the pointing/background/Psf does not vary substantially between the two: 221 \skip MySnapPsfMatchTask 224 And allow the user the freedom to either run the script in default mode, or point to their own images on disk. 225 Note that these images must be readable as an lsst.afw.image.Exposure: 229 We have enabled some minor display debugging in this script via the --debug option. However, if you 230 have an lsstDebug debug.py in your PYTHONPATH you will get additional debugging displays. The following 231 block checks for this script: 236 \dontinclude snapPsfMatchTask.py 237 Finally, we call a run method that we define below. First set up a Config and choose the basis set to use: 241 Make sure the images (if any) that were sent to the script exist on disk and are readable. If no images 242 are sent, make some fake data up for the sake of this example script (have a look at the code if you want 243 more details on generateFakeImages; as a detail of how the fake images were made, you do have to fit for a 244 differential background): 248 Display the two images if --debug: 252 Create and run the Task: 256 And finally provide optional debugging display of the Psf-matched (via the Psf models) science image: 258 @until result.subtractedExposure 260 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 262 ConfigClass = SnapPsfMatchConfig
266 templateFwhmPix=None, scienceFwhmPix=None,
268 return ImagePsfMatchTask.subtractExposures(self,
269 templateExposure=templateExposure,
270 scienceExposure=scienceExposure,
271 templateFwhmPix=templateFwhmPix,
272 scienceFwhmPix=scienceFwhmPix,
273 candidateList=candidateList,
274 doWarping=self.config.doWarping,
The parameters specific to the "Alard-Lupton" (sum-of-Gaussian) Psf-matching basis.
The parameters specific to the delta-function (one basis per-pixel) Psf-matching basis.
Configuration for image-to-image Psf matching.
Psf-match two MaskedImages or Exposures using the sources in the images.
def subtractExposures(self, templateExposure, scienceExposure, templateFwhmPix=None, scienceFwhmPix=None, candidateList=None)
Image-based Psf-matching of two subsequent snaps from the same visit.