Esempio n. 1
0
    def test_functions_callable(self):
        arr = np.ones((5, 5))

        mask = _sigma_clip(arr, cen_func=np.median)
        mask = _sigma_clip(arr, dev_func=np.std)

        # testing forced 1.0pm0.5
        def _test_cen(*args, **kwargs):
            return 1.0

        def _test_dev(*args, **kwargs):
            return 0.5

        # 1.2 should not be masked with 1.0pm0.5, 2.0 and 1000 yes
        arr[0, 0] = 1.2
        arr[1, 1] = 2
        arr[3, 2] = 1000

        mask = _sigma_clip(arr, 1, cen_func=_test_cen, dev_func=_test_dev)
        for i in range(5):
            for j in range(5):
                if (i, j) in [(1, 1), (3, 2)]:
                    assert_true(mask[i, j])
                else:
                    assert_false(mask[i, j])
Esempio n. 2
0
    def test_reset_data(self, tmpdir):
        d1 = np.array([[1, 2], [3, 4]]).astype('float32')
        m = MemMapArray(d1,
                        os.path.join(tmpdir, 'reset.npy'),
                        dtype='float64',
                        memmap=True)
        assert_true(np.issubdtype(m.dtype, np.float64))
        assert_equal(m, d1)
        assert_false(m.empty)
        assert_true(m.memmap)

        m.reset_data(d1)
        assert_true(np.issubdtype(m.dtype, np.float32))
        assert_equal(m, d1)
        assert_false(m.empty)
        assert_true(m.memmap)

        m.reset_data(d1.astype('int16'))
        assert_true(np.issubdtype(m.dtype, np.int16))
        assert_equal(m, d1)
        assert_false(m.empty)
        assert_true(m.memmap)

        m.reset_data(None)
        assert_true(m.empty)
        assert_true(m._contained is None)
        assert_true(m.memmap)
        m.disable_memmap()

        m.reset_data(np.ones((10, 10)), dtype='float32')
        assert_true(np.issubdtype(m.dtype, np.float32))
        assert_equal(m, np.ones((10, 10)))
        assert_false(m.empty)
        assert_false(m.memmap)
Esempio n. 3
0
    def test_enable_disable_memmap(self, tmpdir):
        f = os.path.join(tmpdir, 'npn_empty.npy')
        arr = [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]
        a = MemMapArray(arr, filename=f, dtype=None, memmap=False)
        assert_false(a.memmap)
        assert_false(os.path.exists(f))

        a.enable_memmap()
        assert_true(a.memmap)
        assert_true(os.path.exists(f))
        assert_is_instance(a._contained, np.memmap)

        # First keep the file
        a.disable_memmap(remove=False)
        assert_false(a.memmap)
        assert_true(os.path.exists(f))
        assert_is_not_instance(a._contained, np.memmap)

        a.enable_memmap()
        assert_true(a.memmap)
        assert_true(os.path.exists(f))
        assert_is_instance(a._contained, np.memmap)

        # Remove the file
        a.disable_memmap(remove=True)
        assert_false(a.memmap)
        assert_false(os.path.exists(f))
        assert_is_not_instance(a._contained, np.memmap)

        with pytest.raises(ValueError):
            # raises error if name is locked
            a.enable_memmap('not_the_same_name.npy')
Esempio n. 4
0
 def test_extract_header_nowcs(self):
     header = fits.Header.fromstring(_base_header, sep='\n')
     h, wcs = extract_header_wcs(header)
     assert_is_none(wcs)
     assert_is_instance(h, fits.Header)
     assert_equal(h, header)
     assert_false(h is header)
Esempio n. 5
0
    def test_simbad_catalog_check_filter_errors(self):
        # default behavior is raise error
        with pytest.raises(ValueError, match='This catalog does not support'):
            self.cat.check_filter('inexisting')

        with pytest.raises(ValueError, match='This catalog does not support'):
            self.cat.check_filter('inexisting', raise_error=True)

        assert_false(self.cat.check_filter('inexisting', raise_error=False))
Esempio n. 6
0
 def test_process_list(self):
     def dummy_func(i):
         i = 1
         return i
     a = np.zeros(20)
     b = np.ones(20)
     c = process_list(dummy_func, a)
     assert_equal(b, c)
     assert_false(np.array_equal(a, c))
Esempio n. 7
0
    def test_extract_invalid_wcs_header(self):
        # It should no raise, just return empty wcs
        # No header change too
        header = fits.Header.fromstring(_base_header + _invalid_wcs, sep='\n')
        del header['']
        h, wcs = extract_header_wcs(header)

        assert_is_none(wcs)
        assert_is_instance(h, fits.Header)
        assert_equal(h, header)
        assert_false(h is header)
Esempio n. 8
0
 def test_extract_header_nosip(self):
     header = fits.Header.fromstring(_base_header + _wcs_no_sip, sep='\n')
     h, wcs = extract_header_wcs(header)
     assert_is_instance(wcs, WCS)
     assert_equal(wcs.wcs.ctype[0], 'RA---TAN')
     assert_equal(wcs.wcs.ctype[1], 'DEC--TAN')
     assert_is_instance(h, fits.Header)
     for i in _comon_wcs_keys:
         assert_not_in(f'{i}1', h.keys())
         assert_not_in(f'{i}2', h.keys())
     assert_in('DATE-OBS', h.keys())
     assert_false(h is header)
     assert_not_equal(h, header)
Esempio n. 9
0
    def test_create_memmap(self, tmpdir, memmap):
        f = os.path.join(tmpdir, 'npn_empty.npy')
        arr = [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]
        a = MemMapArray(arr, filename=f, dtype=None, memmap=memmap)
        assert_equal(a.filename, f)
        assert_equal(a, arr)
        assert_false(a.empty)
        assert_equal(a.memmap, memmap)
        assert_equal(os.path.exists(f), memmap)
        assert_true(a.dtype == np.int64)

        a[0][0] = 10
        assert_equal(a[0][0], 10)

        a[0][:] = 20
        assert_equal(a[0], [20, 20, 20, 20, 20, 20])
Esempio n. 10
0
 def test_create_empty_memmap(self, tmpdir, memmap):
     f = os.path.join(tmpdir, 'empty.npy')
     a = MemMapArray(None, filename=f, dtype=None, memmap=memmap)
     assert_equal(a.filename, f)
     assert_true(a._contained is None)
     assert_equal(a.memmap, memmap)
     assert_true(a.empty)
     assert_false(os.path.exists(f))
     with pytest.raises(EmptyDataError):
         # dtype whould rise
         a.dtype
     with pytest.raises(EmptyDataError):
         # shape whould rise
         a.shape
     with pytest.raises(EmptyDataError):
         # item whould rise
         a[0]
     with pytest.raises(EmptyDataError):
         # set item whould rise
         a[0] = 1
Esempio n. 11
0
def test_create_and_delete_memmap(tmpdir):
    # Creation
    f = os.path.join(tmpdir, 'testarray.npy')
    g = os.path.join(tmpdir, 'test2array.npy')
    a = np.ones((30, 30), dtype='f8')
    b = create_array_memmap(f, a)
    c = create_array_memmap(g, a, dtype=bool)
    assert_is_instance(b, np.memmap)
    assert_is_instance(c, np.memmap)
    assert_equal(a, b)
    assert_almost_equal(a, c)
    assert_true(os.path.exists(f))
    assert_true(os.path.exists(g))

    # Deletion
    # Since for the uses the object is overwritten, we do it here too
    d = delete_array_memmap(b, read=True, remove=False)
    e = delete_array_memmap(c, read=True, remove=False)
    assert_is_not_instance(d, np.memmap)
    assert_is_not_instance(e, np.memmap)
    assert_is_instance(d, np.ndarray)
    assert_is_instance(e, np.ndarray)
    assert_equal(a, d)
    assert_almost_equal(a, e)
    assert_true(os.path.exists(f))
    assert_true(os.path.exists(g))

    d = delete_array_memmap(b, read=False, remove=True)
    e = delete_array_memmap(c, read=False, remove=True)
    assert_true(d is None)
    assert_true(e is None)
    assert_false(os.path.exists(f))
    assert_false(os.path.exists(g))

    # None should not raise errors
    create_array_memmap('dummy', None)
    delete_array_memmap(None)
Esempio n. 12
0
    def test_all_equal_1d_false(self):
        a = np.ones(10)
        a[2] = 2
        assert_false(all_equal(a))

        a = np.zeros(10)
        a[2] = 2
        assert_false(all_equal(a))

        a = np.array(['aAa']*10)
        a[2] = 'bBb'
        assert_false(all_equal(a))
Esempio n. 13
0
    def test_all_equal_2d_false(self):
        a = np.ones((5, 5))
        a[2][2] = 2
        assert_false(all_equal(a))

        a = np.zeros((5, 5))
        a[2][2] = 2
        assert_false(all_equal(a))

        a = ['aAa']*5
        a = np.array([a]*5)
        a[2][2] = 'bBb'
        assert_false(all_equal(a))
Esempio n. 14
0
def test_math_bool_all_any(tmpdir, memmap, value, other):
    f = os.path.join(tmpdir, 'bool.npy')
    arr = np.array([[0, 1, 0, 1], [1, 0, 1, 0]])
    a = MemMapArray(arr, filename=f, memmap=memmap)
    with pytest.raises(ValueError):
        bool(a)
    assert_false(a.all())
    assert_true(a.any())

    arr = np.array([0, 0, 0])
    a = MemMapArray(arr, filename=f + '1', memmap=memmap)
    assert_false(a.all())
    assert_false(a.any())

    arr = np.array([1, 1, 1])
    a = MemMapArray(arr, filename=f + '2', memmap=memmap)
    assert_true(a.all())
    assert_true(a.any())
Esempio n. 15
0
def test_check_number(v, exp):
    if exp:
        assert_true(check_number(v))
    else:
        assert_false(check_number(v))
Esempio n. 16
0
 def test_check_iterabel_number(self):
     a = 10
     assert_false(check_iterable(a))
Esempio n. 17
0
 def test_check_iterabel_string(self):
     a = '12345'
     assert_false(check_iterable(a))
Esempio n. 18
0
 def test_assert_false(self):
     assert_false(False)
     with pytest.raises(AssertionError):
         assert_false(True)