diff options
Diffstat (limited to 'stsci/sphere/test')
-rw-r--r-- | stsci/sphere/test/test.py | 33 | ||||
-rw-r--r-- | stsci/sphere/test/test_intersection.py | 22 | ||||
-rw-r--r-- | stsci/sphere/test/test_union.py | 12 |
3 files changed, 47 insertions, 20 deletions
diff --git a/stsci/sphere/test/test.py b/stsci/sphere/test/test.py index 567ec1d..5b2d47e 100644 --- a/stsci/sphere/test/test.py +++ b/stsci/sphere/test/test.py @@ -24,6 +24,13 @@ def test_normalize_vector(): l = np.sqrt(np.sum(xyzn * xyzn, axis=-1)) assert_almost_equal(l, 1.0) +def test_normalize_unit_vector(): + for i in range(3): + xyz = [0.0, 0.0, 0.0] + xyz[i] = 1.0 + xyzn = vector.normalize_vector(xyz) + l = np.sqrt(np.sum(xyzn * xyzn, axis=-1)) + assert_almost_equal(l, 1.0) def test_radec_to_vector(): npx, npy, npz = vector.radec_to_vector(np.arange(-360, 360, 1), 90) @@ -250,7 +257,7 @@ def test_great_circle_arc_angle(): A = [1, 0, 0] B = [0, 1, 0] C = [0, 0, 1] - assert great_circle_arc.angle(A, B, C) == 90.0 + assert great_circle_arc.angle(A, B, C) == 270.0 # TODO: More angle tests @@ -260,8 +267,7 @@ def test_cone(): for i in range(50): ra = random.randrange(-180, 180) dec = random.randrange(20, 90) - cone = polygon.SphericalPolygon.from_cone(ra, dec, 8, steps=64) - + polygon.SphericalPolygon.from_cone(ra, dec, 8, steps=64) def test_area(): triangles = [ @@ -277,6 +283,13 @@ def test_area(): poly = polygon.SphericalPolygon(points) calc_area = poly.area() +def test_cone_area(): + saved_area = None + for ra in (0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330): + for dec in (0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330): + area = polygon.SphericalPolygon.from_cone(ra, dec, 30, steps=64).area() + if saved_area is None: saved_area = area + assert_almost_equal(area, saved_area) def test_fast_area(): a = np.array( # Clockwise @@ -304,6 +317,14 @@ def test_fast_area(): [ 0.3536442 , 0.63515101, -0.68667239], [ 0.35331737, 0.6351013 , -0.68688658]]) - assert graph.Graph._fast_area(a) > 0 - assert graph.Graph._fast_area(b) > 0 - assert graph.Graph._fast_area(c) < 0 + apoly = polygon._SingleSphericalPolygon(a) + bpoly = polygon._SingleSphericalPolygon(b) + cpoly = polygon._SingleSphericalPolygon(c) + + aarea = apoly.area() + barea = bpoly.area() + carea = cpoly.area() + + assert aarea > 0 and aarea < np.pi * 2.0 + assert barea > 0 and barea < np.pi * 2.0 + assert carea > np.pi * 2.0 and carea < np.pi * 4.0 diff --git a/stsci/sphere/test/test_intersection.py b/stsci/sphere/test/test_intersection.py index 9b01d8b..dc413a7 100644 --- a/stsci/sphere/test/test_intersection.py +++ b/stsci/sphere/test/test_intersection.py @@ -40,7 +40,7 @@ class intersection_test: num_permutations = math.factorial(len(polys)) step_size = int(max(float(num_permutations) / 20.0, 1.0)) - areas = [x.area() for x in polys] + areas = np.array([x.area() for x in polys]) if GRAPH_MODE: print("%d permutations" % num_permutations) @@ -72,9 +72,11 @@ class intersection_test: plt.savefig(filename) fig.clear() - assert np.all(intersection_area * 0.9 <= areas) + assert np.all(areas >= intersection_area * 0.9) - lengths = np.array([len(x._points) for x in intersections]) + lengths = np.array([ + np.sum(len(x._points) for x in y.iter_polygons_flat()) + for y in intersections]) assert np.all(lengths == [lengths[0]]) areas = np.array([x.area() for x in intersections]) assert_array_almost_equal(areas, areas[0], decimal=1) @@ -164,7 +166,7 @@ def test_intersection_empty(): p2 = p.intersection(polygon.SphericalPolygon([])) - assert_array_almost_equal(p2._points, []) + assert len(p2.polygons) == 0 def test_difficult_intersections(): @@ -236,10 +238,14 @@ def test_ordering(): assert_array_almost_equal(areas[:-1], areas[1:]) def roll_polygon(P, i): - points = P.points - points = np.roll(points[:-1], i, 0) - points = np.append(points, [points[0]], 0) - return polygon.SphericalPolygon(points, P.inside) + polygons = [] + for p in P.polygons: + points = p.points + points = np.roll(points[:-1], i, 0) + points = np.append(points, [points[0]], 0) + p = polygon._SingleSphericalPolygon(points, p.inside) + polygons.append(p) + return polygon.SphericalPolygon(polygons) Aareas = [] Bareas = [] diff --git a/stsci/sphere/test/test_union.py b/stsci/sphere/test/test_union.py index 5559c87..b172e0f 100644 --- a/stsci/sphere/test/test_union.py +++ b/stsci/sphere/test/test_union.py @@ -56,9 +56,7 @@ class union_test: permutation) unions.append(union) union_area = union.area() - print(union._points) - print(permutation[0]._points) - + if GRAPH_MODE: fig = plt.figure() m = Basemap(projection=self._proj, @@ -74,10 +72,11 @@ class union_test: plt.savefig(filename) fig.clear() - print(union_area, areas) assert np.all(union_area * 1.1 >= areas) - lengths = np.array([len(x._points) for x in unions]) + lengths = np.array([ + np.sum(len(x._points) for x in y.iter_polygons_flat()) + for y in unions]) assert np.all(lengths == [lengths[0]]) areas = np.array([x.area() for x in unions]) assert_array_almost_equal(areas, areas[0], 1) @@ -188,7 +187,8 @@ def test_union_empty(): p2 = p.union(polygon.SphericalPolygon([])) - assert_array_almost_equal(p2._points, p._points) + assert len(p2.polygons) == 1 + assert_array_almost_equal(p2.polygons[0].points, p.polygons[0].points) def test_difficult_unions(): |