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-36358: "broken" amplifiers trigger a failure in setting the threshold for defects #155

Merged
merged 2 commits into from
Oct 5, 2022
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
11 changes: 10 additions & 1 deletion python/lsst/cp/pipe/defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from lsst.geom import Box2I, Point2I
from lsst.meas.algorithms import SourceDetectionTask
from lsst.ip.isr import Defects, countMaskedPixels
from lsst.pex.exceptions import InvalidParameterError

from ._lookupStaticCalibration import lookupStaticCalibration

Expand Down Expand Up @@ -246,7 +247,15 @@ def findHotAndColdPixels(self, exp, nSigma):

threshold = afwDetection.createThreshold(nSig, 'stdev', polarity=polarity)

footprintSet = afwDetection.FootprintSet(ampImg, threshold)
try:
footprintSet = afwDetection.FootprintSet(ampImg, threshold)
except InvalidParameterError:
# This occurs if the image sigma value is 0.0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other way this could happen? Testing exceptions should be the last resort. Can't the threshold value be checked?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The threshold itself is fine. It's the image sigma value coming out as zero that causes the InvalidParameterError. Manually calculating the image statistics seemed to be less efficient than doing the try/except, as most amplifiers should work fine.

# Let's mask the whole area.
minValue = np.nanmin(ampImg.image.array) - 1.0
threshold = afwDetection.createThreshold(minValue, 'value', polarity=True)
footprintSet = afwDetection.FootprintSet(ampImg, threshold)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a pretty complicated (and expensive) way to create a FootprintSet covering the whole area. Since a FootprintSet can be created from a Box2I, wouldn't that be simpler and faster?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got lost in the FootprintSet definition before I saw that it could have a Box passed to it. I'll refactor for that instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After coding this and sending to Jenkins, I'm now discovering that the box definition only sets the region, and does not create a footprint set containing footprints that can be used to mask the image.


footprintSet.setMask(maskedIm.mask, ("DETECTED" if polarity else "DETECTED_NEGATIVE"))

if mergedSet is None:
Expand Down
22 changes: 20 additions & 2 deletions tests/test_defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ def test_pixelCounting(self):
def test_getNumGoodPixels(self):
"""Test the the number of pixels in the image not masked is as
expected.

"""
testImage = self.flatExp.clone()
mi = testImage.maskedImage
Expand Down Expand Up @@ -622,7 +621,6 @@ def test_getNumGoodPixels(self):
def test_edgeMasking(self):
"""Check that the right number of edge pixels are masked by
_setEdgeBits().

"""
testImage = self.flatExp.clone()
mi = testImage.maskedImage
Expand All @@ -638,6 +636,26 @@ def test_edgeMasking(self):

self.assertEqual(countMaskedPixels(mi, 'EDGE'), nEdge)

def test_badImage(self):
"""Check that fully-bad images do not fail.
"""
testImage = self.flatExp.clone()
testImage.image.array[:, :] = 125000

config = copy.copy(self.defaultConfig)
# Do not exclude any pixels, so the areas match.
config.nPixBorderUpDown = 0
config.nPixBorderLeftRight = 0

task = cpPipe.defects.MeasureDefectsTask(config=config)
defects = task.findHotAndColdPixels(testImage, [config.nSigmaBright,
config.nSigmaDark])

defectArea = 0
for defect in defects:
defectArea += defect.getBBox().getArea()
self.assertEqual(defectArea, testImage.getBBox().getArea())


class TestMemory(lsst.utils.tests.MemoryTestCase):
pass
Expand Down