Example #1
0
def test_write_fits():
    """ Test that MOC files can be written in fits format """
    a = Region()
    a.add_circles(12, 0, 0.1)
    a.write_fits('test_MOC.fits')
    if not (os.path.exists('test_MOC.fits')): raise AssertionError()
    os.remove('test_MOC.fits')
Example #2
0
def test_write_fits():
    """ Test that MOC files can be written in fits format """
    a = Region()
    a.add_circles(12, 0, 0.1)
    a.write_fits('test_MOC.fits')
    if not (os.path.exists('test_MOC.fits')): raise AssertionError()
    os.remove('test_MOC.fits')
Example #3
0
def test_demote():
    """Test that we can demote a region"""
    a = Region(maxdepth=8)
    a.add_circles(0, np.radians(-90), np.radians(1))
    _ = a.pixeldict.copy()
    fpd = a.get_demoted()
    if not (fpd == a.pixeldict[8]): raise AssertionError()
    for i in range(1, 8):
        if not (len(a.pixeldict[i]) == 0): raise AssertionError()
Example #4
0
def test_demote():
    """Test that we can demote a region"""
    a = Region(maxdepth=8)
    a.add_circles(0, np.radians(-90), np.radians(1))
    _ = a.pixeldict.copy()
    fpd = a.get_demoted()
    if not (fpd == a.pixeldict[8]): raise AssertionError()
    for i in range(1, 8):
        if not (len(a.pixeldict[i]) == 0): raise AssertionError()
Example #5
0
def test_symmetric_difference():
    """
    Test the Region.symmetric_difference() gives expected results"
    """
    a = Region(maxdepth=7)
    a.add_circles(0, np.radians(-90), np.radians(1))
    area = a.get_area()
    b = Region(maxdepth=7)
    b.add_circles(0, np.radians(-90), np.radians(0.5))
    a.symmetric_difference(b)
    if not (a.get_area() == area - b.get_area()): raise AssertionError("test_symmetric_difference FAILED")
Example #6
0
def test_without():
    """
    Test the Region.without gives expected results"
    """
    a = Region(maxdepth=7)
    a.add_circles(0, np.radians(-90), np.radians(1))
    area = a.get_area()
    b = Region(maxdepth=7)
    b.add_circles(0, np.radians(-90), np.radians(0.5))
    a.without(b)
    if not (a.get_area() <= (area - b.get_area())): raise AssertionError("test_without FAILED")
Example #7
0
def test_symmetric_difference():
    """
    Test the Region.symmetric_difference() gives expected results"
    """
    a = Region(maxdepth=7)
    a.add_circles(0, np.radians(-90), np.radians(1))
    area = a.get_area()
    b = Region(maxdepth=7)
    b.add_circles(0, np.radians(-90), np.radians(0.5))
    a.symmetric_difference(b)
    if not (a.get_area() == area - b.get_area()):
        raise AssertionError("test_symmetric_difference FAILED")
Example #8
0
def test_without():
    """
    Test the Region.without gives expected results"
    """
    a = Region(maxdepth=7)
    a.add_circles(0, np.radians(-90), np.radians(1))
    area = a.get_area()
    b = Region(maxdepth=7)
    b.add_circles(0, np.radians(-90), np.radians(0.5))
    a.without(b)
    if not (a.get_area() <= (area - b.get_area())):
        raise AssertionError("test_without FAILED")
Example #9
0
def test_reg():
    """
    Test that .reg files can be written without crashing
    (Not a test that the .reg files are valid)
    """
    ra = np.radians([285])
    dec = np.radians([-66])
    radius = np.radians([3])
    region = Region(maxdepth=5)
    region.add_circles(ra, dec, radius)
    region.write_reg('test.reg')
    if not (os.path.exists('test.reg')): raise AssertionError()
    os.remove('test.reg')
Example #10
0
def test_reg():
    """
    Test that .reg files can be written without crashing
    (Not a test that the .reg files are valid)
    """
    ra = np.radians([285])
    dec = np.radians([-66])
    radius = np.radians([3])
    region = Region(maxdepth=5)
    region.add_circles(ra, dec, radius)
    region.write_reg('test.reg')
    if not (os.path.exists('test.reg')): raise AssertionError()
    os.remove('test.reg')
Example #11
0
def test_sky_within():
    """Test the Ragion.sky_within method"""
    ra = np.radians([13.5, 15])
    dec = np.radians([-45, -40])
    radius = np.radians([0.1, 0.1])
    region = Region(maxdepth=11)
    region.add_circles(ra, dec, radius)
    if not (np.all(region.sky_within(ra[0], dec[0]))): raise AssertionError("Failed on position at center of region")
    if not (np.all(region.sky_within(ra, dec))): raise AssertionError("Failed on list of positions")
    if np.any(region.sky_within(ra[0]+5*radius[0], dec[0])): raise AssertionError("Failed on position outside of region")
    try:
        region.sky_within(np.nan, dec[0])
    except ValueError as e:
        raise AssertionError("Failed with a nan position\n" + e.message)
Example #12
0
def test_pickle():
    """ Test that the Region class can be pickled and loaded without loss """
    ra = 66.38908
    dec = -26.72466
    radius = 22
    region = Region(maxdepth=8)
    region.add_circles(np.radians(ra), np.radians(dec), np.radians(radius))
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    pickle.dump(region, open('out_temp.mim', 'wb'))
    region2 = pickle.load(open('out_temp.mim','rb'))
    if not (region.pixeldict == region2.pixeldict): raise AssertionError('pickle/unpickle does not give same region')
    os.remove('out_temp.mim')
Example #13
0
def test_pickle():
    """ Test that the Region class can be pickled and loaded without loss """
    ra = 66.38908
    dec = -26.72466
    radius = 22
    region = Region(maxdepth=8)
    region.add_circles(np.radians(ra), np.radians(dec), np.radians(radius))
    try:
        import cPickle as pickle
    except ImportError:
        import pickle
    pickle.dump(region, open('out_temp.mim', 'wb'))
    region2 = pickle.load(open('out_temp.mim', 'rb'))
    if not (region.pixeldict == region2.pixeldict):
        raise AssertionError('pickle/unpickle does not give same region')
    os.remove('out_temp.mim')
Example #14
0
def test_sky_within():
    """Test the Ragion.sky_within method"""
    ra = np.radians([13.5, 15])
    dec = np.radians([-45, -40])
    radius = np.radians([0.1, 0.1])
    region = Region(maxdepth=11)
    region.add_circles(ra, dec, radius)
    if not (np.all(region.sky_within(ra[0], dec[0]))):
        raise AssertionError("Failed on position at center of region")
    if not (np.all(region.sky_within(ra, dec))):
        raise AssertionError("Failed on list of positions")
    if np.any(region.sky_within(ra[0] + 5 * radius[0], dec[0])):
        raise AssertionError("Failed on position outside of region")
    try:
        region.sky_within(np.nan, dec[0])
    except ValueError as e:
        raise AssertionError("Failed with a nan position\n" + e.message)
Example #15
0
def test_renorm_demote_symmetric():
    """Test that Region._renorm and Region._demote are mutual inverses"""
    ra = 13.5
    dec = -90
    radius = 0.1
    region = Region(maxdepth=11)
    region.add_circles(np.radians(ra), np.radians(dec), np.radians(radius))
    region._demote_all()
    start_dict = region.pixeldict.copy()
    region._renorm()
    region._demote_all()
    end_dict = region.pixeldict.copy()
    test = True
    for i in range(1, region.maxdepth+1):
        if len(end_dict[i].difference(start_dict[i])) > 0:
            test = False
    if not (test): raise AssertionError('renorm and demote are not symmetric')
Example #16
0
def test_renorm_demote_symmetric():
    """Test that Region._renorm and Region._demote are mutual inverses"""
    ra = 13.5
    dec = -90
    radius = 0.1
    region = Region(maxdepth=11)
    region.add_circles(np.radians(ra), np.radians(dec), np.radians(radius))
    region._demote_all()
    start_dict = region.pixeldict.copy()
    region._renorm()
    region._demote_all()
    end_dict = region.pixeldict.copy()
    test = True
    for i in range(1, region.maxdepth + 1):
        if len(end_dict[i].difference(start_dict[i])) > 0:
            test = False
    if not (test): raise AssertionError('renorm and demote are not symmetric')
Example #17
0
def test_add_circles_list_scalar():
    """Test that Region.add_circles works for vector inputs"""
    ra_list = np.radians([13.5, 13.5])
    dec_list = np.radians([-90, -90])
    radius_list = np.radians([0.1, 0.01])
    ra = ra_list[0]
    dec = dec_list[0]
    radius = radius_list[0]
    region1 = Region(maxdepth=11)
    region2 = Region(maxdepth=11)
    region1.add_circles(ra_list, dec_list, radius_list)
    region1._demote_all()
    region2.add_circles(ra, dec, radius)
    region2._demote_all()
    test = True
    for i in range(1, region1.maxdepth+1):
        if len(region1.pixeldict[i].difference(region2.pixeldict[i])) > 0:
            test = False
    if not (test): raise AssertionError('add_circles gives different results for lists and scalars')
Example #18
0
def test_add_circles_list_scalar():
    """Test that Region.add_circles works for vector inputs"""
    ra_list = np.radians([13.5, 13.5])
    dec_list = np.radians([-90, -90])
    radius_list = np.radians([0.1, 0.01])
    ra = ra_list[0]
    dec = dec_list[0]
    radius = radius_list[0]
    region1 = Region(maxdepth=11)
    region2 = Region(maxdepth=11)
    region1.add_circles(ra_list, dec_list, radius_list)
    region1._demote_all()
    region2.add_circles(ra, dec, radius)
    region2._demote_all()
    test = True
    for i in range(1, region1.maxdepth + 1):
        if len(region1.pixeldict[i].difference(region2.pixeldict[i])) > 0:
            test = False
    if not (test):
        raise AssertionError(
            'add_circles gives different results for lists and scalars')
Example #19
0
def test_intersect():
    """
    Test the Region.intersect gives expected results"
    """
    a = Region(maxdepth=7)
    a.add_circles(0, np.radians(-90), np.radians(1))
    b = Region(maxdepth=7)
    b.add_circles(0, np.radians(-90), np.radians(0.5))
    a.intersect(b)
    if not (a.get_area() == b.get_area()):
        raise AssertionError("test_intersect FAILED")

    a = Region(maxdepth=8)
    a.add_circles(0, np.radians(75), np.radians(3))
    c = Region(maxdepth=8)
    c.add_circles(0, np.radians(90), np.radians(10))
    a.intersect(c)
    if not (a.get_area() == 0.):
        raise AssertionError("test_intersect FAILED")
Example #20
0
def test_intersect():
    """
    Test the Region.intersect gives expected results"
    """
    a = Region(maxdepth=7)
    a.add_circles(0, np.radians(-90), np.radians(1))
    b = Region(maxdepth=7)
    b.add_circles(0, np.radians(-90), np.radians(0.5))
    a.intersect(b)
    if not (a.get_area() == b.get_area()):
        raise AssertionError("test_intersect FAILED")

    a = Region(maxdepth=8)
    a.add_circles(0, np.radians(75), np.radians(3))
    c = Region(maxdepth=8)
    c.add_circles(0, np.radians(90), np.radians(10))
    a.intersect(c)
    if not (a.get_area() == 0.):
        raise AssertionError("test_intersect FAILED")