LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Static Public Attributes | List of all members
lsst.ip.diffim.snapPsfMatch.SnapPsfMatchTask Class Reference

Image-based Psf-matching of two subsequent snaps from the same visit. More...

Inheritance diagram for lsst.ip.diffim.snapPsfMatch.SnapPsfMatchTask:

Public Member Functions

def subtractExposures
 

Static Public Attributes

 ConfigClass = SnapPsfMatchConfig
 

Detailed Description

Image-based Psf-matching of two subsequent snaps from the same visit.

Contents

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Description

SnapPsfMatchTask

This Task differs from ImagePsfMatchTask in that it matches two Exposures assuming that the images have been acquired very closely in time. Under this assumption, the astrometric misalignments and/or relative distortions should be within a pixel, and the Psf-shapes should be very similar. As a consequence, the default configurations for this class assume a very simple solution.

. The spatial variation in the kernel (SnapPsfMatchConfig.spatialKernelOrder) is assumed to be zero

. With no spatial variation, we turn of the spatial clipping loops (SnapPsfMatchConfig.spatialKernelClipping)

. The differential background is not fit for (SnapPsfMatchConfig.fitForBackground)

. The kernel is expected to be appx. a delta function, and has a small size (SnapPsfMatchConfig.kernelSize)

The sub-configurations for the Alard-Lupton (SnapPsfMatchConfigAL) and delta-function (SnapPsfMatchConfigDF) bases also are designed to generate a small, simple kernel.

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Task initialization

Initialization is the same as base class ImagePsfMatch.__init__, with the difference being that the Task's ConfigClass is SnapPsfMatchConfig.

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Invoking the Task

The Task is only configured to have a subtractExposures method, which in turn calls ImagePsfMatchTask.subtractExposures.

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Configuration parameters

See SnapPsfMatchConfig, which uses either SnapPsfMatchConfigDF and SnapPsfMatchConfigAL as its active configuration.

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Quantities set in Metadata

See PsfMatchTask

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Debug variables

The command line task interface supports a flag -d/–debug to import debug.py from your PYTHONPATH. The relevant contents of debug.py for this Task include:

1 import sys
2 import lsstDebug
3 def DebugInfo(name):
4  di = lsstDebug.getInfo(name)
5  if name == "lsst.ip.diffim.psfMatch":
6  di.display = True # enable debug output
7  di.maskTransparency = 80 # ds9 mask transparency
8  di.displayCandidates = True # show all the candidates and residuals
9  di.displayKernelBasis = False # show kernel basis functions
10  di.displayKernelMosaic = True # show kernel realized across the image
11  di.plotKernelSpatialModel = False # show coefficients of spatial model
12  di.showBadCandidates = True # show the bad candidates (red) along with good (green)
13  elif name == "lsst.ip.diffim.imagePsfMatch":
14  di.display = True # enable debug output
15  di.maskTransparency = 30 # ds9 mask transparency
16  di.displayTemplate = True # show full (remapped) template
17  di.displaySciIm = True # show science image to match to
18  di.displaySpatialCells = True # show spatial cells
19  di.displayDiffIm = True # show difference image
20  di.showBadCandidates = True # show the bad candidates (red) along with good (green)
21  elif name == "lsst.ip.diffim.diaCatalogSourceSelector":
22  di.display = False # enable debug output
23  di.maskTransparency = 30 # ds9 mask transparency
24  di.displayExposure = True # show exposure with candidates indicated
25  di.pauseAtEnd = False # pause when done
26  return di
27 lsstDebug.Info = DebugInfo
28 lsstDebug.frame = 1

Note that if you want addional logging info, you may add to your scripts:

1 import lsst.pex.logging as pexLog
2 pexLog.Trace_setVerbosity('lsst.ip.diffim', 5)

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

A complete example of using SnapPsfMatchTask

This code is snapPsfMatchTask.py in the examples directory, and can be run as e.g.

1 examples/snapPsfMatchTask.py
2 examples/snapPsfMatchTask.py --debug
3 examples/snapPsfMatchTask.py --debug --template /path/to/templateExp.fits --science /path/to/scienceExp.fits
First, create a subclass of SnapPsfMatchTask that accepts two exposures. Ideally these exposures would have been taken back-to-back, such that the pointing/background/Psf does not vary substantially between the two:
1 class MySnapPsfMatchTask(SnapPsfMatchTask):
2  """An override for SnapPsfMatchTask"""
3  def __init__(self, *args, **kwargs):
4  SnapPsfMatchTask.__init__(self, *args, **kwargs)
5 
6  def run(self, templateExp, scienceExp):
7  return self.subtractExposures(templateExp, scienceExp)

And allow the user the freedom to either run the script in default mode, or point to their own images on disk. Note that these images must be readable as an lsst.afw.image.Exposure:

1 if __name__ == "__main__":
2  import argparse
3  parser = argparse.ArgumentParser(description="Demonstrate the use of ImagePsfMatchTask")
4 
5  parser.add_argument("--debug", "-d", action="store_true", help="Load debug.py?", default=False)
6  parser.add_argument("--template", "-t", help="Template Exposure to use", default=None)
7  parser.add_argument("--science", "-s", help="Science Exposure to use", default=None)
8 
9  args = parser.parse_args()

We have enabled some minor display debugging in this script via the –debug option. However, if you have an lsstDebug debug.py in your PYTHONPATH you will get additional debugging displays. The following block checks for this script:

1  if args.debug:
2  try:
3  import debug
4  # Since I am displaying 2 images here, set the starting frame number for the LSST debug LSST
5  debug.lsstDebug.frame = 3
6  except ImportError as e:
7  print >> sys.stderr, e

Finally, we call a run method that we define below. First set up a Config and choose the basis set to use:
1 def run(args):
2  #
3  # Create the Config and use sum of gaussian basis
4  #
5  config = SnapPsfMatchTask.ConfigClass()
6  config.doWarping = True
7  config.kernel.name = "AL"

Make sure the images (if any) that were sent to the script exist on disk and are readable. If no images are sent, make some fake data up for the sake of this example script (have a look at the code if you want more details on generateFakeImages; as a detail of how the fake images were made, you do have to fit for a differential background):

1  # Run the requested method of the Task
2  if args.template is not None and args.science is not None:
3  if not os.path.isfile(args.template):
4  raise Exception, "Template image %s does not exist" % (args.template)
5  if not os.path.isfile(args.science):
6  raise Exception, "Science image %s does not exist" % (args.science)
7 
8  try:
9  templateExp = afwImage.ExposureF(args.template)
10  except pexExcept.LsstCppException, e:
11  raise Exception, "Cannot read template image %s" % (args.template)
12  try:
13  scienceExp = afwImage.ExposureF(args.science)
14  except pexExcept.LsstCppException, e:
15  raise Exception, "Cannot read science image %s" % (args.science)
16  else:
17  templateExp, scienceExp = generateFakeImages()
18  config.kernel.active.fitForBackground = True
19  config.kernel.active.spatialBgOrder = 0
20  config.kernel.active.sizeCellX = 128
21  config.kernel.active.sizeCellY = 128

Display the two images if –debug:

1  if args.debug:
2  ds9.mtv(templateExp, frame=1, title="Example script: Input Template")
3  ds9.mtv(scienceExp, frame=2, title="Example script: Input Science Image")

Create and run the Task:

1  # Create the Task
2  psfMatchTask = MySnapPsfMatchTask(config=config)
3 
4  # Run the Task
5  result = psfMatchTask.run(templateExp, scienceExp)

And finally provide optional debugging display of the Psf-matched (via the Psf models) science image:

1  if args.debug:
2  # See if the LSST debug has incremented the frame number; if not start with frame 3
3  try:
4  frame = debug.lsstDebug.frame+1
5  except Exception:
6  frame = 3
7  ds9.mtv(result.matchedExposure, frame=frame, title="Example script: Matched Template Image")
8  if result.getDict().has_key("subtractedExposure"):
9  ds9.mtv(result.subtractedExposure, frame=frame+1, title="Example script: Subtracted Image")

#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Definition at line 87 of file snapPsfMatch.py.

Member Function Documentation

def lsst.ip.diffim.snapPsfMatch.SnapPsfMatchTask.subtractExposures (   self,
  templateExposure,
  scienceExposure,
  templateFwhmPix = None,
  scienceFwhmPix = None,
  candidateList = None 
)

Definition at line 257 of file snapPsfMatch.py.

258  candidateList = None):
259  return ImagePsfMatchTask.subtractExposures(self,
260  templateExposure = templateExposure,
261  scienceExposure = scienceExposure,
262  templateFwhmPix = templateFwhmPix,
263  scienceFwhmPix = scienceFwhmPix,
264  candidateList = candidateList,
265  doWarping = self.config.doWarping,
266  )
267 

Member Data Documentation

lsst.ip.diffim.snapPsfMatch.SnapPsfMatchTask.ConfigClass = SnapPsfMatchConfig
static

Definition at line 252 of file snapPsfMatch.py.


The documentation for this class was generated from the following file: