%matplotlib inline
In this short tutorial, we will compute the static connectivity of the EEG singals.
import numpy as np
import scipy
from scipy import io
eeg = np.load("data/eeg_eyes_opened.npy")
num_trials, num_channels, num_samples = np.shape(eeg)
eeg_ts = np.squeeze(eeg[0, :, :])
As a first example, we are going to compute the static connectivity of the EEG signals using the IPLV estimator.
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
from dyconnmap.fc import iplv
Define the frequency band we are interested to examine, in Hz
band = [1.0, 4.0]
Define the sampling frequency, in Hz
sampling_frequency = 160.0
We will invoke the estimator using the full by-name arguments. The last arguement, pairs
is None
by default, which means all "full connectivity", otherwise you check the documentation about the structure of the value.
ts, avg = iplv(eeg_ts, fb=band, fs=sampling_frequency, pairs=None)
print(f"""Time series array shape: {np.shape(ts)}
Average time series array shape: {np.shape(avg)}""")
Make the connectivity matrix symmetric
avg_symm = avg + avg.T
np.fill_diagonal(avg_symm, 1.0)
Plot the matrix using the standard Matplotlib functions
import matplotlib.pyplot as plt
mtx_min = 0.0 # we know it's 0.0 because of the estimator's properties
mtx_max = np.max(avg)
plt.figure(figsize=(6, 6))
cax = plt.imshow(avg_symm, vmin=mtx_min, vmax=mtx_max, cmap=plt.cm.Spectral)
cb = plt.colorbar(fraction=0.046, pad=0.04)
cb.ax.set_ylabel('Imaginary PLV', fontdict={'fontsize': 20})
plt.title('Connectivity Matrix', fontdict={'fontsize': 20})
plt.xlabel('ROI', fontdict={'fontsize': 20})
plt.ylabel('ROI', fontdict={'fontsize': 20})
plt.show()