can't add events to stim channels

This is my code:

import mne
import numpy as np

data = np.zeros((128,1000))
fs = 100
info = mne.create_info(ch_names=[‘STI 014’]+[str(i) for i in range(127)],sfreq=fs,ch_types=[‘stim’]+[‘eeg’]*127)
raw = mne.io.RawArray(data,info)
events = np.array([[100,0,1],[200,0,2]])
raw.add_events(events,stim_channel=‘STI 014’,replace=True)
raw_events = raw.info.events

I can’t find events in raw.info.events?

Hi @Xiaofang,

your code example results in a bug, because you used the and characters instead of simple quotation marks like " or '.

After fixing that issue, the code runs until raw.info.events. That can’t work, because firstly, raw.info attributes are obtained via a syntax like this one: raw.info["bads"], and secondly, because "events" is not an attribute for raw data.

You can obtain your events like this:

import mne
import numpy as np

data = np.zeros((128,1000))
fs = 100
info = mne.create_info(ch_names=["STI 014"]+[str(i) for i in range(127)],sfreq=fs,ch_types=["stim"]+["eeg"]*127)
raw = mne.io.RawArray(data,info)
events = np.array([[100,0,1],[200,0,2]])
raw.add_events(events,stim_channel="STI 014",replace=True)

raw_events = mne.find_events(raw)

PS: please format the code in your questions using markdown! :slight_smile:

1 Like