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

Added translator for CircleAnnulusPixelRegion #90

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions glue_astronomy/translators/regions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from glue.config import subset_state_translator
from glue.core.subset import (RoiSubsetState, RangeSubsetState, OrState, AndState,
XorState, MultiOrState, Subset, MultiRangeSubsetState)
XorState, MultiOrState, Subset, MultiRangeSubsetState, InvertState)
from glue.core.roi import (RectangularROI, PolygonalROI, CircularROI, PointROI,
RangeROI, AbstractMplRoi, EllipticalROI)
from glue.viewers.image.pixel_selection_subset_state import PixelSubsetState

from astropy import units as u
from regions import (RectanglePixelRegion, PolygonPixelRegion, CirclePixelRegion,
PointPixelRegion, PixCoord, EllipsePixelRegion)
PointPixelRegion, PixCoord, EllipsePixelRegion, CircleAnnulusPixelRegion)


def range_to_rect(data, ori, low, high):
Expand Down Expand Up @@ -132,11 +132,23 @@ def to_object(self, subset):
return PointPixelRegion(PixCoord(*subset_state.get_xy(data, 1, 0)))

elif isinstance(subset_state, AndState):
temp_sub1 = Subset(data=data)
temp_sub1.subset_state = subset_state.state1
temp_sub2 = Subset(data=data)
temp_sub2.subset_state = subset_state.state2
return self.to_object(temp_sub1) & self.to_object(temp_sub2)
if ((not isinstance(subset_state.state1, InvertState)) and
isinstance(subset_state.state1.roi, CircularROI) and
isinstance(subset_state.state2, InvertState) and
isinstance(subset_state.state2.state1.roi, CircularROI) and
(subset_state.state1.roi.xc == subset_state.state2.state1.roi.xc) and
(subset_state.state1.roi.yc == subset_state.state2.state1.roi.yc) and
(subset_state.state1.roi.radius > subset_state.state2.state1.roi.radius)):
pllim marked this conversation as resolved.
Show resolved Hide resolved
return CircleAnnulusPixelRegion(
center=PixCoord(x=subset_state.state1.roi.xc, y=subset_state.state1.roi.yc),
inner_radius=subset_state.state2.state1.roi.radius,
outer_radius=subset_state.state1.roi.radius)
else:
temp_sub1 = Subset(data=data)
temp_sub1.subset_state = subset_state.state1
temp_sub2 = Subset(data=data)
temp_sub2.subset_state = subset_state.state2
return self.to_object(temp_sub1) & self.to_object(temp_sub2)

elif isinstance(subset_state, OrState):
temp_sub1 = Subset(data=data)
Expand Down