LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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 507 of file detection.py.

508 def addExposures(exposureList):
509  """!Add a set of exposures together.
510 
511  \param[in] exposureList sequence of exposures to add
512 
513  \return an exposure of the same size as each exposure in exposureList,
514  with the metadata from exposureList[0] and a masked image equal to the
515  sum of all the exposure's masked images.
516 
517  \throw LsstException if the exposures do not all have the same dimensions (but does not check xy0)
518  """
519  exposure0 = exposureList[0]
520  image0 = exposure0.getMaskedImage()
521 
522  addedImage = image0.Factory(image0, True)
523  addedImage.setXY0(image0.getXY0())
524 
525  for exposure in exposureList[1:]:
526  image = exposure.getMaskedImage()
527  addedImage += image
528 
529  addedExposure = exposure0.Factory(addedImage, exposure0.getWcs())
530  return addedExposure
def addExposures
Add a set of exposures together.
Definition: detection.py:507
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 567 of file detection.py.

568  statsKeys=None):
569  """!Estimate exposure's background using parameters in backgroundConfig.
570 
571  If subtract is true, make a copy of the exposure and subtract the background.
572  If `stats` is True, measure the mean and variance of the background and
573  add them to the background-subtracted exposure's metadata with keys
574  "BGMEAN" and "BGVAR", or the keys given in `statsKeys` (2-tuple of strings).
575 
576  Return background, backgroundSubtractedExposure
577  """
578  displayBackground = lsstDebug.Info(__name__).displayBackground
579 
580  maskedImage = exposure.getMaskedImage()
581 
582  background = getBackground(maskedImage, backgroundConfig)
583 
584  if not background:
585  raise RuntimeError, "Unable to estimate background for exposure"
586 
587  bgimg = None
588 
589  if displayBackground > 1:
590  bgimg = background.getImageF()
591  ds9.mtv(bgimg, title="background", frame=1)
592 
593  if not subtract:
594  return background, None
595 
596  bbox = maskedImage.getBBox()
597  backgroundSubtractedExposure = exposure.Factory(exposure, bbox, afwImage.PARENT, True)
598  copyImage = backgroundSubtractedExposure.getMaskedImage().getImage()
599  if bgimg is None:
600  bgimg = background.getImageF()
601  copyImage -= bgimg
602 
603  # Record statistics of the background in the bgsub exposure metadata.
604  # (lsst.daf.base.PropertySet)
605  if stats:
606  if statsKeys is None:
607  mnkey = 'BGMEAN'
608  varkey = 'BGVAR'
609  else:
610  mnkey,varkey = statsKeys
611  meta = backgroundSubtractedExposure.getMetadata()
612  s = afwMath.makeStatistics(bgimg, afwMath.MEAN | afwMath.VARIANCE)
613  bgmean = s.getValue(afwMath.MEAN)
614  bgvar = s.getValue(afwMath.VARIANCE)
615  meta.addDouble(mnkey, bgmean)
616  meta.addDouble(varkey, bgvar)
617 
618  if displayBackground:
619  ds9.mtv(backgroundSubtractedExposure, title="subtracted")
620 
621  return background, backgroundSubtractedExposure
622 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:531
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 531 of file detection.py.

532 def getBackground(image, backgroundConfig, nx=0, ny=0, algorithm=None):
533  """!Estimate the background of an image (a thin layer on lsst.afw.math.makeBackground)
534 
535  \param[in] image image whose background is to be computed
536  \param[in] backgroundConfig configuration (a BackgroundConfig)
537  \param[in] nx number of x bands; 0 for default
538  \param[in] ny number of y bands; 0 for default
539  \param[in] algorithm name of interpolation algorithm; see lsst.afw.math.BackgroundControl for details
540  """
541  backgroundConfig.validate();
542 
543  if not nx:
544  nx = image.getWidth()//backgroundConfig.binSize + 1
545  if not ny:
546  ny = image.getHeight()//backgroundConfig.binSize + 1
547 
548  sctrl = afwMath.StatisticsControl()
549  sctrl.setAndMask(reduce(lambda x, y: x | image.getMask().getPlaneBitMask(y),
550  backgroundConfig.ignoredPixelMask, 0x0))
551  sctrl.setNanSafe(backgroundConfig.isNanSafe)
552 
553  pl = pexLogging.Debug("meas.utils.sourceDetection.getBackground")
554  pl.debug(3, "Ignoring mask planes: %s" % ", ".join(backgroundConfig.ignoredPixelMask))
555 
556  if not algorithm:
557  algorithm = backgroundConfig.algorithm
558 
559  bctrl = afwMath.BackgroundControl(algorithm, nx, ny,
560  backgroundConfig.undersampleStyle, sctrl,
561  backgroundConfig.statisticsProperty)
562 
563  return afwMath.makeBackground(image, bctrl)
564 
565 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:531

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.