0

i am processing a eeg signal acquired by showing 10 image of each of 40 classes. i want to label the signals converted to epochs to their corresponding class labels.

i extracted events data as:

raw = mne.io.read_raw_bdf(raw_file,  preload =True)
events=mne.find_events(raw, stim_channel = None, initial_event = True, consecutive='increasing',
                        output='step',uint_cast=True, verbose=None)

The events data is as

array([[      0,       0,   65280],
       [   3085,   65280,   65533],
       [  44751,   65280,   65281],
       ...,
       [4962462,   65280,   65281],
       [4974818,   65280,   65281],
       [5021696,   65280,       0]], dtype=int64)

The third col of event data is the event code, which is same 65281 for all 400 images, except the first 2 event code[65280, 65533] being the initial 10 second pause.

event_dict = []
for event, class_label in zip(events, class_labels):
  
    event_dict.append((class_label,event[2]))

print(event_dict)

The event_dict contains data

[('initial event', 65280),
 ('initial event', 65533),
 ('airliner', 65281),
 ('watch', 65281),
 ('folding chair', 65281),
 ('radio telescope', 65281),
 ('jack-o-lantern', 65281),



I am plotting the epochs to view the class labelling

 epochs.plot(n_channels=10, events=events, event_id=event_dict_as_dict)

The epochs are plotted but the label from the second last last 'Pool table is used only.[1]][1]


  [1]: https://i.stack.imgur.com/LyO0k.jpg

the epochs are not correctly labelled

1 Answers1

1

If your event_dict is a list and not a dictionary, you should convert it into a dictionary before using it with mne.Epochs.

Here is how you can modify your code:

import mne

# Your existing event_dict
event_dict = [('initial event', 65280),
              ('initial event', 65533),
              ('airliner', 65281),
              ('watch', 65281),
              ('folding chair', 65281),
              ('radio telescope', 65281),
              ('jack-o-lantern', 65281),
              # ... and so on
             ]

# Create a dictionary from the list
event_dict_as_dict = dict(event_dict)

tmin, tmax = -1, 2  # one image is shown for 2s
epochs = mne.Epochs(raw, events, event_dict_as_dict, tmin, tmax, baseline=(None, 0), preload=True)

In this code, event_dict_as_dict is created by converting your existing event_dict list into a dictionary. Then, you can use this dictionary with the mne.Epochs function.

vlanto
  • 457
  • 6