Coverage for python/lsst/meas/algorithms/dynamicDetection.py : 93%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Configuration for DynamicDetectionTask""" doc="Fraction of the threshold to use for first pass (to find sky objects)") doc="Tweak background level so median PSF flux of sky objects is zero?") doc="Minimum number of sky sources in statistical sample; " "if below this number, we refuse to modify the threshold.")
"""Detection 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 (configurable ``skyObjects``). 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. """
"""Constructor
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. """
# Set up forced measurement. # We'll need the "centroid" and "psfFlux" slots refSchema=self.skySchema)
"""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.
Returns ------- result : `lsst.pipe.base.Struct` Result struct with components:
- ``multiplicative``: multiplicative factor to be applied to the configured detection threshold (`float`). - ``additive``: additive factor to be applied to the background level (`float`). """ # Make a catalog of sky objects
# Forced photometry on sky objects
# Calculate new threshold
np.isfinite(fluxes) & np.isfinite(area) & np.isfinite(bg))
good.sum(), self.config.minNumSources)
"""Detect footprints with a dynamic threshold
This varies from the vanilla ``detectFootprints`` method because we do detection twice: one with a low threshold so that we can find sky uncontaminated by objects, then one more 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 `None` then measure the sigma of the PSF of the ``exposure``. 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.
Return Struct contents ---------------------- positive : `lsst.afw.detection.FootprintSet` Positive polarity footprints (may be `None`) negative : `lsst.afw.detection.FootprintSet` Negative polarity footprints (may be `None`) numPos : `int` Number of footprints in positive or 0 if detection polarity was negative. numNeg : `int` Number of footprints in negative or 0 if detection polarity was positive. background : `lsst.afw.math.BackgroundList` Re-estimated background. `None` if ``reEstimateBackground==False``. factor : `float` Multiplication factor applied to the configured detection threshold. prelim : `lsst.pipe.base.Struct` Results from preliminary detection pass. """
else: oldDetected = maskedImage.mask.array & maskedImage.mask.getPlaneBitMask(["DETECTED", "DETECTED_NEGATIVE"])
# Could potentially smooth with a wider kernel than the PSF in order to better pick up the # wings of stars and galaxies, but for now sticking with the PSF as that's more simple.
# Calculate the proper threshold # seed needs to fit in a C++ 'int' so pybind doesn't choke on it factor, factor*self.config.thresholdValue)
# Blow away preliminary (low threshold) detection mask maskedImage.mask.array |= oldDetected
# Rinse and repeat thresholding with new calculated threshold
self.reEstimateBackground(maskedImage, results.background)
# Re-do the background tweak after any temporary backgrounds have been restored # # But we want to keep any large-scale background (e.g., scattered light from bright stars) # from being selected for sky objects in the calculation, so do another detection pass without # either the local or wide temporary background subtraction; the DETECTED pixels will mark # the area to ignore. finally:
"""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. """ lsst.afw.math.ApproximateControl.UNKNOWN, 0, 0, False) |