Skip to content

Commit

Permalink
Add removeAndClearMaskPlane function to MultibandMask
Browse files Browse the repository at this point in the history
This function was missing in the MultibandMask class.  A unittest
was also added.
  • Loading branch information
laurenam committed Nov 26, 2018
1 parent 5703438 commit e9b0058
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions python/lsst/afw/image/image/multiband.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,27 @@ def removeMaskPlane(name):
"""
Mask[MaskPixel].removeMaskPlane(name)

def removeAndClearMaskPlane(self, name, removeFromDefault=False):
"""Remove and clear a mask from the mask plane
Clear all pixels of the specified mask and remove the plane from the
mask plane dictionary. Also optionally remove the plane from the
default dictionary.
Parameters
----------
name : `str`
Name of the mask plane to remove
removeFromDefault : `bool`, optional
Whether to remove the mask plane from the default dictionary.
Default is `False`.
"""
# Clear all masks in MultibandMask but leave in default dict for now
for single in self.singles:
single.removeAndClearMaskPlane(name, removeFromDefault=False)
# Now remove from default dict according to removeFromDefault
self._refMask.removeAndClearMaskPlane(name, removeFromDefault)

def clearAllMaskPlanes(self):
"""Clear all the pixels
"""
Expand Down
22 changes: 22 additions & 0 deletions tests/test_multiband.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,28 @@ def testRemoveMaskPlane(self):
self.assertIn("FOO", mMask.getMaskPlaneDict())
self.assertNotIn("FOO", Mask().getMaskPlaneDict())

def testRemoveAndClearMaskPlane(self):
mMask = self.mMask1
# Add mask plane FOO and test clearing it without removing plane from
# default dict
mMask.addMaskPlane("FOO")
mMask.removeAndClearMaskPlane("FOO")
self.assertNotIn("FOO", mMask.getMaskPlaneDict())
self.assertIn("FOO", Mask().getMaskPlaneDict())
# Now also remove it from default dict
mMask.addMaskPlane("FOO")
mMask.removeAndClearMaskPlane("FOO", removeFromDefault=True)
self.assertNotIn("FOO", mMask.getMaskPlaneDict())
self.assertNotIn("FOO", Mask().getMaskPlaneDict())
# Now remove and clear the EDGE mask plane and make sure all of the planes
# in the MultibandMask (i.e. the "singles") got updated accordingly
mMask.removeAndClearMaskPlane("EDGE", removeFromDefault=True)
self.assertNotIn("EDGE", mMask.getMaskPlaneDict())
self.assertNotIn("EDGE", Mask().getMaskPlaneDict())
# Assert that all mask planes were updated (i.e. having EDGE removed)
self.assertTrue(np.all([s.array == self.values1[n] & ~self.EDGE for
n, s in enumerate(mMask.singles)]))

def testFilterSlicing(self):
_testImageFilterSlicing(self, self.mMask1, Mask, self.bbox, self.values1[0])

Expand Down

0 comments on commit e9b0058

Please sign in to comment.