summaryrefslogtreecommitdiff
path: root/stsci/sphere/test/test_union.py
diff options
context:
space:
mode:
authormdroe <mdroe@stsci.edu>2014-06-13 14:24:20 -0400
committermdroe <mdroe@stsci.edu>2014-06-13 14:24:20 -0400
commitd323b761917b1c713fbb367a86dac84bfa7e0af6 (patch)
tree642dd555d28607fcd043f5f62dc749caf026703c /stsci/sphere/test/test_union.py
parent23349b8f5f7c89596bfd8289ffaf67f36c2786c8 (diff)
downloadstsci.sphere-d323b761917b1c713fbb367a86dac84bfa7e0af6.tar.gz
Add regression tests based on real data that had trouble in the past.
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci.sphere/trunk@32539 fe389314-cf27-0410-b35b-8c050e845b92 Former-commit-id: f371222ebbc956ebbef4af6fba283e60e90e5a5b
Diffstat (limited to 'stsci/sphere/test/test_union.py')
-rw-r--r--stsci/sphere/test/test_union.py72
1 files changed, 34 insertions, 38 deletions
diff --git a/stsci/sphere/test/test_union.py b/stsci/sphere/test/test_union.py
index 24de9e6..60ea572 100644
--- a/stsci/sphere/test/test_union.py
+++ b/stsci/sphere/test/test_union.py
@@ -113,32 +113,6 @@ def test2():
return [poly1, poly2, poly3, poly4, poly5, poly6]
-# @union_test(0, 90)
-# def test3():
-# random.seed(0)
-# polys = []
-# for i in range(10):
-# polys.append(polygon.SphericalPolygon.from_cone(
-# random.randrange(-180, 180),
-# random.randrange(20, 90),
-# random.randrange(5, 16),
-# steps=16))
-# return polys
-
-
-# @union_test(0, 15)
-# def test4():
-# random.seed(64)
-# polys = []
-# for i in range(10):
-# polys.append(polygon.SphericalPolygon.from_cone(
-# random.randrange(-30, 30),
-# random.randrange(-15, 60),
-# random.randrange(5, 16),
-# steps=16))
-# return polys
-
-
def test5():
from astropy.io import fits
from astropy import wcs as pywcs
@@ -204,18 +178,6 @@ def test8():
return [poly1, poly2]
-if __name__ == '__main__':
- if '--profile' not in sys.argv:
- GRAPH_MODE = True
- from mpl_toolkits.basemap import Basemap
- from matplotlib import pyplot as plt
-
- functions = [(k, v) for k, v in globals().items() if k.startswith('test')]
- functions.sort()
- for k, v in functions:
- v()
-
-
def test_union_empty():
p = polygon.SphericalPolygon.from_cone(
random.randrange(-180, 180),
@@ -226,3 +188,37 @@ def test_union_empty():
p2 = p.union(polygon.SphericalPolygon([]))
assert_array_almost_equal(p2._points, p._points)
+
+
+def test_difficult_unions():
+ # Tests a number of intersections of real data that have been
+ # problematic in previous revisions of sphere
+
+ fname = resolve_imagename(ROOT_DIR, "difficult_intersections.txt")
+ with open(fname, 'rb') as fd:
+ lines = fd.readlines()
+
+ def to_array(line):
+ x = np.frombuffer(line.strip().decode('hex'), dtype='<f8')
+ return x.reshape((len(x) / 3, 3))
+
+ polys = []
+ for i in range(0, len(lines), 2):
+ points, inside, = [
+ to_array(line) for line in lines[i:i+2]]
+ poly = polygon.SphericalPolygon(points, inside)
+ polys.append(poly)
+
+ polygon.SphericalPolygon.multi_union(polys)
+
+
+if __name__ == '__main__':
+ if '--profile' not in sys.argv:
+ GRAPH_MODE = True
+ from mpl_toolkits.basemap import Basemap
+ from matplotlib import pyplot as plt
+
+ functions = [(k, v) for k, v in globals().items() if k.startswith('test')]
+ functions.sort()
+ for k, v in functions:
+ v()