regions icon indicating copy to clipboard operation
regions copied to clipboard

Recover the boolean mask associated to a region

Open WilfriedMercier opened this issue 2 years ago • 2 comments

This pull request is not associated to an issue. The pull request is not ready to be merged yet. Neither tests, nor documentations pages have been created for this pull request yet.

This request implements a 'to_boolean_array' method in both PixelRegion and Regions classes that allows to transform one or multiple (pixel) regions into a boolean mask given an output array shape. A typical use-case would be to load a ds9 region as a boolean mask and be able to directly apply it to some data with a one-liner.

While it is currently possible to do so using either the bounding box attached to the region or, as implemented here, the to_mask and then to_image methods, this process is currently far from trivial. This pull request proposes to add a method that allows to do so with a single method call. The output boolean array will contain True values for pixels within the region(s) and False for pixels outside.

I implemented the 'to_boolean_array' method in PixelRegion because it seemed the easiest to do but it could probably also be implemented in SkyRegion by using the to_pixel method ? Also, the 'to_boolean_array' method in the Regions class currently does not check whether the region is a Pixel or Sky one.

WilfriedMercier avatar Feb 11 '24 19:02 WilfriedMercier

I'm at least loosely in favor of this. I have a lot of code following the pattern:

pixreg = skyreg.to_pixel(wcs)
mask = pixreg.to_mask()
mask.cutout(data)

and similar. I'd find this convenience function useful.

keflavich avatar Feb 11 '24 19:02 keflavich

Ok, great ! I'll implement the method for SkyRegions and then I'll try to add some tests

WilfriedMercier avatar Feb 15 '24 19:02 WilfriedMercier