- MNE version: e.g. 1.7.0
- operating system: Linux Mint 21.1 Cinnamon
Hello,
Iām currently doing a project where I try to analyse eeg data after getting it with LSL protocol (I get the data and the annotations from an xdf file with the library pyxdf). Itās working but the problem comes after that.
After filtering the data to only keep the frequencies Iām interested in (8-14 Hz), and after selecting the electrode Iām interested in (C3), I try to divide the signal in epochs (3 second before the annotation and 6.5 second after).
When I do that 25 of my 40 epochs gets excluded for the following reason : NO_DATA. I donāt understand why itās telling me I have no data because when I look at the eeg signal, there is no cut or flat line in the signal.
Could it be due to artefcacts ?
I will put in attachment a screen of the drop log I get
I canāt put my xdf file in this message, is there an other way I can send the file so you can test the code ?
Here is my code :
Thank you very much for your help.
import pyxdf
import mne
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
import random
from functions import *
from functions import filter_signal_plot_spectrum
from plot_all_subjects import plot_all_subjects
file_path = 'PATH_TO_THE_FILE/sub-P001_ses-S001_task-Default_run-001_eeg.xdf'
streams, fileheader = pyxdf.load_xdf(file_path)
markers = []
# Go through the streams an indentify EEG streams and markers stream
#We first initialize the var that will tell us if we detect these streams
eeg_stream = None
marker_stream = None
#If they exist we store them
for stream in streams:
if stream['info']['type'][0] == 'EEG':
eeg_stream = stream
elif stream['info']['type'][0] == 'Markers':
marker_stream = stream
if marker_stream:
for i, marker in enumerate(marker_stream['time_series'][:]):
markers.append(marker[0])
if (eeg_stream != None) :
data_lsl = eeg_stream['time_series'].T
data_lsl = data_lsl/1000000 # We convert to Volts (it was microVolts)
sfreq = eeg_stream["info"]["effective_srate"]
info = mne.create_info( int(eeg_stream["info"]["channel_count"][0]) , sfreq, ch_types ='eeg')
raw = mne.io.RawArray(data_lsl, info, first_samp= eeg_stream['time_stamps'][0])
if (marker_stream != None) :
evts = np.zeros((len(marker_stream['time_stamps']),3))
for n in range(len(marker_stream['time_stamps'])) :
#We assign to the marker the closest existing timestamp of the eeg
target = marker_stream['time_stamps'][n]
eeg_target = min(eeg_stream['time_stamps'], key= lambda x: abs(x-target))
evts[n][0] = np.where(eeg_stream['time_stamps'] == eeg_target)[0][0]
if(markers[n] == 'left hand') :
evts[n][2] = 2
if(markers[n] == 'right hand'):
evts[n][2] = 3
evts = evts.astype(dtype= int, copy=False)
annotations = mne.annotations_from_events(events= evts, sfreq=sfreq)
raw.set_annotations(annotations)
signal_nb_event = len(markers) - 1 # We don't the event that close the outlet
event_dict = {
"Left Hand" : 2,
"Right Hand" : 3,
}
# Definition of the bounds of the epochs (0 is the time of the event)
t_min, t_max = -3, 6.5 # 3 seconds befor task, 6.5 seconds after the task
# The number of event we can find in the signal
nb_evt = 2 #Left Hand and Right Hand
data = raw.copy().filter(l_freq=50.5, h_freq=49.5,picks = 'all', method = 'iir')
#Alpha (8-14Hz):
dataalpha = data.copy().filter(l_freq=8, h_freq=14, h_trans_bandwidth= 2,picks = 'all')
dataalpha.plot()
#We select the C3 channel (channel number 27)
data_Elec = dataalpha.copy().pick_channels(ch_names = [('27')] )
epchs_freq_Elec = mne.Epochs(data_Elec, evts, event_id= event_dict, picks=("27"), tmin=t_min, tmax=t_max, preload=True)
epchs_freq_Elec.plot_drop_log()
epchs_freq_Elec.plot()