Recover the boolean mask associated to a region#544
Open
WilfriedMercier wants to merge 3 commits intoastropy:mainfrom
Open
Recover the boolean mask associated to a region#544WilfriedMercier wants to merge 3 commits intoastropy:mainfrom
WilfriedMercier wants to merge 3 commits intoastropy:mainfrom
Conversation
added 2 commits
February 11, 2024 19:23
…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
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. |
Author
|
Ok, great ! I'll implement the method for SkyRegions and then I'll try to add some tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.