summaryrefslogtreecommitdiff
path: root/stsci/sphere/test/test_intersection.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_intersection.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_intersection.py')
-rw-r--r--stsci/sphere/test/test_intersection.py46
1 files changed, 24 insertions, 22 deletions
diff --git a/stsci/sphere/test/test_intersection.py b/stsci/sphere/test/test_intersection.py
index 8127e95..8cf10b2 100644
--- a/stsci/sphere/test/test_intersection.py
+++ b/stsci/sphere/test/test_intersection.py
@@ -140,28 +140,6 @@ def test4():
X = Apoly.intersection(Bpoly)
-# def test5():
-# from astropy.io import fits
-# from astropy import wcs as pywcs
-
-# A = fits.open(os.path.join(ROOT_DIR, '2chipA.fits.gz'))
-# B = fits.open(os.path.join(ROOT_DIR, '2chipB.fits.gz'))
-
-# wcs = pywcs.WCS(A[1].header, fobj=A)
-# chipA1 = polygon.SphericalPolygon.from_wcs(wcs)
-# wcs = pywcs.WCS(A[4].header, fobj=A)
-# chipA2 = polygon.SphericalPolygon.from_wcs(wcs)
-# wcs = pywcs.WCS(B[1].header, fobj=B)
-# chipB1 = polygon.SphericalPolygon.from_wcs(wcs)
-# wcs = pywcs.WCS(B[4].header, fobj=B)
-# chipB2 = polygon.SphericalPolygon.from_wcs(wcs)
-
-# Apoly = chipA1.union(chipA2)
-# Bpoly = chipB1.union(chipB2)
-
-# Apoly.overlap(chipB1)
-
-
@intersection_test(0, 90)
def test6():
from astropy.io import fits
@@ -188,6 +166,30 @@ def test_intersection_empty():
assert_array_almost_equal(p2._points, [])
+def test_difficult_intersections():
+ # Tests a number of intersections of real data that have been
+ # problematic in previous revisions of sphere
+
+ def test_intersection(polys):
+ A, B = polys
+ A.intersection(B)
+
+ 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))
+
+ for i in range(0, len(lines), 4):
+ Apoints, Ainside, Bpoints, Binside = [
+ to_array(line) for line in lines[i:i+4]]
+ polyA = polygon.SphericalPolygon(Apoints, Ainside)
+ polyB = polygon.SphericalPolygon(Bpoints, Binside)
+ yield test_intersection, (polyA, polyB)
+
+
if __name__ == '__main__':
if '--profile' not in sys.argv:
GRAPH_MODE = True