LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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 39 of file maskStreaks.py.

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