Project: datamanagement
Issue DM-5174: Manipulating masks is confusing
A possible bug exists in afwImage.Exposure.getMaskedImage(). This function returns a copy of the Exposure's masked image, and not the actual maskedImage owned by the Exposure. This means that any changes made to the mask are done only on the copy, and are not reflected in the Exposure's maskImage. The intended behavior seems to be that a shallow copy be returned with pointers to all the original objects (such as the mask). This however does not seem to be the case, a deep copy is always made instead. Verify that the intended behavior is indeed happening. Steps to reproduce {code:python} coaddExposure = afwImage.ExposureF() coaddExposure.getMaskedImage().getMask().addMaskPlane('TEST') print(coaddExposure.getMaskedImage().getMask().getMaskPlaneDict().asdict()) m = coaddExposure.getMaskedImage().getMask() print(m.getMaskPlaneDict().asdict()) m.removeAndClearMaskPlane('TEST') print(m.getMaskPlaneDict().asdict()) print(coaddExposure.getMaskedImage().getMask().getMaskPlaneDict().asdict()) {code} A second concern, though not necessarily a bug, is that adding and removing mask planes is confusing due to inconsistent manipulation of global state. For example: {code} In [1]: import lsst.afw.image as afwImage # Create two separate Masks In [2]: mask1 = afwImage.MaskU() In [3]: mask2 = afwImage.MaskU() # Neither Mask contains a "TEST" plane In [4]: 'TEST' in mask1.getMaskPlaneDict() Out[4]: False In [5]: 'TEST' in mask2.getMaskPlaneDict() Out[5]: False # Adding a plane to one updates a shared list of planes, so it appears in the other In [6]: mask1.addMaskPlane('TEST') Out[6]: 9 In [7]: 'TEST' in mask1.getMaskPlaneDict() Out[7]: True In [8]: 'TEST' in mask2.getMaskPlaneDict() Out[8]: True # But deleting a plane from one affects only that particular Mask and not the global state In [9]: mask1.removeAndClearMaskPlane('TEST') In [10]: 'TEST' in mask1.getMaskPlaneDict() Out[10]: False In [11]: 'TEST' in mask2.getMaskPlaneDict() Out[11]: True {code}
Story points: 4