24__all__ = (
"SourceDetectionConfig",
"SourceDetectionTask",
"addExposures")
26from contextlib
import contextmanager
39from lsst.utils.timer
import timeMethod
40from .subtractBackground
import SubtractBackgroundTask
44 """Configuration parameters for the SourceDetectionTask
46 minPixels = pexConfig.RangeField(
47 doc="detected sources with fewer than the specified number of pixels will be ignored",
48 dtype=int, optional=
False, default=1, min=0,
50 isotropicGrow = pexConfig.Field(
51 doc=
"Pixels should be grown as isotropically as possible (slower)",
52 dtype=bool, optional=
False, default=
False,
54 combinedGrow = pexConfig.Field(
55 doc=
"Grow all footprints at the same time? This allows disconnected footprints to merge.",
56 dtype=bool, default=
True,
58 nSigmaToGrow = pexConfig.Field(
59 doc=
"Grow detections by nSigmaToGrow * [PSF RMS width]; if 0 then do not grow",
60 dtype=float, default=2.4,
62 returnOriginalFootprints = pexConfig.Field(
63 doc=
"Grow detections to set the image mask bits, but return the original (not-grown) footprints",
64 dtype=bool, optional=
False, default=
False,
66 thresholdValue = pexConfig.RangeField(
67 doc=
"Threshold for footprints; exact meaning and units depend on thresholdType.",
68 dtype=float, optional=
False, default=5.0, min=0.0,
70 includeThresholdMultiplier = pexConfig.RangeField(
71 doc=
"Include threshold relative to thresholdValue",
72 dtype=float, default=1.0, min=0.0,
74 thresholdType = pexConfig.ChoiceField(
75 doc=
"specifies the desired flavor of Threshold",
76 dtype=str, optional=
False, default=
"stdev",
78 "variance":
"threshold applied to image variance",
79 "stdev":
"threshold applied to image std deviation",
80 "value":
"threshold applied to image value",
81 "pixel_stdev":
"threshold applied to per-pixel std deviation",
84 thresholdPolarity = pexConfig.ChoiceField(
85 doc=
"specifies whether to detect positive, or negative sources, or both",
86 dtype=str, optional=
False, default=
"positive",
88 "positive":
"detect only positive sources",
89 "negative":
"detect only negative sources",
90 "both":
"detect both positive and negative sources",
93 adjustBackground = pexConfig.Field(
95 doc=
"Fiddle factor to add to the background; debugging only",
98 reEstimateBackground = pexConfig.Field(
100 doc=
"Estimate the background again after final source detection?",
101 default=
True, optional=
False,
103 background = pexConfig.ConfigurableField(
104 doc=
"Background re-estimation; ignored if reEstimateBackground false",
105 target=SubtractBackgroundTask,
107 tempLocalBackground = pexConfig.ConfigurableField(
108 doc=(
"A local (small-scale), temporary background estimation step run between "
109 "detecting above-threshold regions and detecting the peaks within "
110 "them; used to avoid detecting spuerious peaks in the wings."),
111 target=SubtractBackgroundTask,
113 doTempLocalBackground = pexConfig.Field(
115 doc=
"Enable temporary local background subtraction? (see tempLocalBackground)",
118 tempWideBackground = pexConfig.ConfigurableField(
119 doc=(
"A wide (large-scale) background estimation and removal before footprint and peak detection. "
120 "It is added back into the image after detection. The purpose is to suppress very large "
121 "footprints (e.g., from large artifacts) that the deblender may choke on."),
122 target=SubtractBackgroundTask,
124 doTempWideBackground = pexConfig.Field(
126 doc=
"Do temporary wide (large-scale) background subtraction before footprint detection?",
129 nPeaksMaxSimple = pexConfig.Field(
131 doc=(
"The maximum number of peaks in a Footprint before trying to "
132 "replace its peaks using the temporary local background"),
135 nSigmaForKernel = pexConfig.Field(
137 doc=(
"Multiple of PSF RMS size to use for convolution kernel bounding box size; "
138 "note that this is not a half-size. The size will be rounded up to the nearest odd integer"),
141 statsMask = pexConfig.ListField(
143 doc=
"Mask planes to ignore when calculating statistics of image (for thresholdType=stdev)",
144 default=[
'BAD',
'SAT',
'EDGE',
'NO_DATA'],
157 for maskPlane
in (
"DETECTED",
"DETECTED_NEGATIVE"):
163 """Create the detection task. Most arguments are simply passed onto pipe.base.Task.
170 Keyword arguments passed to `lsst.pipe.base.task.Task.__init__`
172 If schema is not None and configured
for 'both' detections,
173 a
'flags.negative' field will be added to label detections made
with a
178 This task can add fields to the schema, so any code calling this task must ensure that
179 these columns are indeed present
in the input match list.
182 ConfigClass = SourceDetectionConfig
183 _DefaultName = "sourceDetection"
186 pipeBase.Task.__init__(self, **kwds)
187 if schema
is not None and self.config.thresholdPolarity ==
"both":
189 "flags_negative", type=
"Flag",
190 doc=
"set if source was detected as significantly negative"
193 if self.config.thresholdPolarity ==
"both":
194 self.log.warning(
"Detection polarity set to 'both', but no flag will be "
195 "set to distinguish between positive and negative detections")
197 if self.config.reEstimateBackground:
198 self.makeSubtask(
"background")
199 if self.config.doTempLocalBackground:
200 self.makeSubtask(
"tempLocalBackground")
201 if self.config.doTempWideBackground:
202 self.makeSubtask(
"tempWideBackground")
205 def run(self, table, exposure, doSmooth=True, sigma=None, clearMask=True, expId=None):
206 r"""Run source detection and create a SourceCatalog of detections.
211 Table object that will be used to create the SourceCatalog.
213 Exposure to process; DETECTED mask plane will be set in-place.
215 If
True, smooth the image before detection using a Gaussian of width
216 ``sigma``,
or the measured PSF width. Set to
False when running on
217 e.g. a pre-convolved image,
or a mask plane.
219 Sigma of PSF (pixels); used
for smoothing
and to grow detections;
220 if None then measure the sigma of the PSF of the exposure
222 Clear DETECTED{,_NEGATIVE} planes before running detection.
224 Exposure identifier; unused by this implementation, but used
for
225 RNG seed by subclasses.
229 result : `lsst.pipe.base.Struct`
230 The `~lsst.pipe.base.Struct` contains:
236 (`lsst.pipe.base.Struct`).
241 Raised
if flags.negative
is needed, but isn
't in table's schema.
242 lsst.pipe.base.TaskError
243 Raised
if sigma=
None, doSmooth=
True and the exposure has no PSF.
247 If you want to avoid dealing
with Sources
and Tables, you can use
252 raise ValueError(
"Table has incorrect Schema")
253 results = self.
detectFootprints(exposure=exposure, doSmooth=doSmooth, sigma=sigma,
254 clearMask=clearMask, expId=expId)
256 sources.reserve(results.numPos + results.numNeg)
258 results.negative.makeSources(sources)
260 for record
in sources:
263 results.positive.makeSources(sources)
264 results.fpSets = results.copy()
265 results.sources = sources
268 def display(self, exposure, results, convolvedImage=None):
269 """Display detections if so configured
271 Displays the ``exposure`` in frame 0, overlays the detection peaks.
273 Requires that ``lsstDebug`` has been set up correctly, so that
274 ``
lsstDebug.Info(
"lsst.meas.algorithms.detection")`` evaluates `
True`.
276 If the ``convolvedImage``
is non-`
None`
and
278 ``convolvedImage`` will be displayed
in frame 1.
283 Exposure to display, on which will be plotted the detections.
284 results : `lsst.pipe.base.Struct`
285 Results of the
'detectFootprints' method, containing positive
and
286 negative footprints (which contain the peak positions that we will
287 plot). This
is a `Struct`
with ``positive``
and ``negative``
290 Convolved image used
for thresholding.
303 afwDisplay.setDefaultMaskTransparency(75)
305 disp0 = afwDisplay.Display(frame=0)
306 disp0.mtv(exposure, title=
"detection")
308 def plotPeaks(fps, ctype):
311 with disp0.Buffering():
312 for fp
in fps.getFootprints():
313 for pp
in fp.getPeaks():
314 disp0.dot(
"+", pp.getFx(), pp.getFy(), ctype=ctype)
315 plotPeaks(results.positive,
"yellow")
316 plotPeaks(results.negative,
"red")
318 if convolvedImage
and display > 1:
319 disp1 = afwDisplay.Display(frame=1)
320 disp1.mtv(convolvedImage, title=
"PSF smoothed")
322 disp2 = afwDisplay.Display(frame=2)
323 disp2.mtv(afwImage.ImageF(np.sqrt(exposure.variance.array)), title=
"stddev")
326 """Apply a temporary local background subtraction
328 This temporary local background serves to suppress noise fluctuations
329 in the wings of bright objects.
331 Peaks
in the footprints will be updated.
336 Exposure
for which to fit local background.
338 Convolved image on which detection will be performed
339 (typically smaller than ``exposure`` because the
340 half-kernel has been removed around the edges).
341 results : `lsst.pipe.base.Struct`
342 Results of the
'detectFootprints' method, containing positive
and
343 negative footprints (which contain the peak positions that we will
344 plot). This
is a `Struct`
with ``positive``
and ``negative``
350 bg = self.tempLocalBackground.fitBackground(exposure.getMaskedImage())
351 bgImage = bg.getImageF(self.tempLocalBackground.config.algorithm,
352 self.tempLocalBackground.config.undersampleStyle)
353 middle -= bgImage.Factory(bgImage, middle.getBBox())
354 if self.config.thresholdPolarity !=
"negative":
355 results.positiveThreshold = self.
makeThreshold(middle,
"positive")
356 self.
updatePeaks(results.positive, middle, results.positiveThreshold)
357 if self.config.thresholdPolarity !=
"positive":
358 results.negativeThreshold = self.
makeThreshold(middle,
"negative")
359 self.
updatePeaks(results.negative, middle, results.negativeThreshold)
362 """Clear the DETECTED and DETECTED_NEGATIVE mask planes
364 Removes any previous detection mask in preparation
for a new
372 mask &= ~(mask.getPlaneBitMask("DETECTED") | mask.getPlaneBitMask(
"DETECTED_NEGATIVE"))
375 """Calculate size of smoothing kernel
377 Uses the ``nSigmaForKernel`` configuration parameter. Note
378 that that is the full width of the kernel bounding box
379 (so a value of 7 means 3.5 sigma on either side of center).
380 The value will be rounded up to the nearest odd integer.
385 Gaussian sigma of smoothing kernel.
390 Size of the smoothing kernel.
392 return (int(sigma * self.config.nSigmaForKernel + 0.5)//2)*2 + 1
395 """Retrieve the PSF for an exposure
397 If ``sigma`` is provided, we make a ``GaussianPsf``
with that,
398 otherwise use the one
from the ``exposure``.
403 Exposure
from which to retrieve the PSF.
404 sigma : `float`, optional
405 Gaussian sigma to use
if provided.
410 PSF to use
for detection.
413 psf = exposure.getPsf()
415 raise RuntimeError(
"Unable to determine PSF to use for detection: no sigma provided")
416 sigma = psf.computeShape(psf.getAveragePosition()).getDeterminantRadius()
422 """Convolve the image with the PSF
424 We convolve the image with a Gaussian approximation to the PSF,
425 because this
is separable
and therefore fast. It
's technically a
426 correlation rather than a convolution, but since we use a symmetric
427 Gaussian there's no difference.
429 The convolution can be disabled with ``doSmooth=
False``. If we do
430 convolve, we mask the edges
as ``EDGE``
and return the convolved image
431 with the edges removed. This
is because we can
't convolve the edges
432 because the kernel would extend off the image.
439 PSF to convolve with (actually
with a Gaussian approximation
442 Actually do the convolution? Set to
False when running on
443 e.g. a pre-convolved image,
or a mask plane.
447 results : `lsst.pipe.base.Struct`
448 The `~lsst.pipe.base.Struct` contains:
453 Gaussian sigma used
for the convolution. (`float`)
455 self.metadata["doSmooth"] = doSmooth
456 sigma = psf.computeShape(psf.getAveragePosition()).getDeterminantRadius()
457 self.metadata[
"sigma"] = sigma
460 middle = maskedImage.Factory(maskedImage, deep=
True)
461 return pipeBase.Struct(middle=middle, sigma=sigma)
466 self.metadata[
"smoothingKernelWidth"] = kWidth
467 gaussFunc = afwMath.GaussianFunction1D(sigma)
470 convolvedImage = maskedImage.Factory(maskedImage.getBBox())
476 goodBBox = gaussKernel.shrinkBBox(convolvedImage.getBBox())
477 middle = convolvedImage.Factory(convolvedImage, goodBBox, afwImage.PARENT,
False)
481 self.
setEdgeBits(maskedImage, goodBBox, maskedImage.getMask().getPlaneBitMask(
"EDGE"))
483 return pipeBase.Struct(middle=middle, sigma=sigma)
486 r"""Apply thresholds to the convolved image
488 Identifies ``Footprint``\ s, both positive and negative.
490 The threshold can be modified by the provided multiplication
496 Convolved image to threshold.
498 Bounding box of unconvolved image.
500 Multiplier
for the configured threshold.
504 results : `lsst.pipe.base.Struct`
505 The `~lsst.pipe.base.Struct` contains:
508 Positive detection footprints,
if configured.
511 Negative detection footprints,
if configured.
514 Multiplier
for the configured threshold.
517 results = pipeBase.Struct(positive=None, negative=
None, factor=factor,
518 positiveThreshold=
None, negativeThreshold=
None)
520 if self.config.reEstimateBackground
or self.config.thresholdPolarity !=
"negative":
521 results.positiveThreshold = self.
makeThreshold(middle,
"positive", factor=factor)
524 results.positiveThreshold,
526 self.config.minPixels
528 results.positive.setRegion(bbox)
529 if self.config.reEstimateBackground
or self.config.thresholdPolarity !=
"positive":
530 results.negativeThreshold = self.
makeThreshold(middle,
"negative", factor=factor)
533 results.negativeThreshold,
535 self.config.minPixels
537 results.negative.setRegion(bbox)
542 """Finalize the detected footprints
544 Grows the footprints, sets the ``DETECTED`` and ``DETECTED_NEGATIVE``
545 mask planes,
and logs the results.
547 ``numPos`` (number of positive footprints), ``numPosPeaks`` (number
548 of positive peaks), ``numNeg`` (number of negative footprints),
549 ``numNegPeaks`` (number of negative peaks) entries are added to the
555 Mask image on which to flag detected pixels.
556 results : `lsst.pipe.base.Struct`
557 Struct of detection results, including ``positive``
and
558 ``negative`` entries; modified.
560 Gaussian sigma of PSF.
562 Multiplier
for the configured threshold.
564 for polarity, maskName
in ((
"positive",
"DETECTED"), (
"negative",
"DETECTED_NEGATIVE")):
565 fpSet = getattr(results, polarity)
568 if self.config.nSigmaToGrow > 0:
569 nGrow = int((self.config.nSigmaToGrow * sigma) + 0.5)
570 self.metadata[
"nGrow"] = nGrow
571 if self.config.combinedGrow:
574 stencil = (afwGeom.Stencil.CIRCLE
if self.config.isotropicGrow
else
575 afwGeom.Stencil.MANHATTAN)
577 fp.dilate(nGrow, stencil)
578 fpSet.setMask(mask, maskName)
579 if not self.config.returnOriginalFootprints:
580 setattr(results, polarity, fpSet)
583 results.numPosPeaks = 0
585 results.numNegPeaks = 0
589 if results.positive
is not None:
590 results.numPos = len(results.positive.getFootprints())
591 results.numPosPeaks = sum(len(fp.getPeaks())
for fp
in results.positive.getFootprints())
592 positive =
" %d positive peaks in %d footprints" % (results.numPosPeaks, results.numPos)
593 if results.negative
is not None:
594 results.numNeg = len(results.negative.getFootprints())
595 results.numNegPeaks = sum(len(fp.getPeaks())
for fp
in results.negative.getFootprints())
596 negative =
" %d negative peaks in %d footprints" % (results.numNegPeaks, results.numNeg)
598 self.log.info(
"Detected%s%s%s to %g %s",
599 positive,
" and" if positive
and negative
else "", negative,
600 self.config.thresholdValue*self.config.includeThresholdMultiplier*factor,
601 "DN" if self.config.thresholdType ==
"value" else "sigma")
604 """Estimate the background after detection
609 Image on which to estimate the background.
611 List of backgrounds; modified.
615 bg : `lsst.afw.math.backgroundMI`
616 Empirical background model.
618 bg = self.background.fitBackground(maskedImage)
619 if self.config.adjustBackground:
620 self.log.warning(
"Fiddling the background by %g", self.config.adjustBackground)
621 bg += self.config.adjustBackground
622 self.log.info(
"Resubtracting the background after object detection")
623 maskedImage -= bg.getImageF(self.background.config.algorithm,
624 self.background.config.undersampleStyle)
626 actrl = bg.getBackgroundControl().getApproximateControl()
628 bg.getAsUsedUndersampleStyle(), actrl.getStyle(), actrl.getOrderX(),
629 actrl.getOrderY(), actrl.getWeighting()))
633 """Clear unwanted results from the Struct of results
635 If we specifically want only positive or only negative detections,
636 drop the ones we don
't want, and its associated mask plane.
642 results : `lsst.pipe.base.Struct`
643 Detection results, with ``positive``
and ``negative`` elements;
646 if self.config.thresholdPolarity ==
"positive":
647 if self.config.reEstimateBackground:
648 mask &= ~mask.getPlaneBitMask(
"DETECTED_NEGATIVE")
649 results.negative =
None
650 elif self.config.thresholdPolarity ==
"negative":
651 if self.config.reEstimateBackground:
652 mask &= ~mask.getPlaneBitMask(
"DETECTED")
653 results.positive =
None
656 def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True, expId=None):
657 """Detect footprints on an exposure.
662 Exposure to process; DETECTED{,_NEGATIVE} mask plane will be
664 doSmooth : `bool`, optional
665 If
True, smooth the image before detection using a Gaussian
666 of width ``sigma``,
or the measured PSF width of ``exposure``.
667 Set to
False when running on e.g. a pre-convolved image,
or a mask
669 sigma : `float`, optional
670 Gaussian Sigma of PSF (pixels); used
for smoothing
and to grow
671 detections;
if `
None` then measure the sigma of the PSF of the
673 clearMask : `bool`, optional
674 Clear both DETECTED
and DETECTED_NEGATIVE planes before running
676 expId : `dict`, optional
677 Exposure identifier; unused by this implementation, but used
for
678 RNG seed by subclasses.
682 results : `lsst.pipe.base.Struct`
683 A `~lsst.pipe.base.Struct` containing:
686 Positive polarity footprints.
689 Negative polarity footprints.
692 Number of footprints
in positive
or 0
if detection polarity was
695 Number of footprints
in negative
or 0
if detection polarity was
698 Re-estimated background. `
None`
if
699 ``reEstimateBackground==
False``.
702 Multiplication factor applied to the configured detection
705 maskedImage = exposure.maskedImage
710 psf = self.
getPsf(exposure, sigma=sigma)
712 convolveResults = self.
convolveImage(maskedImage, psf, doSmooth=doSmooth)
713 middle = convolveResults.middle
714 sigma = convolveResults.sigma
718 if self.config.doTempLocalBackground:
725 results.positive = self.
setPeakSignificance(middle, results.positive, results.positiveThreshold)
726 results.negative = self.
setPeakSignificance(middle, results.negative, results.negativeThreshold,
729 if self.config.reEstimateBackground:
734 self.
display(exposure, results, middle)
739 """Set the significance of each detected peak to the pixel value divided
740 by the appropriate standard-deviation for ``config.thresholdType``.
742 Only sets significance
for "stdev" and "pixel_stdev" thresholdTypes;
743 we leave it undefined
for "value" and "variance" as it does
not have a
744 well-defined meaning
in those cases.
749 Exposure that footprints were detected on, likely the convolved,
750 local background-subtracted image.
752 Footprints detected on the image.
754 Threshold used to find footprints.
755 negative : `bool`, optional
756 Are we calculating
for negative sources?
758 if footprints
is None or footprints.getFootprints() == []:
760 polarity = -1
if negative
else 1
764 mapper.addMinimalSchema(footprints.getFootprints()[0].peaks.schema)
765 mapper.addOutputField(
"significance", type=float,
766 doc=
"Ratio of peak value to configured standard deviation.")
772 for old, new
in zip(footprints.getFootprints(), newFootprints.getFootprints()):
774 newPeaks.extend(old.peaks, mapper=mapper)
775 new.getPeaks().clear()
776 new.setPeakCatalog(newPeaks)
779 if self.config.thresholdType ==
"pixel_stdev":
780 for footprint
in newFootprints.getFootprints():
781 footprint.updatePeakSignificance(exposure.variance, polarity)
782 elif self.config.thresholdType ==
"stdev":
783 sigma = threshold.getValue() / self.config.thresholdValue
784 for footprint
in newFootprints.getFootprints():
785 footprint.updatePeakSignificance(polarity*sigma)
787 for footprint
in newFootprints.getFootprints():
788 for peak
in footprint.peaks:
789 peak[
"significance"] = 0
794 """Make an afw.detection.Threshold object corresponding to the task's
795 configuration and the statistics of the given image.
800 Image to measure noise statistics
from if needed.
801 thresholdParity: `str`
802 One of
"positive" or "negative", to set the kind of fluctuations
803 the Threshold will detect.
805 Factor by which to multiply the configured detection threshold.
806 This
is useful
for tweaking the detection threshold slightly.
813 parity = False if thresholdParity ==
"negative" else True
814 thresholdValue = self.config.thresholdValue
815 thresholdType = self.config.thresholdType
816 if self.config.thresholdType ==
'stdev':
817 bad = image.getMask().getPlaneBitMask(self.config.statsMask)
819 sctrl.setAndMask(bad)
821 thresholdValue *= stats.getValue(afwMath.STDEVCLIP)
822 thresholdType =
'value'
825 threshold.setIncludeMultiplier(self.config.includeThresholdMultiplier)
826 self.log.debug(
"Detection threshold: %s", threshold)
830 """Update the Peaks in a FootprintSet by detecting new Footprints and
831 Peaks in an image
and using the new Peaks instead of the old ones.
836 Set of Footprints whose Peaks should be updated.
838 Image to detect new Footprints
and Peak
in.
840 Threshold object
for detection.
842 Input Footprints
with fewer Peaks than self.config.nPeaksMaxSimple
843 are
not modified,
and if no new Peaks are detected
in an input
844 Footprint, the brightest original Peak
in that Footprint
is kept.
846 for footprint
in fpSet.getFootprints():
847 oldPeaks = footprint.getPeaks()
848 if len(oldPeaks) <= self.config.nPeaksMaxSimple:
853 sub = image.Factory(image, footprint.getBBox())
858 self.config.minPixels
861 for fpForPeaks
in fpSetForPeaks.getFootprints():
862 for peak
in fpForPeaks.getPeaks():
863 if footprint.contains(peak.getI()):
864 newPeaks.append(peak)
865 if len(newPeaks) > 0:
867 oldPeaks.extend(newPeaks)
873 """Set the edgeBitmask bits for all of maskedImage outside goodBBox
878 Image on which to set edge bits in the mask.
880 Bounding box of good pixels,
in ``LOCAL`` coordinates.
882 Bit mask to OR
with the existing mask bits
in the region
883 outside ``goodBBox``.
885 msk = maskedImage.getMask()
887 mx0, my0 = maskedImage.getXY0()
888 for x0, y0, w, h
in ([0, 0,
889 msk.getWidth(), goodBBox.getBeginY() - my0],
890 [0, goodBBox.getEndY() - my0, msk.getWidth(),
891 maskedImage.getHeight() - (goodBBox.getEndY() - my0)],
893 goodBBox.getBeginX() - mx0, msk.getHeight()],
894 [goodBBox.getEndX() - mx0, 0,
895 maskedImage.getWidth() - (goodBBox.getEndX() - mx0), msk.getHeight()],
899 edgeMask |= edgeBitmask
903 """Context manager for removing wide (large-scale) background
905 Removing a wide (large-scale) background helps to suppress the
906 detection of large footprints that may overwhelm the deblender.
907 It does, however, set a limit on the maximum scale of objects.
909 The background that we remove will be restored upon exit from
915 Exposure on which to remove large-scale background.
919 context : context manager
920 Context manager that will ensure the temporary wide background
923 doTempWideBackground = self.config.doTempWideBackground
924 if doTempWideBackground:
925 self.log.info(
"Applying temporary wide background subtraction")
926 original = exposure.maskedImage.image.array[:].copy()
927 self.tempWideBackground.run(exposure).background
930 image = exposure.maskedImage.image
931 mask = exposure.maskedImage.mask
932 noData = mask.array & mask.getPlaneBitMask(
"NO_DATA") > 0
933 isGood = mask.array & mask.getPlaneBitMask(self.config.statsMask) == 0
934 image.array[noData] = np.median(image.array[~noData & isGood])
938 if doTempWideBackground:
939 exposure.maskedImage.image.array[:] = original
943 """Add a set of exposures together.
948 Sequence of exposures to add.
953 An exposure of the same size as each exposure
in ``exposureList``,
954 with the metadata
from ``exposureList[0]``
and a masked image equal
955 to the sum of all the exposure
's masked images.
957 exposure0 = exposureList[0]
958 image0 = exposure0.getMaskedImage()
960 addedImage = image0.Factory(image0, True)
961 addedImage.setXY0(image0.getXY0())
963 for exposure
in exposureList[1:]:
964 image = exposure.getMaskedImage()
967 addedExposure = exposure0.Factory(addedImage, exposure0.getWcs())
A circularly symmetric Gaussian Psf class with no spatial variation, intended mostly for testing purp...
A polymorphic base class for representing an image's Point Spread Function.
A Threshold is used to pass a threshold value to detection algorithms.
A class to contain the data, WCS, and other information needed to describe an image of the sky.
A class to represent a 2-dimensional array of pixels.
Represent a 2-dimensional array of bitmask pixels.
A class to manipulate images, masks, and variance as a single object.
Parameters to control convolution.
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Pass parameters to a Statistics object.
Defines the fields and offsets for a table.
A mapping between the keys of two Schemas, used to copy data between them.
Table class that contains measurements made on a single exposure.
An integer coordinate rectangle.
def tempWideBackgroundContext(self, exposure)
def getPsf(self, exposure, sigma=None)
def __init__(self, schema=None, **kwds)
def makeThreshold(self, image, thresholdParity, factor=1.0)
def setPeakSignificance(self, exposure, footprints, threshold, negative=False)
def convolveImage(self, maskedImage, psf, doSmooth=True)
def applyTempLocalBackground(self, exposure, middle, results)
def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True, expId=None)
def reEstimateBackground(self, maskedImage, backgrounds)
def updatePeaks(self, fpSet, image, threshold)
def finalizeFootprints(self, mask, results, sigma, factor=1.0)
def setEdgeBits(maskedImage, goodBBox, edgeBitmask)
def clearUnwantedResults(self, mask, results)
def clearMask(self, mask)
def display(self, exposure, results, convolvedImage=None)
def applyThreshold(self, middle, bbox, factor=1.0)
def calculateKernelSize(self, sigma)
Threshold createThreshold(const double value, const std::string type="value", const bool polarity=true)
Factory method for creating Threshold objects.
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
void convolve(OutImageT &convolvedImage, InImageT const &inImage, KernelT const &kernel, ConvolutionControl const &convolutionControl=ConvolutionControl())
Convolve an Image or MaskedImage with a Kernel, setting pixels of an existing output image.
def addExposures(exposureList)