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

Recover the boolean mask associated to a region #544

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

WilfriedMercier
Copy link

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.

…h True for pixels within at least one of the regions and False for pixels outside.
…th True for pixels within the region and False for pixels outside of it
@keflavich
Copy link
Contributor

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.

@WilfriedMercier
Copy link
Author

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

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

Successfully merging this pull request may close these issues.

2 participants