Notice of change of Mask typename in Python

#Mask name change

tl;dr : Mask objects can now be created and used by referring to the afwImage.Mask object, not afwImage.MaskU

As a friendly heads up to everyone, I want to make you aware of a name change to the mask type. Previously the Mask template specialization for python was named MaskU (meaning to create a mask or access static properties one would call afwImage.MaskU). The name for The mask type has been changed to MaskX subsequent to the change of data types (from uint16 to int32).

However, there is an additional change to be aware of. Previously MaskU was a derived class from the abstract base class Mask, meaning one could run isinstance(myMask, Mask) to check if a variable was a mask regardless of the underlying datatype. MaskX has been set as the default type to construct when calling the base class Mask. This means a MaskX object can be constructed directly from the base class as such:

mask = afwImage.Mask()

Additionally all static and class methods of the default mask type registered to the Mask base class are available through the base class as well, so the following just works.

bit = afwImage.Mask.getPlaneBitMask("SAT")

These changes should render needing to remember the type specialization name for the default mask type unnecessary.

#Additional details

The following is for anyone interested in additional information about how this will affect alternative mask types. Currently there is only one mask type used in the LSST stack, the above mentioned MaskX. If in the future we introduce additional types, say MaskU8 for masks backed with uint8 the base class can still be used as a constructor, specifying the desired type as follows

myMask = afwImage.Mask(dtype=np.uint8) # Construct a MaskU8 type
staticResult = afwImage.Mask[np.uint8].someStaticMethod() # Call a static method from the MaskU8 type

Pleas note, MaskU8 is not a real type but simply a demonstration of what could hypothetically be done. This illustrates how the base class can be used to select type specializations without knowing the exact specialization names.

2 Likes