diff options
| author | lim <lim@stsci.edu> | 2012-06-21 15:14:44 -0400 | 
|---|---|---|
| committer | lim <lim@stsci.edu> | 2012-06-21 15:14:44 -0400 | 
| commit | 1121435a46e8796e83649003ea232eb6e2f4152c (patch) | |
| tree | c1eab0e1278415d8ee2c1b42a28f9276fb921c07 /lib | |
| parent | ca973fa7003fe9f4ea4d2db3fcca7fe9cdecef16 (diff) | |
| download | stsci.sphere-1121435a46e8796e83649003ea232eb6e2f4152c.tar.gz | |
lim added minor skyline doc and finished skyline tests
git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci_python/branches/sphere@17465 fe389314-cf27-0410-b35b-8c050e845b92
Former-commit-id: 4d99fa976cbdf1fbdf9b23abb8ab899f8fa3043d
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/skyline.py | 4 | ||||
| -rw-r--r-- | lib/test/test_skyline.py | 127 | 
2 files changed, 104 insertions, 27 deletions
| diff --git a/lib/skyline.py b/lib/skyline.py index 8a9755f..10c1c65 100644 --- a/lib/skyline.py +++ b/lib/skyline.py @@ -312,7 +312,7 @@ class SkyLine(object):          -------          max_skyline: `SkyLine` instance or `None`              `SkyLine` that overlaps the most or `None` if no -            overlap found. +            overlap found. This is *not* a copy.          max_overlap_area: float              Area of intersection. @@ -345,7 +345,7 @@ class SkyLine(object):          max_pair: tuple              Pair of `SkyLine` instances with max overlap              among given *skylines*. If no overlap found, -            return `None`. +            return `None`. These are *not* copies.          """                 max_pair = None diff --git a/lib/test/test_skyline.py b/lib/test/test_skyline.py index 24cdce7..1ce3e09 100644 --- a/lib/test/test_skyline.py +++ b/lib/test/test_skyline.py @@ -16,6 +16,8 @@ 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 @@ -37,14 +39,29 @@ im_66_tan = SkyLine(f_66_tan, extname='primary')  #----- SHARED FUNCTIONS ----- -def compare_members(im1, im2): -    assert len(im1.members) == len(im2.members) +def same_members(mem1, mem2): +    assert len(mem1) == len(mem2) -    for m in im1.members: -        assert m in im2.members +    for m in mem1: +        assert m in mem2 -    for m in im2.members: -        assert m in im1.members +    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 ----- @@ -76,11 +93,30 @@ def test_copy():  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()) +    radecs = 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(radecs[i][0], ra) +        assert_almost_equal(radecs[i][1], dec) + + +#----- WCS ----- + +def test_wcs(): +    wcs = im_2chipA.to_wcs() +    new_p = SphericalPolygon.from_wcs(wcs) +    subset_polygon(im_2chipA, new_p) +  #----- UNION ----- @@ -89,9 +125,15 @@ def do_add_image(im1, im2):      u2 = im2.add_image(im1)      assert u1.same_points_as(u2) -    compare_members(u1, u2) +    same_members(u1.members, u2.members) + +    all_mems = im1.members + im2.members +    same_members(u1.members, all_mems) -def test_add_image():     +    subset_polygon(im1, u1) +    subset_polygon(im2, u1) + +def test_add_image():      # Dithered      do_add_image(im_2chipA, im_2chipB) @@ -99,14 +141,21 @@ def test_add_image():      do_add_image(im_2chipA, im_66_tan) -# ----- INTERSECTION ----- +#----- INTERSECTION -----  def do_intersect_image(im1, im2):      i1 = im1.find_intersection(im2)      i2 = im2.find_intersection(im1)      assert i1.same_points_as(i2) -    compare_members(i1, 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 @@ -116,35 +165,63 @@ def test_find_intersection():      do_intersect_image(im_2chipA, im_66_tan) -# ----- INTENDED USE CASE ----- +#----- 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()) -def NOT_DONE_science(): +    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] -    assert_almost_equal(im_2chipA.overlap(mos), 1.0) -    assert_almost_equal(im_2chipB.overlap(mos), 1.0) -     -    assert_almost_equal(im_2chipC.overlap(mos), 0.0) -    assert_almost_equal(im_66_tan.overlap(mos), 0.0) +    subset_polygon(im_2chipA, mos) +    subset_polygon(im_2chipB, mos) +    no_polygon(im_2chipC, mos) +    no_polygon(im_66_tan, mos) -# ----- UNSTABLE ----- +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_overlap_1(): -    i1 = im_2chipA.find_intersection(im_2chipB) -    i2 = im_2chipB.find_intersection(im_2chipA) -    assert_almost_equal(i1.overlap(i2), 1.0) # ok if ran alone -      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 - 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) # failed here - known bug +    assert_almost_equal(i1.overlap(i2), 1.0)      assert_almost_equal(u1.overlap(u2), 1.0) | 
