summaryrefslogtreecommitdiff
path: root/lib/skyline.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/skyline.py')
-rw-r--r--lib/skyline.py117
1 files changed, 78 insertions, 39 deletions
diff --git a/lib/skyline.py b/lib/skyline.py
index a8e27a2..df6a390 100644
--- a/lib/skyline.py
+++ b/lib/skyline.py
@@ -7,7 +7,7 @@ generalized steps::
#. Initialize SkyLine objects for each input image.
This object would be the union of all the input
image's individual chips WCS footprints.
-
+
#. Determine overlap between all images. The
determination would employ a recursive operation
to return the extended list of all overlap values
@@ -18,19 +18,19 @@ generalized steps::
pair which produces the largest overlap with the
first input image. This defines the initial
reference SkyLine object.
-
+
#. Perform some operation on the 2 images: for example,
match sky in intersecting regions, or aligning
second image with the first (reference) image.
-
+
#. Update the second image, either apply the sky value
or correct the WCS, then generate a new SkyLine
object for that image.
-
+
#. Create a new reference SkyLine object as the union
of the initial reference object and the newly
updated SkyLine object.
-
+
#. Repeat Steps 2-6 for all remaining input images.
This process will work reasonably fast as most operations
@@ -55,15 +55,55 @@ from __future__ import division, print_function
# THIRD-PARTY
import pyfits
-from stwcs import wcsutil
+from stwcs import wcsutil
# LOCAL
-from polygon import SphericalPolygon
+from sphere.polygon import SphericalPolygon
__all__ = ['SkyLine']
+__version__ = '0.1a'
+__vdate__ = '31-May-2012'
+
+class SkyLineMember(object):
+ def __init__(self, fname, ext):
+ """Container for SkyLine members.
+
+ Given FITS image and extension, will store its SphericalPolygon
+ instance from WCS under `polygon`.
+
+ self: obj
+ SkyLineMember instance.
+
+ fname: str
+ FITS image.
+
+ ext: int
+ Image extension.
+
+ """
+ self._fname = fname
+ self._ext = ext
+ self._polygon = SphericalPolygon.from_wcs(
+ wcsutil.HSTWCS(fname, ext=ext))
+
+ def __repr__(self):
+ return 'SkyLineMember(%r, %r, %r)' % (self.fname, self.ext,
+ self.polygon)
+
+ @property
+ def fname(self):
+ return self._fname
+
+ @property
+ def ext(self):
+ return self._ext
+
+ @property
+ def polygon(self):
+ return self._polygon
class SkyLine(SphericalPolygon):
-
+
def __init__(self, fname):
"""Initialize SkyLine object instance.
@@ -74,47 +114,46 @@ class SkyLine(SphericalPolygon):
fname: str
FITS image.
+
+ """
+ # Inherit from SphericalPolygon
+ SphericalPolygon.__init__(self, [], None)
- """
- # Find SCI extensions
+ # Convert SCI data to SkyLineMember
+ poly_list = []
with pyfits.open(fname) as pf:
- sci_extnum = tuple([i for i,ext in enumerate(pf) if
- 'SCI' in ext.name.upper()])
- assert len(sci_extnum) > 0, \
- 'SkyLine cannot find SCI ext in {}.'.format(fname)
+ for i,ext in enumerate(pf):
+ if 'SCI' in ext.name.upper():
+ poly_list.append(SkyLineMember(fname, i))
- # Initialize mosaic with first chip
- all_sph = SphericalPolygon.from_wcs(
- wcsutil.HSTWCS(fname, ext=sci_extnum[0]))
+ assert len(poly_list) > 0, \
+ 'SkyLine cannot find SCI ext in {}.'.format(fname)
- # Mosaic all the chips
- for i in sci_extnum[1:]:
- prev_sph = all_sph.__copy__()
-
- cur_sph = SphericalPolygon.from_wcs(
- wcsutil.HSTWCS(fname, ext=i))
-
- all_sph = prev_sph.union(cur_sph)
+ self._members = poly_list
- # SkyLine = final mosaic inheriting from SphericalPolygon
- SphericalPolygon.__init__(self, all_sph.points, all_sph.inside)
+ # Put mosaic of all the chips in SkyLine
+ mosaic = SphericalPolygon.multi_union(self.polygons)
+ self._points = mosaic.points
+ self._inside = mosaic.inside
- # Add attribute to track images in SkyLine
- self._image_list = [fname]
+ @property
+ def members(self):
+ """List of SkyLineMember objects."""
+ return self._members
@property
- def image_list(self):
- """List of images in SkyLine."""
- return self._image_list
+ def polygons(self):
+ """List of SkyLineMember polygons."""
+ return [m.polygon for m in self.members]
# Overload parent class with following changes
# a. add own attr
# b. update self var in-place, no return
-
+
def add_image(self,skyline):
"""Make composite SkyLine"""
pass
-
+
def compute_overlap(self, skyline):
"""Return sphere object with intersect of 2 skylines.
@@ -122,21 +161,21 @@ class SkyLine(SphericalPolygon):
"""
pass
-
+
def find_intersection(self, skyline):
"""
Return WCS object of overlap of 2 skylines.
"""
pass
-
+
def within(self, pos):
"""
Return bool if pos is in skyline or not.
"""
pass
-
+
def create_wcs(self):
"""Create WCS from SkyLine object.
@@ -149,7 +188,7 @@ class SkyLine(SphericalPolygon):
"""
pass
-
+
def footprints(self):
"""Compute edges of skyline."""
pass
@@ -159,5 +198,5 @@ def test():
"""Basic use case."""
# Allow disjoint?
-
+
pass