LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Classes | Functions | Variables
lsst.meas.algorithms.detection Namespace Reference

Classes

class  BackgroundConfig
 Config for background estimation. More...
 
class  SourceDetectionConfig
 Configuration parameters for the SourceDetectionTask. More...
 
class  SourceDetectionTask
 Detect positive and negative sources on an exposure and return a new table.SourceCatalog. More...
 

Functions

def addExposures
 Add a set of exposures together. More...
 
def getBackground
 Estimate the background of an image (a thin layer on lsst.afw.math.makeBackground) More...
 
def estimateBackground
 Estimate exposure's background using parameters in backgroundConfig. More...
 

Variables

tuple __all__
 

Function Documentation

def lsst.meas.algorithms.detection.addExposures (   exposureList)

Add a set of exposures together.

Parameters
[in]exposureListsequence of exposures to add
Returns
an exposure of the same size as each exposure in exposureList, with the metadata from exposureList[0] and a masked image equal to the sum of all the exposure's masked images.
Exceptions
LsstExceptionif the exposures do not all have the same dimensions (but does not check xy0)

Definition at line 501 of file detection.py.

502 def addExposures(exposureList):
503  """!Add a set of exposures together.
504 
505  \param[in] exposureList sequence of exposures to add
506 
507  \return an exposure of the same size as each exposure in exposureList,
508  with the metadata from exposureList[0] and a masked image equal to the
509  sum of all the exposure's masked images.
510 
511  \throw LsstException if the exposures do not all have the same dimensions (but does not check xy0)
512  """
513  exposure0 = exposureList[0]
514  image0 = exposure0.getMaskedImage()
515 
516  addedImage = image0.Factory(image0, True)
517  addedImage.setXY0(image0.getXY0())
518 
519  for exposure in exposureList[1:]:
520  image = exposure.getMaskedImage()
521  addedImage += image
522 
523  addedExposure = exposure0.Factory(addedImage, exposure0.getWcs())
524  return addedExposure
def addExposures
Add a set of exposures together.
Definition: detection.py:501
def lsst.meas.algorithms.detection.estimateBackground (   exposure,
  backgroundConfig,
  subtract = True,
  stats = True,
  statsKeys = None 
)

Estimate exposure's background using parameters in backgroundConfig.

If subtract is true, make a copy of the exposure and subtract the background. If stats is True, measure the mean and variance of the background and add them to the background-subtracted exposure's metadata with keys "BGMEAN" and "BGVAR", or the keys given in statsKeys (2-tuple of strings).

Return background, backgroundSubtractedExposure

Definition at line 561 of file detection.py.

562  statsKeys=None):
563  """!Estimate exposure's background using parameters in backgroundConfig.
564 
565  If subtract is true, make a copy of the exposure and subtract the background.
566  If `stats` is True, measure the mean and variance of the background and
567  add them to the background-subtracted exposure's metadata with keys
568  "BGMEAN" and "BGVAR", or the keys given in `statsKeys` (2-tuple of strings).
569 
570  Return background, backgroundSubtractedExposure
571  """
572  displayBackground = lsstDebug.Info(__name__).displayBackground
573 
574  maskedImage = exposure.getMaskedImage()
575 
576  background = getBackground(maskedImage, backgroundConfig)
577 
578  if not background:
579  raise RuntimeError, "Unable to estimate background for exposure"
580 
581  bgimg = None
582 
583  if displayBackground > 1:
584  bgimg = background.getImageF()
585  ds9.mtv(bgimg, title="background", frame=1)
586 
587  if not subtract:
588  return background, None
589 
590  bbox = maskedImage.getBBox()
591  backgroundSubtractedExposure = exposure.Factory(exposure, bbox, afwImage.PARENT, True)
592  copyImage = backgroundSubtractedExposure.getMaskedImage().getImage()
593  if bgimg is None:
594  bgimg = background.getImageF()
595  copyImage -= bgimg
596 
597  # Record statistics of the background in the bgsub exposure metadata.
598  # (lsst.daf.base.PropertySet)
599  if stats:
600  if statsKeys is None:
601  mnkey = 'BGMEAN'
602  varkey = 'BGVAR'
603  else:
604  mnkey,varkey = statsKeys
605  meta = backgroundSubtractedExposure.getMetadata()
606  s = afwMath.makeStatistics(bgimg, afwMath.MEAN | afwMath.VARIANCE)
607  bgmean = s.getValue(afwMath.MEAN)
608  bgvar = s.getValue(afwMath.VARIANCE)
609  meta.addDouble(mnkey, bgmean)
610  meta.addDouble(varkey, bgvar)
611 
612  if displayBackground:
613  ds9.mtv(backgroundSubtractedExposure, title="subtracted")
614 
615  return background, backgroundSubtractedExposure
616 estimateBackground.ConfigClass = BackgroundConfig
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1023
def getBackground
Estimate the background of an image (a thin layer on lsst.afw.math.makeBackground) ...
Definition: detection.py:525
def lsst.meas.algorithms.detection.getBackground (   image,
  backgroundConfig,
  nx = 0,
  ny = 0,
  algorithm = None 
)

Estimate the background of an image (a thin layer on lsst.afw.math.makeBackground)

Parameters
[in]imageimage whose background is to be computed
[in]backgroundConfigconfiguration (a BackgroundConfig)
[in]nxnumber of x bands; 0 for default
[in]nynumber of y bands; 0 for default
[in]algorithmname of interpolation algorithm; see lsst.afw.math.BackgroundControl for details

Definition at line 525 of file detection.py.

526 def getBackground(image, backgroundConfig, nx=0, ny=0, algorithm=None):
527  """!Estimate the background of an image (a thin layer on lsst.afw.math.makeBackground)
528 
529  \param[in] image image whose background is to be computed
530  \param[in] backgroundConfig configuration (a BackgroundConfig)
531  \param[in] nx number of x bands; 0 for default
532  \param[in] ny number of y bands; 0 for default
533  \param[in] algorithm name of interpolation algorithm; see lsst.afw.math.BackgroundControl for details
534  """
535  backgroundConfig.validate();
536 
537  if not nx:
538  nx = image.getWidth()//backgroundConfig.binSize + 1
539  if not ny:
540  ny = image.getHeight()//backgroundConfig.binSize + 1
541 
542  sctrl = afwMath.StatisticsControl()
543  sctrl.setAndMask(reduce(lambda x, y: x | image.getMask().getPlaneBitMask(y),
544  backgroundConfig.ignoredPixelMask, 0x0))
545  sctrl.setNanSafe(backgroundConfig.isNanSafe)
546 
547  pl = pexLogging.Debug("meas.utils.sourceDetection.getBackground")
548  pl.debug(3, "Ignoring mask planes: %s" % ", ".join(backgroundConfig.ignoredPixelMask))
549 
550  if not algorithm:
551  algorithm = backgroundConfig.algorithm
552 
553  bctrl = afwMath.BackgroundControl(algorithm, nx, ny,
554  backgroundConfig.undersampleStyle, sctrl,
555  backgroundConfig.statisticsProperty)
556 
557  return afwMath.makeBackground(image, bctrl)
558 
559 getBackground.ConfigClass = BackgroundConfig
boost::shared_ptr< Background > makeBackground(ImageT const &img, BackgroundControl const &bgCtrl)
A convenience function that uses function overloading to make the correct type of Background...
Definition: Background.h:446
Pass parameters to a Background object.
Definition: Background.h:62
Pass parameters to a Statistics objectA class to pass parameters which control how the stats are calc...
Definition: Statistics.h:92
def getBackground
Estimate the background of an image (a thin layer on lsst.afw.math.makeBackground) ...
Definition: detection.py:525

Variable Documentation

tuple lsst.meas.algorithms.detection.__all__
Initial value:
1 = ("SourceDetectionConfig", "SourceDetectionTask", "getBackground",
2  "estimateBackground", "BackgroundConfig", "addExposures")

Definition at line 33 of file detection.py.