Skip to main content

natMEEG - Naturalistic M/EEG data analysis

natMEEG logo

PyPI version DOI

Formerly named pyEEG

natMEEG is a library for processing M/EEG data built mostly on top of MNE-Python and scikit-learn. It is designed for data collected with naturalistic stimuli, so it works with continuous recordings rather than trial-based designs. It supports analysis of continuous M/EEG and generation of temporal response functions from continuous signals or real-valued events (for example, word-level or phoneme-level features).

You can find the documentation here.

⚠️Note:

  • The library provides tools for computing TRFs (Temporal Response Functions) with the TRFEstimator class in pyeeg/models/, which implements memory-efficient and accelerated computation for handling multiple epochs or multiple subjects.
  • The project was formerly known as pyEEG and has been renamed natMEEG to better reflect its focus on naturalistic M/EEG data analysis.

Features

natMEEG provides tools across the full naturalistic M/EEG analysis pipeline:

  • Temporal Response Functions (TRF) — TRFEstimator (pyeeg.models) for memory-efficient, accelerated TRF estimation from continuous signals and real-valued event features, with ridge and robust Cauchy fitting, banded ridge (feature_alphas), sample weighting, and pluggable solvers.
  • Canonical Correlation Analysis — CCA_Estimator (pyeeg.cca) with lagged/regularized CCA and visualization; mCCA (pyeeg.mcca) for multiway CCA / hyperalignment preprocessing.
  • Connectivity — pyeeg.connectivity with Granger causality, phase transfer entropy (PTE), weighted phase lag index (wPLI), phase linearity measurement (PLM), and cross-spectral density.
  • Simulation — pyeeg.simulate with AR/VAR generation and neural-mass models (Hopf oscillator, Wilson–Cowan, Kuramoto, CTRNN, Jansen–Rit and its network extension) for generating synthetic coupled dynamics and TRF test data.
  • Feature extraction — pyeeg.features for aligning stimulus annotations (TextGrid), extracting LLM-derived features (surprisal, entropy, KL divergence; requires torch via the [features] extra), syntactic features (tree depth, opening, closing), dimensionality reduction, and end-to-end encoding pipelines.
  • Preprocessing — pyeeg.preprocess with Whitener (PCA/ZCA), WaveletTransform, MultichanWienerFilter, filterbanks, and covariance estimators.
  • VAR modeling — fit_ar / fit_var (pyeeg.models) for autoregressive and vector autoregressive coefficient estimation.
  • Visualization — pyeeg.vizu with topomaps, filterbank plots, TRF significance overlays, and pairwise boxplots.
  • IO — pyeeg.io for EEGLAB/FieldTrip → MNE conversion and aligned word-level feature handling.

See the documentation for full API reference. See the changelog for release history.


Installation

Dependencies

natMEEG requires:

  • Python (>= 3.10)
  • psutil
  • tqdm
  • NumPy
  • SciPy
  • scikit-learn
  • matplotlib
  • h5py
  • pandas
  • mne (>= 0.16) [optional]

To generate the doc, Python package sphinx (>= 1.1.0), sphinx_rtd_theme and nbsphinx are required.

User Installation

From PyPI

You can install the package from PyPI using pip:

pip install natmeeg

If you want to install docs building dependencies, you can do:

pip install natmeeg[docs]

If you want to install the package with all dependencies (including MNE), you can do:

pip install natmeeg[full]

From Source

If you prefer to install the package from source, you can clone the repository or download release archive or also use the source distribution (.tar.gz file from PyPi) and build it locally. There is a C-extension that needs to compile, so you need to have a C compiler installed on your machine.

From terminal, cd in root directory of the library after cloning this repository (directory containing pyproject.toml file).

To get the package installed only through symbolic links, namely so that you can modify the source code and use modified versions at will when importing the package in your python scripts do:

pip install -e .

Otherwise, for a standard installation, you can run:

pip install .

Windows Users

There are C-extensions in the library, so you need to have a C compiler installed on your machine. If the default compiler does not work, you can try to install Visual Studio Build Tools and try again.

Optionally try with MinGW, making sure after instalation of it to add the path to mingw/bin in your PATH environment variable. You can check if it is correctly installed by running the following command in your terminal:

gcc --version

If this build tool is available it should be detected during build process (running pip install ., pip install -e . or python -m build).

Usage

The most common usage of the library is to compute temporal response functions (TRF) from continuous M/EEG data. The library provides a TRFEstimator class that allows you to fit a TRF model to your data. The TRF model can be used to predict the M/EEG signal from a stimulus signal (e.g. a continuous audio signal or a sequence of word features):

from pyeeg import TRFEstimator

trf = TRFEstimator(tmin=-0.2, tmax=0.5, srate=fs, alpha=100.0) # TRF between -200ms and 500ms, regularization parameter alpha=100.0
trf.fit(X, y) # assuming data loaded: X is the stimulus signal, y is the M/EEG signal, they must have the same number of samples (rows)
print(trf.score(X, y)) # Normally you would use a separate test set for scoring
trf.plot() # plot the TRF

Choosing a Solver

The TRFEstimator auto-selects an appropriate solver by default (SVD-based ridge for regularized fits, ordinary least squares otherwise). For advanced use cases, any Solver subclass can be injected via the solver= parameter:

from pyeeg.solvers import SVDSolver, ConjugateGradientSolver, IRLSSolver

# Fast iterative solver (same results as SVD, often 10-50x faster)
trf = TRFEstimator(tmin=-0.2, tmax=0.5, srate=fs, alpha=100.0,
                   solver=ConjugateGradientSolver())

# Robust fitting with Cauchy loss (downweights outliers)
trf = TRFEstimator(tmin=-0.2, tmax=0.5, srate=fs, alpha=100.0,
                   solver=IRLSSolver(max_iter=50))

See scripts/examples/solver_showcase.py for a full comparison of all solvers.

Examples

See files in examples/.

Computing Envelope TRF and spatial map from CCA

See examples/CCA_envelope.ipynb

Computing Word-feature TRF

See examples/TRF_wordonsets.ipynb

Computing TRF from syntactic features

See examples/TRF_syntactic_feats.ipynb

Simulating TRF data

See examples/TRF_simulation_tutorial.ipynb

Working with Word vectors

See examples/import_WordVectors.ipynb

Documentation

You can generate an offline HTML version, or a PDF file of all the docs by following the following instructions (HTML pages are easier to navigate in and prettier than the PDF thanks to the nice theme brought by sphinx_rtd_theme).

Generate the documentation

To generate the documentation you will need sphinx to be installed in your Python environment, as well as the extension nbsphinx (for Jupyter Notebook integration) and the theme package sphinx_rtd_theme. Install those with:

pip install natMEEG[docs]

You can access the doc as HTML or PDF format. First get the source documentation files by cloning the repository or downloading the release archive. The documentation is located in the docs folder. To generate the documentation HTML pages, type in a terminal:

For Unix environment (from root directory, as it uses the Makefile):

make doc

For Windows environment (from docs folder, where make.bat is located):

cd docs
make.bat html

Then you can open the docs/build/html/index.html page in your favourite browser.

And for PDF version, simply use docpdf instead of doc above. Then open docs/build/latex/natMEEG.pdf in a PDF viewer.

Note: The PDF documentation can only be generated if latex and latxmk are present on the machine

To clean files created during build process (can be necessary to re-build the documentation):

make clean

License

This project is licensed under the terms of the GPL-3.0 license. See the LICENSE file for details.

Citation

DOI

Weissbart, H. Natmeeg - M/EEG Data Analysis in Naturalistic Context. 1.7.1, Zenodo, 24 Aug. 2026, https://doi.org/10.5281/zenodo.22081524.

Metadata

Release files for natmeeg 2.2.0

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

Source distribution (sdist)

Source distribution for natmeeg 2.2.0
File Size Uploaded
natmeeg-2.2.0.tar.gz 1.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for natmeeg 2.2.0
File
natmeeg-2.2.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
natmeeg-2.2.0-cp313-cp313-manylinux1_x86_64.manylinux_2_5_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.5+ x86-64 Details
natmeeg-2.2.0-cp313-cp313-macosx_10_13_universal2.whl CPython 3.13 CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64) Details
natmeeg-2.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
natmeeg-2.2.0-cp312-cp312-manylinux1_x86_64.manylinux_2_5_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.5+ x86-64 Details
natmeeg-2.2.0-cp312-cp312-macosx_10_13_universal2.whl CPython 3.12 CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64) Details
natmeeg-2.2.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
natmeeg-2.2.0-cp310-cp310-manylinux1_x86_64.manylinux_2_5_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.5+ x86-64 Details
natmeeg-2.2.0-cp310-cp310-macosx_10_9_universal2.whl CPython 3.10 CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) Details

Total release size: 9.9 MB

Release files / natmeeg-2.2.0.tar.gz

Download URL natmeeg-2.2.0.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
a5d34d0f0bfe5f4b8591b1be6e8b69a5a7a165f0ab2db28ad06da01138e0ee7f
BLAKE2b-256 checksum
How to use checksums
4e0ad5522d5ca82238a78b9dea611b6c994e61bef1915c56769f6f52392ac819
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp313-cp313-win_amd64.whl

Download URL natmeeg-2.2.0-cp313-cp313-win_amd64.whl
Size 961.1 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
73420362d3f6f63514e1a71e2bb465a5f2c7a4fb97dd9f24a99c74fcc4261c07
BLAKE2b-256 checksum
How to use checksums
48ab58ba2388c2cd8dc40d5762d1b1db6e905b71789bf072c1f9a718636f6106
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp313-cp313-manylinux1_x86_64.manylinux_2_5_x86_64.whl

Download URL natmeeg-2.2.0-cp313-cp313-manylinux1_x86_64.manylinux_2_5_x86_64.whl
Size 979.9 kB
Tags CPython 3.13 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
b1d0f0ecd7977b424ab248d78dc3149908b5071d5d08124461cd0d2b16f974a3
BLAKE2b-256 checksum
How to use checksums
427122c2c8995a6ea4e13f3d1bd383b326ca57ee4eb879c688956a4a2990cb20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp313-cp313-macosx_10_13_universal2.whl

Download URL natmeeg-2.2.0-cp313-cp313-macosx_10_13_universal2.whl
Size 960.9 kB
Tags CPython 3.13 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
f6ba27c27ac935e486493f5144d592d9a801ad8e0af0a765c80a9df2b8cc50f0
BLAKE2b-256 checksum
How to use checksums
fd364f359fbda29b93fe864803c27dc7258877c86c46b25d84cf1c57163346cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp312-cp312-win_amd64.whl

Download URL natmeeg-2.2.0-cp312-cp312-win_amd64.whl
Size 961.1 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
b2bfba8978e54064469402340dcaed9fee6d447f22054b161d1f4b9a6f07e5dc
BLAKE2b-256 checksum
How to use checksums
70363efa23e591736370b8088b5c46b76403af6e2d412b90674f0d0c0d385518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp312-cp312-manylinux1_x86_64.manylinux_2_5_x86_64.whl

Download URL natmeeg-2.2.0-cp312-cp312-manylinux1_x86_64.manylinux_2_5_x86_64.whl
Size 979.8 kB
Tags CPython 3.12 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
16a1e91ae3eb9a26fd2c9c67ad794ae48ce097ea0a4a8c1f6faa2f97682e9e81
BLAKE2b-256 checksum
How to use checksums
a77badf44367ae8e0336e314d12fc8a1b659dd3bfcc8cacba1a9a502566c6de2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp312-cp312-macosx_10_13_universal2.whl

Download URL natmeeg-2.2.0-cp312-cp312-macosx_10_13_universal2.whl
Size 960.9 kB
Tags CPython 3.12 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
876abfc3027f342e1512c2a1e7b62c03ce2fc816bac1d6259722913167395aaf
BLAKE2b-256 checksum
How to use checksums
4b72a0dccff5da28e35dc3150d1566f1574c61b70bc9a7c9cbbe59df1511e291
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp310-cp310-win_amd64.whl

Download URL natmeeg-2.2.0-cp310-cp310-win_amd64.whl
Size 961.1 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
734bf699e56c9a0bd9683be5cc83649357441c0e0450beb660a11b4e248b726d
BLAKE2b-256 checksum
How to use checksums
d61ad2568f6f6b051a347cf68119ba9efc18ea6acd5f0491bba232b7cf323806
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp310-cp310-manylinux1_x86_64.manylinux_2_5_x86_64.whl

Download URL natmeeg-2.2.0-cp310-cp310-manylinux1_x86_64.manylinux_2_5_x86_64.whl
Size 979.1 kB
Tags CPython 3.10 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
3965a22d94b032a4429ae35035f7004e90f223974f0bdadfd66d85913f137f64
BLAKE2b-256 checksum
How to use checksums
19239f459009261837b7342d168113ce71c7cd95bde160a1b86784adca4363c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / natmeeg-2.2.0-cp310-cp310-macosx_10_9_universal2.whl

Download URL natmeeg-2.2.0-cp310-cp310-macosx_10_9_universal2.whl
Size 960.8 kB
Tags CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
e084b004b1c2214610876bd1cee90a3e9f5541d658e2adb538bc62bcfee1eb3b
BLAKE2b-256 checksum
How to use checksums
de9fd57a5bb898f05b738ef837f0dd6ea056a630c26aa55d652a25d245a1bced
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

2.2.0 This release

10 release files

2.1.3

10 release files

2.1.2

10 release files

2.1.1

10 release files

2.1.0

10 release files

2.0.2

10 release files

2.0.1

10 release files

2.0.0

10 release files

1.7.1

10 release files

1.7.0

9 release files

1.6.8

10 release files

1.6.5

4 release files

1.6.4

4 release files

1.6.0

3 release files

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