def test_plv(): """ Test PAC function: PLV. 1. Confirm consistency of output with example data 2. Confirm consistency of output with example data using iir filter 3. Confirm PAC=1 when expected 4. Confirm PAC=0 when expected """ # Load data data = np.load(os.path.dirname(pacpy.__file__) + '/tests/exampledata.npy') assert np.allclose( plv(data, data, (13, 30), (80, 200)), 0.23778, atol=10 ** -5) assert np.allclose( plv(data, data, (13, 30), (80, 200), filterfn=butterf), 0.24696, atol=10 ** -5) # Test that the PLV function outputs close to 0 and 1 when expected lo, hi = genPAC1() assert plv(lo, hi, (4, 6), (90, 110)) > 0.99 lo, hi = genPAC0() assert plv(lo, hi, (4, 6), (90, 110)) < 0.05
def test_plv(): """ Test PAC function: PLV. 1. Confirm consistency of output with example data 2. Confirm consistency of output with example data using firfls filter 3. Confirm PAC=1 when expected 4. Confirm PAC=0 when expected """ # Load data data = np.load(os.path.dirname(pacpy.__file__) + '/tests/exampledata.npy') assert np.allclose(plv(data, data, (13, 30), (80, 200)), 0.25114, atol=10**-5) assert np.allclose(plv(data, data, (13, 30), (80, 200), filterfn=firfls), 0.24715, atol=10**-5) # Test that the PLV function outputs close to 0 and 1 when expected lo, hi = genPAC1() assert plv(lo, hi, (4, 6), (90, 110)) > 0.99 lo, hi = genPAC0() assert plv(lo, hi, (4, 6), (90, 110)) < 0.01 # Test that Filterfn = False works as expected datalo = firf(data, (13, 30)) datahi = firf(data, (80, 200)) datahiamp = np.abs(hilbert(datahi)) datahiamplo = firf(datahiamp, (13, 30)) pha1 = np.angle(hilbert(datalo)) pha2 = np.angle(hilbert(datahiamplo)) pha1, pha2 = _trim_edges(pha1, pha2) assert np.allclose(plv(pha1, pha2, (13, 30), (80, 200), filterfn=False), plv(data, data, (13, 30), (80, 200)), atol=10**-5)
def test_plv(): """ Test PAC function: PLV. 1. Confirm consistency of output with example data 2. Confirm consistency of output with example data using firfls filter 3. Confirm PAC=1 when expected 4. Confirm PAC=0 when expected """ # Load data data = np.load(os.path.dirname(pacpy.__file__) + '/tests/exampledata.npy') assert np.allclose( plv(data, data, (13, 30), (80, 200)), 0.25114, atol=10 ** -5) assert np.allclose( plv(data, data, (13, 30), (80, 200), filterfn=firfls), 0.24715, atol=10 ** -5) # Test that the PLV function outputs close to 0 and 1 when expected lo, hi = genPAC1() assert plv(lo, hi, (4, 6), (90, 110)) > 0.99 lo, hi = genPAC0() assert plv(lo, hi, (4, 6), (90, 110)) < 0.01 # Test that Filterfn = False works as expected datalo = firf(data, (13, 30)) datahi = firf(data, (80, 200)) datahiamp = np.abs(hilbert(datahi)) datahiamplo = firf(datahiamp, (13, 30)) pha1 = np.angle(hilbert(datalo)) pha2 = np.angle(hilbert(datahiamplo)) pha1, pha2 = _trim_edges(pha1, pha2) assert np.allclose( plv(pha1, pha2, (13, 30), (80, 200), filterfn=False), plv(data, data, (13, 30), (80, 200)), atol=10 ** -5)
def test_raiseinputerrors(): """ Confirm that ValueErrors from dumb user input are raised """ # Load data data = np.load(os.path.dirname(pacpy.__file__) + '/tests/exampledata.npy') data2 = copy.copy(data) data2[-1] = np.nan with pytest.raises(ValueError) as excinfo: plv(data, data[:-1], (13, 30), (80, 200)) assert 'same length' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: plv(data, data2, (13, 30), (80, 200)) assert 'NaNs' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: plv(data, data, (13, 30, 31), (80, 200)) assert 'two elements' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: plv(data, data, (13, 30), (80, 200, 201)) assert 'two elements' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: plv(data, data, (-13, 30), (80, 200)) assert 'must be > 0' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: plv(data, data, (13, 30), (-80, 200)) assert 'must be > 0' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: mi_tort(data, data, (13, 30), (80, 200), Nbins=1) assert 'integer >1' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: mi_tort(data, data, (13, 30), (80, 200), Nbins=8.8) assert 'integer >1' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: otc(data, (80, 200), -1) assert 'positive number' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: otc(data, (80, 200), 4, t_modsig=(.5, -.5)) assert 'Invalid time range' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: _peaktimes(data, prc=101) assert '0 and 100' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: _chunk_time(data, samp_buffer=-1) assert 'positive number' in str(excinfo.value) with pytest.raises(ValueError) as excinfo: _chunk_time(data, samp_buffer=2.5) assert 'integer' in str(excinfo.value)