From 4ae0e62b03444c1ad3e51e64e97664c500874c4d Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 18 Feb 2017 22:46:16 +0800 Subject: Move region.py to astro dir --- astro/region.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ region/region.py | 78 -------------------------------------------------------- 2 files changed, 78 insertions(+), 78 deletions(-) create mode 100644 astro/region.py delete mode 100644 region/region.py diff --git a/astro/region.py b/astro/region.py new file mode 100644 index 0000000..47a1636 --- /dev/null +++ b/astro/region.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# +# Aaron Li +# 2015/06/19 + +""" +Class Region for regions on the spherical surface. +Used in astronomy to select/define a certian region, e.g, DS9. +""" + +import sys + + +class Region(object): + """ + Basic region class for regions on the spherical surface, + similar definition as to DS9 regions. + + Coordinate style: (ra, dec) + Unit: degree + ra: [0, 2\pi) + dec: [-\pi/2, \pi/2] + """ + + # currently supported region types (similar to DS9) + REGION_TYPES = ["circle", "ellipse", "box", "annulus", "pie", "panda"] + + def __init__(self, regtype, xc, yc, + radius=None, radius2=None, + width=None, height=None, rotation=None, + start=None, end=None): + if regtype.lower() not in self.REGION_TYPES: + raise ValueError("only following region types supported: %s" %\ + " ".join(self.REGION_TYPES)) + self.regtype = regtype.lower() + self.xc = xc + self.yc = yc + self.radius = radius + self.radius2 = radius2 + self.width = width + self.height = height + self.rotation = rotation + + def __repr__(self): + return "Region: %s" % self.regtype + + def dump(self): + return {"regtype": self.regtype, + "xc": self.xc, + "yc": self.yc, + "radius": self.radius, + "radius2": self.radius2, + "width": self.width, + "height": self.height, + "rotation": self.rotation + } + + def is_inside(self, point): + """ + Determine whether the given point is inside the region. + """ + x = point[0] + y = point[1] + if self.regtype == "box": + #print("WARNING: rotation box currently not supported!", + # file=sys.stderr) + xmin = self.xc - self.width/2.0 + xmax = self.xc + self.width/2.0 + ymin = self.yc - self.height/2.0 + ymax = self.yc + self.height/2.0 + if all([x >= xmin, x <= xmax, y >= ymin, y <= ymax]): + return True + else: + return False + else: + raise ValueError("region type '%s' currently not implemented" %\ + self.regtype) + diff --git a/region/region.py b/region/region.py deleted file mode 100644 index 47a1636..0000000 --- a/region/region.py +++ /dev/null @@ -1,78 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Aaron Li -# 2015/06/19 - -""" -Class Region for regions on the spherical surface. -Used in astronomy to select/define a certian region, e.g, DS9. -""" - -import sys - - -class Region(object): - """ - Basic region class for regions on the spherical surface, - similar definition as to DS9 regions. - - Coordinate style: (ra, dec) - Unit: degree - ra: [0, 2\pi) - dec: [-\pi/2, \pi/2] - """ - - # currently supported region types (similar to DS9) - REGION_TYPES = ["circle", "ellipse", "box", "annulus", "pie", "panda"] - - def __init__(self, regtype, xc, yc, - radius=None, radius2=None, - width=None, height=None, rotation=None, - start=None, end=None): - if regtype.lower() not in self.REGION_TYPES: - raise ValueError("only following region types supported: %s" %\ - " ".join(self.REGION_TYPES)) - self.regtype = regtype.lower() - self.xc = xc - self.yc = yc - self.radius = radius - self.radius2 = radius2 - self.width = width - self.height = height - self.rotation = rotation - - def __repr__(self): - return "Region: %s" % self.regtype - - def dump(self): - return {"regtype": self.regtype, - "xc": self.xc, - "yc": self.yc, - "radius": self.radius, - "radius2": self.radius2, - "width": self.width, - "height": self.height, - "rotation": self.rotation - } - - def is_inside(self, point): - """ - Determine whether the given point is inside the region. - """ - x = point[0] - y = point[1] - if self.regtype == "box": - #print("WARNING: rotation box currently not supported!", - # file=sys.stderr) - xmin = self.xc - self.width/2.0 - xmax = self.xc + self.width/2.0 - ymin = self.yc - self.height/2.0 - ymax = self.yc + self.height/2.0 - if all([x >= xmin, x <= xmax, y >= ymin, y <= ymax]): - return True - else: - return False - else: - raise ValueError("region type '%s' currently not implemented" %\ - self.regtype) - -- cgit v1.2.2