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_otc(): """ Test PAC function: OTC """ # Load data data = np.load(os.path.dirname(pacpy.__file__) + '/tests/exampledata.npy') # Confirm consistency in result t_modsig = (-.5, .5) fs = 1000. f_hi = (80, 200) f_step = 4 pac, tf, a_events, mod_sig = otc(data, f_hi, f_step, fs=fs, t_modsig=t_modsig) assert np.allclose(pac, 235.02888, atol=10**-5) # Confirm correct shapes in outputs assert np.shape(tf) == ((f_hi[1] - f_hi[0]) / f_step, len(data)) for i in range(len(a_events)): assert np.max(a_events[i]) <= len(data) assert np.shape(mod_sig) == ((f_hi[1] - f_hi[0]) / f_step, len( np.arange(t_modsig[0], t_modsig[1], 1 / fs)))
def test_otc(): """ Test PAC function: OTC """ # Load data data = np.load(os.path.dirname(pacpy.__file__) + '/tests/exampledata.npy') # Confirm consistency in result t_modsig = (-.5, .5) fs = 1000. f_hi = (80, 200) f_step = 4 pac, tf, a_events, mod_sig = otc( data, f_hi, f_step, fs=fs, t_modsig=t_modsig) assert np.allclose(pac, 235.02888, atol=10 ** -5) # Confirm correct shapes in outputs assert np.shape(tf) == ((f_hi[1] - f_hi[0]) / f_step, len(data)) for i in range(len(a_events)): assert np.max(a_events[i]) <= len(data) assert np.shape(mod_sig) == ( (f_hi[1] - f_hi[0]) / f_step, len(np.arange(t_modsig[0], t_modsig[1], 1 / fs)))