Plotting Raw EEG signals

  • MNE version: e.g. 0.24.1
  • operating system: Ubuntu 20.04
#extracting eeg data and labeling
cols_list=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
eeg_raw = pd.read_csv('/home/aurore/eeg/data/Carlijn_Sit_Train_data/Carlijn_Sit_Train_data5.csv', header=None,usecols=cols_list, prefix='eeg')

ch_names= ['EEG1','EEG2','EEG3','EEG4','EEG5','EEG6','EEG7','EEG8','EEG9','EEG10','EEG11','EEG12','EEG13','EEG14','EEG15','EEG16']
sfreq=500
ch_types = ['eeg'] * 16
info = mne.create_info(ch_names=ch_names, sfreq=sfreq,ch_types = ch_types)
info['lowpass']=0.1
info['highpass']=100
eeg_raw_np=eeg_raw.to_numpy().transpose()

rawAurore = mne.io.RawArray(eeg_raw_np, info)
rawAurore.plot()
print(rawAurore.info)

I have been recording some EEG data from the gtec Nautilus headset. I am trying to plot it via the MNE package but I have struggles with it. The channel’s data aren’t showing up properly. What is going wrong? I can plot it correctly when i simply use plt.plot()…

The data seems to be scaled incorrectly. MNE expects EEG signal in V, and you probably have it in µV. Therefore, dividing by 10^6 to convert to V might do the trick.

It unfortunately does not make the trick. By dividing my eeg data by 1e6, I get this plot:

What are the data means, minima, and maxima?

This array represents the mean for every channel (16 channels)
[-2.07639746e-08 -1.84736637e-08 -2.60456712e-08 -1.07056338e-08
 -3.50582107e-08 -8.93639772e-09 -2.36951378e-08 -8.13024605e-09
  9.41100607e-10 -1.02837258e-08 -1.13612198e-09 -5.76478096e-09
  1.24304284e-08  1.30558460e-08 -5.09543558e-09  7.85983950e-08]`

The next array represents the maxima of every channel:
[4.19258301e-03 2.51899976e-03 1.18923574e-02 3.62315552e-03
 9.63265869e-04 3.24972290e-03 3.21279810e-03 2.31229419e-03
 3.85584741e-03 2.48471753e-03 4.42166113e-03 9.40465942e-04
 1.71706201e-03 6.89180762e-03 3.11295020e-03 2.03371510e-07]

Then you can see the array with every minima of every channel:
[-1.16874329e-03 -9.32007715e-03 -3.22880933e-03 -1.01792151e-03
 -3.49732837e-03 -9.11778992e-04 -1.19499248e-02 -6.65349365e-04
 -1.07882239e-03 -9.21418945e-03 -1.23046838e-03 -3.44146021e-03
 -6.36056641e-03 -2.56745801e-02 -8.62682251e-04 -1.25151694e-07]

Thanks for helping out!

Hm, unless these are artifact spikes it looks like your data is stored in mV? Can you try dividing by 1000 to see if this gives proper µV data traces? If that doesn’t work, can you post how it looks like when plotting with plt.plot()?

I use this:

x = np.arange(0,270,0.002)  #270%0.002 samples in total
x=x[:,np.newaxis]
y=eeg_raw_np[6,:]
y=y[:,np.newaxis]

plt.plot(x,y,'-', markersize=1)
plt.axis([50, 200, -0.2, 0.2])  #used to zoom in

I get the following plots:
eegdataunzoomed
eegdatazoomed

OK, the data is definitely not scaled correctly. You should see a signal between ±50µV (depends on the derivation of course, so this is just a guess), but you have ±50mV. Therefore, dividing by 1000 should solve the plotting issue. There’s a huge artifact at the beginning, so make sure to scroll forward to around second 30 to see the signals.

When I tried to use the MNE library, I divided my data by both1000 and 10e6 but it does not change anything… I forgot to tell you just before :confused: it’s really weird because clearly there should be something

Can you share the CSV so that I can run your code in your top post?

It seems that I cannot share via this post my CSV file. Is there any other way ? I tried to convert it to PNG but impossible since my file is too big, I tried to make it smaller but still not successful.

Any online file drop service would do.

Thanks!

OK, there are two problems:

  1. You need to multiply the data by 1e-3 to convert it to Volts, e.g. eeg_raw_np = eeg_raw.to_numpy().transpose() * 1e-3.
  2. You mixed up info['lowpass'] = 0.1 and info['highpass'] = 100, because the highpass should be 0.1Hz and the lowpass 100Hz.

Both changes yield a signal that plots perfectly fine.

Ok i did exactly what you said resulting in this:

#extracting eeg data and labeling
cols_list=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
eeg_raw = pd.read_csv('/home/aurore/eeg/data/Carlijn_Sit_Train_data/Carlijn_Sit_Train_data5.csv', header=None,usecols=cols_list, prefix='eeg')

ch_names= ['EEG1','EEG2','EEG3','EEG4','EEG5','EEG6','EEG7','EEG8','EEG9','EEG10','EEG11','EEG12','EEG13','EEG14','EEG15','EEG16']
sfreq=500
ch_types = ['eeg'] * 16
info = mne.create_info(ch_names=ch_names, sfreq=sfreq,ch_types = ch_types)
info['lowpass']=100
info['highpass']=0.1
eeg_raw_np=(eeg_raw.to_numpy().transpose())*1e-3

rawAurore = mne.io.RawArray(eeg_raw_np, info)
rawAurore.plot()
print(rawAurore.info)

But it still shows this very bad plot :sweat_smile: :face_with_monocle:
It might be something to do with the packages , because there is this red warning. I will try to maybe update some packages or smtgh

You need to scroll to second 50, there is a huge spike at the start of the data. Then, you probably need to adjust the zoom level a bit. You can also do rawAurore.plot(clipping=None) to allow the traces to be drawn outside their bounding box.

About that warning: it is best to completely remove the two lines where you set the lowpass and highpass (but this doesn’t affect the plotted data at all).

Thank you very much for all the help! It all works :smiley:

1 Like