SourceDetectionTask¶
- class lsst.meas.algorithms.SourceDetectionTask(schema=None, **kwds)¶
- Bases: - Task- Detect peaks and footprints of sources in an image. - This task expects the image to have been background subtracted first. Running detection on images with a non-zero-centered background may result in a single source detected on the entire image containing thousands of peaks, or other pathological outputs. - Parameters:
- schemalsst.afw.table.Schema
- Schema object used to create the output - lsst.afw.table.SourceCatalog
- **kwds
- Keyword arguments passed to - lsst.pipe.base.Task.__init__
- If schema is not None and configured for ‘both’ detections,
- a ‘flags.negative’ field will be added to label detections made with a
- negative threshold.
 
- schema
 - Notes - This task convolves the image with a Gaussian approximation to the PSF, matched to the sigma of the input exposure, because this is separable and fast. The PSF would have to be very non-Gaussian or non-circular for this approximation to have a significant impact on the signal-to-noise of the detected sources. - Methods Summary - applyTempLocalBackground(exposure, middle, ...)- Apply a temporary local background subtraction - applyThreshold(middle, bbox[, factor, factorNeg])- Apply thresholds to the convolved image - calculateKernelSize(sigma)- Calculate the size of the smoothing kernel. - clearMask(mask)- Clear the DETECTED and DETECTED_NEGATIVE mask planes. - clearUnwantedResults(mask, results)- Clear unwanted results from the Struct of results - convolveImage(maskedImage, psf[, doSmooth])- Convolve the image with the PSF. - detectFootprints(exposure[, doSmooth, ...])- Detect footprints on an exposure. - display(exposure, results[, convolvedImage])- Display detections if so configured - Empty (clear) the metadata for this Task and all sub-Tasks. - finalizeFootprints(mask, results, sigma[, ...])- Finalize the detected footprints. - Get metadata for all tasks. - Get the task name as a hierarchical name including parent task names. - getName()- Get the name of the task. - getPsf(exposure[, sigma])- Create a single Gaussian PSF for an exposure. - Get a dictionary of all tasks as a shallow copy. - makeField(doc)- Make a - lsst.pex.config.ConfigurableFieldfor this task.- makeSubtask(name, **keyArgs)- Create a subtask as a new instance as the - nameattribute of this task.- makeThreshold(image, thresholdParity[, factor])- Make an afw.detection.Threshold object corresponding to the task's configuration and the statistics of the given image. - reEstimateBackground(maskedImage, backgrounds)- Estimate the background after detection - removeBadPixels(middle)- Set the significance of flagged pixels to zero. - run(table, exposure[, doSmooth, sigma, ...])- Detect sources and return catalog(s) of detections. - setEdgeBits(maskedImage, goodBBox, edgeBitmask)- Set the edgeBitmask bits for all of maskedImage outside goodBBox - setPeakSignificance(exposure, footprints, ...)- Set the significance of each detected peak to the pixel value divided by the appropriate standard-deviation for - config.thresholdType.- tempWideBackgroundContext(exposure)- Context manager for removing wide (large-scale) background - timer(name[, logLevel])- Context manager to log performance data for an arbitrary block of code. - updatePeaks(fpSet, image, threshold)- Update the Peaks in a FootprintSet by detecting new Footprints and Peaks in an image and using the new Peaks instead of the old ones. - Methods Documentation - applyTempLocalBackground(exposure, middle, results)¶
- Apply a temporary local background subtraction - This temporary local background serves to suppress noise fluctuations in the wings of bright objects. - Peaks in the footprints will be updated. - Parameters:
- exposurelsst.afw.image.Exposure
- Exposure for which to fit local background. 
- middlelsst.afw.image.MaskedImage
- Convolved image on which detection will be performed (typically smaller than - exposurebecause the half-kernel has been removed around the edges).
- resultslsst.pipe.base.Struct
- Results of the ‘detectFootprints’ method, containing positive and negative footprints (which contain the peak positions that we will plot). This is a - Structwith- positiveand- negativeelements that are of type- lsst.afw.detection.FootprintSet.
 
- exposure
 
 - applyThreshold(middle, bbox, factor=1.0, factorNeg=None)¶
- Apply thresholds to the convolved image - Identifies - Footprints, both positive and negative. The threshold can be modified by the provided multiplication- factor.- Parameters:
- middlelsst.afw.image.MaskedImage
- Convolved image to threshold. 
- bboxlsst.geom.Box2I
- Bounding box of unconvolved image. 
- factorfloat
- Multiplier for the configured threshold. 
- factorNegfloatorNone
- Multiplier for the configured threshold for negative detection polarity. If - None, will be set equal to- factor(i.e. equal to the factor used for positive detection polarity).
 
- middle
- Returns:
- resultslsst.pipe.base.Struct
- The - Structcontains:- positive
- Positive detection footprints, if configured. ( - lsst.afw.detection.FootprintSetor- None)
- negative
- Negative detection footprints, if configured. ( - lsst.afw.detection.FootprintSetor- None)
- factor
- Multiplier for the configured threshold. ( - float)
- factorNeg
- Multiplier for the configured threshold for negative detection polarity. ( - float)
 
 
- results
 
 - calculateKernelSize(sigma)¶
- Calculate the size of the smoothing kernel. - Uses the - nSigmaForKernelconfiguration parameter. Note that that is the full width of the kernel bounding box (so a value of 7 means 3.5 sigma on either side of center). The value will be rounded up to the nearest odd integer.
 - clearMask(mask)¶
- Clear the DETECTED and DETECTED_NEGATIVE mask planes. - Removes any previous detection mask in preparation for a new detection pass. - Parameters:
- masklsst.afw.image.Mask
- Mask to be cleared. 
 
- mask
 
 - clearUnwantedResults(mask, results)¶
- Clear unwanted results from the Struct of results - If we specifically want only positive or only negative detections, drop the ones we don’t want, and its associated mask plane. - Parameters:
- masklsst.afw.image.Mask
- Mask image. 
- resultslsst.pipe.base.Struct
- Detection results, with - positiveand- negativeelements; modified.
 
- mask
 
 - convolveImage(maskedImage, psf, doSmooth=True)¶
- Convolve the image with the PSF. - We convolve the image with a Gaussian approximation to the PSF, because this is separable and therefore fast. It’s technically a correlation rather than a convolution, but since we use a symmetric Gaussian there’s no difference. - The convolution can be disabled with - doSmooth=False. If we do convolve, we mask the edges as- EDGEand return the convolved image with the edges removed. This is because we can’t convolve the edges because the kernel would extend off the image.- Parameters:
- maskedImagelsst.afw.image.MaskedImage
- Image to convolve. 
- psflsst.afw.detection.Psf
- PSF to convolve with (actually with a Gaussian approximation to it). 
- doSmoothbool
- Actually do the convolution? Set to False when running on e.g. a pre-convolved image, or a mask plane. 
 
- maskedImage
- Returns:
- resultslsst.pipe.base.Struct
- The - Structcontains:- middle
- Convolved image, without the edges. ( - lsst.afw.image.MaskedImage)
- sigma
- Gaussian sigma used for the convolution. ( - float)
 
 
- results
 
 - detectFootprints(exposure, doSmooth=True, sigma=None, clearMask=True, expId=None, background=None, backgroundToPhotometricRatio=None)¶
- Detect footprints on an exposure. - Parameters:
- exposurelsst.afw.image.Exposure
- Exposure to process; DETECTED{,_NEGATIVE} mask plane will be set in-place. 
- doSmoothbool, optional
- If True, smooth the image before detection using a Gaussian of width - sigma, or the measured PSF width of- exposure. Set to False when running on e.g. a pre-convolved image, or a mask plane.
- sigmafloat, optional
- Gaussian Sigma of PSF (pixels); used for smoothing and to grow detections; if - Nonethen measure the sigma of the PSF of the- exposure.
- clearMaskbool, optional
- Clear both DETECTED and DETECTED_NEGATIVE planes before running detection. 
- expIddict, optional
- Exposure identifier; unused by this implementation, but used for RNG seed by subclasses. 
- backgroundlsst.afw.math.BackgroundList, optional
- Background that was already subtracted from the exposure; will be modified in-place if - reEstimateBackground=True.
- backgroundToPhotometricRatiolsst.afw.image.Image, optional
- Image to convert photometric-flattened image to background-flattened image if - reEstimateBackground=Trueand exposure has been photometric-flattened.
 
- exposure
- Returns:
- resultslsst.pipe.base.Struct
- A - Structcontaining:- positive
- Positive polarity footprints. ( - lsst.afw.detection.FootprintSetor- None)
- negative
- Negative polarity footprints. ( - lsst.afw.detection.FootprintSetor- None)
- numPos
- Number of footprints in positive or 0 if detection polarity was negative. ( - int)
- numNeg
- Number of footprints in negative or 0 if detection polarity was positive. ( - int)
- background
- Re-estimated background. - Noneor the input- backgroundif- reEstimateBackground==False. (- lsst.afw.math.BackgroundList)
- factor
- Multiplication factor applied to the configured detection threshold. ( - float)
 
 
- results
 
 - display(exposure, results, convolvedImage=None)¶
- Display detections if so configured - Displays the - exposurein frame 0, overlays the detection peaks.- Requires that - lsstDebughas been set up correctly, so that- lsstDebug.Info("lsst.meas.algorithms.detection")evaluates- True.- If the - convolvedImageis non-- Noneand- lsstDebug.Info("lsst.meas.algorithms.detection") > 1, the- convolvedImagewill be displayed in frame 1.- Parameters:
- exposurelsst.afw.image.Exposure
- Exposure to display, on which will be plotted the detections. 
- resultslsst.pipe.base.Struct
- Results of the ‘detectFootprints’ method, containing positive and negative footprints (which contain the peak positions that we will plot). This is a - Structwith- positiveand- negativeelements that are of type- lsst.afw.detection.FootprintSet.
- convolvedImagelsst.afw.image.Image, optional
- Convolved image used for thresholding. 
 
- exposure
 
 - finalizeFootprints(mask, results, sigma, factor=1.0, factorNeg=None)¶
- Finalize the detected footprints. - Grow the footprints, set the - DETECTEDand- DETECTED_NEGATIVEmask planes, and log the results.- numPos(number of positive footprints),- numPosPeaks(number of positive peaks),- numNeg(number of negative footprints),- numNegPeaks(number of negative peaks) entries are added to the- resultsstruct.- Parameters:
- masklsst.afw.image.Mask
- Mask image on which to flag detected pixels. 
- resultslsst.pipe.base.Struct
- Struct of detection results, including - positiveand- negativeentries; modified.
- sigmafloat
- Gaussian sigma of PSF. 
- factorfloat
- Multiplier for the configured threshold. Note that this is only used here for logging purposes. 
- factorNegfloatorNone
- Multiplier used for the negative detection polarity threshold. If - None, a factor equal to- factor(i.e. equal to the one used for positive detection polarity) is assumed. Note that this is only used here for logging purposes.
 
- mask
 
 - getFullMetadata() TaskMetadata¶
- Get metadata for all tasks. - Returns:
- metadataTaskMetadata
- The keys are the full task name. Values are metadata for the top-level task and all subtasks, sub-subtasks, etc. 
 
- metadata
 - Notes - The returned metadata includes timing information (if - @timer.timeMethodis used) and any metadata set by the task. The name of each item consists of the full task name with- .replaced by- :, followed by- .and the name of the item, e.g.:- topLevelTaskName:subtaskName:subsubtaskName.itemName - using - :in the full task name disambiguates the rare situation that a task has a subtask and a metadata item with the same name.
 - getFullName() str¶
- Get the task name as a hierarchical name including parent task names. - Returns:
- fullNamestr
- The full name consists of the name of the parent task and each subtask separated by periods. For example: - The full name of top-level task “top” is simply “top”. 
- The full name of subtask “sub” of top-level task “top” is “top.sub”. 
- The full name of subtask “sub2” of subtask “sub” of top-level task “top” is “top.sub.sub2”. 
 
 
- fullName
 
 - getName() str¶
- Get the name of the task. - Returns:
- taskNamestr
- Name of the task. 
 
- taskName
 - See also - getFullName
- Get the full name of the task. 
 
 - getPsf(exposure, sigma=None)¶
- Create a single Gaussian PSF for an exposure. - If - sigmais provided, we make a- GaussianPsfwith that, otherwise use the sigma from the psf of the- exposureto make the- GaussianPsf.- Parameters:
- exposurelsst.afw.image.Exposure
- Exposure from which to retrieve the PSF. 
- sigmafloat, optional
- Gaussian sigma to use if provided. 
 
- exposure
- Returns:
- psflsst.afw.detection.GaussianPsf
- PSF to use for detection. 
 
- psf
- Raises:
- RuntimeError
- Raised if - sigmais not provided and- exposuredoes not contain a- Psfobject.
 
 
 - getTaskDict() dict[str, weakref.ReferenceType[lsst.pipe.base.task.Task]]¶
- Get a dictionary of all tasks as a shallow copy. - Returns:
- taskDictdict
- Dictionary containing full task name: task object for the top-level task and all subtasks, sub-subtasks, etc. 
 
- taskDict
 
 - classmethod makeField(doc: str) ConfigurableField¶
- Make a - lsst.pex.config.ConfigurableFieldfor this task.- Parameters:
- docstr
- Help text for the field. 
 
- doc
- Returns:
- configurableFieldlsst.pex.config.ConfigurableField
- A - ConfigurableFieldfor this task.
 
- configurableField
 - Examples - Provides a convenient way to specify this task is a subtask of another task. - Here is an example of use: - class OtherTaskConfig(lsst.pex.config.Config): aSubtask = ATaskClass.makeField("brief description of task") 
 - makeSubtask(name: str, **keyArgs: Any) None¶
- Create a subtask as a new instance as the - nameattribute of this task.- Parameters:
- namestr
- Brief name of the subtask. 
- **keyArgs
- Extra keyword arguments used to construct the task. The following arguments are automatically provided and cannot be overridden: - config.
- parentTask.
 
 
- name
 - Notes - The subtask must be defined by - Task.config.name, an instance of- ConfigurableFieldor- RegistryField.
 - makeThreshold(image, thresholdParity, factor=1.0)¶
- Make an afw.detection.Threshold object corresponding to the task’s configuration and the statistics of the given image. - Parameters:
- imageafw.image.MaskedImage
- Image to measure noise statistics from if needed. 
- thresholdParity: `str`
- One of “positive” or “negative”, to set the kind of fluctuations the Threshold will detect. 
- factorfloat
- Factor by which to multiply the configured detection threshold. This is useful for tweaking the detection threshold slightly. 
 
- image
- Returns:
- thresholdlsst.afw.detection.Threshold
- Detection threshold. 
 
- threshold
 
 - reEstimateBackground(maskedImage, backgrounds, backgroundToPhotometricRatio=None)¶
- Estimate the background after detection - Parameters:
- maskedImagelsst.afw.image.MaskedImage
- Image on which to estimate the background. 
- backgroundslsst.afw.math.BackgroundList
- List of backgrounds; modified. 
- backgroundToPhotometricRatiolsst.afw.image.Image, optional
- Image to multiply a photometrically-flattened image by to obtain a background-flattened image. Only used if - config.doApplyFlatBackgroundRatiois- True.
 
- maskedImage
- Returns:
- bglsst.afw.math.backgroundMI
- Empirical background model. 
 
- bg
 
 - removeBadPixels(middle)¶
- Set the significance of flagged pixels to zero. - Parameters:
- middlelsst.afw.image.Exposure
- Score or maximum likelihood difference image. The image plane will be modified in place. 
 
- middle
 
 - run(table, exposure, doSmooth=True, sigma=None, clearMask=True, expId=None, background=None, backgroundToPhotometricRatio=None)¶
- Detect sources and return catalog(s) of detections. - Parameters:
- tablelsst.afw.table.SourceTable
- Table object that will be used to create the SourceCatalog. 
- exposurelsst.afw.image.Exposure
- Exposure to process; DETECTED mask plane will be set in-place. 
- doSmoothbool, optional
- If True, smooth the image before detection using a Gaussian of width - sigma, or the measured PSF width. Set to False when running on e.g. a pre-convolved image, or a mask plane.
- sigmafloat, optional
- Sigma of PSF (pixels); used for smoothing and to grow detections; if None then measure the sigma of the PSF of the exposure 
- clearMaskbool, optional
- Clear DETECTED{,_NEGATIVE} planes before running detection. 
- expIdint, optional
- Exposure identifier; unused by this implementation, but used for RNG seed by subclasses. 
- backgroundlsst.afw.math.BackgroundList, optional
- Background that was already subtracted from the exposure; will be modified in-place if - reEstimateBackground=True.
- backgroundToPhotometricRatiolsst.afw.image.Image, optional
- Image to convert photometric-flattened image to background-flattened image if - reEstimateBackground=Trueand exposure has been photometric-flattened.
 
- table
- Returns:
- resultlsst.pipe.base.Struct
- The - Structcontains:- sources
- Detected sources on the exposure. ( - lsst.afw.table.SourceCatalog)
- positive
- Positive polarity footprints. ( - lsst.afw.detection.FootprintSetor- None)
- negative
- Negative polarity footprints. ( - lsst.afw.detection.FootprintSetor- None)
- numPos
- Number of footprints in positive or 0 if detection polarity was negative. ( - int)
- numNeg
- Number of footprints in negative or 0 if detection polarity was positive. ( - int)
- background
- Re-estimated background. - Noneif- reEstimateBackground==False. (- lsst.afw.math.BackgroundList)
- factor
- Multiplication factor applied to the configured detection threshold. ( - float)
 
 
- result
- Raises:
- ValueError
- Raised if flags.negative is needed, but isn’t in table’s schema. 
- lsst.pipe.base.TaskError
- Raised if sigma=None, doSmooth=True and the exposure has no PSF. 
 
 - Notes - If you want to avoid dealing with Sources and Tables, you can use - detectFootprints()to just get the- FootprintSets.
 - static setEdgeBits(maskedImage, goodBBox, edgeBitmask)¶
- Set the edgeBitmask bits for all of maskedImage outside goodBBox - Parameters:
- maskedImagelsst.afw.image.MaskedImage
- Image on which to set edge bits in the mask. 
- goodBBoxlsst.geom.Box2I
- Bounding box of good pixels, in - LOCALcoordinates.
- edgeBitmasklsst.afw.image.MaskPixel
- Bit mask to OR with the existing mask bits in the region outside - goodBBox.
 
- maskedImage
 
 - setPeakSignificance(exposure, footprints, threshold, negative=False)¶
- Set the significance of each detected peak to the pixel value divided by the appropriate standard-deviation for - config.thresholdType.- Only sets significance for “stdev” and “pixel_stdev” thresholdTypes; we leave it undefined for “value” and “variance” as it does not have a well-defined meaning in those cases. - Parameters:
- exposurelsst.afw.image.Exposure
- Exposure that footprints were detected on, likely the convolved, local background-subtracted image. 
- footprintslsst.afw.detection.FootprintSet
- Footprints detected on the image. 
- thresholdlsst.afw.detection.Threshold
- Threshold used to find footprints. 
- negativebool, optional
- Are we calculating for negative sources? 
 
- exposure
 
 - tempWideBackgroundContext(exposure)¶
- Context manager for removing wide (large-scale) background - Removing a wide (large-scale) background helps to suppress the detection of large footprints that may overwhelm the deblender. It does, however, set a limit on the maximum scale of objects. - The background that we remove will be restored upon exit from the context manager. - Parameters:
- exposurelsst.afw.image.Exposure
- Exposure on which to remove large-scale background. 
 
- exposure
- Returns:
- contextcontext manager
- Context manager that will ensure the temporary wide background is restored. 
 
 
 - timer(name: str, logLevel: int = 10) Iterator[None]¶
- Context manager to log performance data for an arbitrary block of code. - Parameters:
 - See also - lsst.utils.timer.logInfo
- Implementation function. 
 - Examples - Creating a timer context: - with self.timer("someCodeToTime"): pass # code to time 
 - updatePeaks(fpSet, image, threshold)¶
- Update the Peaks in a FootprintSet by detecting new Footprints and Peaks in an image and using the new Peaks instead of the old ones. - Parameters:
- fpSetafw.detection.FootprintSet
- Set of Footprints whose Peaks should be updated. 
- imageafw.image.MaskedImage
- Image to detect new Footprints and Peak in. 
- thresholdafw.detection.Threshold
- Threshold object for detection. 
- Input Footprints with fewer Peaks than self.config.nPeaksMaxSimple
- are not modified, and if no new Peaks are detected in an input
- Footprint, the brightest original Peak in that Footprint is kept.
 
- fpSet