Skip to main content

EEGraph Logo

GP3 License Python PyPI Build Status codecov

EEGraph is a Python library to model electroencephalograms (EEGs) as graphs, so the connectivity between different brain areas could be analyzed. It has applications in the study of neurologic diseases like Parkinson or epilepsy. The graph can be exported as a NetworkX graph-like object or it can also be graphically visualized.

If you are using this library please cite it as:

Maitin, A. M., Nogales, A., Chazarra, P., & García-Tejedor, Á. J. (2023). EEGraph: An open-source Python library for modeling electroencephalograms using graphs. Neurocomputing, 519, 127-134.

Getting Started

Dependencies

What libraries does EEGraph use.

  • Numpy
  • Pandas
  • Mne
  • Matplotlib
  • NetworkX
  • Plotly
  • Scipy
  • Scot
  • Antropy
  • Kaleido

Installing EEGraph

To install the latest stable version of EEGraph, you can use pip in a terminal:

pip install EEGRAPH

Functions

Documentation

EEGraph documentation is available online. Examples of usage are also available.

Importing EEG data

The different supported EEG file formats by EEGraph.

File format | Extension
  • Brainvision | .vhdr
  • Neuroscan CNT | .cnt
  • European data format | .edf
  • Biosemi data format | .bdf
  • General data format | .gdf
  • EGI simple binary | .egi
  • EGI MFF format | .mff
  • eXimia | .nxe

Connectivity Measures

The different available connectivity measures in EEGraph. Visit documentation for more info.

  • Cross Correlation
  • Pearson Correlation
  • Squared Coherence
  • Imaginary Coherence
  • Corrected Cross Correlation
  • Weighted Phase Lag Index (WPLI)
  • Phase Locking Value (PLV)
  • Phase Lag Index (PLI)
  • Directed Transfer Function (DTF)
  • Power Spectrum
  • Spectral Entropy
  • Shannon Entropy

Usage

Example usage of the library with Pearson Correlation.


Load data

import eegraph
G = eegraph.Graph()
G.load_data(path = 'eeg_sample_1.edf', exclude = ['EEG TAntI1-TAntI', 'EEG TAntD1-TAntD', 'EEG EKG1-EKG2'])

Electrode Montage

An electrode montage file can be specified for channels names while loading EEG data. Visit documentation for more info.

import eegraph
G = eegraph.Graph()
G.load_data(path = 'eeg_sample_1.edf', electrode_montage_path = 'electrodemontage.set.ced')

Modelate data

Without frequency bands
graphs, connectivity_matrix = G.modelate(window_size = 2, connectivity = 'pearson_correlation')
With frequency bands
graphs, connectivity_matrix = G.modelate(window_size = 2, connectivity = 'squared_coherence', bands = ['delta','theta','alpha'])

Threshold

A custom threshold can be specified as a parameter in modelate. Default threshold values can be found in the documentation.

graphs, connectivity_matrix = G.modelate(window_size = 2, connectivity = 'pearson_correlation', threshold = 0.8)

Window size

The window size can be defined as an int or list.

int: The set window size in seconds, e.g.(2). All the time intervals will be 2 seconds long.

list: The specific time intervals in seconds, e.g.[0, 3, 8]. The time intervalls will be the same as specified in the input.


Visualize graph

In order to visualize graphs, EEG channel names must be in one of the following formats:

  • Standard: 'Fp1', 'Fp2', 'C3', 'Cz'...
  • Dash separated: 'Fp1-EEG', 'Fp2-EEG', 'C3-EEG', 'Cz-EEG'...
  • Space separated: 'EEG Fp1', 'EEG Fp2', 'EEG C3', 'EEG Cz'...

For the Space separtor the information on the left side of the separator will be ignored, the standard electrode name must be on the right side.

For the Dash separtor the information on the right side of the separator will be ignored, the standard electrode name must be on the left side.

G.visualize(graphs[0], 'graph_1')

Connectivity Graph Output Example

Execution example video

https://user-images.githubusercontent.com/41289779/201069364-95fa82dd-a96b-454f-af79-7f124edb7d03.mp4

EEGraph Workflow

EEGraph Workflow Example

Contributing

See Contribution guidelines for more information.

Versioning

See CHANGELOG.txt for major/breaking updates and version history.

Contact

Centro de Estudios e Innovación en Gestión del Conocimiento (CEIEC), Universidad Francisco de Vitoria.

Disclaimer

  • There is a known issue with DTF connectivity, sometimes the error 'math domain error' is shown, it is part of an external library.

License

This project is licensed under the GPL-3.0 License.

Metadata

Release files for EEGRAPH 0.1.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for EEGRAPH 0.1.17
File Size Uploaded
EEGRAPH-0.1.17.tar.gz 36.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for EEGRAPH 0.1.17
File Interpreter ABI Platform
EEGRAPH-0.1.17-py3-none-any.whl Python 3 none any Details

Total release size: 65.9 kB

Release files / EEGRAPH-0.1.17.tar.gz

Download URL EEGRAPH-0.1.17.tar.gz
Size 36.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d2adf21226108291c77df2daddb333a1a2ca53fdd585beeaeae84873c01707b3
BLAKE2b-256 checksum
How to use checksums
8da00790037005b1bedd6dde5df2ad04bc9f82a7ceafd34e515ed1beba722895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release files / EEGRAPH-0.1.17-py3-none-any.whl

Download URL EEGRAPH-0.1.17-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c88bd13de8ee58edd0792c4557c642cb4ac40afe923c7e2e995a3781de05a09
BLAKE2b-256 checksum
How to use checksums
de264b274acfec3d118173d53b2ffb1202504050ce8095d71497d2da2c444b59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.12

Release history Release notifications | RSS feed

This release

0.1.17 This release

2 release files

0.1.16

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page