I'm analysing an EEG dataset which contains event markers for four separate conditions. The data has been segmented into epochs defined by these event markers. Stimuli from each condition appeared ten times during the experiment - therefore my dataset contains 40 epochs, ten per condition.
I'm generating evokeds for each condition with the following code:
for subject in subjects:
epochs_fname[subject] = data_path + subject + '-epo.fif'
epochs[subject] = mne.read_epochs(epochs_fname[subject])
evoked[subject] = {cond:(epochs[subject][cond]).average() for cond in (conditions)}
However I would like to base my evokeds on only the first instance of each condition (i.e. the first time participants saw a stimulus from cond_1, the first time they saw a stimulus from cond_2, and so on). To this end, is there a way to index the nth epoch from each condition that would fit in the above code?
epochs[subject][cond][0] (or maybe epochs[subject][cond][:1]) should work.
But be careful about dropped epochs by looking at `epochs.selection` to
make sure the first instance didn't get dropped e.g. due to reject/flat
params.
Thanks for your email. Unfortunately this didn't work - it simply returned a single epoch per subject (the first epoch in the dataset, I suspect). I also tried epochs[subject][cond[0]] which returned the following error: 'Event "n" is not in epochs', which suggests to me that it may not actually be possible to index in this way..?
Thanks for your email. Unfortunately this didn't work - it simply returned
a single epoch per subject (the first epoch in the dataset, I suspect).
This sounds very close to what you want. I probably should have been more
explicit and noted that the code I suggested would need to be looped over
conditions (cond), like:
evokeds[subject] = {cond: epochs[subject][cond][0].average() for cond
in conditions}
evokeds[subject] = {cond: epochs[subject][cond][0].average() for cond in
conditions}
...only returns a single epoch. Sorry for the miscommunication.
Can you be a bit clearer about what you mean by "returns"? Which variables
are what length? For example, if evokeds[subject] is a length-1 dictionary
(what I think you're saying), this is only possible if `conditions` is
itself also length 1. But every entry in the `evokeds[subject]` dict should
be an Evoked instance with `nave==1`, namely the first (valid) epoch from
that condition, which is what I think you're trying to get.
Many apologies...please disregard my last email. It seems that I was misreading my output - your suggestion DID indeed work. In answer to your question, by 'returns' I was referring to which epochs were being selected for averaging. So epochs[subject][cond][0] selected/returned the first instance of each condition, as intended.
Thanks very much for the help, and again, sorry for the miscommunication.