def setup_module(module): global tvfcg_plv_ts global tvfcg_plv_fcgs global tvfcg_pac_plv_fcgs original_data = np.load("../examples/data/eeg_32chans_10secs.npy") # TVFCGS with PLV data = original_data[0:2, 0:1024] fb = [1.0, 4.0] fs = 128 estimator = PLV(fb, fs) tvfcg_plv_fcgs = tvfcg(data, estimator, fb, fs) # TVFCGS with PAC and PLV data = original_data[..., 0:1024] fb = [1.0, 4.0] fs = 128 f_lo = fb f_hi = [20.0, 30.0] estimator = PLV(fb, fs) pac = PAC(f_lo, f_hi, fs, estimator) tvfcg_pac_plv_fcgs = tvfcg_cfc(data, pac, f_lo, f_hi, fs) # TVFCGS with PLV (ts) fb = [1.0, 4.0] fs = 128.0 estimator = PLV(fb, fs) u_phases = estimator.preprocess(data) ts, avg = estimator.estimate(u_phases) tvfcg_plv_ts = tvfcg_ts(ts, [1.0, 4.0], 128, avg_func=estimator.mean)
def try_TVFCG_PAC(data): fb = [1.0, 4.0] fs = 128 f_lo = fb f_hi = [20.0, 30.0] estimator = PLV(fb, fs) pac = PAC(f_lo, f_hi, fs, estimator) fcgs = tvfcg_cfc(data, pac, f_lo, f_hi, fs) return fcgs
def test_pac_one_channel(): data = np.load("../examples/data/eeg_32chans_10secs.npy") data = data[0:1, 0:128] fs = 128 f_lo = [1.0, 4.0] f_hi = [20.0, 30.0] estimator = PLV(f_lo, fs) ts, avg = pac(data, f_lo, f_hi, fs, estimator) avg = np.squeeze(np.real(avg)) expected = 0.468296707219 nose.tools.assert_almost_equal(avg, expected)
def try_PAC(data): fb = [1.0, 4.0] fs = 128 pairs = None n_jobs = 1 plv = PLV(fb, fs, pairs) f_lo = [1.0, 4.0] f_hi = [20.0, 30.0] pac = PAC(f_lo, f_hi, fs, plv) phases, phases_lohi = pac.preprocess(data) cfc, avg = pac.estimate(phases, phases_lohi) return cfc, avg
def test_sliding_window(): rng = np.random.RandomState(1) data = np.load("../examples/data/random_timeseries.npy") estimator = PLV() dfcg = sliding_window(data, estimator, window_length=25, step=1, pairs=None) dfcg_r = np.real(dfcg) dfcg_r = np.float32(dfcg_r) dfcg_r = np.nan_to_num(dfcg_r) expected = np.load("data/test_sliding_window.npy") # Disable test on Travis; all options seem to fail. if "TRAVIS" in os.environ: assert True else: np.testing.assert_array_almost_equal(dfcg_r, expected)
def test_pac_multiple_channels(): data = np.load("../examples/data/eeg_32chans_10secs.npy") fs = 128 fb_lo = [1.0, 4.0] fb_hi = [20.0, 30.0] estimator = PLV(fb_lo, fs) ts, avg = pac(data, fb_lo, fb_hi, 128, estimator) ts = np.nan_to_num(ts) avg = np.nan_to_num(avg) expected_ts = np.load("data/test_pac_plv_ts.npy") expected_ts = np.nan_to_num(ts) np.testing.assert_array_equal(ts, expected_ts) avg = np.float32(avg) expected_avg = np.load("data/test_pac_plv_avg.npy") expected_avg = np.nan_to_num(expected_avg) expected_avg = np.float32(expected_avg) np.testing.assert_allclose(avg, expected_avg, rtol=1e-10, atol=0.0)
import numpy as np np.set_printoptions(precision=3, linewidth=256) from dyconnmap.fc import pac, PAC, PLV if __name__ == "__main__": data = np.load( "/home/makism/Github/dyconnmap/examples/data/eeg_32chans_10secs.npy") # # Common configuration # fb = [1.0, 4.0] fs = 128 pairs = None estimator = PLV(fb, fs, pairs) f_lo = [1.0, 4.0] f_hi = [20.0, 30.0] # # Functional # cfc, avg = pac(data, f_lo, f_hi, fs, estimator, pairs=None) print(avg) # # Object-oriented # pac = PAC(f_lo, f_hi, fs, estimator)
fs = 128.0 now = time.time() ts, avg = plv(data, fb, fs) print("Finished in", time.time() - now, "sec") # TVFCGs from time seriess now = time.time() fcgs = tvfcg_ts(ts, [1.0, 4.0], 128) print("Finished in", time.time() - now, "sec") # TVFCGs fb = [1.0, 4.0] fs = 128.0 estimator = PLV(fb, fs) fcgs = tvfcg(data, estimator, fb, fs) # PAC lo = [1.0, 4.0] hi = [8.0, 13.0] fs = 128.0 estimator = PLV(fb, fs) now = time.time() cfc_ts, cfc_avg = pac(data, lo, hi, fs, estimator) print("Finished in", time.time() - now, "sec") # TVFCGs + PAC pac_estimator = PAC(lo, hi, fs, estimator)