with MNE in python, we have more opportunities to handle the eeg .

on official website you could get lot of toturials , but for the resting state of data, there are but covered .

1. read the data

import mne
raw=mne.io.read_raw_egi('I:\\jiahua\\REVIS Rohdaten\\REVIS_01\\Day 1\\01_day1_pre 20140303 0857001.RAW')

2. resample the data

raw250.resample(256, npad="auto")  # set sampling frequency to 256Hz

3.remove the bad channels
tmin, tmax = 0, None
raw250=raw.crop(tmin, tmax).load_data() %% 将数据导入内存
raw250.plot( n_channels=128,butterfly=None,scalings='auto', remove_dc=True,)%% 这里可视化的时候
点击不要的channels,系统自动记录index 到 bads里面 

picks = mne.pick_types(raw.info, eeg=Ture, stim=False, exclude='bads')%% 选择新的数据

4. filter the data

raw250.filter(1, 30., fir_design='firwin') 过滤数据

5. read the channel location

montage = mne.channels.read_montage(kind='GSN-HydroCel-128')

raw250.set_montage(montage, set_dig=True) %% 对于后续的ica和可视化非常重要

6.segement the data as 2 second each epoch

from mne import Epochs
events = mne.make_fixed_length_events(raw250, id=1, duration=2)%% 定义事件 主要方便截取静息态数据的

eepochs = Epochs(raw250, events, tmin=0., tmax=2, picks=picks,baseline=None,
                    detrend=1, decim=8)%% 将数据分为2秒长的片段

7.remove the epoch visually

eepochs.plot(block=True,n_channels=128,scalings='auto')%% 这里点击epoch 去掉不要的epoch ,系统自动

8 interplorate the bad channles

evoked.interpolate_bads(reset_bads=False)%% not implemented


n_components = 25  # if float, select n_components by explained variance of PCA
method = 'fastica'  # for comparison with EEGLAB try "extended-infomax" here
decim = 3  # we need sufficient statistics, not all time points -> saves time

# we will also set state of the random number generator - ICA is a
# non-deterministic algorithm, but we want to have the same decomposition
# and the same order of components each time this tutorial is run
random_state = 23

ica = ICA(n_components=n_components, method=method, random_state=random_state)


ica.plot_components()  # can you spot some potential bad guys?