Cannot subselect epochs by certain part of the event name

  • MNE-Python version: 0.22.0
  • operating system: Windows 10, build 19041.928

I have a large epoch object consisting of concatenated epoch objects from several files. Because each file was obtained from a different subject, I have included the subject’s code (first five characters from the filename) into the epochs’ event_dict. I did this for every subjects’ file and then concatenated the epoch objects using mne.concatenate_epochs(). This is the event_dict I used to create each individual epoch object:

event_dict = {"stim/" + str(file[0:5]) + "/delib/W": 110,
                    "resp/" + str(file[0:5]) + "/delib/W/left": 111,
                    "resp/" + str(file[0:5]) + "/delib/W/right": 112,
                    "stim/" + str(file[0:5]) + "/delib/M": 120,
                    "resp/" + str(file[0:5]) + "/delib/M/left": 121,
                    "resp/" + str(file[0:5]) + "/delib/M/right": 122,
                    "stim/" + str(file[0:5]) + "/arbitDiff/W": 210,
                    "resp/" + str(file[0:5]) + "/arbitDiff/W/left": 211,
                    "resp/" + str(file[0:5]) + "/arbitDiff/W/right": 212,
                    "stim/" + str(file[0:5]) + "/arbitDiff/M": 220,
                    "resp/" + str(file[0:5]) + "/arbitDiff/M/left": 221,
                    "resp/" + str(file[0:5]) + "/arbitDiff/M/right": 222,
                    "stim/" + str(file[0:5]) + "/arbitSame/W": 310,
                    "resp/" + str(file[0:5]) + "/arbitSame/W/left": 311,
                    "resp/" + str(file[0:5]) + "/arbitSame/W/right": 312,
                    "stim/" + str(file[0:5]) + "/arbitSame/M": 320,
                    "resp/" + str(file[0:5]) + "/arbitSame/M/left": 321,
                    "resp/" + str(file[0:5]) + "/arbitSame/M/right": 322}

This is a part of the epoch object printout after concatenation:

<EpochsFIF |  7558 events (all good), -2 -1 sec, baseline [-1.5, -1.2] sec, ~767.7 MB, data loaded,
 'resp/ss023/arbitDiff/M/left': 304
 'resp/ss023/arbitDiff/M/right': 326
 'resp/ss023/arbitDiff/W/left': 300
 'resp/ss023/arbitDiff/W/right': 330
 'resp/ss023/arbitSame/M/left': 274
 'resp/ss023/arbitSame/M/right': 356
 'resp/ss023/arbitSame/W/left': 256
 'resp/ss023/arbitSame/W/right': 373
 'resp/ss023/delib/M/left': 267
 'resp/ss023/delib/M/right': 363
 'resp/ss023/delib/W/left': 294
 'resp/ss023/delib/W/right': 336
 'resp/ss024/arbitDiff/M/left': 304
 'resp/ss024/arbitDiff/M/right': 326
 'resp/ss024/arbitDiff/W/left': 300
 'resp/ss024/arbitDiff/W/right': 330
 'resp/ss024/arbitSame/M/left': 274
 'resp/ss024/arbitSame/M/right': 356
 'resp/ss024/arbitSame/W/left': 256
 'resp/ss024/arbitSame/W/right': 373
 'resp/ss024/delib/M/left': 267
 'resp/ss024/delib/M/right': 363
 'resp/ss024/delib/W/left': 294
 'resp/ss024/delib/W/right': 336
 'resp/ss025/arbitDiff/M/left': 304
 'resp/ss025/arbitDiff/M/right': 326
 'resp/ss025/arbitDiff/W/left': 300
 'resp/ss025/arbitDiff/W/right': 330
 'resp/ss025/arbitSame/M/left': 274
 'resp/ss025/arbitSame/M/right': 356
 'resp/ss025/arbitSame/W/left': 256
 'resp/ss025/arbitSame/W/right': 373
 'resp/ss025/delib/M/left': 267
 'resp/ss025/delib/M/right': 363
 'resp/ss025/delib/W/left': 294
 'resp/ss025/delib/W/right': 336
  ...
 'stim/ss043/arbitDiff/M': 630
 'stim/ss043/arbitDiff/W': 630
 'stim/ss043/arbitSame/M': 630
 'stim/ss043/arbitSame/W': 629
 'stim/ss043/delib/M': 630
 'stim/ss043/delib/W': 630>

Now the problem is that I need to subselect epochs based on the subject. I can subselect epochs using any part of the event string, such as ‘stim’, ‘resp’, ‘delib’, ‘M’ etc., without any problems. But I cannot subselect by ‘ss023’, ‘ss024’ etc.

Why? Is it because the string contains numbers? Or because the string originated in a file name and MNE somehow ‘remembers’ it? Or am I missing something completely different?

Thanks to anyone able to help!

what did you try?

did you type:

epochs[‘ss023’]

?

I think just work. If it doesn’t work can you replicate with public data
or share your code and file so we can investigate?

Alex

Dear Alexandre,

While I was writing my reply, I accidentally solved the problem. :slight_smile:

My mistake was in using the str(file[0:5]) in the event_dict. Because I was using this in a loop where file[0:5] was changing in each step, I ended up with several different keys being assigned the same value (for example, the epochs stim/ss023/delib/W, stim/ss024/delib/W, stim/ss025/delib/W etc., were all assigned number 110; therefore, it is clear why I couldn’t subselect using the subject’s identifier).

Thank you nonetheless!