-
Notifications
You must be signed in to change notification settings - Fork 11
/
example.py
35 lines (28 loc) · 1.25 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import mne
import mne_microstates
from mne.datasets import sample
fname = (sample.data_path() / 'MEG/sample/sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(fname, preload=True)
raw.info['bads'] = ['MEG 2443', 'EEG 053']
raw.pick_types(meg='mag', eeg=True, eog=True, ecg=True)
# Microstate analysis needs average reference
raw.set_eeg_reference('average')
# Filter the data. Make sure slow drifts are eliminated.
raw.filter(1, 40)
# Clean EOG with ICA
ica = mne.preprocessing.ICA(0.99).fit(raw)
bads_eog, _ = ica.find_bads_eog(raw)
bads_ecg, _ = ica.find_bads_ecg(raw)
ica.exclude = bads_eog[:2] + bads_ecg[:2]
raw = ica.apply(raw)
# Select sensor type
# raw.pick_types(meg=False, eeg=True)
raw.pick_types(meg='mag', eeg=False)
# Segment the data into 5 microstates
maps, segmentation, polarity = mne_microstates.segment(raw.get_data(), n_states=5,
random_state=0,
return_polarity=True)
# Plot the topographic maps of the microstates and part of the segmentation
mne_microstates.plot_maps(maps, raw.info)
mne_microstates.plot_segmentation(segmentation[:500], raw.get_data()[:, :500],
raw.times[:500], polarity=polarity[:500])