@@ -308,18 +308,31 @@ def GrattonEmcpEpochs(epochs):
308
308
# -use coefficients to subtract eog from eeg
309
309
'''
310
310
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
+
311
317
#select the correct channels and data
312
318
eeg_chans = pick_types (epochs .info , eeg = True , eog = False )
313
319
eog_chans = pick_types (epochs .info , eeg = False , eog = True )
314
- data = epochs ._data
320
+ original_data = epochs ._data
315
321
316
322
#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 ])
319
332
320
333
#separate eog and eeg
321
- X = rem [:,eeg_chans ,:]
322
- Y = rem [:,eog_chans ,:]
334
+ X = allrem [:,eeg_chans ,:]
335
+ Y = allrem [:,eog_chans ,:]
323
336
324
337
#subtract mean over time from every trial/channel
325
338
X = (X .T - np .mean (X ,2 ).T ).T
@@ -335,8 +348,8 @@ def GrattonEmcpEpochs(epochs):
335
348
b = np .linalg .solve (np .dot (Y ,Y .T ), np .dot (Y ,X .T ))
336
349
337
350
#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 )
340
353
341
354
#subtract weighted eye channels from eeg channels
342
355
eeg_corrected = (raw_eeg .T - np .dot (raw_eog .T ,b )).T
0 commit comments