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 | Public Attributes | Static Public Attributes | Static Private Attributes | List of all members
lsst.pipe.tasks.snapCombine.SnapCombineTask Class Reference
Inheritance diagram for lsst.pipe.tasks.snapCombine.SnapCombineTask:

Public Member Functions

def __init__
 
def run
 
def addSnaps
 
def fixMetadata
 
def makeInitialPsf
 

Public Attributes

 schema
 
 algMetadata
 

Static Public Attributes

 ConfigClass = SnapCombineConfig
 

Static Private Attributes

string _DefaultName = "snapCombine"
 

Detailed Description

Definition at line 96 of file snapCombine.py.

Constructor & Destructor Documentation

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

Definition at line 100 of file snapCombine.py.

101  def __init__(self, *args, **kwargs):
102  pipeBase.Task.__init__(self, *args, **kwargs)
103  self.makeSubtask("repair")
104  self.makeSubtask("diffim")
105  self.schema = afwTable.SourceTable.makeMinimalSchema()
107  self.makeSubtask("detection", schema=self.schema)
108  if self.config.doMeasurement:
109  self.makeSubtask("measurement", schema=self.schema, algMetadata=self.algMetadata)
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81

Member Function Documentation

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 178 of file snapCombine.py.

179  def addSnaps(self, snap0, snap1):
180  """Add two snap exposures together, returning a new exposure
181 
182  @param[in] snap0 snap exposure 0
183  @param[in] snap1 snap exposure 1
184  @return combined exposure
185  """
186  self.log.info("snapCombine addSnaps")
187 
188  combinedExp = snap0.Factory(snap0, True)
189  combinedMi = combinedExp.getMaskedImage()
190  combinedMi.set(0)
191 
192  weightMap = combinedMi.getImage().Factory(combinedMi.getBBox())
193  weight = 1.0
194  badPixelMask = afwImage.MaskU.getPlaneBitMask(self.config.badMaskPlanes)
195  addToCoadd(combinedMi, weightMap, snap0.getMaskedImage(), badPixelMask, weight)
196  addToCoadd(combinedMi, weightMap, snap1.getMaskedImage(), badPixelMask, weight)
197 
198  # pre-scaling the weight map instead of post-scaling the combinedMi saves a bit of time
199  # because the weight map is a simple Image instead of a MaskedImage
200  weightMap *= 0.5 # so result is sum of both images, instead of average
201  combinedMi /= weightMap
202  setCoaddEdgeBits(combinedMi.getMask(), weightMap)
203 
204  # note: none of the inputs has a valid Calib object, so that is not touched
205  # Filter was already copied
206 
207  combinedMetadata = combinedExp.getMetadata()
208  metadata0 = snap0.getMetadata()
209  metadata1 = snap1.getMetadata()
210  self.fixMetadata(combinedMetadata, metadata0, metadata1)
211 
212  return combinedExp
void setCoaddEdgeBits(lsst::afw::image::Mask< lsst::afw::image::MaskPixel > &coaddMask, lsst::afw::image::Image< WeightPixelT > const &weightMap)
set edge bits of coadd mask based on weight map
lsst::afw::geom::Box2I addToCoadd(lsst::afw::image::Image< CoaddPixelT > &coadd, lsst::afw::image::Image< WeightPixelT > &weightMap, lsst::afw::image::Image< CoaddPixelT > const &image, WeightPixelT weight)
add good pixels from an image to a coadd and associated weight map
Definition: addToCoadd.cc:126
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 213 of file snapCombine.py.

214  def fixMetadata(self, combinedMetadata, metadata0, metadata1):
215  """Fix the metadata of the combined exposure (in place)
216 
217  This implementation handles items specified by config.averageKeys and config.sumKeys,
218  which have data type restrictions. To handle other data types (such as sexagesimal
219  positions and ISO dates) you must supplement this method with your own code.
220 
221  @param[in,out] combinedMetadata metadata of combined exposure;
222  on input this is a deep copy of metadata0 (a PropertySet)
223  @param[in] metadata0 metadata of snap0 (a PropertySet)
224  @param[in] metadata1 metadata of snap1 (a PropertySet)
225 
226  @note the inputs are presently PropertySets due to ticket #2542. However, in some sense
227  they are just PropertyLists that are missing some methods. In particular: comments and order
228  are preserved if you alter an existing value with set(key, value).
229  """
230  keyDoAvgList = []
231  if self.config.averageKeys:
232  keyDoAvgList += [(key, 1) for key in self.config.averageKeys]
233  if self.config.sumKeys:
234  keyDoAvgList += [(key, 0) for key in self.config.sumKeys]
235  for key, doAvg in keyDoAvgList:
236  opStr = "average" if doAvg else "sum"
237  try:
238  val0 = metadata0.get(key)
239  val1 = metadata1.get(key)
240  except Exception:
241  self.log.warn("Could not %s metadata %r: missing from one or both exposures" % (opStr, key,))
242  continue
243 
244  try:
245  combinedVal = val0 + val1
246  if doAvg:
247  combinedVal /= 2.0
248  except Exception:
249  self.log.warn("Could not %s metadata %r: value %r and/or %r not numeric" % \
250  (opStr, key, val0, val1))
251  continue
252 
253  combinedMetadata.set(key, combinedVal)
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 254 of file snapCombine.py.

255  def makeInitialPsf(self, exposure, fwhmPix=None):
256  """Initialise the detection procedure by setting the PSF and WCS
257 
258  @param exposure Exposure to process
259  @return PSF, WCS
260  """
261  assert exposure, "No exposure provided"
262  wcs = exposure.getWcs()
263  assert wcs, "No wcs in exposure"
264 
265  if fwhmPix is None:
266  fwhmPix = self.config.initialPsf.fwhm / wcs.pixelScale().asArcseconds()
267 
268  size = self.config.initialPsf.size
269  model = self.config.initialPsf.model
270  self.log.info("installInitialPsf fwhm=%s pixels; size=%s pixels" % (fwhmPix, size))
271  psfCls = getattr(measAlg, model + "Psf")
272  psf = psfCls(size, size, fwhmPix/(2.0*num.sqrt(2*num.log(2.0))))
273  return psf
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 111 of file snapCombine.py.

112  def run(self, snap0, snap1, defects=None):
113  """Combine two snaps
114 
115  @param[in] snap0: snapshot exposure 0
116  @param[in] snap1: snapshot exposure 1
117  @defects[in] defect list (for repair task)
118  @return a pipe_base Struct with fields:
119  - exposure: snap-combined exposure
120  - sources: detected sources, or None if detection not performed
121  """
122  # initialize optional outputs
123  sources = None
124 
125  if self.config.doRepair:
126  self.log.info("snapCombine repair")
127  psf = self.makeInitialPsf(snap0, fwhmPix=self.config.repairPsfFwhm)
128  snap0.setPsf(psf)
129  snap1.setPsf(psf)
130  self.repair.run(snap0, defects=defects, keepCRs=False)
131  self.repair.run(snap1, defects=defects, keepCRs=False)
132  self.display('repair0', exposure=snap0)
133  self.display('repair1', exposure=snap1)
134 
135  if self.config.doDiffIm:
136  if self.config.doPsfMatch:
137  self.log.info("snapCombine psfMatch")
138  diffRet = self.diffim.run(snap0, snap1, "subtractExposures")
139  diffExp = diffRet.subtractedImage
140 
141  # Measure centroid and width of kernel; dependent on ticket #1980
142  # Useful diagnostic for the degree of astrometric shift between snaps.
143  diffKern = diffRet.psfMatchingKernel
144  width, height = diffKern.getDimensions()
145  # TBD...
146  #psfAttr = measAlg.PsfAttributes(diffKern, width//2, height//2)
147 
148  else:
149  diffExp = afwImage.ExposureF(snap0, True)
150  diffMi = diffExp.getMaskedImage()
151  diffMi -= snap1.getMaskedImage()
152 
153  psf = self.makeInitialPsf(snap0)
154  diffExp.setPsf(psf)
155  table = afwTable.SourceTable.make(self.schema)
156  table.setMetadata(self.algMetadata)
157  detRet = self.detection.makeSourceCatalog(table, diffExp)
158  sources = detRet.sources
159  fpSets = detRet.fpSets
160  if self.config.doMeasurement:
161  self.measurement.measure(diffExp, sources)
162 
163  mask0 = snap0.getMaskedImage().getMask()
164  mask1 = snap1.getMaskedImage().getMask()
165  fpSets.positive.setMask(mask0, "DETECTED")
166  fpSets.negative.setMask(mask1, "DETECTED")
167 
168  maskD = diffExp.getMaskedImage().getMask()
169  fpSets.positive.setMask(maskD, "DETECTED")
170  fpSets.negative.setMask(maskD, "DETECTED_NEGATIVE")
171 
172  combinedExp = self.addSnaps(snap0, snap1)
173 
174  return pipeBase.Struct(
175  exposure = combinedExp,
176  sources = sources,
177  )

Member Data Documentation

string lsst.pipe.tasks.snapCombine.SnapCombineTask._DefaultName = "snapCombine"
staticprivate

Definition at line 98 of file snapCombine.py.

lsst.pipe.tasks.snapCombine.SnapCombineTask.algMetadata

Definition at line 105 of file snapCombine.py.

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

Definition at line 97 of file snapCombine.py.

lsst.pipe.tasks.snapCombine.SnapCombineTask.schema

Definition at line 104 of file snapCombine.py.


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