DynamicDetectionTask#
- class lsst.meas.algorithms.DynamicDetectionTask(*args, **kwargs)#
Bases:
SourceDetectionTaskDetection of sources on an image with a dynamic threshold
We first detect sources using a lower threshold than normal (see config parameter
prelimThresholdFactor) in order to identify good sky regions (configurableskyObjects). Then we perform forced PSF photometry on those sky regions. Using those PSF flux measurements and estimated errors, we set the threshold so that the stdev of the measurements matches the median estimated error.Besides the usual initialisation of configurables, we also set up the forced measurement which is deliberately not represented in this Task’s configuration parameters because we’re using it as part of the algorithm and we don’t want to allow it to be modified.
Methods Summary
calculateThreshold(exposure, seed[, sigma, ...])Calculate new threshold
detectFootprints(exposure[, doSmooth, ...])Detect footprints with a dynamic threshold
tweakBackground(exposure, bgLevel[, bgList])Modify the background by a constant value
Methods Documentation
- calculateThreshold(exposure, seed, sigma=None, minFractionSourcesFactor=1.0, isBgTweak=False, nPixMaskErode=None, maxMaskErodeIter=10)#
Calculate new threshold
This is the main functional addition to the vanilla
SourceDetectionTask.We identify sky objects and perform forced PSF photometry on them. Using those PSF flux measurements and estimated errors, we set the threshold so that the stdev of the measurements matches the median estimated error.
Parameters#
- exposure
lsst.afw.image.Exposure Exposure on which we’re detecting sources.
- seed
int RNG seed to use for finding sky objects.
- sigma
float, optional Gaussian sigma of smoothing kernel; if not provided, will be deduced from the exposure’s PSF.
- minFractionSourcesFactor
float Change the fraction of required sky sources from that set in
self.config.minFractionSourcesby this factor. NOTE: this is intended for use in the background tweak pass (the detection threshold is much lower there, so many more pixels end up marked as DETECTED or DETECTED_NEGATIVE, leaving less room for sky object placement).- isBgTweak
bool Set to
Truefor the background tweak pass (for more helpful log messages).- nPixMaskErode
int, optional Number of pixels by which to erode the detection masks on each iteration of best-effort sky object placement.
- maxMaskErodeIter
int, optional Maximum number of iterations for the detection mask erosion.
Returns#
- result
lsst.pipe.base.Struct Result struct with components:
multiplicativeMultiplicative factor to be applied to the configured detection threshold (
float).additiveAdditive factor to be applied to the background level (
float).
Raises#
- InsufficientSourcesError
Raised if the number of good sky sources found is less than the minimum fraction (
self.config.minFractionSources``*``minFractionSourcesFactor) of the number requested (self.skyObjects.config.nSources).
- exposure
- detectFootprints(exposure, doSmooth=True, sigma=None, clearMask=True, expId=None, background=None, backgroundToPhotometricRatio=None)#
Detect footprints with a dynamic threshold
This varies from the vanilla
detectFootprintsmethod because we do detection three times: first with a high threshold to detect “bright” (both positive and negative, the latter to identify very over-subtracted regions) sources for which we grow the DETECTED and DETECTED_NEGATIVE masks significantly to account for wings. Second, with a low threshold to mask all non-empty regions of the image. These two masks are combined and used to identify regions of sky uncontaminated by objects. A final round of detection is then done with the new calculated threshold.Parameters#
- exposure
lsst.afw.image.Exposure Exposure to process; DETECTED{,_NEGATIVE} mask plane will be set in-place.
- doSmooth
bool, optional If True, smooth the image before detection using a Gaussian of width
sigma.- sigma
float, optional Gaussian Sigma of PSF (pixels); used for smoothing and to grow detections; if
Nonethen measure the sigma of the PSF of theexposure.- clearMask
bool, optional Clear both DETECTED and DETECTED_NEGATIVE planes before running detection.
- expId
int, optional Exposure identifier, used as a seed for the random number generator. If absent, the seed will be the sum of the image.
- background
lsst.afw.math.BackgroundList, optional Background that was already subtracted from the exposure; will be modified in-place if
reEstimateBackground=True.- backgroundToPhotometricRatio
lsst.afw.image.Image, optional Unused; if set will Raise.
Returns#
- results
lsst.pipe.base.Struct The results
Structcontains:positivePositive polarity footprints. (
lsst.afw.detection.FootprintSetorNone)negativeNegative polarity footprints. (
lsst.afw.detection.FootprintSetorNone)numPosNumber of footprints in positive or 0 if detection polarity was negative. (
int)numNegNumber of footprints in negative or 0 if detection polarity was positive. (
int)backgroundRe-estimated background.
Noneor the inputbackgroundifreEstimateBackground==False. (lsst.afw.math.BackgroundList)factorMultiplication factor applied to the configured detection threshold. (
float)prelimResults from preliminary detection pass. (
lsst.pipe.base.Struct)
- exposure
- tweakBackground(exposure, bgLevel, bgList=None)#
Modify the background by a constant value
Parameters#
- exposure
lsst.afw.image.Exposure Exposure for which to tweak background.
- bgLevel
float Background level to remove
- bgList
lsst.afw.math.BackgroundList, optional List of backgrounds to append to.
Returns#
- bg
lsst.afw.math.BackgroundMI Constant background model.
- exposure