LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
Classes | Functions
lsst.pipe.tasks.maskStreaks Namespace Reference

Classes

class  Line
 
class  LineCollection
 
class  LineProfile
 
class  MaskStreaksConfig
 
class  MaskStreaksTask
 

Functions

def setDetectionMask (maskedImage, forceSlowBin=False, binning=None, detectedPlane="DETECTED", badMaskPlanes=("NO_DATA", "INTRP", "BAD", "SAT", "EDGE"), detectionThreshold=5)
 

Function Documentation

◆ setDetectionMask()

def lsst.pipe.tasks.maskStreaks.setDetectionMask (   maskedImage,
  forceSlowBin = False,
  binning = None,
  detectedPlane = "DETECTED",
  badMaskPlanes = ("NO_DATA", "INTRP", "BAD", "SAT", "EDGE"),
  detectionThreshold = 5 
)
Make detection mask and set the mask plane

Creat a binary image from a masked image by setting all data with signal-to-
noise below some threshold to zero, and all data above the threshold to one.
If the binning parameter has been set, this procedure will be preceded by a
weighted binning of the data in order to smooth the result, after which the
result is scaled back to the original dimensions. Set the detection mask
plane with this binary image.

Parameters
----------
maskedImage : `lsst.afw.image.maskedImage`
    Image to be (optionally) binned and converted
forceSlowBin : bool (optional)
    Force usage of slower binning method to check that the two methods
    give the same result.
binning : int (optional)
    Number of pixels by which to bin image
detectedPlane : str (optional)
    Name of mask with pixels that were detected above threshold in image
badMaskPlanes : set (optional)
    Names of masks with pixels that are rejected
detectionThreshold : float (optional)
    Boundary in signal-to-noise between non-detections and detections for
    making a binary image from the original input image

Definition at line 40 of file maskStreaks.py.

41 badMaskPlanes=("NO_DATA", "INTRP", "BAD", "SAT", "EDGE"), detectionThreshold=5):
42 """Make detection mask and set the mask plane
43
44 Creat a binary image from a masked image by setting all data with signal-to-
45 noise below some threshold to zero, and all data above the threshold to one.
46 If the binning parameter has been set, this procedure will be preceded by a
47 weighted binning of the data in order to smooth the result, after which the
48 result is scaled back to the original dimensions. Set the detection mask
49 plane with this binary image.
50
51 Parameters
52 ----------
53 maskedImage : `lsst.afw.image.maskedImage`
54 Image to be (optionally) binned and converted
55 forceSlowBin : bool (optional)
56 Force usage of slower binning method to check that the two methods
57 give the same result.
58 binning : int (optional)
59 Number of pixels by which to bin image
60 detectedPlane : str (optional)
61 Name of mask with pixels that were detected above threshold in image
62 badMaskPlanes : set (optional)
63 Names of masks with pixels that are rejected
64 detectionThreshold : float (optional)
65 Boundary in signal-to-noise between non-detections and detections for
66 making a binary image from the original input image
67 """
68 data = maskedImage.image.array
69 weights = 1 / maskedImage.variance.array
70 mask = maskedImage.getMask()
71
72 detectionMask = ((mask.array & mask.getPlaneBitMask(detectedPlane)))
73 badPixelMask = mask.getPlaneBitMask(badMaskPlanes)
74 badMask = (mask.array & badPixelMask) > 0
75 fitMask = detectionMask.astype(bool) & ~badMask
76
77 fitData = np.copy(data)
78 fitData[~fitMask] = 0
79 fitWeights = np.copy(weights)
80 fitWeights[~fitMask] = 0
81
82 if binning:
83 # Do weighted binning:
84 ymax, xmax = fitData.shape
85 if (ymax % binning == 0) and (xmax % binning == 0) and (not forceSlowBin):
86 # Faster binning method
87 binNumeratorReshape = (fitData * fitWeights).reshape(ymax // binning, binning,
88 xmax // binning, binning)
89 binDenominatorReshape = fitWeights.reshape(binNumeratorReshape.shape)
90 binnedNumerator = binNumeratorReshape.sum(axis=3).sum(axis=1)
91 binnedDenominator = binDenominatorReshape.sum(axis=3).sum(axis=1)
92 else:
93 # Slower binning method when (image shape mod binsize) != 0
94 warnings.warn('Using slow binning method--consider choosing a binsize that evenly divides '
95 f'into the image size, so that {ymax} mod binning == 0 '
96 f'and {xmax} mod binning == 0')
97 xarray = np.arange(xmax)
98 yarray = np.arange(ymax)
99 xmesh, ymesh = np.meshgrid(xarray, yarray)
100 xbins = np.arange(0, xmax + binning, binning)
101 ybins = np.arange(0, ymax + binning, binning)
102 numerator = fitWeights * fitData
103 binnedNumerator, *_ = scipy.stats.binned_statistic_2d(ymesh.ravel(), xmesh.ravel(),
104 numerator.ravel(), statistic='sum',
105 bins=(ybins, xbins))
106 binnedDenominator, *_ = scipy.stats.binned_statistic_2d(ymesh.ravel(), xmesh.ravel(),
107 fitWeights.ravel(), statistic='sum',
108 bins=(ybins, xbins))
109 binnedData = np.zeros(binnedNumerator.shape)
110 ind = binnedDenominator != 0
111 np.divide(binnedNumerator, binnedDenominator, out=binnedData, where=ind)
112 binnedWeight = binnedDenominator
113 binMask = (binnedData * binnedWeight**0.5) > detectionThreshold
114 tmpOutputMask = binMask.repeat(binning, axis=0)[:ymax]
115 outputMask = tmpOutputMask.repeat(binning, axis=1)[:, :xmax]
116 else:
117 outputMask = (fitData * fitWeights**0.5) > detectionThreshold
118
119 # Clear existing Detected Plane:
120 maskedImage.mask.array &= ~maskedImage.mask.getPlaneBitMask(detectedPlane)
121
122 # Set Detected Plane with the binary detection mask:
123 maskedImage.mask.array[outputMask] |= maskedImage.mask.getPlaneBitMask(detectedPlane)
124
125
126@dataclass