Preamble
import mne
import numpy as np # for multi-dimensional containers
import pandas as pd # for DataFrames
import plotly.graph_objects as go # for data visualisation
Dataset
Download sample data from Mike Cohen.
import warnings
warnings.filterwarnings("ignore")
def load_data(tmin, tmax):
epochs = mne.io.read_epochs_eeglab('sampleEEGdata.mat', verbose=False).crop(tmin, tmax)
return epochs
Scaling
Default Scaling
epochs = load_data(-0.2,1)
values = epochs.to_data_frame()
values = values.groupby("time").mean()
values.head(3)
epoch | Fp1 | AF7 | AF3 | F1 | F3 | F5 | F7 | FT7 | FC5 | ... | CP4 | CP2 | P2 | P4 | P6 | P8 | P10 | PO8 | PO4 | O2 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
time | |||||||||||||||||||||
-0.199219 | 49.0 | -0.891870 | -0.701918 | -1.706986 | -1.024161 | -0.976764 | -1.014164 | -1.002770 | -1.402991 | -1.496777 | ... | -1.511028 | -1.477739 | -1.723046 | -1.574034 | -1.598564 | -1.779448 | -0.940347 | -1.883280 | -1.808410 | -2.185663 |
-0.195312 | 49.0 | 0.233510 | 0.506950 | -0.445840 | 0.333534 | 0.195593 | 0.212527 | 0.163632 | -0.052681 | -0.010986 | ... | 0.125678 | 0.130709 | 0.035723 | 0.130725 | 0.134243 | 0.357075 | 0.358627 | -0.038384 | -0.170933 | -0.259101 |
-0.191406 | 49.0 | -0.507979 | -1.007955 | -0.986916 | -0.328037 | -0.593872 | -0.573180 | -0.562565 | -1.356027 | -0.634322 | ... | 0.207923 | 0.279907 | 0.127276 | 0.382046 | 0.444502 | 0.647713 | 0.310199 | 0.538165 | 0.387237 | 0.784565 |
3 rows × 65 columns
No Scaling
epochs = load_data(-0.2,1)
values = epochs.to_data_frame(scalings=1)
values = values.groupby("time").mean()
values.head(3)
epoch | Fp1 | AF7 | AF3 | F1 | F3 | F5 | F7 | FT7 | FC5 | ... | CP4 | CP2 | P2 | P4 | P6 | P8 | P10 | PO8 | PO4 | O2 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
time | |||||||||||||||||||||
-0.199219 | 49.0 | -8.918701e-07 | -7.019182e-07 | -1.706986e-06 | -1.024161e-06 | -9.767636e-07 | -1.014164e-06 | -1.002770e-06 | -1.402991e-06 | -1.496777e-06 | ... | -1.511028e-06 | -1.477739e-06 | -1.723046e-06 | -1.574034e-06 | -1.598564e-06 | -1.779448e-06 | -9.403469e-07 | -1.883280e-06 | -1.808410e-06 | -2.185663e-06 |
-0.195312 | 49.0 | 2.335097e-07 | 5.069503e-07 | -4.458401e-07 | 3.335338e-07 | 1.955928e-07 | 2.125266e-07 | 1.636316e-07 | -5.268077e-08 | -1.098647e-08 | ... | 1.256775e-07 | 1.307085e-07 | 3.572303e-08 | 1.307252e-07 | 1.342428e-07 | 3.570746e-07 | 3.586267e-07 | -3.838408e-08 | -1.709330e-07 | -2.591015e-07 |
-0.191406 | 49.0 | -5.079792e-07 | -1.007955e-06 | -9.869164e-07 | -3.280373e-07 | -5.938724e-07 | -5.731804e-07 | -5.625650e-07 | -1.356027e-06 | -6.343224e-07 | ... | 2.079225e-07 | 2.799072e-07 | 1.272755e-07 | 3.820456e-07 | 4.445024e-07 | 6.477130e-07 | 3.101987e-07 | 5.381648e-07 | 3.872367e-07 | 7.845649e-07 |
3 rows × 65 columns
Explicit scaling to default setting
epochs = load_data(-0.2,1)
values = epochs.to_data_frame(scalings=1e6)
values = values.groupby("time").mean()
values.head(3)
epoch | Fp1 | AF7 | AF3 | F1 | F3 | F5 | F7 | FT7 | FC5 | ... | CP4 | CP2 | P2 | P4 | P6 | P8 | P10 | PO8 | PO4 | O2 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
time | |||||||||||||||||||||
-0.199219 | 49.0 | -0.891870 | -0.701918 | -1.706986 | -1.024161 | -0.976764 | -1.014164 | -1.002770 | -1.402991 | -1.496777 | ... | -1.511028 | -1.477739 | -1.723046 | -1.574034 | -1.598564 | -1.779448 | -0.940347 | -1.883280 | -1.808410 | -2.185663 |
-0.195312 | 49.0 | 0.233510 | 0.506950 | -0.445840 | 0.333534 | 0.195593 | 0.212527 | 0.163632 | -0.052681 | -0.010986 | ... | 0.125678 | 0.130709 | 0.035723 | 0.130725 | 0.134243 | 0.357075 | 0.358627 | -0.038384 | -0.170933 | -0.259101 |
-0.191406 | 49.0 | -0.507979 | -1.007955 | -0.986916 | -0.328037 | -0.593872 | -0.573180 | -0.562565 | -1.356027 | -0.634322 | ... | 0.207923 | 0.279907 | 0.127276 | 0.382046 | 0.444502 | 0.647713 | 0.310199 | 0.538165 | 0.387237 | 0.784565 |
3 rows × 65 columns
Plotting with Plotly
fig = go.Figure(layout=dict(xaxis=dict(title='time')))
for ch in epochs.info['ch_names']:
fig.add_scatter(x=epochs.times, y=values[ch], name=ch)
fig.show()