MNE DataFrame Scaling

Preamble

In [13]:
import mne
import numpy as np                 # for multi-dimensional containers
import pandas as pd                # for DataFrames

pio.templates['shahin'] = pio.to_templated(go.Figure().update_layout(yaxis=dict(autorange = "reversed"),margin=dict(t=0,r=0,b=40,l=40))).layout.template
pio.templates.default = 'shahin'

Dataset

Download sample data from Mike Cohen.

In [14]:
import warnings
warnings.filterwarnings("ignore")

def load_data(tmin, tmax):
    epochs = mne.io.read_epochs_eeglab('sampleEEGdata.mat').crop(tmin, tmax)
    return epochs

Scaling

Default Scaling

In [15]:
epochs = load_data(-0.2,1)
values = epochs.to_data_frame()
values = values.groupby("time").mean()
values.head(3)
Extracting parameters from sampleEEGdata.mat...
99 matching events found
No baseline correction applied
Not setting metadata
0 projection items activated
Ready.
Converting "time" to "<class 'numpy.int64'>"...
Out[15]:
channel Fp1 AF7 AF3 F1 F3 F5 F7 FT7 FC5 FC3 ... CP4 CP2 P2 P4 P6 P8 P10 PO8 PO4 O2
time
-199 -0.891870 -0.701918 -1.706986 -1.024161 -0.976764 -1.014164 -1.002770 -1.402991 -1.496777 -1.314428 ... -1.511028 -1.477739 -1.723046 -1.574034 -1.598564 -1.779448 -0.940347 -1.883280 -1.808410 -2.185663
-195 0.233510 0.506950 -0.445840 0.333534 0.195593 0.212527 0.163632 -0.052681 -0.010986 0.129063 ... 0.125678 0.130709 0.035723 0.130725 0.134243 0.357075 0.358627 -0.038384 -0.170933 -0.259101
-191 -0.507979 -1.007955 -0.986916 -0.328037 -0.593872 -0.573180 -0.562565 -1.356027 -0.634322 -0.383950 ... 0.207923 0.279907 0.127276 0.382046 0.444502 0.647713 0.310199 0.538165 0.387237 0.784565

3 rows × 64 columns

No Scaling

In [16]:
epochs = load_data(-0.2,1)
values = epochs.to_data_frame(scalings=1)
values = values.groupby("time").mean()
values.head(3)
Extracting parameters from sampleEEGdata.mat...
99 matching events found
No baseline correction applied
Not setting metadata
0 projection items activated
Ready.
Converting "time" to "<class 'numpy.int64'>"...
Out[16]:
channel Fp1 AF7 AF3 F1 F3 F5 F7 FT7 FC5 FC3 ... CP4 CP2 P2 P4 P6 P8 P10 PO8 PO4 O2
time
-199 -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.314428e-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
-195 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.290634e-07 ... 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
-191 -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 -3.839501e-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 × 64 columns

Explicit scaling to default setting

In [17]:
epochs = load_data(-0.2,1)
values = epochs.to_data_frame(scalings=1e6)
values = values.groupby("time").mean()
values.head(3)
Extracting parameters from sampleEEGdata.mat...
99 matching events found
No baseline correction applied
Not setting metadata
0 projection items activated
Ready.
Converting "time" to "<class 'numpy.int64'>"...
Out[17]:
channel Fp1 AF7 AF3 F1 F3 F5 F7 FT7 FC5 FC3 ... CP4 CP2 P2 P4 P6 P8 P10 PO8 PO4 O2
time
-199 -0.891870 -0.701918 -1.706986 -1.024161 -0.976764 -1.014164 -1.002770 -1.402991 -1.496777 -1.314428 ... -1.511028 -1.477739 -1.723046 -1.574034 -1.598564 -1.779448 -0.940347 -1.883280 -1.808410 -2.185663
-195 0.233510 0.506950 -0.445840 0.333534 0.195593 0.212527 0.163632 -0.052681 -0.010986 0.129063 ... 0.125678 0.130709 0.035723 0.130725 0.134243 0.357075 0.358627 -0.038384 -0.170933 -0.259101
-191 -0.507979 -1.007955 -0.986916 -0.328037 -0.593872 -0.573180 -0.562565 -1.356027 -0.634322 -0.383950 ... 0.207923 0.279907 0.127276 0.382046 0.444502 0.647713 0.310199 0.538165 0.387237 0.784565

3 rows × 64 columns