def concatenate_run_dataset(sub_id = sub, proc='bipolar_montage', task = 'rest_baseline', preload = True): subject = cifar_load_subject.Subject(name=sub_id, task = task, run='1') fpath = subject.dataset_path(proc=proc, suffix='BP_montage', ext='.set') raw = mne.io.read_raw_eeglab(fpath, preload=preload) raw_1 = raw.copy() subject = cifar_load_subject.Subject(name=sub_id, task = task, run='2') fpath = subject.dataset_path(proc=proc, suffix='BP_montage', ext='.set') raw = mne.io.read_raw_eeglab(fpath, preload=preload) raw_2 = raw.copy() raw_1.append([raw_2]) return raw_1
import seaborn as sns import helper_functions as fun import HFB_process as hf from scipy.io import loadmat #%% sub_id = 'DiAs' visual_chan_table = 'visual_channels_BP_montage.csv' proc = 'preproc' sfreq = 250; suffix = 'preprocessed_raw' ext = '.fif' categories = ['Rest', 'Face', 'Place'] subject = cf.Subject(name=sub_id) datadir = subject.processing_stage_path(proc=proc) # %% Plot spectral GC fres = 1024; fmax = sfreq/2; fname = sub_id + 'spectral_gc.mat' fpath = datadir.joinpath(fname) sGC = loadmat(fpath) f = sGC['f'] freqs = np.arange(start=0, stop= fmax, step = fmax/fres) (nchan, nchan, nfreq, ncat) = f.shape f_tot = np.zeros((nfreq, ncat))
proc = 'preproc' for sub in subjects: for task in tasks: for run in runs: sub = sub task = task run = run suffix = 'bad_chans_removed_raw' ext = '.fif' suffix2save = 'bad_chans_removed' ext2save = '.mat' # %% Import data subject = cifar_load_subject.Subject(name=sub, task=task, run=run) fpath = subject.dataset_path(proc=proc, suffix=suffix, ext=ext) raw = mne.io.read_raw_fif(fpath, preload=True) dfelec = subject.df_electrodes_info() # drop bad channels bads = raw.info['bads'] raw_drop_bads = raw.copy().drop_channels(bads) # Extract time series and save to matlab time_series = raw_drop_bads.get_data() fpath2save = subject.dataset_path(proc=proc,
#%% sub_id = 'DiAs' proc = 'preproc' stage = '_BP_montage_preprocessed_raw.fif' picks = ['LTo1-LTo2', 'LTo5-LTo6'] sfreq = 250 tmin = 0 tmax = 1.75 win_size = 0.200 step = 0.020 detrend = False #%% Load data subject = cf.Subject(sub_id) datadir = subject.processing_stage_path(proc=proc) visual_populations = subject.pick_visual_chan() #%% ts, time = hf.sliding_lfp(picks, proc=proc, stage=stage, sub_id=sub_id, tmin=tmin, tmax=tmax, win_size=win_size, step=step, detrend=detrend, sfreq=sfreq)
t_postim = 1.75 tmin_prestim = -0.4 tmax_prestim = -0.1 tmin_postim = 0.1 tmax_postim = 0.5 alpha = 0.05 zero_method = 'pratt' alternative = 'two-sided' for sub in sub_id: # Subject parameters sub = sub #%% Read preprocessed data subject = cf.Subject(name=sub) datadir = subject.processing_stage_path(proc=proc) hfb_db = subject.load_data(proc=proc, stage=stage, epo=epo) dfelec = subject.df_electrodes_info() visual_populations = hf.hfb_to_visual_populations( hfb_db, dfelec, tmin_prestim=tmin_prestim, tmax_prestim=tmax_prestim, tmin_postim=tmin_postim, tmax_postim=tmax_postim, alpha=alpha, zero_method=zero_method) # Create single subject dataframe df_visual = pd.DataFrame.from_dict(visual_populations)
proc = 'preproc' fname = sub_id + '_BP_montage_preprocessed_raw.fif' tmin = 100 tmax = 102 l_freq = 70 band_size=20.0 l_trans_bandwidth= 10.0 h_trans_bandwidth= 10.0 filter_length='auto' phase='minimum' ichan = 6 figname = 'HFB_envelope_extraction.jpg' figpath = Path.home().joinpath('projects','CIFAR','figures', figname) #%% Load data subject = cf.Subject() fpath = subject.processing_stage_path(proc = proc) fpath = fpath.joinpath(fname) raw = mne.io.read_raw_fif(fpath, preload=True) raw = raw.crop(tmin=tmin, tmax=tmax) times = raw.times #%% Test bands bands = hf.freq_bands() #%% Test HFB extraction HFA = hf.extract_envelope(raw, l_freq = 60, band_size=100.0, l_trans_bandwidth= 10.0, h_trans_bandwidth= 10.0, filter_length='auto', phase='minimum') HFB = hf.extract_hfb(raw, l_freq=60.0, nband=6, band_size=20.0,
return raw_rest #%% Concatenate raw = concatenate_task_dataset(sub_id = sub) #%% Mark bad channels raw.plot(scalings=1e-4, duration =200) #%% Check psd raw.plot_psd(xscale = 'log') # %% Save dataset in fif and mat subject = cifar_load_subject.Subject(name=sub) fpath_save = subject.processing_stage_path(proc='preproc') dataset_save = sub + '_BP_montage_concatenated_bads_marked_raw.fif' fname_save = fpath_save.joinpath(dataset_save) raw.save(fname_save, overwrite=True) # Drop bad chans and save in mat format bads = raw.info['bads'] raw_drop_bads = raw.copy().drop_channels(bads) dataset_save = sub+ '_BP_montage_preprocessed_raw.fif' fname_save = fpath_save.joinpath(dataset_save) raw_drop_bads.save(fname_save, overwrite=True)