Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-42161: eo_pipe/cp_verify parity: defects #232

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 27 additions & 5 deletions python/lsst/cp/pipe/defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,15 @@ def _findHotAndColdPixels(self, exp):
# bright pixels, and both for flats, as they have bright and dark pix
footprintList = []

hotPixelCount = {}
coldPixelCount = {}

for amp in exp.getDetector():
ampName = amp.getName()

hotPixelCount[ampName] = 0
coldPixelCount[ampName] = 0

ampImg = maskedIm[amp.getBBox()].clone()

# crop ampImage depending on where the amp lies in the image
Expand Down Expand Up @@ -268,7 +276,7 @@ def _findHotAndColdPixels(self, exp):
datasetType = exp.getMetadata().get('IMGTYPE', 'UNKNOWN')
if np.isnan(expTime):
self.log.warning("expTime=%s for AMP %s in %s. Setting expTime to 1 second",
expTime, amp.getName(), datasetType)
expTime, ampName, datasetType)
expTime = 1.
thresholdType = self.config.thresholdType
if thresholdType == 'VALUE':
Expand All @@ -289,7 +297,7 @@ def _findHotAndColdPixels(self, exp):
# Find equivalent sigma values.
if stDev == 0.0:
self.log.warning("stDev=%s for AMP %s in %s. Setting nSigma to inf.",
stDev, amp.getName(), datasetType)
stDev, ampName, datasetType)
nSigmaList = [np.inf]
else:
nSigmaList = [valueThreshold/stDev]
Expand All @@ -305,7 +313,7 @@ def _findHotAndColdPixels(self, exp):

self.log.info("Image type: %s. Amp: %s. Threshold Type: %s. Sigma values and Pixel"
"Values (hot and cold pixels thresholds): %s, %s",
datasetType, amp.getName(), thresholdType, nSigmaList, valueThreshold)
datasetType, ampName, thresholdType, nSigmaList, valueThreshold)
mergedSet = None
for sigma in nSigmaList:
nSig = np.abs(sigma)
Expand All @@ -330,13 +338,23 @@ def _findHotAndColdPixels(self, exp):
else:
mergedSet.merge(footprintSet)

if polarity:
# hot pixels
for fp in footprintSet.getFootprints():
hotPixelCount[ampName] += fp.getArea()
else:
# cold pixels
for fp in footprintSet.getFootprints():
coldPixelCount[ampName] += fp.getArea()

footprintList += mergedSet.getFootprints()

self.debugView('defectMap', ampImg,
Defects.fromFootprintList(mergedSet.getFootprints()), exp.getDetector())

defects = Defects.fromFootprintList(footprintList)
defects = self.maskBlocksIfIntermitentBadPixelsInColumn(defects)
defects, count = self.maskBlocksIfIntermitentBadPixelsInColumn(defects)
defects.updateCounters(columns=count, hot=hotPixelCount, cold=coldPixelCount)

return defects

Expand Down Expand Up @@ -390,7 +408,10 @@ def maskBlocksIfIntermitentBadPixelsInColumn(self, defects):
equal than self.config.badPixelColumnThreshold, the input
list is returned. Otherwise, the defects list returned
will include boxes that mask blocks of on-and-of pixels.
badColumnCount : `int`
Number of bad columns masked.
"""
badColumnCount = 0
# Get the (x, y) values of each bad pixel in amp.
coordinates = []
for defect in defects:
Expand All @@ -416,8 +437,9 @@ def maskBlocksIfIntermitentBadPixelsInColumn(self, defects):
multipleX.append(a)
if len(multipleX) != 0:
defects = self._markBlocksInBadColumn(x, y, multipleX, defects)
badColumnCount += 1

return defects
return defects, badColumnCount

def _markBlocksInBadColumn(self, x, y, multipleX, defects):
"""Mask blocks in a column if number of on-and-off bad pixels is above
Expand Down
2 changes: 1 addition & 1 deletion tests/test_defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def check_maskBlocks(self, inputDefects, expectedDefects):
task = self.defaultTask
task.config = config

defectsWithColumns = task.maskBlocksIfIntermitentBadPixelsInColumn(inputDefects)
defectsWithColumns, count = task.maskBlocksIfIntermitentBadPixelsInColumn(inputDefects)
boxesMeasured = []
for defect in defectsWithColumns:
boxesMeasured.append(defect.getBBox())
Expand Down