mne.epoch method

:question: If you have a question or issue with MNE-Python, please include the following info:

  • MNE version: 1.8

  • operating system: e.g. macOS 12 / Windows 10 / Ubuntu 18.04
    Hi, all epochs are dropped when I use the mne.epoch function. I want to know if it is because of my .bdf file or because I set the baseline correction range incorrectly. Here is my source code and the problem

    for idx, sub in enumerate(sub_info):

      sub_path = os.path.join(data_dir,sub)
      print("Current processing subject:", sub)
      trigger, onset, duration, rawdata, [unit, impedance, experiments] = read_data(sub_path)
    
      # read_the_remark_data
      remark_data = hdf5storage.loadmat(os.path.join(sub_path, 'After_remarks.mat'))['After_remark']
      vids = np.squeeze(remark_data['vid'])
    
      frequency = rawdata.info['sfreq']
    
      events = np.transpose(np.vstack((np.vstack((onset, duration)), trigger)))
    
      # The first batch and the second batch have different unit (uV and V)
      original_raw = rawdata.copy()
    
      # Epochs cutting
      cut_seconds = -30; event_id = 102;
      epochs = mne.Epochs(original_raw, events, event_id=event_id, tmin=cut_seconds, tmax=0, preload=True)
    

def read_data(folderPath):

Read the data

rawdata = mne.io.read_raw_bdf(os.path.join(folderPath, 'data.bdf'), preload=True)
rawdata,unit = unit_check(rawdata)
fs = rawdata.info['sfreq']
# Read the event
## read events
try:
    events = mne.read_annotations(os.path.join(folderPath, 'evt.bdf'))
    onset = np.array([int(x * fs) for x in events.onset] )
    duration = np.array([int(x) for x in events.duration])
    trigger = np.array([i for i in events.description])
    print("Original trigger events:", trigger)
    # Impedance checking
    trigger,onset,duration,impedance = inter_impedance_inspect(trigger,onset,duration)
    trigger = np.array([int(x) for x in trigger])
    # Check wheter there is ERP data
    trigger,onset, duration, experiment = trigger_check(trigger,onset, duration)
    return trigger, onset, duration, rawdata, [unit, impedance, experiment]
except:
    raise RuntimeError("No event was found")

My problem:

Extracting EDF parameters from /home/zyy/mycode/AIEEG-main-faced/data/sub000/data.bdf…
BDF file detected
/home/zyy/mycode/AIEEG-main-faced/Preprocessing/Preprocessing.py:146: RuntimeWarning: Number of records from the header does not match the file size (perhaps the recording was not stopped before exiting). Inferring from the file size.
rawdata = mne.io.read_raw_bdf(os.path.join(folderPath, β€˜data.bdf’), preload=True)
Setting channel info structure…
Creating raw.info structure…
Reading 0 … 18999 = 0.000 … 18.999 secs…
Unit change : 0.01649761137060406
Original trigger events: [β€˜100’ β€˜100’ β€˜100’ β€˜100’ β€˜100’ β€˜11’ β€˜101’ β€˜102’ β€˜8’ β€˜101’ β€˜102’ β€˜2’ β€˜101’
β€˜102’ β€˜5’ β€˜101’ β€˜102’ β€˜6’ β€˜101’ β€˜102’ β€˜9’ β€˜101’ β€˜102’ β€˜3’ β€˜101’ β€˜102’
β€˜12’ β€˜101’ β€˜102’ β€˜20’ β€˜101’ β€˜102’ β€˜17’ β€˜101’ β€˜102’ β€˜26’ β€˜101’ β€˜102’ β€˜23’
β€˜101’ β€˜102’ β€˜13’ β€˜101’ β€˜102’ β€˜15’ β€˜101’ β€˜102’ β€˜14’ β€˜101’ β€˜102’ β€˜16’ β€˜101’
β€˜102’ β€˜10’ β€˜101’ β€˜102’ β€˜1’ β€˜101’ β€˜102’ β€˜4’ β€˜101’ β€˜102’ β€˜7’ β€˜101’ β€˜102’
β€˜28’ β€˜101’ β€˜102’ β€˜25’ β€˜101’ β€˜102’ β€˜22’ β€˜101’ β€˜102’ β€˜19’ β€˜101’ β€˜102’ β€˜18’
β€˜101’ β€˜102’ β€˜21’ β€˜101’ β€˜102’ β€˜27’ β€˜101’ β€˜102’ β€˜24’ β€˜101’ β€˜102’
β€˜Start Impedance’ β€˜Stop Impedance’]

There is an Impedance in the dataset but at the end
Not setting metadata
28 matching events found
Setting baseline interval to [-30.0, 0.0] s
Applying baseline correction (mode: mean)
0 projection items activated
Using data from preloaded Raw for 28 events and 30001 original time points …
28 bad epochs dropped
/home/zyy/mycode/AIEEG-main-faced/Preprocessing/main.py:62: RuntimeWarning: All epochs were dropped!
You might need to alter reject/flat-criteria or drop bad channels to avoid this. You can use Epochs.plot_drop_log() to see which channels are responsible for the dropping of epochs.

Hello @cola8yy and welcome to the forum!

Your recording seems to be only 19 seconds long, hence it would appear logical that you cannot create 30 second long epochs.

Best wishes,
Richard

Which may be a sign that the sample frequency is incorrectly set

1 Like

Thanks for your reply! :smiley:I tried to capture 4s epochs but the above problem still occurred. :confounded: And I re-downloaded the dataset and did an MD5 check on it to make sure my dataset was not corrupted.

Best wishes,
cola8yy

Thanks for your reply! :smiley:When I run read_data.m, the sampling frequency is already normalized.

Best wishes,
cola8yy

I updated the dataset again and the problem has been solved. Thank you very much!

Best wishes,
cola8yy

2 Likes

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