def LFP_to_dict(LFP, visual_chan, tmin=-0.5, tmax=1.75, sfreq=250): """Return dictionary with all category specific LFP and visual channels information""" visual_LFP = LFP.copy().pick(visual_chan['chan_name'].tolist()) LFP_dict = visual_chan.to_dict(orient='list') categories = ['Rest', 'Face', 'Place'] for cat in categories: epochs, events = hf.epoch_category(visual_LFP, cat=cat, tmin=-0.5, tmax=1.75) epochs = epochs.resample(sfreq) X = epochs.copy().get_data() X = np.transpose(X, axes=(1, 2, 0)) LFP_dict[cat] = X LFP_dict['time'] = epochs.times population_to_channel = hf.parcellation_to_indices(visual_chan, parcellation='group') DK_to_channel = hf.parcellation_to_indices(visual_chan, parcellation='DK') LFP_dict['population_to_channel'] = population_to_channel LFP_dict['DK_to_channel'] = DK_to_channel return LFP_dict
from scipy.io import savemat, loadmat #%% Plot mvgc subject = "DiAs" # Anatomical info ecog = hf.Ecog(args.cohort_path, subject=subject, proc=args.proc, stage=args.stage, epoch=args.epoch) df_visual = ecog.read_channels_info(fname=args.channels) functional_group = df_visual["group"].unique() functional_indices = hf.parcellation_to_indices(df_visual, 'group', matlab=True) visual_chan = df_visual['chan_name'].to_list() # Read results result_path = Path('~', 'neocortex', 'results').expanduser() fname = subject + '_GC_sliding.mat' gc_path = result_path.joinpath(fname) gc = loadmat(gc_path) fb = gc['Fb'] sig = gc['sig'] z = gc['z'] pval = gc['pval']
LFP_dict = LFP_to_dict(LFP, visual_chan, tmin=-0.5, tmax=1.75, sfreq=250) #%% LFP_dict = visual_chan.to_dict(orient='list') for cat in categories: epochs, events = hf.epoch_category(visual_LFP, cat=cat, tmin=-0.5, tmax=1.75) epochs = epochs.resample(sfreq) X = epochs.copy().get_data() X = np.transpose(X, axes=(1, 2, 0)) LFP_dict[cat] = X LFP_dict['time'] = epochs.times population_to_channel = hf.parcellation_to_indices(visual_chan, parcellation='group') DK_to_channel = hf.parcellation_to_indices(visual_chan, parcellation='DK') LFP_dict['population_to_channel'] = population_to_channel LFP_dict['DK_to_channel'] = DK_to_channel #%% Save dictionary fname = sub_id + '_visual_LFP_all_categories.mat' fpath = datadir.joinpath(fname) # Save data in Rest x Face x Place array of time series savemat(fpath, LFP_dict)
# -Check that there are output visual_data X is correct with HFB_visual (i.e. check that # permutation works) # - Create a module for category specific electrodes # - Rearrange HFB module consequently #%% pd.options.display.max_rows = 999 sub_id = 'DiAs' visual_chan_table = 'visual_channels_BP_montage.csv' proc = 'preproc' cat = 'Face' sfreq = 100 picks = ['LGRD60-LGRD61', 'LTo1-LTo2'] tmin_crop = 0.5 tmax_crop = 1.5 suffix = 'preprocessed_raw' ext = '.fif' #%%v subject = cf.Subject(name=sub_id) datadir = subject.processing_stage_path(proc=proc) visual_chan = subject.pick_visual_chan() sorted_visual_chan = visual_chan.sort_values(by='latency') # %% group = visual_chan['group'].unique().tolist() anatomical_indices = hf.parcellation_to_indices(visual_chan, parcellation='DK')
visual_chan = subject.pick_visual_chan() HFB = hf.visually_responsive_HFB(sub_id=sub_id) ts[s], time = fun.ts_all_categories(HFB, tmin_crop=tmin_crop, tmax_crop=tmax_crop) df_sorted = df_sorted.append( df.loc[df['subject_id'] == sub_id].sort_values(by='latency')) df_sorted = df_sorted.reset_index(drop=True) #%% X = np.concatenate(tuple(ts), axis=0) #%% pop_to_idx = hf.parcellation_to_indices(df_sorted, parcellation='group') pop = df_sorted['group'].unique() npop = len(pop) ts_pop = [0] * npop for i, p in enumerate(pop): idx = pop_to_idx[p] X_p = np.take(X, idx, axis=0) ts_pop[i] = np.average(X_p, axis=0) X_pop = np.stack(ts_pop) ntrial = X_p.shape[2] std_pop = np.std(X_pop, axis=2) X_pop = np.average(X_pop, axis=2) #%% Plot result