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)
def test_mi_tort(): """ Test PAC function: Tort MI 1. Confirm consistency of output with example data 2. Confirm PAC=1 when expected 3. Confirm PAC=0 when expected """ # Load data data = np.load(os.path.dirname(pacpy.__file__) + '/tests/exampledata.npy') assert np.allclose( mi_tort(data, data, (13, 30), (80, 200)), 0.00363, atol=10 ** -5) # Test that the Tort MI function outputs close to 0 and 1 when expected lo, hi = genPAC1(phabias=.2, fhi=300) assert mi_tort(lo, hi, (4, 6), (100, 400)) > 0.7 lo, hi = genPAC0() assert mi_tort(lo, hi, (4, 6), (100, 400)) < 10 ** -5
def test_mi_tort(): """ Test PAC function: Tort MI 1. Confirm consistency of output with example data 2. Confirm PAC=1 when expected 3. Confirm PAC=0 when expected """ # Load data data = np.load(os.path.dirname(pacpy.__file__) + '/tests/exampledata.npy') assert np.allclose(mi_tort(data, data, (13, 30), (80, 200)), 0.00363, atol=10**-5) # Test that the Tort MI function outputs close to 0 and 1 when expected lo, hi = genPAC1(phabias=.2, fhi=300) assert mi_tort(lo, hi, (4, 6), (100, 400)) > 0.7 lo, hi = genPAC0() assert mi_tort(lo, hi, (4, 6), (100, 400)) < 10**-5
def test_mi_tort(): """ Test PAC function: Tort MI 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( mi_tort(data, data, (13, 30), (80, 200)), 0.00366, atol=10 ** -5) assert np.allclose(mi_tort( data, data, (13, 30), (80, 200), filterfn=butterf), 0.00429, atol=10 ** -5) # Test that the Tort MI function outputs close to 0 and 1 when expected lo, hi = genPAC1(phabias=.2, fhi=300) assert mi_tort(lo, hi, (4, 6), (100, 400)) > 0.8 lo, hi = genPAC0() assert mi_tort(lo, hi, (4, 6), (90, 110)) < 10 ** -5 # Test that Filterfn = False works as expected datalo = firf(data, (13,30)) datahi = firf(data, (80,200)) pha = np.angle(hilbert(datalo)) amp = np.abs(hilbert(datahi)) assert np.allclose( mi_tort(pha, amp, (13, 30), (80, 200), filterfn=False), mi_tort(data, data, (13, 30), (80, 200)), atol=10 ** -5)