summaryrefslogtreecommitdiff
path: root/stsci
diff options
context:
space:
mode:
authormdroe <mdroe@stsci.edu>2014-06-04 16:10:55 -0400
committermdroe <mdroe@stsci.edu>2014-06-04 16:10:55 -0400
commit6068d3056d787384074a43ae8840163deeefd3f8 (patch)
tree1b76449716740843d2cb35ef67d7f97b34cf83cd /stsci
parent5f6068fb585a25d9d07800844a0fa23f4b6347c9 (diff)
downloadstsci.sphere-6068d3056d787384074a43ae8840163deeefd3f8.tar.gz
Fix tests
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci.sphere/trunk@32336 fe389314-cf27-0410-b35b-8c050e845b92 Former-commit-id: 40fd6b9821b5bf6120173a87d83d322988c6f4d9
Diffstat (limited to 'stsci')
-rw-r--r--stsci/sphere/graph.py68
-rw-r--r--stsci/sphere/test/test.py4
-rw-r--r--stsci/sphere/test/test_intersection.py53
-rw-r--r--stsci/sphere/test/test_skyline.py225
-rw-r--r--stsci/sphere/test/test_union.py77
5 files changed, 84 insertions, 343 deletions
diff --git a/stsci/sphere/graph.py b/stsci/sphere/graph.py
index 0e5b1d3..f5d720d 100644
--- a/stsci/sphere/graph.py
+++ b/stsci/sphere/graph.py
@@ -423,72 +423,42 @@ class Graph:
import traceback
traceback.print_exc()
self._dump_graph(title=title)
- import pdb
- pdb.set_trace()
raise
def _dump_graph(self, title=None, lon_0=0, lat_0=90,
- projection='vandg', func=lambda x: len(x._edges), poly=None,
- edge=None, file=None, show=True):
+ projection='vandg', func=lambda x: len(x._edges)):
from mpl_toolkits.basemap import Basemap
from matplotlib import pyplot as plt
fig = plt.figure()
m = Basemap()
- in_edge = edge
-
counts = {}
for node in self._nodes:
count = func(node)
counts.setdefault(count, [])
counts[count].append(list(node._point))
- if poly is not None:
- poly.draw(m, lw=20.0, color="black", alpha=0.3)
-
- if edge is not None:
- A, B = [x._point for x in edge._nodes]
- r0, d0 = vector.vector_to_radec(A[0], A[1], A[2])
- r1, d1 = vector.vector_to_radec(B[0], B[1], B[2])
- x0, y0 = m(r0, d0)
- x1, y1 = m(r1, d1)
- m.drawgreatcircle(r0, d0, r1, d1, color="green", lw=10, alpha=0.5)
- in_edge = None
- minx = min(x0, x1)
- maxx = max(x0, x1)
- miny = min(y0, y1)
- maxy = max(y0, y1)
-
- for edge in list(self._edges):
- count = getattr(edge, '_count', 0)
- A, B = [x._point for x in edge._nodes]
- r0, d0 = vector.vector_to_radec(A[0], A[1], A[2])
- r1, d1 = vector.vector_to_radec(B[0], B[1], B[2])
- if count:
- m.drawgreatcircle(r0, d0, r1, d1, color="red", lw=2*count)
- else:
- m.drawgreatcircle(r0, d0, r1, d1, color="black", lw=0.5)
-
- if in_edge is None:
- minx = np.inf
- miny = np.inf
- maxx = -np.inf
- maxy = -np.inf
+ minx = np.inf
+ miny = np.inf
+ maxx = -np.inf
+ maxy = -np.inf
for k, v in counts.items():
v = np.array(v)
ra, dec = vector.vector_to_radec(v[:, 0], v[:, 1], v[:, 2])
x, y = m(ra, dec)
m.plot(x, y, 'o', label=str(k))
- if in_edge is None:
- for x0 in x:
- minx = min(x0, minx)
- maxx = max(x0, maxx)
- for y0 in y:
- miny = min(y0, miny)
- maxy = max(y0, maxy)
+ for x0 in x:
+ minx = min(x0, minx)
+ maxx = max(x0, maxx)
+ for y0 in y:
+ miny = min(y0, miny)
+ maxy = max(y0, maxy)
- # for polygon in self._source_polygons:
- # polygon.draw(m)
+ for edge in list(self._edges):
+ A, B = [x._point for x in edge._nodes]
+ r0, d0 = vector.vector_to_radec(A[0], A[1], A[2])
+ r1, d1 = vector.vector_to_radec(B[0], B[1], B[2])
+ m.drawgreatcircle(r0, d0, r1, d1, color='blue')
plt.xlim(minx, maxx)
plt.ylim(miny, maxy)
@@ -496,11 +466,7 @@ class Graph:
plt.title("%s, %d v, %d e" % (
title, len(self._nodes), len(self._edges)))
plt.legend()
- if file is not None:
- plt.savefig(file)
- elif show:
- plt.show()
- plt.close('all')
+ plt.show()
def union(self):
"""
diff --git a/stsci/sphere/test/test.py b/stsci/sphere/test/test.py
index b551090..7c5eb35 100644
--- a/stsci/sphere/test/test.py
+++ b/stsci/sphere/test/test.py
@@ -156,8 +156,8 @@ def test_point_in_poly():
def test_point_in_poly_lots():
- import pyfits
- fits = pyfits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
+ from astropy.io import fits
+ fits = fits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
header = fits[0].header
poly1 = polygon.SphericalPolygon.from_wcs(
diff --git a/stsci/sphere/test/test_intersection.py b/stsci/sphere/test/test_intersection.py
index 6dacb3d..3576cc1 100644
--- a/stsci/sphere/test/test_intersection.py
+++ b/stsci/sphere/test/test_intersection.py
@@ -83,10 +83,9 @@ class intersection_test:
@intersection_test(0, 90)
def test1():
- import pyfits
- import os
+ from astropy.io import fits
- fits = pyfits.open(resolve_imagename(ROOT_DIR,'1904-66_TAN.fits'))
+ fits = fits.open(resolve_imagename(ROOT_DIR,'1904-66_TAN.fits'))
header = fits[0].header
poly1 = polygon.SphericalPolygon.from_wcs(
@@ -107,8 +106,8 @@ def test2():
@intersection_test(0, 90)
def test3():
- import pyfits
- fits = pyfits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
+ from astropy.io import fits
+ fits = fits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
header = fits[0].header
poly1 = polygon.SphericalPolygon.from_wcs(
@@ -120,11 +119,11 @@ def test3():
def test4():
- import pyfits
- import pywcs
+ from astropy.io import fits
+ from astropy import wcs as pywcs
- A = pyfits.open(os.path.join(ROOT_DIR, '2chipA.fits.gz'))
- B = pyfits.open(os.path.join(ROOT_DIR, '2chipB.fits.gz'))
+ 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)
@@ -141,32 +140,32 @@ def test4():
X = Apoly.intersection(Bpoly)
-def test5():
- import pyfits
- import pywcs
+# def test5():
+# from astropy.io import fits
+# from astropy import wcs as pywcs
- A = pyfits.open(os.path.join(ROOT_DIR, '2chipA.fits.gz'))
- B = pyfits.open(os.path.join(ROOT_DIR, '2chipB.fits.gz'))
+# 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)
+# 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 = chipA1.union(chipA2)
+# Bpoly = chipB1.union(chipB2)
- Apoly.overlap(chipB1)
+# Apoly.overlap(chipB1)
@intersection_test(0, 90)
def test6():
- import pyfits
- fits = pyfits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
+ from astropy.io import fits
+ fits = fits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
header = fits[0].header
poly1 = polygon.SphericalPolygon.from_wcs(
diff --git a/stsci/sphere/test/test_skyline.py b/stsci/sphere/test/test_skyline.py
deleted file mode 100644
index 929f0ba..0000000
--- a/stsci/sphere/test/test_skyline.py
+++ /dev/null
@@ -1,225 +0,0 @@
-"""
-SkyLine tests.
-
-:Author: Pey Lian Lim
-
-:Organization: Space Telescope Science Institute
-
-Examples
---------
->>> cd path/to/project
->>> nosetests
-
-"""
-from __future__ import absolute_import
-
-from copy import copy
-from numpy.testing import assert_almost_equal
-
-from ..vector import vector_to_radec
-from ..polygon import SphericalPolygon
-from ..skyline import SkyLine
-
-from .test_util import ROOT_DIR
-from .test_shared import resolve_imagename
-
-
-#---------------------------------------#
-# Load footprints used by all the tests #
-#---------------------------------------#
-f_2chipA = resolve_imagename(ROOT_DIR, '2chipA.fits') # ACS/WFC #1
-im_2chipA = SkyLine(f_2chipA)
-f_2chipB = resolve_imagename(ROOT_DIR, '2chipB.fits') # ACS/WFC #2
-im_2chipB = SkyLine(f_2chipB)
-f_2chipC = resolve_imagename(ROOT_DIR, '2chipC.fits') # WFC3/UVIS
-im_2chipC = SkyLine(f_2chipC)
-f_66_tan = resolve_imagename(ROOT_DIR, '1904-66_TAN.fits')
-im_66_tan = SkyLine(f_66_tan, extname='primary')
-
-
-#----- SHARED FUNCTIONS -----
-
-def same_members(mem1, mem2):
- assert len(mem1) == len(mem2)
-
- for m in mem1:
- assert m in mem2
-
- for m in mem2:
- assert m in mem1
-
-def subset_members(mem_child, mem_parent):
- assert len(mem_parent) > len(mem_child)
-
- for m in mem_child:
- assert m in mem_parent
-
-def subset_polygon(p_child, p_parent):
- """Overlap not working. Do this instead until fixed."""
- assert p_parent.area() >= p_child.area()
- assert p_parent.contains_point(p_child.inside)
-
-def no_polygon(p_child, p_parent):
- """Overlap not working. Do this instead until fixed."""
- assert not p_parent.contains_point(p_child.inside)
-
-
-#----- MEMBERSHIP -----
-
-def do_member_overlap(im):
- for m in im.members:
- assert_almost_equal(m.polygon.overlap(im), 1.0)
-
-def test_membership():
- do_member_overlap(im_2chipA)
- do_member_overlap(im_2chipB)
- do_member_overlap(im_66_tan)
-
- assert len(im_2chipA.members) == 1
- assert im_2chipA.members[0].fname == f_2chipA
- assert im_2chipA.members[0].ext == (1,4)
-
-
-#----- COPY -----
-
-def test_copy():
- a_copy = copy(im_2chipA)
- assert a_copy is not im_2chipA
-
-
-#----- SPHERICAL POLYGON RELATED -----
-
-def test_sphericalpolygon():
- assert im_2chipA.contains_point(im_2chipA.inside)
-
- assert im_2chipA.intersects_poly(im_2chipB.polygon)
-
- assert im_2chipA.intersects_arc(im_2chipA.inside, im_2chipB.inside)
-
- assert im_2chipA.overlap(im_2chipB) < im_2chipA.overlap(im_2chipA)
-
- assert_almost_equal(im_2chipA.area(), im_2chipB.area())
-
- ra_A, dec_A = im_2chipA.to_radec()
- for i in xrange(len(im_2chipA.points)):
- p = im_2chipA.points[i]
- ra, dec = vector_to_radec(p[0], p[1], p[2], degrees=True)
- assert_almost_equal(ra_A[i], ra)
- assert_almost_equal(dec_A[i], dec)
-
-
-#----- WCS -----
-
-def test_wcs():
- wcs = im_2chipA.to_wcs()
- new_p = SphericalPolygon.from_wcs(wcs)
- subset_polygon(im_2chipA, new_p)
-
-
-#----- UNION -----
-
-def do_add_image(im1, im2):
- u1 = im1.add_image(im2)
- u2 = im2.add_image(im1)
-
- assert u1.same_points_as(u2)
- same_members(u1.members, u2.members)
-
- all_mems = im1.members + im2.members
- same_members(u1.members, all_mems)
-
- subset_polygon(im1, u1)
- subset_polygon(im2, u1)
-
-def test_add_image():
- # Dithered
- do_add_image(im_2chipA, im_2chipB)
-
- # Not related
- do_add_image(im_2chipA, im_66_tan)
-
-
-#----- INTERSECTION -----
-
-def do_intersect_image(im1, im2):
- i1 = im1.find_intersection(im2)
- i2 = im2.find_intersection(im1)
-
- assert i1.same_points_as(i2)
- same_members(i1.members, i2.members)
-
- if len(i1.points) > 0:
- subset_members(im1.members, i1.members)
- subset_members(im2.members, i1.members)
-
- subset_polygon(i1, im1)
- subset_polygon(i1, im2)
-
-def test_find_intersection():
- # Dithered
- do_intersect_image(im_2chipA, im_2chipB)
-
- # Not related
- do_intersect_image(im_2chipA, im_66_tan)
-
-
-#----- SKYLINE OVERLAP -----
-
-def test_max_overlap():
- max_s, max_a = im_2chipA.find_max_overlap([im_2chipB, im_2chipC, im_66_tan])
- assert max_s is im_2chipB
- assert_almost_equal(max_a, im_2chipA.intersection(im_2chipB).area())
-
- max_s, max_a = im_2chipA.find_max_overlap([im_2chipB, im_2chipA])
- assert max_s is im_2chipA
- assert_almost_equal(max_a, im_2chipA.area())
-
-def test_max_overlap_pair():
- assert SkyLine.max_overlap_pair(
- [im_2chipB, im_2chipC, im_2chipA, im_66_tan]) == (im_2chipB, im_2chipA)
-
- assert SkyLine.max_overlap_pair([im_2chipC, im_2chipA, im_66_tan]) is None
-
-
-#----- INTENDED USE CASE -----
-
-def test_science_1():
- mos, inc, exc = SkyLine.mosaic([im_2chipA, im_2chipB, im_2chipC, im_66_tan])
-
- assert inc == [f_2chipA, f_2chipB]
- assert exc == [f_2chipC, f_66_tan]
-
- subset_polygon(im_2chipA, mos)
- subset_polygon(im_2chipB, mos)
-
- no_polygon(im_2chipC, mos)
- no_polygon(im_66_tan, mos)
-
-def test_science_2():
- """Like `test_science_1` but different input order."""
- mos, inc, exc = SkyLine.mosaic([im_2chipB, im_66_tan, im_2chipC, im_2chipA])
-
- assert inc == [f_2chipB, f_2chipA]
- assert exc == [f_66_tan, f_2chipC]
-
- subset_polygon(im_2chipA, mos)
- subset_polygon(im_2chipB, mos)
-
- no_polygon(im_2chipC, mos)
- no_polygon(im_66_tan, mos)
-
-
-#----- UNSTABLE -----
-
-def DISABLED_unstable_overlap():
- i1 = im_2chipA.find_intersection(im_2chipB)
- i2 = im_2chipB.find_intersection(im_2chipA)
-
- u1 = im_2chipA.add_image(im_2chipB)
- u2 = im_2chipB.add_image(im_2chipA)
-
- # failed here before - known bug
- # failure not always the same due to hash mapping
- assert_almost_equal(i1.overlap(u1), 1.0)
- assert_almost_equal(i1.overlap(i2), 1.0)
- assert_almost_equal(u1.overlap(u2), 1.0)
diff --git a/stsci/sphere/test/test_union.py b/stsci/sphere/test/test_union.py
index 4b649f6..b106907 100644
--- a/stsci/sphere/test/test_union.py
+++ b/stsci/sphere/test/test_union.py
@@ -86,8 +86,8 @@ class union_test:
@union_test(0, 90)
def test1():
- import pyfits
- fits = pyfits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
+ from astropy.io import fits
+ fits = fits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
header = fits[0].header
poly1 = polygon.SphericalPolygon.from_wcs(
@@ -113,37 +113,37 @@ 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
+# @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():
- import pyfits
- import pywcs
+ from astropy.io import fits
+ from astropy import wcs as pywcs
- A = pyfits.open(os.path.join(ROOT_DIR, '2chipA.fits.gz'))
+ A = fits.open(os.path.join(ROOT_DIR, '2chipA.fits.gz'))
wcs = pywcs.WCS(A[1].header, fobj=A)
chipA1 = polygon.SphericalPolygon.from_wcs(wcs)
@@ -154,10 +154,10 @@ def test5():
def test6():
- import pyfits
- import pywcs
+ from astropy.io import fits
+ from astropy import wcs as pywcs
- A = pyfits.open(os.path.join(ROOT_DIR, '2chipC.fits.gz'))
+ A = fits.open(os.path.join(ROOT_DIR, '2chipC.fits.gz'))
wcs = pywcs.WCS(A[1].header, fobj=A)
chipA1 = polygon.SphericalPolygon.from_wcs(wcs)
@@ -169,17 +169,17 @@ def test6():
@union_test(0, 90)
def test7():
- import pyfits
- import pywcs
+ from astropy.io import fits
+ from astropy import wcs as pywcs
- A = pyfits.open(os.path.join(ROOT_DIR, '2chipA.fits.gz'))
+ A = fits.open(os.path.join(ROOT_DIR, '2chipA.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)
- B = pyfits.open(os.path.join(ROOT_DIR, '2chipB.fits.gz'))
+ B = fits.open(os.path.join(ROOT_DIR, '2chipB.fits.gz'))
wcs = pywcs.WCS(B[1].header, fobj=B)
chipB1 = polygon.SphericalPolygon.from_wcs(wcs)
@@ -191,8 +191,9 @@ def test7():
@union_test(0, 90)
def test8():
- import pyfits
- fits = pyfits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
+ from astropy.io import fits
+
+ fits = fits.open(resolve_imagename(ROOT_DIR, '1904-66_TAN.fits'))
header = fits[0].header
poly1 = polygon.SphericalPolygon.from_wcs(