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

Review for DM-4800: Use simpler method of converting from Mask to FootprintSet #6

Merged
merged 2 commits into from
Jan 14, 2016
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
9 changes: 2 additions & 7 deletions python/lsst/ip/isr/isr.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,8 @@ def getDefectListFromMask(maskedImage, maskName, growFootprints=1):
@return meas.algrithms.DefectListT of regions in mask
"""
mask = maskedImage.getMask()
workmask = afwImage.MaskU(mask, True)
workmask &= mask.getPlaneBitMask(maskName)
thresh = afwDetection.Threshold(0.5)
maskimg = afwImage.ImageU(workmask.getBBox())
maskimg[:] = workmask
ds = afwDetection.FootprintSet(maskimg, thresh)
fpList = ds.getFootprints()
thresh = afwDetection.Threshold(mask.getPlaneBitMask(maskName), afwDetection.Threshold.BITMASK)
fpList = afwDetection.FootprintSet(mask, thresh).getFootprints()
return defectListFromFootprintList(fpList, growFootprints)

def makeThresholdMask(maskedImage, threshold, growFootprints=1, maskName = 'SAT'):
Expand Down
29 changes: 28 additions & 1 deletion tests/testDefect.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,34 @@ def testDefectBase(self):
for d in defectList:
displayUtils.drawBBox(d.getBBox(), ctype=ds9.CYAN, borderWidth=.5)
ds9.incrDefaultFrame()


def testDefectsFromMaskedImage(self):
"""Test creation of a DefectList from a MaskedImage."""
mim = afwImage.MaskedImageF(10, 10)

# Nothing masked -> no defects.
defectList = ipIsr.getDefectListFromMask(mim, "BAD", growFootprints=0)
self.assertEqual(len(defectList), 0)

# Mask a single pixel.
mask = mim.getMask()
mask.set(5, 5, mask.getPlaneBitMask("BAD"))
defectList = ipIsr.getDefectListFromMask(mim, "BAD", growFootprints=0)
self.assertEqual(len(defectList), 1)
self.assertEqual(defectList[0].getX0(), 5)
self.assertEqual(defectList[0].getY0(), 5)

# Setting a different plane does not register as a defect.
mask.set(1, 1, mask.getPlaneBitMask("SUSPECT"))
defectList = ipIsr.getDefectListFromMask(mim, "SUSPECT", growFootprints=0)
self.assertEqual(len(defectList), 1)

# But adding another BAD pixel does.
mask.set(9, 9, mask.getPlaneBitMask("BAD"))
defectList = ipIsr.getDefectListFromMask(mim, "BAD", growFootprints=0)
self.assertEqual(len(defectList), 2)


def suite():
"""Returns a suite containing all the test cases in this module."""
tests.init()
Expand Down