How to achieve ICA eye electromyography removal?The original data is EEG data in. csv format

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

Columns 1-32 are EEG data, columns 33 are data indexes, and columns 34 are time scale information.

import pandas as pd
import numpy as np
import mne
import csv
from mne.preprocessing import ICA
from mne_icalabel import label_components
from mne.time_frequency import tfr_morlet
dataframe = pd.read_csv(“/MNEfile/mne_raw/wang/脑电/Data2.csv”)
data = dataframe.transpose().to_numpy()
arr=np.array(data)
newarr=np.multiply(arr,0.000001)
print(newarr)
ch_names = 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(newarr, info)

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

raw.plot(duration=5,n_channels=34,clipping=None)
raw.drop_channels(raw.info[‘bads’])
print(raw.info)

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

raw.set_eeg_reference(ref_channels=“average”)
raw=raw.filter(l_freq=0.1,h_freq=30)
filt_raw = raw.copy().filter(l_freq=1.0, h_freq=100.0)
filt_raw = filt_raw.set_eeg_reference(“average”)
ica=ICA(max_iter=“auto”,method=“infomax”,random_state=97,fit_params=dict(extended=True))
ica.fit(filt_raw)
ica

The error message is shown in the following figure

Jiao

Hi Jiao,
It looks like your EEG raw data contain illegal number, ‘Inf’ or ‘NaN’, using following code to check that. This may occur, for example when wireless EEG system sometimes lose packet due to bad network. Just delete this epoch. Also, you can update MNE to v.1.70, easier for your future study.

#查找NaN和Inf值的结合
nan_inf_mask = np.isnan(data) | np.isinf(data)
print(“NaN and Inf values in array:”)
print(nan_inf_mask)

#查找包含NaN或Inf值的行
rows_with_nan_or_inf = np.any(nan_inf_mask, axis=1)
print(“Rows with NaN or Inf values:”)
print(rows_with_nan_or_inf)

#查找包含NaN或Inf值的列
cols_with_nan_or_inf = np.any(nan_inf_mask, axis=0)
print(“Columns with NaN or Inf values:”)
print(cols_with_nan_or_inf)

1 Like