コード例 #1
0
def category_slided_ts(hfb_visual,
                       visual_chan,
                       categories=['Rest', 'Face', 'Place'],
                       tmin_crop=-0.5,
                       tmax_crop=1.75,
                       sfreq=250,
                       sample_min=125,
                       sample_max=375,
                       kappa=3,
                       segment_size=20):
    ncat = len(categories)
    ts = [0] * ncat
    ts_time = [0] * ncat
    for idx, cat in enumerate(categories):
        hfb = hf.category_specific_hfb(hfb_visual,
                                       cat=cat,
                                       tmin_crop=tmin_crop,
                                       tmax_crop=tmax_crop)
        hfb = hfb.resample(sfreq=sfreq)
        X, time_slide = epoch_slide(hfb, sample_min, sample_max, kappa,
                                    segment_size)
        X_ordered = np.zeros_like(X)
        sorted_ch_indices = visual_chan.index.tolist()
        for ichan, i in enumerate(sorted_ch_indices):
            X_ordered[:, ichan, :] = X[:, i, :]
            X = X_ordered
        ts[idx] = X
        ts_time[idx] = time_slide

    ts = np.stack(ts)
    ts_time = np.stack(time_slide)
    (ncat, nseg, ntrial, nchan, nobs) = ts.shape
    ts = np.transpose(ts, (3, 4, 2, 1, 0))
    ts_time = np.transpose(ts_time, (1, 0))
    return ts, ts_time
コード例 #2
0
def ts_win_cat(hfb_visual,
               visual_chan,
               categories=['Rest', 'Face', 'Place'],
               tmin_crop=-0.5,
               tmax_crop=1.75,
               sfreq=250,
               sample_start=125,
               sample_stop=375,
               step=5,
               window_size=20):
    ncat = len(categories)
    ts = [0] * ncat
    ts_time = [0] * ncat
    for idx, cat in enumerate(categories):
        hfb = hf.category_specific_hfb(hfb_visual,
                                       cat=cat,
                                       tmin_crop=tmin_crop,
                                       tmax_crop=tmax_crop)
        hfb = hfb.resample(sfreq=sfreq)
        X, time_win = epoch_win(hfb, sample_start, sample_stop, step,
                                window_size)
        # X_ordered = np.zeros_like(X)
        # sorted_ch_indices = visual_chan.index.tolist()
        # for ichan, i in enumerate(sorted_ch_indices):
        #     X_ordered[:, ichan, :] = X[:, i, :]
        #     X = X_ordered
        ts[idx] = X

    ts = np.stack(ts)
    (ncat, nwin, ntrial, nchan, nobs) = ts.shape
    ts = np.transpose(ts, (3, 4, 2, 1, 0))
    time_win = np.transpose(time_win, (1, 0))
    return ts, time_win
コード例 #3
0
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
コード例 #4
0
def ts_all_categories(HFB, tmin_crop=0.050, tmax_crop=0.250):

    categories = ['Rest', 'Face', 'Place']
    ncat = len(categories)
    ts = [0]*ncat
    for idx, cat in enumerate(categories):
        epochs = hf.category_specific_HFB(HFB, cat=cat, tmin_crop=tmin_crop,
                                       tmax_crop=tmax_crop)
        epochs = epochs.resample(sfreq=sfreq)
        X = epochs.get_data().copy()
        time = epochs.times
        ts[idx] = X

    ts = np.stack(ts)
    (ncat, ntrial, nchan, nobs) = ts.shape
    ts = np.transpose(ts, (2, 3, 1, 0))
    return ts, time
コード例 #5
0
tmin_postim = 0.2
tmax_postim = 0.5
alpha = 0.05
zero_method = 'pratt'
alternative = 'two-sided'
matplotlib.rcParams.update({'font.size': 18})

#%% Detect visual channels

subject = cf.Subject(name=sub_id)
hfb_db = subject.load_data(proc=proc, stage=stage, epo=epo)
visual_channels, effect_size = hf.detect_visual_chan(
    hfb_db,
    tmin_prestim=tmin_prestim,
    tmax_prestim=-tmax_prestim,
    tmin_postim=tmin_postim,
    tmax_postim=tmax_postim,
    alpha=alpha,
    zero_method=zero_method,
    alternative=alternative)
hfb_visual = hfb_db.copy().pick_channels(visual_channels).crop()
hfb = hfb_visual.copy().pick_channels(['LTo1-LTo2'])
event_id = hfb.event_id
face_id = hf.extract_stim_id(event_id, cat='Face')
place_id = hf.extract_stim_id(event_id, cat='Place')
image_id = face_id + place_id
times = hfb_visual.times

#%%

hfb_postim = hfb_visual.copy().crop(tmin=0, tmax=1.5)
コード例 #6
0
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')
# visual_chan = hf.pick_visual_chan(picks, visual_chan)
HFB = hf.visually_responsive_HFB(sub_id = sub_id)

# %%

HFB_cat_po = hf.category_specific_HFB(HFB, cat=cat, tmin_crop = 0.1, tmax_crop=0.5)
HFB_cat_pr = hf.category_specific_HFB(HFB, cat=cat, tmin_crop =-0.4, tmax_crop=-0.1)

X_po = HFB_cat_po.copy().get_data()
X_pr = HFB_cat_pr.copy().get_data()

X_po = X_po.flatten()
X_pr = X_pr.flatten()

times_po = HFB_cat_po.times
times_pr = HFB_cat_pr.times
subjects = [
    'AnRa', 'AnRi', 'ArLa', 'BeFe', 'DiAs', 'FaWa', 'JuRo', 'NeLa', 'SoGi'
]
postim_amplitude_list = [0] * len(subjects)
prestim_amplitude_list = [0] * len(subjects)
all_visual_chans = []
all_effect_sizes = []
for i, sub_id in enumerate(subjects):
    subject = cf.Subject(name=sub_id)
    hfb_db = subject.load_data(proc=proc, stage=stage, epo=epo)
    visual_channels, effect_size = hf.detect_visual_chan(
        hfb_db,
        tmin_prestim=tmin_prestim,
        tmax_prestim=-tmax_prestim,
        tmin_postim=tmin_postim,
        tmax_postim=tmax_postim,
        alpha=alpha,
        zero_method=zero_method,
        alternative=alternative)
    hfb_visual = hfb_db.copy().pick_channels(visual_channels).crop()
    all_visual_chans.extend(visual_channels)
    all_effect_sizes.extend(effect_size)
    A_prestim = hfb_visual.copy().crop(tmin=tmin_prestim,
                                       tmax=tmax_prestim).get_data()
    A_prestim = np.ndarray.flatten(A_prestim)
    A_postim = hfb_visual.copy().crop(tmin=tmin_postim,
                                      tmax=tmax_postim).get_data()
    A_postim = np.ndarray.flatten(A_postim)
    skewness_prestim = stats.skew(A_prestim)
    skewness_postim = stats.skew(A_postim)
コード例 #8
0
import numpy as np
import matplotlib.pyplot as plt
import argparse

from pathlib import Path, PurePath
from config import args
from scipy.io import savemat

#%% Read baseline time series

tmin_crop = -0.5
tmax_crop = 0

ecog = hf.Ecog(args.cohort_path,
               subject=args.subject,
               proc=args.proc,
               stage=args.stage,
               epoch=args.epoch)
hfb = ecog.read_dataset()

# Read ROI info for mvgc
df_visual = ecog.read_channels_info(fname=args.channels)
df_electrodes = ecog.read_channels_info(fname='electrodes_info.csv')
functional_indices = hf.parcellation_to_indices(df_visual,
                                                'group',
                                                matlab=True)
visual_chan = df_visual['chan_name'].to_list()

#%% Read condition specific time serieschannels pre peak

# Read visual hfb
コード例 #9
0
# -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')
コード例 #10
0
phase = 'minimum'
ichan = 6
figname = 'hfb_normalisation.jpg'
figpath = Path.home().joinpath('projects', 'CIFAR', 'figures', figname)
matplotlib.rcParams.update({'font.size': 20})

#%% Load data

subject = cf.Subject(name=sub_id)
hfb = subject.load_data(proc=proc, stage=stage, epo=False)
hfb = hfb.pick_channels(['LTo1-LTo2'])
#%% Test epoching

epochs = hf.epoch_hfb(hfb,
                      t_prestim=-0.5,
                      t_postim=1.75,
                      baseline=None,
                      preload=True)

epochs.plot_image()
A = epochs.copy().get_data()

#%% Test baseline extraction

baseline = hf.extract_baseline(epochs, tmin=-0.400, tmax=-0.100)

#%% Test db transformwith MNE
units = dict(eeg='dB')
hfb_db = hf.db_transform(epochs, tmin=-0.4, tmax=-0.1, t_prestim=-0.5)
hfb_db.plot_image(units=units, scalings=1, combine='median')
コード例 #11
0
#%% Import libraries

import mne
import pandas as pd
import HFB_process as hf
import numpy as np
import matplotlib.pyplot as plt
import argparse

from pathlib import Path, PurePath
from config import args
from scipy.io import savemat

#%% Import dataset:

ecog = hf.Ecog(args.cohort_path, subject=args.subject, proc=args.proc, 
                       stage = args.stage, epoch=args.epoch)
lfp = ecog.read_dataset(task = 'rest_baseline', run=1)

# Pick visual channels

df_visual = ecog.read_channels_info(fname=args.channels)
visual_chan = df_visual['chan_name'].to_list()
lfp = lfp.pick_channels(visual_chan)
#%% Plot spectral lfp 

%matplotlib qt

lfp.plot_psd(xscale='log')

#%% Plot time series
コード例 #12
0
picks = ['LTo1-LTo2', 'LTo5-LTo6']
sfreq = 100
tmin = 0
tmax = 1.75
win_size = 0.100
step = 0.050
detrend = True
norder = 3
#%%
subject = cf.Subject(sub_id)
datadir = subject.processing_stage_path(proc=proc)
visual_populations = subject.pick_visual_chan()
ts, time = hf.chan_specific_category_ts(picks,
                                        proc='preproc',
                                        stage='_BP_montage_HFB_raw.fif',
                                        sub_id='DiAs',
                                        sfreq=sfreq,
                                        tmin_crop=0,
                                        tmax_crop=1.75)
(n, m, N, c) = ts.shape
#%%


def detrend_ts(ts, norder=3, axis=0):
    """
    Detrend time series with statsmodel detrend function 
    """
    (n, m, N, c) = ts.shape

    for ichan in range(n):
        for icat in range(c):
コード例 #13
0
sub_id = 'DiAs'
proc = 'preproc'
stage = '_BP_montage_HFB_raw.fif'
picks = ['LGRD58-LGRD59', 'LTo1-LTo2', 'LTo5-LTo6']
sfreq = 250
tmin_crop = 0
tmax_crop = 1

#%%
subject = cf.Subject(sub_id)
datadir = subject.processing_stage_path(proc=proc)
visual_populations = subject.pick_visual_chan()
ts, time = hf.chan_specific_category_ts(picks,
                                        sub_id=sub_id,
                                        proc=proc,
                                        stage=stage,
                                        tmin_crop=tmin_crop,
                                        tmax_crop=tmax_crop)
trend = np.average(ts, axis=2)
trend = trend[:, :, 1]

trend_dict = {'data': trend, 'sfreq': sfreq, 'time': time, 'sub_id': sub_id}
fname = sub_id + '_trend.mat'
fpath = datadir.joinpath(fname)

savemat(fpath, trend_dict)

#%%

plt.plot(time, trend[2, :])
コード例 #14
0
    fname = 'visual_channels_BP_montage.csv'
    fpath = brain_path.joinpath(fname)
    visual_chan = pd.read_csv(fpath)

    # Drop unwanted channels

    visual_chan = visual_chan[visual_chan.group != 'other']
    visual_chan = visual_chan.reset_index(drop=True)
    visual_chan_name = visual_chan['chan_name'].values.tolist()
    group = visual_chan['group'].unique().tolist()

    # Extract visual HFB
    HFB_visual = raw.copy().pick_channels(visual_chan_name)

    # Extract category specific time series

    visual_data = hf.HFB_to_visual(HFB_visual,
                                   group,
                                   visual_chan,
                                   cat=cat,
                                   tmin_crop=tmin_crop,
                                   tmax_crop=tmax_crop)

    # Save data

    fname = sub + '_' + cat + '_visual_HFB.mat'
    fpath = datadir.joinpath(fname)

    # Save data in Rest x Face x Place array of time series

    savemat(fpath, visual_data)
コード例 #15
0
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)
    df_visual = df_visual.sort_values(by='Y', ignore_index=True)
    # Uncomment if want to remove null latency
    # index_names = df_visual[df_visual['latency']==0].index
    #df_visual = df_visual.drop(index_names)

    brain_path = subject.brain_path()
    fname = 'visual_BP_channels.csv'
    fpath = brain_path.joinpath(fname)
コード例 #16
0
Created on Tue May 18 09:33:20 2021
This script remove bad channels for all subjects and concatenate ieeg dataset
@author: guime
"""

import mne
import pandas as pd
import HFB_process as hf
import numpy as np

from pathlib import Path, PurePath
from config import args
#%%

for subject in args.cohort:
    ecog = hf.Ecog(args.cohort_path, subject=subject, proc='bipolar_montage')
    raw_concat = ecog.concatenate_raw()
    raw_concat = hf.drop_bad_chans(raw_concat,
                                   q=99,
                                   voltage_threshold=500e-6,
                                   n_std=5)
    # Check if channels looks ok by plotting psd
    raw_concat.plot_psd(xscale='log')
    # Save file
    subject_path = args.cohort_path.joinpath(subject)
    proc_path = subject_path.joinpath('EEGLAB_datasets', args.proc)
    fname = subject + '_bad_chans_removed_raw.fif'
    fpath = proc_path.joinpath(fname)
    raw_concat.save(fpath, overwrite=True)

#%%
コード例 #17
0
import numpy as np
import matplotlib.pyplot as plt
import argparse

from pathlib import Path, PurePath
from config import args
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)
コード例 #18
0
import matplotlib.pyplot as plt
import pandas as pd

from pathlib import Path, PurePath
from mne.viz import plot_filter, plot_ideal_filter
from scipy import signal, fftpack
from scipy import stats
from statsmodels.stats.multitest import fdrcorrection, multipletests

from scipy.io import loadmat, savemat
# %%
pd.options.display.max_rows = 999

sub_id = 'DiAs'
visual_chan_table = 'visual_channels_BP_montage.csv'
proc = 'preproc'
sfreq = 100
picks = ['LGRD60-LGRD61', 'LTo1-LTo2']
tmin_crop = 0.5
tmax_crop = 1.5
suffix = 'preprocessed_raw'
ext = '.fif'

#%%

subject = cf.Subject(name=sub_id)
datadir = subject.processing_stage_path(proc=proc)
visual_chan = subject.low_high_chan()
# visual_chan = hf.pick_visual_chan(picks, visual_chan)
HFB = hf.low_high_HFB(visual_chan)
コード例 #19
0
"""
Created on Thu May 13 17:02:35 2021

@author: guime
"""

import mne
import os
import pandas as pd
import HFB_process as hf

from pathlib import Path, PurePath
from config import args

#%% Test read data
ecog = hf.Ecog(args.cohort_path, proc='bipolar_montage')
raw = ecog.read_dataset(run=2, task='rest_baseline')

#%% Test read channels info

ecog = hf.Ecog(args.cohort_path, proc='bipolar_montage')
channels_info = ecog.read_channels_info(fname='electrodes_info.csv')

#%% Test concatenation

raw_concat = ecog.concatenate_raw()

#%% Plot concatenated data

raw_concat.plot(duration=10, scalings=1e-4)
コード例 #20
0
sub_id = 'DiAs'
proc = 'preproc'
stage_hfb = '_BP_montage_HFB_raw.fif'
stage_lfp = '_BP_montage_preprocessed_raw.fif'
picks = ['LTo1-LTo2', 'LTo5-LTo6']
sfreq = 250
fmin = 0.1
fmax = 200

#%%

subject = cf.Subject(sub_id)
datadir = subject.processing_stage_path(proc=proc)
visual_populations = subject.pick_visual_chan()
hfb, visual_chan = hf.load_visual_hfb(sub_id=sub_id,
                                      proc=proc,
                                      stage=stage_hfb)
hfb = hfb.pick_channels(picks)

lfp = subject.load_data(proc=proc, stage=stage_lfp)
lfp = lfp.pick_channels(picks)

#%%

start = 60
stop = 325
psd_rest_hfb, freqs = fun.hfb_to_psd(hfb,
                                     start=start,
                                     stop=stop,
                                     duration=20,
                                     tmin=-0.1,
コード例 #21
0

sub_id = ['AnRa',  'AnRi',  'ArLa',  'BeFe',  'DiAs',  'FaWa',  'JuRo', 'NeLa', 'SoGi']
functional_group = {'subject_id': [], 'chan_name':[], 'category': [], 
                    'brodman': [], 'DK': []}

for sub in sub_id: 
    #%% Import data
    subject = cf_load.Subject(sub)
    fpath = subject.fpath(suffix='lnrmv', proc = preproc)
    raw = subject.import_data(fpath)
    dfelec = subject.dfelec()
    
    # %% Extract HFB
    
    bands = HFB_process.freq_bands() # Select Bands of interests 
    HFB_db = HFB_process.extract_HFB_db(raw, bands)
    
    # place and face id
    events, event_id = mne.events_from_annotations(raw)
    face_id = HFB_process.extract_stim_id(event_id)
    place_id = HFB_process.extract_stim_id(event_id, cat='Place')
    
    # Check test looks ok
   # HFB_process.plot_stim_response(HFB_db, picks='LTo6', stim_id=face_id)
    
    
    # %% Detect face, place and bicat channels
    
    visual = HFB_process.make_visual_cat(HFB_db, face_id, place_id)
    
コード例 #22
0
@author: guime
"""
import mne
import pandas as pd
import HFB_process as hf
import numpy as np
import matplotlib.pyplot as plt

from pathlib import Path, PurePath
from config import args

#%% load data and visual chans info

subject = 'DiAs'
ecog = hf.Ecog(args.cohort_path,
               subject=subject,
               proc='preproc',
               stage='_hfb_db_epo.fif',
               epoch=True)
hfb = ecog.read_dataset()
fname = 'visual_channels.csv'
subject_path = args.cohort_path.joinpath(subject)
brain_path = subject_path.joinpath('brain')
fpath = brain_path.joinpath(fname)
df_visual = pd.read_csv(fpath)

chans = ['LTo1-LTo2', 'LTo5-LTo6']

#%%
コード例 #23
0
visual_chan_table = 'visual_channels_BP_montage.csv'
proc = 'preproc'
sfreq = 250
# picks = ['LGRD58-LGRD59', 'LGRD60-LGRD61', 'LTo1-LTo2', 'LTo3-LTo4']
tmin_crop = -0.5
tmax_crop = 1.75
suffix = 'preprocessed_raw'
ext = '.fif'

#%%

subject = cf.Subject(name=sub_id)
datadir = subject.processing_stage_path(proc=proc)
visual_chan = subject.pick_visual_chan()
# visual_chan = hf.pick_visual_chan(picks, visual_chan)
HFB = hf.visually_responsive_HFB(sub_id=sub_id)

categories = ['Rest', 'Face', 'Place']

_, visual_data = hf.HFB_to_visual_data(HFB,
                                       visual_chan,
                                       sfreq=sfreq,
                                       cat='Face',
                                       tmin_crop=tmin_crop,
                                       tmax_crop=tmax_crop)
visual_time_series = visual_data

for cat in categories:
    X, visual_data = hf.HFB_to_visual_data(HFB,
                                           visual_chan,
                                           sfreq=sfreq,
コード例 #24
0
import pandas as pd
import HFB_process as hf
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import helper_functions as fun

from pathlib import Path, PurePath
from config import args
from scipy.io import savemat

#%%

ecog = hf.Ecog(args.cohort_path,
               subject=args.subject,
               proc=args.proc,
               stage=args.stage,
               epoch=args.epoch)
hfb = ecog.read_dataset()
df_visual = ecog.read_channels_info(fname=args.channels)
visual_chan = df_visual['chan_name'].to_list()
ts, time = hf.category_ts(hfb,
                          visual_chan,
                          sfreq=args.sfreq,
                          tmin_crop=args.tmin_crop,
                          tmax_crop=args.tmax_crop)
#%%

population_hfb, populations = hf.ts_to_population_hfb(ts,
                                                      df_visual,
                                                      parcellation='group')
コード例 #25
0
tmax_postim = 0.5
alpha = 0.05
zero_method = 'pratt'
alternative = 'two-sided'
matplotlib.rcParams.update({'font.size': 18})

#%% Detect visual channels

subject = cf.Subject(name=sub_id)
dfelec = subject.df_electrodes_info()
hfb_db = subject.load_data(proc=proc, stage=stage, epo=epo)
visual_channels, effect_size = hf.detect_visual_chan(
    hfb_db,
    tmin_prestim=tmin_prestim,
    tmax_prestim=-tmax_prestim,
    tmin_postim=tmin_postim,
    tmax_postim=tmax_postim,
    alpha=alpha,
    zero_method=zero_method,
    alternative=alternative)
hfb_visual = hfb_db.copy().pick_channels(visual_channels).crop()
event_id = hfb_visual.event_id
face_id = hf.extract_stim_id(event_id, cat='Face')
place_id = hf.extract_stim_id(event_id, cat='Place')
image_id = face_id + place_id
times = hfb_visual.times

#%% Test face and place classification

group, category_selectivity = hf.classify_Face_Place(hfb_visual,
                                                     face_id,
コード例 #26
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)

#%%

ts_dict = {'data': ts, 'sfreq': sfreq, 'time': time, 'sub_id': sub_id}
fname = sub_id + '_ts_sliding.mat'
fpath = datadir.joinpath(fname)

savemat(fpath, ts_dict)
コード例 #27
0
categories = ['Rest', 'Face', 'Place']
tmin_crop = -0.5
tmax_crop = 1.75
suffix = 'preprocessed_raw'
ext = '.fif'
sample_start = 125
sample_stop = 375
step = 10
window_size = 40

#%% Load data

subject = cf.Subject(name=sub_id)
datadir = subject.processing_stage_path(proc=proc)
visual_chan = subject.pick_visual_chan()
HFB_visual = hf.visually_responsive_HFB(sub_id=sub_id)

#%% Sliding window time series per category

ts, ts_time = fun.ts_win_cat(HFB_visual, visual_chan, categories, tmin_crop,
                             tmax_crop, sfreq, sample_start, sample_stop, step,
                             window_size)

# %% Detrend ts

# (nchan, nobs, ntrial, nseg, ncat) = ts.shape
# for w in range(nseg):
#     for c in range(ncat):
#         for itrial in range(ntrial):
#             ts[:, :, itrial, w, c] = detrend(ts[:, :, itrial, w, c], order=2, axis=1)
コード例 #28
0
    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


# %%

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'
コード例 #29
0
import mne
import pandas as pd
import HFB_process as hf
import numpy as np
import matplotlib.pyplot as plt

from pathlib import Path, PurePath
from config import args

#%% Detect visual channels

subject = 'AnRa'
ecog = hf.Ecog(args.cohort_path,
               subject=subject,
               proc='preproc',
               stage='_hfb_db_epo.fif',
               epoch=True)
hfb = ecog.read_dataset()
visual_detection = hf.VisualDetector(tmin_prestim=args.tmin_prestim,
                                     tmax_prestim=args.tmax_prestim,
                                     tmin_postim=args.tmin_postim,
                                     tmax_postim=args.tmax_postim,
                                     alpha=args.alpha,
                                     zero_method=args.zero_method,
                                     alternative=args.alternative)

#%%

visual_chan, effect_size = visual_detection.detect(hfb)
#%% Classify visual channels
コード例 #30
0
subject = cf.Subject(name=sub_id)
datadir = subject.processing_stage_path(proc=proc)
visual_chan = subject.low_high_chan()
visual_chan_name = visual_chan['chan_name'].tolist()

raw = subject.read_eeglab(proc=proc, suffix=suffix)

raw_visual = raw.copy().pick(visual_chan_name)

#%% Plot

raw_visual.plot(duration=0.1, scalings=1e-4)

#%%

epochs = hf.epoch_category(raw_visual, cat='Face', tmin=-0.5, tmax=1.75)

#%% Make dictionary with all state

categories = ['Rest', 'Face', 'Place']
columns = ['Rest', 'Face', 'Place', 'populations']
visual_time_series = {'Rest': [], 'Face': [], 'Place': [], 'populations': []}

for cat in categories:
    visual_data = hf.HFB_to_visual_data(HFB,
                                        visual_chan,
                                        cat=cat,
                                        tmin_crop=tmin_crop,
                                        tmax_crop=tmax_crop)
    X = visual_data['data']
    visual_time_series[cat] = X