Skip to content

Commit 74acf60

Browse files
committed
updated emcp to subtract average from each conditoin instead of overall
1 parent 19de4a0 commit 74acf60

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

P3_exampleBV.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
raw = LoadBVData(sub,session,data_dir,exp)
2424
#Pre-Process EEG Data
2525
temp_epochs = PreProcess(raw,event_id,
26-
emcp_epochs=True, rereference=True,
26+
emcp_epochs=False, rereference=True,
2727
plot_erp=False, rej_thresh_uV=1000,
2828
epoch_time=(-.2,1), baseline=(-.2,0) )
2929
if len(temp_epochs) > 0:
@@ -32,13 +32,11 @@
3232
print('Sub ' + sub + ', Cond '
3333
+ session + 'all trials rejected')
3434

35-
print(epochs)
3635
epochs = concatenate_epochs(epochs)
37-
print(epochs)
3836

3937
#Engineer Features for Model
4038
feats = FeatureEngineer(epochs,model_type='NN',electrode_median=False,
41-
frequency_domain=False)
39+
frequency_domain=False)
4240
#Create Model
4341
model,_ = CreateModel(feats, units=[16,16])
4442
#Train with validation, then Test

emcp_test.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
from utils import *
2+
3+
4+
5+
6+
7+
28
data_dir = '/Users/kylemathewson/Desktop/data/'
39
exp = 'P3'
410
subs = [ '001']
@@ -9,23 +15,21 @@
915
sub = subs[0]
1016
session = sessions[0]
1117
raw = LoadBVData(sub,session,data_dir,exp)
18+
19+
1220
epochs = PreProcess(raw,event_id,
21+
emcp_epochs=False, rereference=True,
22+
plot_erp=True, rej_thresh_uV=250,
23+
epoch_time=(-.2,1), baseline=(-.2,0) )
24+
epochs_new = PreProcess(raw,event_id,
1325
emcp_epochs=True, rereference=True,
14-
plot_erp=False, rej_thresh_uV=250,
26+
plot_erp=True, rej_thresh_uV=250,
1527
epoch_time=(-.2,1), baseline=(-.2,0) )
1628

29+
1730
#plot results
1831
epochs['Target'].plot()
1932
epochs_new['Target'].plot()
2033

2134

2235

23-
24-
25-
26-
27-
28-
29-
30-
31-

utils.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,31 @@ def GrattonEmcpEpochs(epochs):
308308
# -use coefficients to subtract eog from eeg
309309
'''
310310

311+
event_names = ['A_error','B_error']
312+
i = 0
313+
for key, value in sorted(epochs.event_id.items(), key=lambda x: (x[1], x[0])):
314+
event_names[i] = key
315+
i += 1
316+
311317
#select the correct channels and data
312318
eeg_chans = pick_types(epochs.info, eeg=True, eog=False)
313319
eog_chans = pick_types(epochs.info, eeg=False, eog=True)
314-
data = epochs._data
320+
original_data = epochs._data
315321

316322
#subtract the average over trials from each trial
317-
avg = np.mean(epochs._data,axis=0)
318-
rem = data-avg
323+
rem = {}
324+
for event in event_names:
325+
data = epochs[event]._data
326+
avg = np.mean(epochs[event]._data,axis=0)
327+
rem[event] = data-avg
328+
329+
#concatenate trials together of different types
330+
## then put them all back together in X (regression on all at once)
331+
allrem = np.concatenate([rem[event] for event in event_names])
319332

320333
#separate eog and eeg
321-
X = rem[:,eeg_chans,:]
322-
Y = rem[:,eog_chans,:]
334+
X = allrem[:,eeg_chans,:]
335+
Y = allrem[:,eog_chans,:]
323336

324337
#subtract mean over time from every trial/channel
325338
X = (X.T - np.mean(X,2).T).T
@@ -335,8 +348,8 @@ def GrattonEmcpEpochs(epochs):
335348
b = np.linalg.solve(np.dot(Y,Y.T), np.dot(Y,X.T))
336349

337350
#get original data and electrodes first for matrix math
338-
raw_eeg = np.moveaxis(data[:,eeg_chans,:],0,1)
339-
raw_eog = np.moveaxis(data[:,eog_chans,:],0,1)
351+
raw_eeg = np.moveaxis(original_data[:,eeg_chans,:],0,1)
352+
raw_eog = np.moveaxis(original_data[:,eog_chans,:],0,1)
340353

341354
#subtract weighted eye channels from eeg channels
342355
eeg_corrected = (raw_eeg.T - np.dot(raw_eog.T,b)).T

0 commit comments

Comments
 (0)