最近在做有关的项目,根据mne文档写的内容 就不写注释了。这里我用的是csv的数据直接读取。
import numpy as np
import mne
import matplotlib.pyplot as plt
from mne.preprocessing import ICA
from mne.time_frequency import tfr_morlet
import pandas as pd
from itertools import chain
# Read the CSV file as a NumPy array 需要电信号
data1 = []
for i in range(1, 23):
data = pd.read_csv('data.csv', usecols=[str(i)])
list1 = data.values.tolist()
final_list = list(chain.from_iterable(list1))
data1.append(final_list)
# Some information about the channels
# ch_names = []
# for i in range(1, 20):
# ch_names.append("ch " + str(i))
ch_names=['Fz', 'FC3', 'FC1', 'FCz', 'FC2', 'FC4', 'C5', 'C3', 'C1', 'Cz', 'C2', 'C4', 'C6', 'CP3', 'CP1','CPz', 'CP2', 'CP4', 'P1', 'Pz', 'P2', 'POz']
# Sampling rate of the Nautilus machine 采样频率
sfreq = 100 # Hz
# Create the info structure needed by MNE
info = mne.create_info(ch_names, sfreq,ch_types='eeg')
# Finally, create the Raw object
raw = mne.io.RawArray(data1, info)
# #电极信息
montage = mne.channels.make_standard_montage("standard_1020")
raw.set_montage(montage)
#ICA
ica = mne.preprocessing.ICA(n_components=22, random_state=97, max_iter=800)
ica.fit(raw)
ica.exclude = [1, 2,3] # details on how we picked these are omitted here
ica.plot_properties(raw, picks=ica.exclude)
plt.show()
生成的图?
|