LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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