Unable to extract triggers even after assigning the correct channel type

  • MNE version: 1.9. 0
  • operating system: Windows 10

Hello,

I have attempted to use mne.find_events to extract my stimulus triggers but have not been successful.


raw = mne.io.read_raw_edf(edf_path)
raw.copy().pick(picks='TRIG').plot(start=100, duration = 2000, scalings = {'eeg' : 12000e-6}) #displays a plot with the triggers visible

events = mne.find_events(raw, stim_channel ='TRIG')
print(events) #returns []

I understand MNE is looking for a ‘stim’ channel but is unable to locate it. Therefore, I attempted to assign the correct channel type (stim) to ‘TRIG’ though the following:


stim_chans = ['TRIG'] #along with assigning other channel types
ch_labels = list(seeg_chans +ecog_chans + misc_chans + ecg_chans + eeg_chans + stim_chans)
ch_types = list(list(np.tile('seeg', len(seeg_chans))) + \
                list(np.tile('ecog', len(ecog_chans))) + \
                list(np.tile('misc', len(misc_chans))) + \
                list(np.tile('ecg', len(ecg_chans))) + \
                list(np.tile('eeg', len(eeg_chans))) + \
                list(np.tile('stim', len(stim_chans))))
chan_type_dict = dict(zip(ch_labels, ch_types))

After this, I attempted to verify that I assigned ‘TRIG’ as my stim channel. Then I proceeded to use mne.find_events again.

from mne import pick_types
picks=pick_types(raw.info,stim=True)
print(picks) #returns [273]

 mne.channel_type(raw.info,273) #returns 'stim'

events =mne.find_events(raw, stim_channel = 'TRIG')
print(events) #returns []

mne.find_events(raw, stim_channel="TRIG") #returns array([], shape=(0, 3), dtype=int32)

I wonder if I’m still not assigning the stimulus channel correctly. I know ‘TRIG’ is where my triggers are as I can visually see them when I plot the channel, but I cannot extract the events.

It’s not clear how you are setting this channel to stim, all you have to call is:

raw.set_channel_types({"ch_name": "stim"})

With ch_name as the name of your trigger channel in raw.ch_names.

Mathieu

1 Like

Thank you Mathieu for the help. I’ve modified the code a bit to implement your suggestion, but I’m still running into some issues. I’m trying to assign channel types to all my electrodes. The idea would be that after I assign ‘TRIG’ as the ‘stim’ channel, I’d be able to call mne.find_events().


seeg_chans = ['RHT1', 'RHT2', 'RHT3', 'RHT4', 'RHT5', 'RHT6', 'RHT7']
ecog_chans = ['STI1', 'STI2', 'STI3', 'STI4', 'STI5', 'STI6', 'STI7', 'STI8']
misc_chans = ['Trigger Event', 'OSAT', 'PR', 'Pleth']
ecg_chans = ['EKG1','EKG2', 'EKG3','EKG4']
stim_chans = ['TRIG']


ch_labels = list(seeg_chans +ecog_chans + misc_chans + ecg_chans + eeg_chans + stim_chans)
ch_types =list(list(['seeg']* len(seeg_chans))  + \
             list(['ecog']* len(ecog_chans)) + \
             list(['misc']* len(misc_chans)) + \
             list(['ecg']* len(ecg_chans)) + \
            list(['stim']* len(stim_chans)))

chan_type_tuples = [(ch_labels,ch_types) for ch_labels, ch_types in zip(ch_labels,ch_types)]
chan_type_dict = [{ch_labels: ch_types} for ch_labels, ch_types in chan_type_tuples]

#chan_type_dict outputes the folllowing: [{'RHT1': 'seeg'}, {'RHT2': 'seeg'},....,{'EKG4': 'ecg'}, {'TRIG': 'stim'}]

for i in range(len(chan_type_dict)):
    raw.set_channel_types(chan_type_dict[i])

However, when I run mne.find_events(raw, stim_channel=“TRIG”) I still end up with an empty array(, shape=(0,3), dtype=int32)