forked from MadsJensen/CAA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhilbert_epoching.py
100 lines (80 loc) · 2.97 KB
/
hilbert_epoching.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import mne
from my_settings import *
import pandas as pd
import numpy as np
import sys
import matplotlib
matplotlib.use('Agg')
n_jobs = 1
subject = sys.argv[1]
raw = mne.io.Raw(save_folder + "%s_hilbert_ica_mc_raw_tsss.fif" % subject,
preload=True)
include = []
picks = mne.pick_types(raw.info, meg=True, eeg=True, stim=False, eog=False,
include=include, exclude='bads')
tmin, tmax = -0.5, 1.5 # Epoch time
# All the behavioral results
results = pd.read_csv(log_folder + "results_all.csv")
# select only the relevant subject
log_tmp = results[results.subject == int(subject)].reset_index()
raw.del_proj(0)
# Select events to extract epochs from.
event_id = {"all_trials": 99}
# Setup for reading the raw data
events = mne.find_events(raw, min_duration=0.015)
events = mne.event.merge_events(events, [1, 2, 4, 8], 99,
replace_events=True)
event_id = {}
epoch_ids = []
for i, row in log_tmp.iterrows():
if row.condition_type == "ctl":
epoch_name = "ctl"
epoch_id = "1"
elif row.condition_type == "ent":
epoch_name = "ent"
epoch_id = "2"
if row.condition_side == "left":
epoch_name = epoch_name + "/" + "left"
epoch_id = epoch_id + "1"
elif row.condition_side == "right":
epoch_name = epoch_name + "/" + "right"
epoch_id = epoch_id + "0"
if row.congruent is True:
epoch_name = epoch_name + "/" + "cong"
epoch_id = epoch_id + "1"
elif row.congruent is False:
epoch_name = epoch_name + "/" + "incong"
epoch_id = epoch_id + "0"
if row.correct is True:
epoch_name = epoch_name + "/" + "correct"
epoch_id = epoch_id + "1"
elif row.correct is False:
epoch_name = epoch_name + "/" + "incorrect"
epoch_id = epoch_id + "0"
if row.in_phase is True:
epoch_name = epoch_name + "/" + "in_phase"
epoch_id = epoch_id + "1"
elif row.in_phase is False:
epoch_name = epoch_name + "/" + "out_phase"
epoch_id = epoch_id + "0"
epoch_name = epoch_name + "/" + str(row.PAS)
epoch_id = epoch_id + str(row.PAS)
epoch_ids.append(int(epoch_id))
if epoch_name is not event_id:
event_id[str(epoch_name)] = int(epoch_id)
idx = np.arange(0, len(events), 4)
for i in range(len(events[idx])):
events[idx[i]][2] = epoch_ids[i]
# picks = mne.pick_types(raw.info, meg=True, eeg=True, stim=False,
# eog=False,
# include=include, exclude='bads')
# Read epochs
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, -0.2), reject=reject_params,
add_eeg_ref=True,
preload=True)
epochs.drop_bad(reject_params)
epochs._data = np.abs(epochs._data)**2
fig = epochs.plot_drop_log(subject=subject, show=False)
fig.savefig(epochs_folder + "pics/hilbert_pow_%s_drop_log.png" % subject)
epochs.save(epochs_folder + "%s_hilbert_pow_trial_start-epo.fif" % subject)