Skip to main content

A library to process M/EEG data with a set of utility functions with a framework focused on continuous recordings and naturalistic stimuli.

Project description

natMEEG - Naturalistic M/EEG data analysis

PyPI version

v1.5.1 (2025-04-14)

Formerly named pyEEG

natMEEG is a library for processing M/EEG data built mostly on top of MNE-py and scikit-learn. It is framed to work with data collected with naturalistic stimuli, therefore with continuous recordings rather than trial-based designs. It allows analysis of continuous m/eeg and generation of temporal response functions with continuous signals as stimuli or real-valued events (e.g. word-level or phoneme-level features).

You can find the documentation here.

⚠️Caution:

  • Note that this code repository is relatively old and unmaintained. Most useful code about computing TRF is contained in pyeeg/models.py, especially in the class TRFEstimator and the function _svd_regress: the latter implements TRF estimation with memory efficient and accelerated computation for handling multiple epochs or multiple subjects.
  • It is recommended to use the code as a reference for your own implementation rather than relying on it for production use.
  • Finaly note that the repository went through a name change from pyEEG to natMEEG, so you might find references to pyEEG in the code and documentation.

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
print(trf.score(X, y)) # Normally you would use a separate test set for this, but here we use the same data for simplicity
trf.plot() # plot the TRF

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

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/pyEEG.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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

natmeeg-1.6.8.tar.gz (274.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

natmeeg-1.6.8-cp313-cp313-win_amd64.whl (145.5 kB view details)

Uploaded CPython 3.13Windows x86-64

natmeeg-1.6.8-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.whl (159.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.5+ x86-64

natmeeg-1.6.8-cp313-cp313-macosx_10_13_universal2.whl (141.9 kB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

natmeeg-1.6.8-cp312-cp312-win_amd64.whl (145.5 kB view details)

Uploaded CPython 3.12Windows x86-64

natmeeg-1.6.8-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.whl (159.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.5+ x86-64

natmeeg-1.6.8-cp312-cp312-macosx_10_13_universal2.whl (141.9 kB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

natmeeg-1.6.8-cp310-cp310-win_amd64.whl (145.5 kB view details)

Uploaded CPython 3.10Windows x86-64

natmeeg-1.6.8-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl (159.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.5+ x86-64

natmeeg-1.6.8-cp310-cp310-macosx_10_9_universal2.whl (142.0 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file natmeeg-1.6.8.tar.gz.

File metadata

  • Download URL: natmeeg-1.6.8.tar.gz
  • Upload date:
  • Size: 274.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for natmeeg-1.6.8.tar.gz
Algorithm Hash digest
SHA256 4499dab58d8f70944205a2f69304c36d91a8ea1b9449126b46098a5b823b94f0
MD5 8ca2b60d6ce9ebf1f92de7bd781f2da0
BLAKE2b-256 493d7a3a31cd9472942abed30bf051d98b59ed19a4bd93fcf7a04858d9996634

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: natmeeg-1.6.8-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 145.5 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for natmeeg-1.6.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 704b9aa7a56f5166a68939b6d8948b7adbbd2aa2588f5a63f80ff09619f6ef8b
MD5 f959a4d1cd23c39b65b8780c9aaaae8d
BLAKE2b-256 8cc3e9f0a46ba59478e25873dd97b4e3938f2a4f7dae5d2218f9368f1c43cba5

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for natmeeg-1.6.8-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 58604b535b49cac0169ce23ad9f60698b3eeed0e17f79a706b0170ff22b92e88
MD5 0522fbd86f9aa75a9ce857861f4281e5
BLAKE2b-256 40b4e94dab94db40ed0e29ac2ebfd6637b9b0e7e29ac8697cffa8cda243c8a09

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for natmeeg-1.6.8-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 79c684bb0383cabe2c3e3f7de2c527823fce25ac5aad838469d47ca1f98f76f2
MD5 8c8c3912bbc21546b51c23d2447fd157
BLAKE2b-256 8da49ab9176fe4a9c9ca3f2bb76f2caaf3a8fca8b89aa338437b53bec292e91a

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: natmeeg-1.6.8-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 145.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for natmeeg-1.6.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1d6fb3252da696693c817a8dae4824fa64505342326aea7806f95d32b7f4860e
MD5 cdc874f4e5075544d583ecbffce19539
BLAKE2b-256 c18861427dc062101e70999b0bc68f85bf496b90a4604fb5953856c67be25879

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for natmeeg-1.6.8-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 62827308921ad0639c3649e62664f8b5ef166c47e72a4d804ec5f31085c6e4cd
MD5 56f0aededafd04205dbbd9d4c2b8221f
BLAKE2b-256 c6b6c392c376ce2ed9f83f5f718a46bd9694d27cb5ab55f1a3d0f6c1eaf67678

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for natmeeg-1.6.8-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 5d198a4e0cc42ed90a5fd56ed94fd7bf0758c8cdbafdd697f127545f30777af7
MD5 255723ef24b8ee164126ea5ae3dd1ef0
BLAKE2b-256 0481b43e7f490cc06e1bdf436a720ce672ccdd74c9f7a29e4ba9d70399a9d7d0

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: natmeeg-1.6.8-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 145.5 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for natmeeg-1.6.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8b5eabd1d1d485774d4ad4573a7e93a66383a6c274cb5463b894397f966ee131
MD5 5d503130ec910be488f45f4ed9318d6b
BLAKE2b-256 d8e8b1db8aae3458f0c80796e7a675dcf6316cf7ce2a740d09b1c1b8ec3539e4

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for natmeeg-1.6.8-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3f5478bb911a3f779100fb39e4a38b5751b4b7e54fedc9cc184e75bdf4182814
MD5 7eefac6cb7a2d726ce4adaa65026fd5b
BLAKE2b-256 2474f36b6a42672f889d5c69c03221131f7b7d7931718ee95045ac2c0a87f812

See more details on using hashes here.

File details

Details for the file natmeeg-1.6.8-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for natmeeg-1.6.8-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 d250100a254805b524a928de47e38d595cabfcd1371824d8b1c1c9752116dc68
MD5 7cf253d7a12d4fbbcfbf2941710bb3c4
BLAKE2b-256 1f4fb153136a840ca759ce9f3acf42b11fdda0685836626736d3edf479c56e1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page