summaryrefslogtreecommitdiff
path: root/lib/skyline.py
diff options
context:
space:
mode:
authorlim <lim@stsci.edu>2012-06-01 15:42:44 -0400
committerlim <lim@stsci.edu>2012-06-01 15:42:44 -0400
commitf7a6460e40d1ebaceb01c8275b79df03c3a6d210 (patch)
treece3629de3659f95f471d3649a44918989a9adbef /lib/skyline.py
parentdead44d3663918173834ef6d8b26948d1776da43 (diff)
downloadstsci.sphere-f7a6460e40d1ebaceb01c8275b79df03c3a6d210.tar.gz
lim modified SkyLine union to return new instance
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/branches/sphere@17198 fe389314-cf27-0410-b35b-8c050e845b92 Former-commit-id: 474e7447680df01116b75425b95fa724e7e003bb
Diffstat (limited to 'lib/skyline.py')
-rw-r--r--lib/skyline.py62
1 files changed, 49 insertions, 13 deletions
diff --git a/lib/skyline.py b/lib/skyline.py
index 6368061..5754128 100644
--- a/lib/skyline.py
+++ b/lib/skyline.py
@@ -54,7 +54,7 @@ Examples
from __future__ import division, print_function
# STDLIB
-from copy import deepcopy
+from copy import copy, deepcopy
# THIRD-PARTY
import pyfits
@@ -193,43 +193,79 @@ class SkyLine(SphericalPolygon):
"""See SphericalPolygon."""
return SphericalPolygon.multi_union(polygons, method=method)
+ @classmethod
+ def multi_intersection(cls, polygons, method='parallel'):
+ """See SphericalPolygon."""
+ return SphericalPolygon.multi_intersection(polygons, method=method)
+
def union(self, other):
"""
- Updates *self* with the union of *self* and *other*.
+ Return a new `SkyLine` that is the union of *self* and *other*.
Skips *other* members that are already in *self*.
Parameters
----------
- self: obj
- `SkyLine` instance to be updated.
+ self, other: obj
+ `SkyLine` instance.
- other: obj
- `SkyLine` instance to be added.
+ Returns
+ -------
+ out_skyline: obj
+ `SkyLine` instance.
Examples
--------
>>> s1 = SkyLine('image1.fits')
>>> s2 = SkyLine('image2.fits')
- >>> s1.union(s2) # s1 is updated
+ >>> s3 = s1.union(s2)
See also
--------
sphere.polygon.SphericalPolygon.union
"""
+ out_skyline = copy(self)
+
+ # Not using set -- need to keep order
new_members = [m for m in other.members if m not in self.members]
- if len(new_members) == 0:
- return
+
+ if len(new_members) > 0:
+ all_poly = self.multi_union(self.polygons +
+ [m.polygon for m in new_members])
+ out_skyline._update(all_poly, self.members + new_members)
+
+ return out_skyline
- all_poly = self.multi_union(self.polygons +
- [m.polygon for m in new_members])
+ def intersection(self, other):
+ """
+ Return a new `SkyLine` that is the intersection of
+ *self* and *other*.
- self._update(all_poly, self.members + new_members)
+ Parameters
+ ----------
+ self, other: obj
+ `SkyLine` instance.
+ Returns
+ -------
+ out_skyline: obj
+ `SkyLine` instance.
+
+ Examples
+ --------
+ >>> s1 = SkyLine('image1.fits')
+ >>> s2 = SkyLine('image2.fits')
+ >>> s3 = s1.intersection(s2)
+
+ See also
+ --------
+ sphere.polygon.SphericalPolygon.intersection
+
+ """
+ pass
# 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"""