load and display csv file correctly

Hello,
I am trying time-frequency analysis by using csv file according to “Overview of MEG/EEG analysis with MNE-Python”. But, I could not load csv file correctly.
“raw.plot” displays only axis not wave, if I add scalings=“auto” , wave forms appear.
But stim(event,misc) wave does not appear.
My question:

  1. Please let me know how to load csv file and display the waveform correctly.
    The data is 'eeg’x5ch, 'misc’x2ch. Please see the below.
  2. If available, please let me know how to convert csv file to fif format.
    I can not use raw.save(`raw.fif’,overwrite=True) command.

There are many variables, and the selection is very complicated for a beginner.
Looking forward to hearing from any advise.

Best regards,
Tetsu


import numpy as np
import pandas as pd
import mne

Loading data

data = pd.read_csv(“C:/users/oyamatetsuji/desktop/veri_dEc09aft.csv”, dtype = np.float64)

user_frame = pd.read_csv(“C:/users/oyamatetsuji/desktop/veri_dEc09aft.csv”, dtype = np.float64)
data = user_frame.transpose().to_numpy()
n_channels = 7
sampling_freq = 2000

ch_names = [‘ch1’,‘ch2’,‘ch3’,‘ch4’,‘ch5’,‘ch6’,‘ch7’]

ch_names = [“Fp1”,“Fp2”,“Fz”,“Cz”,“Pz”,“O1”,“O2”]
ch_types = [“eeg”,“eeg”,“eeg”,“eeg”,“eeg”,“misc”,“misc”]

ch_types = [“misc”,“misc”,“misc”,“misc”,“misc”,“misc”,“misc”]

info = mne.create_info(ch_names=ch_names, ch_types=ch_types, sfreq = sampling_freq)
info.set_montage(“standard_1020”)
info[“description”] = “My custom dataset”
info[“bads”] =
print(info)

raw = mne.io.RawArray(data, info)

raw.save(‘raw.fif’, overwrite=True)

raw.plot(show_scrollbars=False,show_scalebars=False)

raw.plot()

print(raw)
print(raw.info)

raw.compute_psd(fmax=50).plot(picks=“data”, exclude=“bads”, amplitude=False)
raw.plot(duration=5, n_channels=7)


Your data is likely not scaled in Volts (which is what MNE expects). You can rescale your data using:

raw.apply_function(lambda x: x * 1e-6, channel_wise=False)

See for example Scaling issue while plotting EEG signal - #2 by cbrnr.

2 Likes

Dear cbrnr,
Thank you for your comment. Very helpful.
I could display the waveform not using (scalings=“auto”).
And I could reach to the “Epoching continuous data” of “Overview of MEG/EEG analysis with MNE-Python”, still not to “Time-frequency analysis”.