LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.pipe.tasks.snapCombine.SnapCombineTask Class Reference

More...

Inheritance diagram for lsst.pipe.tasks.snapCombine.SnapCombineTask:

Public Member Functions

def __init__ (self, *args, **kwargs)
 
def run (self, snap0, snap1, defects=None)
 
def addSnaps (self, snap0, snap1)
 
def fixMetadata (self, combinedMetadata, metadata0, metadata1)
 
def makeInitialPsf (self, exposure, fwhmPix=None)
 

Public Attributes

 schema
 
 algMetadata
 

Static Public Attributes

 ConfigClass = SnapCombineConfig
 

Detailed Description

Combine snaps.

Contents

Debug variables

The command line task interface supports a flag -d to import debug.py from your PYTHONPATH; see Debugging Tasks with lsstDebug for more about debug.py files.

The available variables in SnapCombineTask are:

display
A dictionary containing debug point names as keys with frame number as value. Valid keys are:
repair0
Display the first snap after repairing.
repair1
Display the second snap after repairing.

Definition at line 136 of file snapCombine.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.tasks.snapCombine.SnapCombineTask.__init__ (   self,
args,
**  kwargs 
)

Definition at line 169 of file snapCombine.py.

169  def __init__(self, *args, **kwargs):
170  pipeBase.Task.__init__(self, *args, **kwargs)
171  self.makeSubtask("repair")
172  self.makeSubtask("diffim")
173  self.schema = afwTable.SourceTable.makeMinimalSchema()
174  self.algMetadata = dafBase.PropertyList()
175  self.makeSubtask("detection", schema=self.schema)
176  if self.config.doMeasurement:
177  self.makeSubtask("measurement", schema=self.schema, algMetadata=self.algMetadata)
178 
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68

Member Function Documentation

◆ addSnaps()

def lsst.pipe.tasks.snapCombine.SnapCombineTask.addSnaps (   self,
  snap0,
  snap1 
)
Add two snap exposures together, returning a new exposure

@param[in] snap0 snap exposure 0
@param[in] snap1 snap exposure 1
@return combined exposure

Definition at line 250 of file snapCombine.py.

250  def addSnaps(self, snap0, snap1):
251  """Add two snap exposures together, returning a new exposure
252 
253  @param[in] snap0 snap exposure 0
254  @param[in] snap1 snap exposure 1
255  @return combined exposure
256  """
257  self.log.info("snapCombine addSnaps")
258 
259  combinedExp = snap0.Factory(snap0, True)
260  combinedMi = combinedExp.getMaskedImage()
261  combinedMi.set(0)
262 
263  weightMap = combinedMi.getImage().Factory(combinedMi.getBBox())
264  weight = 1.0
265  badPixelMask = afwImage.Mask.getPlaneBitMask(self.config.badMaskPlanes)
266  addToCoadd(combinedMi, weightMap, snap0.getMaskedImage(), badPixelMask, weight)
267  addToCoadd(combinedMi, weightMap, snap1.getMaskedImage(), badPixelMask, weight)
268 
269  # pre-scaling the weight map instead of post-scaling the combinedMi saves a bit of time
270  # because the weight map is a simple Image instead of a MaskedImage
271  weightMap *= 0.5 # so result is sum of both images, instead of average
272  combinedMi /= weightMap
273  setCoaddEdgeBits(combinedMi.getMask(), weightMap)
274 
275  # note: none of the inputs has a valid PhotoCalib object, so that is not touched
276  # Filter was already copied
277 
278  combinedMetadata = combinedExp.getMetadata()
279  metadata0 = snap0.getMetadata()
280  metadata1 = snap1.getMetadata()
281  self.fixMetadata(combinedMetadata, metadata0, metadata1)
282 
283  return combinedExp
284 

◆ fixMetadata()

def lsst.pipe.tasks.snapCombine.SnapCombineTask.fixMetadata (   self,
  combinedMetadata,
  metadata0,
  metadata1 
)
Fix the metadata of the combined exposure (in place)

This implementation handles items specified by config.averageKeys and config.sumKeys,
which have data type restrictions. To handle other data types (such as sexagesimal
positions and ISO dates) you must supplement this method with your own code.

@param[in,out] combinedMetadata metadata of combined exposure;
    on input this is a deep copy of metadata0 (a PropertySet)
@param[in] metadata0 metadata of snap0 (a PropertySet)
@param[in] metadata1 metadata of snap1 (a PropertySet)

@note the inputs are presently PropertySets due to ticket #2542. However, in some sense
they are just PropertyLists that are missing some methods. In particular: comments and order
are preserved if you alter an existing value with set(key, value).

Definition at line 285 of file snapCombine.py.

285  def fixMetadata(self, combinedMetadata, metadata0, metadata1):
286  """Fix the metadata of the combined exposure (in place)
287 
288  This implementation handles items specified by config.averageKeys and config.sumKeys,
289  which have data type restrictions. To handle other data types (such as sexagesimal
290  positions and ISO dates) you must supplement this method with your own code.
291 
292  @param[in,out] combinedMetadata metadata of combined exposure;
293  on input this is a deep copy of metadata0 (a PropertySet)
294  @param[in] metadata0 metadata of snap0 (a PropertySet)
295  @param[in] metadata1 metadata of snap1 (a PropertySet)
296 
297  @note the inputs are presently PropertySets due to ticket #2542. However, in some sense
298  they are just PropertyLists that are missing some methods. In particular: comments and order
299  are preserved if you alter an existing value with set(key, value).
300  """
301  keyDoAvgList = []
302  if self.config.averageKeys:
303  keyDoAvgList += [(key, 1) for key in self.config.averageKeys]
304  if self.config.sumKeys:
305  keyDoAvgList += [(key, 0) for key in self.config.sumKeys]
306  for key, doAvg in keyDoAvgList:
307  opStr = "average" if doAvg else "sum"
308  try:
309  val0 = metadata0.getScalar(key)
310  val1 = metadata1.getScalar(key)
311  except Exception:
312  self.log.warning("Could not %s metadata %r: missing from one or both exposures", opStr, key)
313  continue
314 
315  try:
316  combinedVal = val0 + val1
317  if doAvg:
318  combinedVal /= 2.0
319  except Exception:
320  self.log.warning("Could not %s metadata %r: value %r and/or %r not numeric",
321  opStr, key, val0, val1)
322  continue
323 
324  combinedMetadata.set(key, combinedVal)
325 

◆ makeInitialPsf()

def lsst.pipe.tasks.snapCombine.SnapCombineTask.makeInitialPsf (   self,
  exposure,
  fwhmPix = None 
)
Initialise the detection procedure by setting the PSF and WCS

@param exposure Exposure to process
@return PSF, WCS

Definition at line 326 of file snapCombine.py.

326  def makeInitialPsf(self, exposure, fwhmPix=None):
327  """Initialise the detection procedure by setting the PSF and WCS
328 
329  @param exposure Exposure to process
330  @return PSF, WCS
331  """
332  assert exposure, "No exposure provided"
333  wcs = exposure.getWcs()
334  assert wcs, "No wcs in exposure"
335 
336  if fwhmPix is None:
337  fwhmPix = self.config.initialPsf.fwhm / wcs.getPixelScale().asArcseconds()
338 
339  size = self.config.initialPsf.size
340  model = self.config.initialPsf.model
341  self.log.info("installInitialPsf fwhm=%s pixels; size=%s pixels", fwhmPix, size)
342  psfCls = getattr(measAlg, model + "Psf")
343  psf = psfCls(size, size, fwhmPix/(2.0*num.sqrt(2*num.log(2.0))))
344  return psf

◆ run()

def lsst.pipe.tasks.snapCombine.SnapCombineTask.run (   self,
  snap0,
  snap1,
  defects = None 
)
Combine two snaps

@param[in] snap0: snapshot exposure 0
@param[in] snap1: snapshot exposure 1
@defects[in] defect list (for repair task)
@return a pipe_base Struct with fields:
- exposure: snap-combined exposure
- sources: detected sources, or None if detection not performed

Definition at line 180 of file snapCombine.py.

180  def run(self, snap0, snap1, defects=None):
181  """Combine two snaps
182 
183  @param[in] snap0: snapshot exposure 0
184  @param[in] snap1: snapshot exposure 1
185  @defects[in] defect list (for repair task)
186  @return a pipe_base Struct with fields:
187  - exposure: snap-combined exposure
188  - sources: detected sources, or None if detection not performed
189  """
190  # initialize optional outputs
191  sources = None
192 
193  if self.config.doRepair:
194  self.log.info("snapCombine repair")
195  psf = self.makeInitialPsf(snap0, fwhmPix=self.config.repairPsfFwhm)
196  snap0.setPsf(psf)
197  snap1.setPsf(psf)
198  self.repair.run(snap0, defects=defects, keepCRs=False)
199  self.repair.run(snap1, defects=defects, keepCRs=False)
200 
201  repair0frame = getDebugFrame(self._display, "repair0")
202  if repair0frame:
203  getDisplay(repair0frame).mtv(snap0)
204  repair1frame = getDebugFrame(self._display, "repair1")
205  if repair1frame:
206  getDisplay(repair1frame).mtv(snap1)
207 
208  if self.config.doDiffIm:
209  if self.config.doPsfMatch:
210  self.log.info("snapCombine psfMatch")
211  diffRet = self.diffim.run(snap0, snap1, "subtractExposures")
212  diffExp = diffRet.subtractedImage
213 
214  # Measure centroid and width of kernel; dependent on ticket #1980
215  # Useful diagnostic for the degree of astrometric shift between snaps.
216  diffKern = diffRet.psfMatchingKernel
217  width, height = diffKern.getDimensions()
218 
219  else:
220  diffExp = afwImage.ExposureF(snap0, True)
221  diffMi = diffExp.getMaskedImage()
222  diffMi -= snap1.getMaskedImage()
223 
224  psf = self.makeInitialPsf(snap0)
225  diffExp.setPsf(psf)
226  table = afwTable.SourceTable.make(self.schema)
227  table.setMetadata(self.algMetadata)
228  detRet = self.detection.run(table, diffExp)
229  sources = detRet.sources
230  fpSets = detRet.fpSets
231  if self.config.doMeasurement:
232  self.measurement.measure(diffExp, sources)
233 
234  mask0 = snap0.getMaskedImage().getMask()
235  mask1 = snap1.getMaskedImage().getMask()
236  fpSets.positive.setMask(mask0, "DETECTED")
237  fpSets.negative.setMask(mask1, "DETECTED")
238 
239  maskD = diffExp.getMaskedImage().getMask()
240  fpSets.positive.setMask(maskD, "DETECTED")
241  fpSets.negative.setMask(maskD, "DETECTED_NEGATIVE")
242 
243  combinedExp = self.addSnaps(snap0, snap1)
244 
245  return pipeBase.Struct(
246  exposure=combinedExp,
247  sources=sources,
248  )
249 
def mtv(data, frame=None, title="", wcs=None, *args, **kwargs)
Definition: ds9.py:92
def run(self, coaddExposures, bbox, wcs)
Definition: getTemplate.py:603
def measure(mi, x, y, size, statistic, stats)
Definition: fringe.py:517
def getDebugFrame(debugDisplay, name)
Definition: lsstDebug.py:95

Member Data Documentation

◆ algMetadata

lsst.pipe.tasks.snapCombine.SnapCombineTask.algMetadata

Definition at line 174 of file snapCombine.py.

◆ ConfigClass

lsst.pipe.tasks.snapCombine.SnapCombineTask.ConfigClass = SnapCombineConfig
static

Definition at line 166 of file snapCombine.py.

◆ schema

lsst.pipe.tasks.snapCombine.SnapCombineTask.schema

Definition at line 173 of file snapCombine.py.


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