Ejemplo 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])
Ejemplo n.º 2
0
    def test_sigmclip_types(self):
        arr = np.arange(10)

        # must work with numbers
        _sigma_clip(arr, 1)

        # must work with 2-elements array
        _sigma_clip(arr, np.array([1, 2]))
        _sigma_clip(arr, [1, 2])
        _sigma_clip(arr, (1, 2))
Ejemplo n.º 3
0
    def test_1D_simple(self):
        with NumpyRNGContext(123):
            arr = np.random.normal(5, 2, 100)
        arr[32] = 1000
        arr[25] = 1000
        arr[12] = -1000
        exp = np.zeros(100, dtype=bool)
        exp[32] = True
        exp[25] = True
        exp[12] = True

        mask = _sigma_clip(arr, 3)
        assert_equal(mask, exp)
Ejemplo n.º 4
0
    def test_invalid(self):
        arr = np.ones((5, 5))
        exp = np.zeros((5, 5), dtype=bool)

        indx = [(1, 1), (2, 1), (2, 3)]

        arr[indx[0]] = 1000
        arr[indx[1]] = np.inf
        arr[indx[2]] = np.nan

        for i in indx:
            exp[i] = True

        mask = _sigma_clip(arr)
        assert_equal(mask, exp)
Ejemplo n.º 5
0
    def test_unkown_sigmaclip(self):
        arr = np.arange(10)
        with pytest.raises(TypeError):
            _sigma_clip(arr, 'testing')

        with pytest.raises(TypeError):
            _sigma_clip(arr, '1,2')

        # too many values must raise
        with pytest.raises(ValueError):
            _sigma_clip(arr, [1, 2, 3])
Ejemplo n.º 6
0
    def test_2D_defaults(self):
        # mean:4.532 median:4.847 std:282 mad_std: 2.02
        arr = np.array([[6.037, 5.972, 5.841, 2.775, 0.711],
                        [6.539, 4.677, -1000, 5.633, 3.478],
                        [4.847, 7.563, 3.323, 7.952, 6.646],
                        [6.136, 2.690, 4.193, 1000., 4.483],
                        [5.673, 7.479, 3.874, 4.756, 2.021]])
        # using defaults median and mad_std
        expect_1 = [[0, 0, 0, 1, 1], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0],
                    [0, 1, 0, 1, 0], [0, 1, 0, 0, 1]]
        expect_1 = np.array(expect_1, dtype=bool)

        expect_3 = [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0],
                    [0, 0, 0, 1, 0], [0, 0, 0, 0, 0]]
        expect_3 = np.array(expect_3, dtype=bool)

        mask = _sigma_clip(arr, 3)
        assert_equal(mask, expect_3)
Ejemplo n.º 7
0
    def test_functions_invalid(self):
        arr = np.ones((5, 5))

        with pytest.raises(KeyError, match='invalid'):
            _sigma_clip(arr, cen_func='invalid')
        with pytest.raises(KeyError, match='invalid'):
            _sigma_clip(arr, dev_func='invalid')
        with pytest.raises(KeyError, match='1'):
            _sigma_clip(arr, cen_func=1)
        with pytest.raises(KeyError, match='1'):
            _sigma_clip(arr, dev_func=1)
        with pytest.raises(TypeError):
            _sigma_clip(arr, cen_func=[])
        with pytest.raises(TypeError):
            _sigma_clip(arr, dev_func=[])
Ejemplo n.º 8
0
    def test_functions_names(self):
        arr = np.ones((5, 5))

        # all this should run
        _sigma_clip(arr, cen_func='median')
        _sigma_clip(arr, cen_func='mean')
        _sigma_clip(arr, dev_func='std')
        _sigma_clip(arr, cen_func='mean', dev_func='std')
        _sigma_clip(arr, dev_func='mad_std')
        _sigma_clip(arr, cen_func='median', dev_func='mad_std')