Averaging data in MNE
The following script is an example for a standard averaging procedure. Obviously, you may want to use different parameters - have a look at the manual for details and more options.
You should have processed your raw data using [http://imaging.mrc-cbu.cam.ac.uk/meg/Maxfilter Maxfilter].
Note that MNE will not process EEG data from the CBU correctly unless you apply "mne_check_eeg_locations" to your files (see below).
You can mark bad channels in your fif-files using mne_mark_bad_channels. These bad channels will be excluded from further MNE operations (forward solution, inverse operator etc.).
The end result will be fiff-files with averages for each condition defined in the specification file (see below). They can be read into Matlab using fiff_read_evoked.
## Your variables
datapath='<myMEGdatapath>' # root directory for your MEG data
# MEG IDs (your directory structure may differ)
subj_pre=(\
'meg10_0001' \
'meg10_0002' \
'meg10_0003' \
)
# MEG subdirectories (your directory structure may differ)
subj_dir=(\
'100001' \
'100002' \
'100003' \
)
## Processing:
nsubjects=${#subjects[*]}
lastsubj=`expr $nsubjects - 1`
# REPORT number of files to be processed:
for m in `seq 0 ${lastsubj}`
do
echo " "
echo " Averaging SUBJECT ${subjects[m]}"
echo " "
inpath=${path}'/'${subj_dir[m]}'/'${subjects[m]}
echo ${inpath}
mne_process_raw \
--raw ${datapath}/${subj_dir[m]}/${subjects[m]}/yourrawMEGfile1.fif \
--raw ${datapath}/${subj_dir[m]}/${subjects[m]}/yourrawMEGfile2.fif \
--raw ${datapath}/${subj_dir[m]}/${subjects[m]}/yourrawMEGfile3.fif \
--eventsout ${datapath}/${subj_dir[m]}/${subjects[m]}/yourrawMEGfile1-eve.txt \
--eventsout ${datapath}/${subj_dir[m]}/${subjects[m]}/yourrawMEGfile2-eve.txt \
--eventsout ${datapath}/${subj_dir[m]}/${subjects[m]}/yourrawMEGfile3-eve.txt \
--ave YourSpecificationFile.ave \
--gave ${datapath}/${subj_dir[m]}/${subjects[m]}/gave.fif \
--saveavetag _avg \
--highpass 0.1 \
--projoff
done # subjectsNote: You can modify the event information in the eve.txt-files, and read the modified information later using the --events option. This is useful when you want to average with respect to trigger combinations (e.g. correct responses only) etc.
The specification file YourSpecificationFile.ave should be of the form:
average {
# Rejection values
#
gradReject 2000e-13
magReject 3e-12
eegReject 120e-6
eogReject 150e-6
logfile ave_logfile.txt
# Category specifications
#
category {
name "Cond1"
event 1
tmin -0.1
tmax 1.0
bmin -0.1
bmax 0.0
}
category {
name "Cond2"
event 2
tmin -0.1
tmax 1.0
bmin -0.1
bmax 0.0
}
}
Fixing EEG electrode positions
Unless you apply mne_check_eeg_locations to your data, MNE will get confused with the EEG electrode digitisation used at the CBU, and e.g. the creation of the forward solution for EEG will fail.
# Your variables
datapath='<myMEGdatapath>' # root directory for your MEG data
# MEG IDs (your directory structure may differ)
subj_pre=(\
'meg10_0001' \
'meg10_0002' \
'meg10_0003' \
)
# MEG subdirectories (your directory structure may differ)
subj_dir=(\
'100001' \
'100002' \
'100003' \
)
#condition names as used in file names
conds=('cond1' 'cond2' 'cond3')
# Processing:
nsubjects=${#subj_pre[*]}
lastsubj=`expr $nsubjects - 1`
nconds=${#conds[*]}
lastcond=`expr $nconds - 1`
for m in `seq 0 ${lastsubj}`
do
echo " "
echo " Fixing electrodes for SUBJECT ${subjects[m]}"
echo " "
for c in `seq 0 ${lastcond}`
do
mne_check_eeg_locations \
--file ${datapath}/${subj_pre[m]}/${subj_dir[m]}/${conds[c]}.fif \
--fix
done # conditions
done # subjects
Marking Bad Channels
datapath='<myMEGdatapath>' # root directory for your MEG data
mne_mark_bad_channels \
--bad YourSubjectBads.txt \ # File with bad channel information
${datapath}/YourSubjectDir/YourSubjectFile1.fif \
${datapath}/YourSubjectDir/YourSubjectFile2.fif \
${datapath}/YourSubjectDir/YourSubjectFile3.fif \where YourSubjectBads.txt could look like this
EEG001 EEG044
if EEG channels 1 and 44 are bad. I had problems when I created these text files in Windows - if in doubt, open the file under Linux (e.g. using nedit), use "save as" and make sure it's in Linux (not Dos) format.
