Harmonicity Metrics Computation on MNE Epochs File
Harmonicity Metrics Computation on MNE Epochs File#
In this notebook, we demonstrate how to compute harmonicity metrics from an MNE epochs file using the Biotuner library. Harmonicity metrics provide insights into the periodic structure of EEG signals and can be useful for various applications in neuroscience research. Biotuner is a powerful tool for extracting these metrics by analyzing the harmonic architecture of M/EEG data.
# Import necessary modules
import mne
from mne.datasets import multimodal
from mne import make_fixed_length_events
from biotuner.biotuner2d import biotuner_mne
# Define the biotuner parameters
bt_dict = {
'peaks_function': 'EMD',
'precision': 1,
'fmin': 2,
'fmax': 90,
'n_peaks': 5,
'harm_thresh': 30,
'delta_lim': 100,
}
# Path to the multimodal data
data_path = multimodal.data_path()
# Filepath to the multimodal data
raw_file = str(data_path.joinpath('multimodal_raw.fif'))
# Suppress output
mne.set_log_level('ERROR')
# Load the raw data
raw = mne.io.read_raw_fif(raw_file, preload=True)
# Filter the data
raw.filter(l_freq=2., h_freq=90.)
# Get the names of the MEG channels
meg_channels = mne.pick_types(raw.info, meg=True)
# Keep only the first 10 MEG channels
meg_channels = meg_channels[:10]
# Update 'sf' in the bt_dict
bt_dict['sf'] = raw.info['sfreq']
# Create events
events = make_fixed_length_events(raw, start=0, stop=None, duration=2.0)
# Epoch the data
tmin = 0.0 # start of each epoch (0s before the trigger)
tmax = 2.0 # end of each epoch (2s after the trigger)
# Make sure only 10 epochs are created
if len(events) > 3:
events = events[:3]
# Pick only the first 10 MEG channels
raw.pick_channels([raw.ch_names[i] for i in meg_channels])
# Epoch the data
epochs = mne.Epochs(raw, events, tmin=tmin, tmax=tmax, baseline=None, preload=True)
# Compute biotuner metrics on epochs file
bt_df = biotuner_mne(epochs, bt_dict, savefile=True, savename='multimodal_raw')
c:\users\user\github\biotuner\biotuner\metrics.py:659: RuntimeWarning: divide by zero encountered in double_scalars
harm_temp.append(1 / delta_norm)
c:\Users\User\anaconda3\envs\biotuner\lib\site-packages\numpy\lib\function_base.py:380: RuntimeWarning: Mean of empty slice.
avg = a.mean(axis)
c:\Users\User\anaconda3\envs\biotuner\lib\site-packages\numpy\core\_methods.py:189: RuntimeWarning: invalid value encountered in double_scalars
ret = ret.dtype.type(ret / rcount)
c:\users\user\github\biotuner\biotuner\peaks_extraction.py:827: RuntimeWarning: invalid value encountered in true_divide
coh /= temp2
c:\Users\User\anaconda3\envs\biotuner\lib\site-packages\numpy\core\fromnumeric.py:3440: RuntimeWarning: Mean of empty slice.
return _methods._mean(a, axis=axis, dtype=dtype,
bt_df
trial | electrode | peaks_function | precision | fmin | fmax | n_peaks | harm_thresh | delta_lim | sf | ... | sum_q_for_all_intervals | harm_sim | matrix_harm_sim | matrix_cons | matrix_denom | cons | tenney | harm_fit | harmsim | subharm_tension | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 52 | 33.76 | 27.408042 | 0.331773 | 3078.000000 | 0.243590 | 2.914161 | 11 | 33.760684 | [0.040245430660774836] |
1 | 0 | 1 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 28703 | 38.92 | 44.497354 | 0.623413 | 3325.200000 | 0.625000 | 3.035390 | 15 | 38.918388 | [0.08681323594992725] |
2 | 0 | 2 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 14493 | 33.10 | 3.744248 | 0.038370 | 4463.000000 | 0.365224 | 5.114485 | 10 | 33.099289 | [0.08750497897263645] |
3 | 0 | 3 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 373 | 23.85 | 10.532544 | 0.109504 | 61.000000 | 0.351923 | 3.408947 | 12 | 23.846154 | [0.03407356717408203] |
4 | 0 | 4 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 6643025 | 31.47 | 13.313946 | 0.155624 | 3825.750000 | 0.268640 | 6.229364 | 5 | 31.474884 | [0.1350282792829261] |
5 | 0 | 5 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 241 | 24.70 | 11.466942 | 0.119611 | 47.333333 | 0.440909 | 3.312544 | 12 | 24.696970 | [0.03335222463092775] |
6 | 0 | 6 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 518689 | 12.02 | 8.476437 | 0.090718 | 3956.666667 | 0.343832 | 5.180535 | 11 | 12.015883 | [0.11689849920521807] |
7 | 0 | 7 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 29897 | 36.77 | 11.390282 | 0.119260 | 5422.500000 | 0.433333 | 4.150084 | 9 | 36.774950 | [0.09721535992779774] |
8 | 0 | 8 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 1453 | 21.22 | 13.350769 | 0.146396 | 53.466667 | 0.472394 | 4.368141 | 9 | 21.222480 | [0.0945973868157042] |
9 | 0 | 9 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 518 | 40.59 | 12.854671 | 0.135105 | 59.000000 | 0.325490 | 3.763756 | 9 | 40.588235 | [0.08667506229176597] |
10 | 1 | 0 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 6294041 | 13.19 | 9.868479 | 0.107444 | 3310.133333 | 0.411584 | 4.694222 | 10 | 13.188127 | [0.094220521933636] |
11 | 1 | 1 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 83 | 42.68 | 40.753629 | 0.579590 | 2516.533333 | 0.424242 | 3.309644 | 14 | 42.676768 | [0.0950166640113226] |
12 | 1 | 2 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 2663695 | 30.63 | 6.615343 | 0.069626 | 2461.333333 | 0.357101 | 5.246129 | 10 | 30.633896 | [0.11812990118576759] |
13 | 1 | 3 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 362 | 54.89 | 33.688886 | 0.419370 | 2359.972222 | 0.419048 | 4.273919 | 9 | 54.894180 | [0.12751767843497627] |
14 | 1 | 4 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 7008125 | 13.71 | 8.305882 | 0.088653 | 3880.666667 | 0.378200 | 5.334104 | 10 | 13.711387 | [0.12551460309881624] |
15 | 1 | 5 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 246 | 35.98 | 8.321897 | 0.087179 | 4186.500000 | 0.442495 | 3.967141 | 12 | 35.983187 | [0.16609746768320133] |
16 | 1 | 6 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 34970 | 36.71 | 27.389032 | 0.352668 | 3735.533333 | 0.264411 | 5.394392 | 9 | 36.705859 | [0.1402171529768576] |
17 | 1 | 7 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 2967794 | 30.64 | 6.704366 | 0.070518 | 3414.166667 | 0.390667 | 4.125512 | 11 | 30.639777 | [0.0816930528050395] |
18 | 1 | 8 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 59 | 56.67 | 23.393769 | 0.258938 | 3471.000000 | 0.397917 | 3.593157 | 10 | 56.666667 | [0.12140059506352861] |
19 | 1 | 9 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 5917909 | 10.10 | 6.558216 | 0.069720 | 3939.133333 | 0.352273 | 6.133720 | 7 | 10.097506 | [0.16524134542296162] |
20 | 2 | 0 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 349 | 32.82 | 25.944670 | 0.292576 | 3368.600000 | 0.209524 | 3.750084 | 15 | 32.817460 | [0.15660936139458068] |
21 | 2 | 1 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 1826 | 31.06 | 14.386101 | 0.160324 | 3061.888889 | 0.275084 | 5.297506 | 6 | 31.055556 | [0.1443963218278032] |
22 | 2 | 2 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 66 | 46.67 | 24.512396 | 0.272902 | 1656.333333 | 0.408333 | 3.427142 | 10 | 46.666667 | [0.10506273525832888] |
23 | 2 | 3 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 843 | 20.02 | 12.219981 | 0.129773 | 37.933333 | 0.424866 | 4.347529 | 10 | 20.022282 | [0.08233474456933955] |
24 | 2 | 4 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 2745255 | 19.83 | 21.547547 | 0.295447 | 3129.266667 | 0.210909 | 3.705701 | 14 | 19.831489 | [0.09423720971902239] |
25 | 2 | 5 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 232 | 35.39 | 8.155326 | 0.085397 | 3795.500000 | 0.410833 | 4.125512 | 11 | 35.388889 | [0.044989875320305316] |
26 | 2 | 6 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 124 | 38.43 | 35.991951 | 0.465078 | 3027.133333 | 0.476190 | 2.990912 | 11 | 38.425926 | [0.13364980249370828] |
27 | 2 | 7 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 8296287 | 30.73 | 20.636476 | 0.247780 | 3694.777778 | 0.336508 | 4.101061 | 11 | 30.734219 | [0.14876591904748074] |
28 | 2 | 8 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 880809 | 30.21 | 6.031381 | 0.063156 | 3972.833333 | 0.256258 | 3.993197 | 12 | 30.206086 | [0.10044430391744703] |
29 | 2 | 9 | EMD | 1 | 2 | 90 | 5 | 30 | 100 | 600.61499 | ... | 2490511 | 13.44 | 13.450237 | 0.151170 | 4338.666667 | 0.399194 | 3.974835 | 10 | 13.439635 | [0.11772585065374275] |
30 rows × 28 columns