使用事件和类标签创建脑电图信号的纪元

问题描述 投票:0回答:1

我正在处理通过显示 40 个类别中每个类别的 10 个图像获得的脑电图信号。我想将转换为纪元的信号标记为其相应的类标签。

我将事件数据提取为:

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)

事件数据如下

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

事件数据的第三列是事件代码,对于所有 400 个图像来说都是相同的 65281,除了前 2 个事件代码 [65280, 65533] 是最初的 10 秒暂停。

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

print(event_dict)

event_dict包含数据

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

我创建了这个事件字典来传递给 mne.epochs 这样

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

但这并没有按原样接受 event_dict

TypeError: event_id[0] 必须是 int,得到

我想将纪元标记为他们的类名称

python signal-processing mne-python eeglab
1个回答
0
投票

mne.Epochs
期望
event_id
参数是一个字典,其中键是整数(事件代码),值是表示事件 ID 的整数。

要使用类名称标记纪元,您需要将类标签映射到唯一的整数,然后使用这些唯一的整数作为键创建一个

event_id
字典。

具体操作方法如下:

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 mapping of class labels to unique integers
class_labels = list(set(label for label, _ in event_dict))
class_to_int = {label: idx for idx, label in enumerate(class_labels)}

# Create an event_id dictionary using the unique integer IDs
event_id = {class_to_int[label]: code for label, code in event_dict if label != 'initial event'}

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

确保将注释

# ... and so on
替换为
event_dict
中的其余类标签-事件代码对。

© www.soinside.com 2019 - 2024. All rights reserved.