{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this short tutorial, we will compute the static connectivity of the EEG singals." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- - -" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import scipy\n", "from scipy import io" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "eeg = np.load(\"data/eeg_eyes_opened.npy\")\n", "\n", "num_trials, num_channels, num_samples = np.shape(eeg)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "eeg_ts = np.squeeze(eeg[0, :, :])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Static connectivity\n", "\n", "As a first example, we are going to compute the static connectivity of the EEG signals using the IPLV estimator." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import warnings\n", "warnings.simplefilter(action='ignore', category=FutureWarning)\n", "\n", "from dyconnmap.fc import iplv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the frequency band we are interested to examine, in Hz" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "band = [1.0, 4.0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the sampling frequency, in Hz" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "sampling_frequency = 160.0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ts, avg = iplv(eeg_ts, fb=band, fs=sampling_frequency, pairs=None)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"\"\"Time series array shape: {np.shape(ts)}\n", "Average time series array shape: {np.shape(avg)}\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make the connectivity matrix symmetric" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "avg_symm = avg + avg.T\n", "np.fill_diagonal(avg_symm, 1.0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot\n", "\n", "Plot the matrix using the standard Matplotlib functions" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "mtx_min = 0.0 # we know it's 0.0 because of the estimator's properties\n", "mtx_max = np.max(avg)\n", "\n", "plt.figure(figsize=(6, 6))\n", "cax = plt.imshow(avg_symm, vmin=mtx_min, vmax=mtx_max, cmap=plt.cm.Spectral)\n", "cb = plt.colorbar(fraction=0.046, pad=0.04)\n", "cb.ax.set_ylabel('Imaginary PLV', fontdict={'fontsize': 20})\n", "plt.title('Connectivity Matrix', fontdict={'fontsize': 20})\n", "plt.xlabel('ROI', fontdict={'fontsize': 20})\n", "plt.ylabel('ROI', fontdict={'fontsize': 20})\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.7" } }, "nbformat": 4, "nbformat_minor": 4 }