Skip to content

Reusable EEG processing and analysis package built with MNE-Python during an end-of-study internship at CRPN Marseille 2025

Notifications You must be signed in to change notification settings

Dewmith/mnedisc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Signal Processing with MNE Python

🧠 Introduction

This repository provides a modular and reusable pipeline for preprocessing and analyzing EEG (Electroencephalography) data using MNE-Python. Developed as part of a project within the DIΒ²SΒ²C unit at the CRPN research center, this package is designed to streamline EEG workflowsβ€”from raw signal cleaning to power spectral analysis and condition-based statistical comparisons.

The goal is to address a common limitation in EEG research: the lack of standardized, flexible pipelines that can adapt to different experiments while maintaining reproducibility. This tool supports:

  • Event-based preprocessing with filtering, ICA, and epoching
  • Condition-wise power spectral density (PSD) computation
  • Group-level statistical contrasts with cluster-based permutation testing
  • SLURM-compatible execution for high-performance computing environments

Whether you're working on cognitive neuroscience, clinical EEG, or mental imagery experiments, this pipeline provides a solid foundation for scalable, interpretable EEG data analysis.

πŸš€ How to Install

To install the package, we will create a python virtual environment. It is an important tool for anyone developing code in Python. It makes defining and managing code that depends on multiple software packages easier to install by preventing software conflicts, it can also help performing tests, debugging, and collaborating with other developers.

For the creation of python virtual environment and installation of the MNE package, we will be using a python package called UV. It is a single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more. It allows the installation of packages while automatically checking and installing the dependencies (and recursively for sub-packages). Hence, speeding up installations of main packages such as MNE which uses approximately 60 - 100 sub-packages depending on the requirement (signal processing, visualization, etc.), which would require manual operations if UV was not used.

1. πŸ“₯ Download the Package

Download the latest release of the mnedisc package from the dev_mith/hands_on branch of the MNEDISC project.

How to download?

  1. On the repository page, click the blue Code button (top-right).
  2. In the dropdown, click Download ZIP.
  3. Once downloaded, unzip the archive.
  4. Rename the folder from mnedsic-dev_mith/hands_on to mnedsic.
  5. Place the mnedsic folder in your working directory (for example: desktop/mnedisc).

You can now continue with Step 2 to create and activate the virtual environment inside this folder.

2. πŸ”§ Install UV

Open your terminal and run the following commands based on your operating system:

🍎🐧 MAC/LINUX With curl

curl -LsSf https://astral.sh/uv/install.sh | sh

🍎🐧 MAC/LINUX With wget

wget -qO- https://astral.sh/uv/install.sh | sh

πŸͺŸ Windows

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

3. πŸ“ Move to the working folder

cd mnedisc

4. Install the custom virtual environment named .mnedisc_venv with Python version 3.12.7

uv venv .mnedisc_venv --python 3.12.7

πŸ› οΈ Troubleshooting uv not found

🍎🐧 Mac/Linux

Add uv to your system PATH so it can be accessed from any terminal session.

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc

5. πŸ”‹ Activating the venv

🍎🐧 Mac/Linux

source .mnedisc_venv/bin/activate

πŸͺŸ Windows

.mnedisc_venv\Scripts\activate

6. πŸ“¦ Installing the dependencies

uv pip install -r requirements.txt

πŸ› οΈ Troubleshooting

πŸ› οΈ Troubleshooting on macOS 🍎

CMake Not Installed

Some dependencies (for example, MNE or NumPy builds) require CMake.
If you see errors like this during installation:

CMake is required to build some of the extensions

Install CMake using Homebrew:

brew install cmake

After installation, try running the dependency installation again:

uv pip install -r requirements.txt

⚠️ Typer Installation Warning (Can Be Ignored)

When using uv to install dependencies, you might see this warning during installation:

warning: The package typer==0.15.2 does not have an extra named all

This happens because uv may internally reference an optional extras group (typer[all]) that no longer exists in version 0.15.2.

βœ… You can safely ignore this warning. Typer and other required dependencies will still install correctly.

7. πŸ§ͺ Run Environment Test

python test_venv.py

8. βœ… If all tests pass, you are ready to officially install the custom MNEDISC package😈!

uv pip install -e .

Test the package installation

uv pip show mnedisc

9. Ensure the config files are placed at the correct directories and the variables are set as desired with the help of:

πŸ“„ Config Template README

10. Ensure the data is structured in BIDS format. Help on how to prepare the data can be found here:

πŸ“„ Data Preparation Guide

11. Run the Preprocessing Pipeline

python main_python_scripts/main_Pre_processing.py

12. Run the Analysis Pipeline

python main_python_scripts/main_Analysis.py

πŸ’‘ Tip: To deactivate the virtual environment enter: deactivate

⚑ Running on Cluster

To speed up processing, especially when handling multiple EEG subjects or running computationally intensive statistical analysis, you can execute the pipeline on a computing cluster using SLURM job scheduling.

Cluster execution allows:

  • Parallel subject-wise preprocessing using job arrays
  • Efficient use of CPU and memory resources

βœ… Important: Before running these scripts on the cluster, make sure you have cloned this repository on the cluster or recreated the same directory structure as your local setup.

13. Continue below for details on how to configure .slurm files:

πŸ“„ Config Template for .slurm

14. Run the Preprocessing Pipeline on Cluster

sbatch main_python_scripts/run_eeg_pre_processing.slurm

πŸ’‘ Note: Results saved in main_python_scripts/Cluster_Logs/Pre_processing_logs/logs

15. Run the Analysis Pipeline Cluster

sbatch main_python_scripts/run_eeg_analysis.slurm

πŸ’‘ Note: Results saved in main_python_scripts/Cluster_Logs/Analysis_logs/logs

πŸ’‘ Tip: Check the batch status with the keyword: squeue

License

This software is distributed under the terms of the GNU General Public License as published by the Free Software Foundation. Further details on the GPLv3 license can be found at http://www.gnu.org/copyleft/gpl.html.

FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND IN THE HOPE THAT IT WILL BE USEFUL BUT WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.

Authors: Anne-Sophie Dubarry, Dewmith WEERASENA

Copyright Image

About

Reusable EEG processing and analysis package built with MNE-Python during an end-of-study internship at CRPN Marseille 2025

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •