astropy / regions

Astropy package for region handling
https://astropy-regions.readthedocs.io
BSD 3-Clause "New" or "Revised" License
61 stars 55 forks source link

to_mask for list of regions #318

Open keflavich opened 4 years ago

keflavich commented 4 years ago

I am sure this is a duplicate of something we already have done, but I can't find it.

How do we make a mask from a list of regions? A convenience function to replace this:

    fullmask = np.zeros(image.shape, dtype='bool')
    for reg in regs:

        preg = reg.to_pixel(image.wcs)
        msk = preg.to_mask()
        mimg = msk.to_reg()
        fullmask |= mimg

would be nice. Does it exist?

keflavich commented 4 years ago

the better approach seems to be closer to:

        composite_region = reduce(operator.or_, regs)
        preg = composite_region.to_pixel(ww.celestial)
        msk = preg.to_mask()
        cutout_pixels = msk.cutout(data)[msk.data.astype('bool')]

for what I'm trying to do (in this case, get at the pixel values so I can take their standard deviation...)