23 __all__ = [
"SnapPsfMatchConfigDF",
"SnapPsfMatchConfigAL",
"SnapPsfMatchConfig",
"SnapPsfMatchTask"]
26 from .psfMatch
import PsfMatchConfigDF, PsfMatchConfigAL
27 from .imagePsfMatch
import ImagePsfMatchTask, ImagePsfMatchConfig
31 """Delta-function Psf-matching config optimized for snap subtraction""" 34 PsfMatchConfigDF.setDefaults(self)
46 """Sum-of-Gaussian (Alard-Lupton) Psf-matching config optimized for snap subtraction""" 49 PsfMatchConfigAL.setDefaults(self)
58 kernel = pexConfig.ConfigChoiceField(
61 AL=SnapPsfMatchConfigAL,
62 DF=SnapPsfMatchConfigDF
67 doWarping = pexConfig.Field(
69 doc=
"Warp the snaps?",
74 ImagePsfMatchConfig.setDefaults(self)
77 self.
kernel.active.spatialKernelOrder = 0
80 self.
kernel.active.fitForBackground =
False 83 self.
kernel.active.kernelSize = 7
86 self.
kernel.active.spatialKernelClipping =
False 98 @anchor SnapPsfMatchTask_ 100 @brief Image-based Psf-matching of two subsequent snaps from the same visit 102 @section ip_diffim_snappsfmatch_Contents Contents 104 - @ref ip_diffim_snappsfmatch_Purpose 105 - @ref ip_diffim_snappsfmatch_Initialize 106 - @ref ip_diffim_snappsfmatch_IO 107 - @ref ip_diffim_snappsfmatch_Config 108 - @ref ip_diffim_snappsfmatch_Metadata 109 - @ref ip_diffim_snappsfmatch_Debug 110 - @ref ip_diffim_snappsfmatch_Example 112 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 114 @section ip_diffim_snappsfmatch_Purpose Description 116 @copybrief SnapPsfMatchTask 118 This Task differs from ImagePsfMatchTask in that it matches two Exposures assuming that the images have 119 been acquired very closely in time. Under this assumption, the astrometric misalignments and/or 120 relative distortions should be within a pixel, and the Psf-shapes should be very similar. As a 121 consequence, the default configurations for this class assume a very simple solution. 123 . The spatial variation in the kernel (SnapPsfMatchConfig.spatialKernelOrder) is assumed to be zero 125 . With no spatial variation, we turn of the spatial clipping loops (SnapPsfMatchConfig.spatialKernelClipping) 127 . The differential background is _not_ fit for (SnapPsfMatchConfig.fitForBackground) 129 . The kernel is expected to be appx. a delta function, and has a small size (SnapPsfMatchConfig.kernelSize) 131 The sub-configurations for the Alard-Lupton (SnapPsfMatchConfigAL) and delta-function (SnapPsfMatchConfigDF) 132 bases also are designed to generate a small, simple kernel. 134 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 136 @section ip_diffim_snappsfmatch_Initialize Task initialization 138 Initialization is the same as base class ImagePsfMatch.__init__, with the difference being that the Task's 139 ConfigClass is SnapPsfMatchConfig. 141 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 143 @section ip_diffim_snappsfmatch_IO Invoking the Task 145 The Task is only configured to have a subtractExposures method, which in turn calls 146 ImagePsfMatchTask.subtractExposures. 148 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 150 @section ip_diffim_snappsfmatch_Config Configuration parameters 152 See @ref SnapPsfMatchConfig, which uses either @ref SnapPsfMatchConfigDF and @ref SnapPsfMatchConfigAL 153 as its active configuration. 155 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 157 @section ip_diffim_snappsfmatch_Metadata Quantities set in Metadata 159 See @ref ip_diffim_psfmatch_Metadata "PsfMatchTask" 161 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 163 @section ip_diffim_snappsfmatch_Debug Debug variables 165 The @link lsst.pipe.base.cmdLineTask.CmdLineTask command line task@endlink interface supports a 166 flag @c -d/--debug to import @b debug.py from your @c PYTHONPATH. The relevant contents of debug.py 167 for this Task include: 173 di = lsstDebug.getInfo(name) 174 if name == "lsst.ip.diffim.psfMatch": 175 di.display = True # enable debug output 176 di.maskTransparency = 80 # ds9 mask transparency 177 di.displayCandidates = True # show all the candidates and residuals 178 di.displayKernelBasis = False # show kernel basis functions 179 di.displayKernelMosaic = True # show kernel realized across the image 180 di.plotKernelSpatialModel = False # show coefficients of spatial model 181 di.showBadCandidates = True # show the bad candidates (red) along with good (green) 182 elif name == "lsst.ip.diffim.imagePsfMatch": 183 di.display = True # enable debug output 184 di.maskTransparency = 30 # ds9 mask transparency 185 di.displayTemplate = True # show full (remapped) template 186 di.displaySciIm = True # show science image to match to 187 di.displaySpatialCells = True # show spatial cells 188 di.displayDiffIm = True # show difference image 189 di.showBadCandidates = True # show the bad candidates (red) along with good (green) 190 elif name == "lsst.ip.diffim.diaCatalogSourceSelector": 191 di.display = False # enable debug output 192 di.maskTransparency = 30 # ds9 mask transparency 193 di.displayExposure = True # show exposure with candidates indicated 194 di.pauseAtEnd = False # pause when done 196 lsstDebug.Info = DebugInfo 200 Note that if you want addional logging info, you may add to your scripts: 202 import lsst.log.utils as logUtils 203 logUtils.traceSetAt("ip.diffim", 4) 206 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 208 @section ip_diffim_snappsfmatch_Example A complete example of using SnapPsfMatchTask 210 This code is snapPsfMatchTask.py in the examples directory, and can be run as @em e.g. 212 examples/snapPsfMatchTask.py 213 examples/snapPsfMatchTask.py --debug 214 examples/snapPsfMatchTask.py --debug --template /path/to/templateExp.fits --science /path/to/scienceExp.fits 217 @dontinclude snapPsfMatchTask.py 218 First, create a subclass of SnapPsfMatchTask that accepts two exposures. Ideally these exposures would have 219 been taken back-to-back, such that the pointing/background/Psf does not vary substantially between the two: 220 @skip MySnapPsfMatchTask 223 And allow the user the freedom to either run the script in default mode, or point to their own images on disk. 224 Note that these images must be readable as an lsst.afw.image.Exposure: 228 We have enabled some minor display debugging in this script via the --debug option. However, if you 229 have an lsstDebug debug.py in your PYTHONPATH you will get additional debugging displays. The following 230 block checks for this script: 235 @dontinclude snapPsfMatchTask.py 236 Finally, we call a run method that we define below. First set up a Config and choose the basis set to use: 240 Make sure the images (if any) that were sent to the script exist on disk and are readable. If no images 241 are sent, make some fake data up for the sake of this example script (have a look at the code if you want 242 more details on generateFakeImages; as a detail of how the fake images were made, you do have to fit for a 243 differential background): 247 Display the two images if --debug: 251 Create and run the Task: 255 And finally provide optional debugging display of the Psf-matched (via the Psf models) science image: 257 @until result.subtractedExposure 259 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 261 ConfigClass = SnapPsfMatchConfig
265 templateFwhmPix=None, scienceFwhmPix=None,
267 return ImagePsfMatchTask.subtractExposures(self,
268 templateExposure=templateExposure,
269 scienceExposure=scienceExposure,
270 templateFwhmPix=templateFwhmPix,
271 scienceFwhmPix=scienceFwhmPix,
272 candidateList=candidateList,
273 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.