New event IDs by concatenating previous event ID information

MNE version: 1.1.1
Operating system: macOS 11.2.3

Hi there!

I am trying to create an event dictionary, however, I am running into some problems. For each event of interest (i.e.: 222) I have three preceedings event IDs which encode item number, sentence version, and condition information respectively. I am interested in the condition information only. More precisely, for each event 222, I want to concatenate the previous value, thus creating my conditions, namely 222 - 101; 222 - 109; 222 - 201; 222 - 209. I cannot seem to find any information about working with these types of event IDs as I have noticed that event IDs are usually not repeated. I have concatenated all 222 with their previous value, so for each 222, I get the condition value attached. However, I am not sure if this would allow me to create an event dictionary. I am including my code below. I would highly appreciate any help you might want to share!

##load data and find events

data_path = ('/xx/xx/xx/xx.vhdr')
raw =''/xx/xx/xx/xx.vhdr'', preload=True)
events = mne.events_from_annotations(raw)
raw.pick_types(meg=False, stim=False, eog=False, eeg=True)

##list of line index where the third column == 222

index = [i for i, x in enumerate(events[0]) if x[2] == 222]

##build item concatenating 222 and condition

item_by_condition = []
for i in index:
    item = ['{} - {}'.format('222', events[0][i - 1][2]), events[0][i][0]],



[(['222 - 201', 4739],), (['222 - 101', 9067],), (['222 - 109', 13712],), (['222 - 209', 18040],), (['222 - 109', 22685],), ....

##create event dictionary

event_dict = {'reg_correct': 222-201, 'reg_incor': 222-109, 'irreg_correct': 222-201,
              'irreg_incorrect': 222-209}

Hello @Scosta and welcome to the forum!

I would suggest that instead of manipulating events, you could make use of our powerful machinery for creating and handling epochs metadata.

There is a function to create metadata automatically based on events, see this tutorial:

I know it’s rather long and quite complex, but I believe it’s worth your time working through this, as I think your use case here is where metadata really comes in very handy,

Best wishes,

1 Like

Hi @richard,

Thank you so much for your reply and for signposting me to this tutorial! It looks very detailed - this is great :slight_smile:

Thank you once again and I wish you a lovely day,

1 Like