Finding events in EEG plot

  • MNE version: 1.9.0 (latest release)
  • operating system: MacBook Air M4, macOS-15.4.1-arm64-arm-64bit

Hi there,

I am using MNE Python and am trying to extract specific annotations from an EEG FIF file to epoch and then get ERPs. My full code is as follows:

%matplotlib inline
%matplotlib
%matplotlib notebook

import mne
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import copy
import matplotlib

raw = mne.io.read_raw_fif("/Users/cinthiamuniz/Downloads/HC_Task_S1/HC_01_off_task_S1_V1_events_raw.fif", preload = True)

raw.filter(0.1,30,fir_design='firwin',phase='zero-double')

raw_tmp1=raw.copy().set_channel_types({'EXG1': 'eog','EXG2': 'eog','EXG3': 'eog','EXG4': 'eog',
                               'Erg2':'misc','Erg1':'misc','Status':'misc','EXG5':'emg',
                                'EXG6':'emg','EXG7':'emg','EXG8':'emg'}) 

raw_tmp1.drop_channels(['GSR1','GSR2','Resp','Plet','Temp']) 

raw_tmp1.set_montage("biosemi64")

Then I try to create an event dictionary I can reference later for epoching (this is just a draft I know code values might be wrong)


event_dict = {
    "fix": 10,
    "start": 11,
    "start_or_24":12
    "start_diode": 6,
    "start_or_25":5,
    "one": 4,
    "stop":13,
    "stop_diode":2,
    "plan": 13,
    "plan_synch": 1,
    "unplan_synch": 2,
    "plan": 3,
    "unplan": 4,
}

But I do not know the embedded values of each event, so I try to find them manually by using print(events [:15]) and raw_tmp1.plot() .

If my event line is [41058 0 10], then I would go through the plot and identify the event’s name at that point. However, when doing that, I realize it marks events when in the plot there is none and the some of the events in the plot are not marked in the print(events) line, so I do not know how to fix this since it looks like my data might not be read well for future epoching.

use raw_tmp1.plot(events=events) and the figure will show the onset of each event as vertical lines and also shows the event code.

Thank you so much, Marijn! This helped a lot since it made the visualization of the data more clear.

I am just putting this here in case anyone encounters a similar problem:

I was also running events = mne.find_events(FilteredData, stim_channel='Status', shortest_event=0.5) which now I understand was not useful for me since some of my annotations were not stim related.

After changing my line code to

annotations = raw.annotations

events, event_id = mne.events_from_annotations(raw)

raw_tmp1.plot(events=events)

I was able to get an automated event ID that was also visible in the plot and aligned with the printed events.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.