Exemplo n.º 1
0
def test_random_state():
    # Test that the random state controls reproducibility
    sig_0 = simulate_pac_default(random_state=0)
    sig_1 = simulate_pac_default(random_state=1)
    sig_2 = simulate_pac_default(random_state=0)
    assert_raises(AssertionError, assert_array_almost_equal, sig_0, sig_1)
    assert_array_almost_equal(sig_0, sig_2)
Exemplo n.º 2
0
def test_different_dimension_in_input():
    # Test that 1D or 2D signals are accepted, but not 3D
    for dim in [(4, -1), (-1, ), (1, -1)]:
        fast_peak_locking(signal.reshape(*dim))

    dim = (2, 2, -1)
    assert_raises(ValueError, fast_peak_locking, signal.reshape(*dim))
Exemplo n.º 3
0
def test_no_surrogate():
    # Test the errors when n_surrogates == 0
    for method in ALL_PAC_METRICS:
        est = ComodTest(method=method, n_surrogates=0).fit(signal)

        with assert_raises(ValueError):
            est.comod_z_score_
        with assert_raises(ValueError):
            est.surrogate_max_

    with assert_raises(ValueError):
        est.plot(contour_level=0.01)
    plt.close('all')
Exemplo n.º 4
0
def test_plot_comodulogram():
    # Smoke test with the standard plotting function
    est = ComodTest().fit(signal)
    est.plot()

    # Smoke test with the special plotting functions
    ax = plt.figure().gca()
    for method in ALL_PAC_METRICS:
        est = ComodTest(low_fq_range=[low_fq], method=method,
                        ax_special=ax).fit(signal)

    # Test that it raises an error if ax_special is not None and low_fq_range
    # has more than one element
    func = partial(fast_comod, ax_special=ax)
    assert_raises(ValueError, func)
    plt.close('all')
Exemplo n.º 5
0
def test_input_checking():
    # test that we have a ValueError for bad parameters
    func = partial(fast_comod, method='wrong')
    assert_raises(ValueError, func)
    func = partial(fast_comod, fs='wrong')
    assert_raises(ValueError, func)
    func = partial(fast_comod, low_sig='wrong')
    assert_raises(ValueError, func)
    func = partial(fast_comod, high_sig='wrong')
    assert_raises(ValueError, func)
Exemplo n.º 6
0
def test_dehumming_improve_snr():
    # Test that dehumming removes the added noise
    rng = np.random.RandomState(0)
    fs = 250.
    enf = 50.
    clean = rng.randn(512)
    noisy = clean.copy()

    # add ENF noise
    time = np.arange(512) / float(fs)
    for harmonic in (1, 2):
        noisy += np.sin(time * 2 * np.pi * enf * harmonic) / harmonic

    for dim in [(1, 512), (512, ), (512, 1)]:
        dehummed = dehummer(
            noisy.reshape(*dim), fs, enf=enf)
        assert_greater(norm(noisy - clean), norm(dehummed.ravel() - clean))
        assert_array_equal(dehummed.shape, dim)

    # test that the dehumming does not accept 2d arrays
    assert_raises(ValueError, dehummer, noisy.reshape(2, 256), fs)
Exemplo n.º 7
0
def test_make_basis_new_sigdriv():
    # Test that make_basis works the same with a new sigdriv,
    # using stored orthonormalization transform.
    model_params = {'ordar': 5, 'ordriv': 2, 'criterion': False}
    for normalize in (True, False):
        for ortho in (True, False):
            for this_sigdriv, this_sigdriv_imag in ([_sigdriv, _sigdriv_imag],
                                                    [_noise, _noise[::-1]]):
                dar = dar_no_fit(ortho=ortho,
                                 normalize=normalize,
                                 sigdriv=this_sigdriv,
                                 sigdriv_imag=this_sigdriv_imag,
                                 **model_params)
                newbasis = dar.make_basis(sigdriv=this_sigdriv,
                                          sigdriv_imag=this_sigdriv_imag)
                assert_array_almost_equal(newbasis, dar.basis_)

                # Different result if we change a parameter
                dar_ortho = dar_no_fit(not ortho, normalize, **model_params)
                dar_norma = dar_no_fit(ortho, not normalize, **model_params)
                for dar2 in [dar_ortho, dar_norma]:
                    assert_raises(AssertionError, assert_array_almost_equal,
                                  dar.basis_, dar2.basis_)