Skip to content

Commit

Permalink
🐛 Fix rectangle_to_polygon_region when rectangle angle is not an astr…
Browse files Browse the repository at this point in the history
…opy.Angle
  • Loading branch information
Xen0Xys authored and ManonMarchand committed May 27, 2024
1 parent c469b5b commit 7999699
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/ipyaladin/region_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from astropy.coordinates import SkyCoord, CartesianRepresentation, Angle
from astropy.coordinates.matrix_utilities import rotation_matrix
from astropy.units import Quantity

try:
from regions import (
Expand Down Expand Up @@ -58,7 +59,10 @@ def rectangle_to_polygon_region(region: RectangleSkyRegion) -> PolygonSkyRegion:
)
center = region.center.represent_as("cartesian").xyz

rot_mat = rotation_matrix(Angle(-region.angle.deg, unit="deg"), center)
angle = region.angle
if isinstance(region.angle, Quantity):
angle = Angle(region.angle)
rot_mat = rotation_matrix(Angle(-angle.deg, unit="deg"), center)

corners = np.array(
[
Expand Down Expand Up @@ -131,20 +135,32 @@ def _from_stcs(self, stcs: str) -> None:

def _from_circle_sky_region(self, region: CircleSkyRegion) -> None:
self.region_type = "circle"
radius = region.radius
if isinstance(region.radius, Quantity):
radius = Angle(region.radius)
self.infos = {
"ra": region.center.ra.deg,
"dec": region.center.dec.deg,
"radius": region.radius.deg,
"radius": radius.deg,
}

def _from_ellipse_sky_region(self, region: EllipseSkyRegion) -> None:
self.region_type = "ellipse"
angle = region.angle
if isinstance(region.angle, Quantity):
angle = Angle(region.angle)
a = region.width
if isinstance(region.width, Quantity):
a = Angle(region.width)
b = region.height
if isinstance(region.height, Quantity):
b = Angle(region.height)
self.infos = {
"ra": region.center.ra.deg,
"dec": region.center.dec.deg,
"a": region.width.deg,
"b": region.height.deg,
"theta": region.angle.deg,
"a": a.deg,
"b": b.deg,
"theta": angle.deg,
}

def _from_line_sky_region(self, region: LineSkyRegion) -> None:
Expand Down

0 comments on commit 7999699

Please sign in to comment.