How to draw the original waveform correctly instead of presenting a full screen vertical line

The content of. csv EEG data includes the first 32 columns of EEG, 33 columns of data index, and 34 columns of time scale

  • MNE version: e.g. 0.24.0
  • operating system: Windows 10

import pandas as pd
import numpy as np
import mne
import csv
from mne.preprocessing import ICA
from mne.time_frequency import tfr_morlet
dataframe = pd.read_csv(“/MNEfile/mne_raw/李至鑫/脑电/Data2.csv”)
data = dataframe.transpose().to_numpy()
ch_names = [‘Fp1’, ‘Fp2’, ‘Fz’, ‘F3’, ‘F4’, ‘F7’, ‘F8’, ‘FCz’, ‘FC3’, ‘FC4’, ‘FT7’, ‘FT8’, ‘Cz’, ‘C3’, ‘C4’, ‘T3’, ‘T4’, ‘CPz’, ‘CP3’, ‘CP4’, ‘TP7’, ‘TP8’, ‘Pz’, ‘P3’, ‘P4’, ‘T5’, ‘T6’, ‘Oz’, ‘O1’, ‘O2’, ‘HEOL’, ‘HEOR’,‘Data indexing’,‘Time scale’]
ch_types = [‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’,
… ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’, ‘eeg’,‘misc’, ‘misc’, ‘misc’, ‘misc’]
sampling_freq = 256
info = mne.create_info(ch_names= ch_names, ch_types= ch_types, sfreq= sampling_freq)
raw = mne.io.RawArray(data, info)

montage = mne.channels.make_standard_montage(“standard_1020”)
raw.set_montage(montage)

chan_types_dict={“Fp1”:“eog”,“Fp2”:“eog”}
raw.set_channel_types(chan_types_dict)
print(raw.info)

raw.plot(duration=5,n_channels=28,clipping=None)

MNE expects data in SI units, thus Volts for EEG.
What you see is the correct waveform, zoomed in by the scaling factor to Volts since you likely provided values which were microvolts or something else.

Use +/- to zoom in/out interactively on the plot, but really what you should do is apply a scaling factor to data before providing it to RawArray.

Mathieu

Thank you very much for your reply.
The method you provided has an immediate effect. As a beginner in MNE, I would like to ask you again how to convert units?

Jiao

Take your numpy array and multiply it with the appropriate scalar. In the code above, the variable data.

2 Likes

Thank you for your reply. This method is indeed effective. In addition, if the default unit of Mne is changed from volts (v) to microvolts (UV), it appears to have the same effect, but relevant information has not been found.
May I ask Mathieu Scheltienne if there is a method to convert the default unit (v) of mne to microvolts (UV)?

Jiao

MNE works only in SI units, if you provide something else, it won’t even know. Everything will work correctly but the units displayed in plotting windows and the default scaling used will all be wrong.

After communicating with you, I feel that I have gained a more comprehensive understanding of mne. In addition, I have also discovered an issue called “there is an error message” Assertion Error "when drawing a power spectrum for csv EEG data”, The code used is as presented at the beginning of the post. After entering the code “raw. compute psd(). plot()”, an error message is displayed as follows. I would like to ask Mr. Mathieu Scheltienne how to solve the problem of failed power spectrum export?

Thank you very much.
Jiao

The error message is as follows

Effective window size : 8.000 (s)
Traceback (most recent call last):
File “”, line 1, in
File “”, line 12, in compute_psd
File “F:\MNEfile\python_install\Lib\site-packages\mne\io\base.py”, line 2232, in compute_psd
return Spectrum(
^^^^^^^^^
File “F:\MNEfile\python_install\Lib\site-packages\mne\time_frequency\spectrum.py”, line 1146, in init
self._compute_spectra(data, fmin, fmax, n_jobs, method_kw, verbose)
File “F:\MNEfile\python_install\Lib\site-packages\mne\time_frequency\spectrum.py”, line 445, in _compute_spectra
result = self._psd_func(
^^^^^^^^^^^^^^^
File “”, line 12, in psd_array_welch
File “F:\MNEfile\python_install\Lib\site-packages\mne\time_frequency\psd.py”, line 233, in psd_array_welch
assert np.allclose(good_mask, good_mask[[0]], equal_nan=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

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