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