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

Use the DM Mask for Existed Masks #63

Open
teweitsai opened this issue Feb 7, 2021 · 0 comments
Open

Use the DM Mask for Existed Masks #63

teweitsai opened this issue Feb 7, 2021 · 0 comments

Comments

@teweitsai
Copy link
Collaborator

Use the DM mask instead of numpy.ndarray(dtype=int) for existed masks. The followings are the example code by Robert:

import matplotlib.pyplot as plt

%matplotlib ipympl
plt.rcParams['figure.figsize'] = [7, 6]

import lsst.afw.image as afwImage
import lsst.afw.display as afwDisplay

afwDisplay.setDefaultBackend("matplotlib")

# Add a new mask plane called "AOS" to all Masks in this session
AOS = 1 << afwImage.Mask.addMaskPlane("AOS")
afwDisplay.setDefaultMaskPlaneColor("AOS", afwDisplay.CYAN)  # actually most color names are accepted

# create a MaskedImage with an image, a mask, and a variance plane
mi = afwImage.MaskedImageF(11, 21)
#
# Set some pixels in the image and mask.   I could do this "natively", but in the case
# I'm using the numpy interface (the .array)
mi.image.array[5:15, 5:6] = 10
mi.mask.array[10, 5] |= AOS
mi.mask.array[0:3, :] |= afwImage.Mask.getPlaneBitMask("BAD")
mi.mask.array[1, 1] |= afwImage.Mask.getPlaneBitMask("DETECTED")
#
# Make use of that mask;  I could have used np.where instead
#
mi.image.array[(mi.mask.array & AOS) != 0] = 20
#
# And display the result.
#
if False:
    fig = 1; plt.close(fig); fig = plt.figure(fig)
    disp = afwDisplay.Display(fig)
else:
    disp = afwDisplay.Display(1, reopenPlot=True)

disp.setImageColormap('gray')
disp.scale('linear', 'minmax')
disp.mtv(mi, title="Using a Mask")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant