Unit errors when reading from csv file

  • MNE version: 1.3.1
  • operating system: macOS Ventura

Hi everyone, I’m trying to read EEG data from a csv file but I’m having a problem with the units, even after applying a solution described here on the forum << raw.apply_function(lambda x: x * 1e-6) >> . When plotting raw, the unit of microvolts appears in the upper right corner.

Here is my code:

file_name = 'example.csv'
data = pd.read_csv(file_name, skiprows=0, usecols=[*range(2, 18)])
channel_names = ['FP1', 'FP2', 'F3', 'F4', 'FC1', 'FC2', 'C4', 'C3', 'Cz', 'CP2', 'CP1', 'P4', 'Pz', 'P3', 'O2', 'O1']
sample_frequency = 512
info = mne.create_info(ch_names= channel_names, sfreq= sample_frequency, ch_types='eeg')
raw = mne.io.RawArray(data.transpose(), info)
raw.apply_function(lambda x: x * 1e-6)
raw.plot( scalings = 'auto' )
plt.show()

Thank you very much in advance.

Hello,

I’m going to guess you meant the upper left corner. Which is normal, EEG channels are plotted by default with a +/- 20uV scale displaying the range 40 uV in the top left corner. If you set scalings='auto' and get uV in the top left corner, you likely scaled the data correctly.

For instance:

from mne.datasets import sample
from mne.io import read_raw_fif
from mne.viz import set_browser_backend


raw = read_raw_fif(sample.data_path() / "MEG" / "sample" / "sample_audvis_raw.fif", preload=True)
raw.pick_types(eeg=True)
raw.filter(1., 40.)
set_browser_backend("matplotlib")
raw.plot(scalings="auto")

displays 23.58 uV in the top left corner.

Mathieu

1 Like

Thank You, Mathieu! You were right about the data being in the top left corner, my mistake.