Skip to main content

Spectral parameterization.

Project description

ProjectStatus Version BuildStatus Coverage License PythonVersions Paper

Spectral parameterization (specparam, formerly fooof) is a fast, efficient, and physiologically-informed tool to parameterize neural power spectra.

WARNING: this Github repository has been updated to a major update / breaking change from previous releases, which were under the fooof name, and now contains major breaking update for the new specparam version of the code. The new version is not fully released, though a test version is available (see installation instructions below).

Overview

The power spectrum model conceives of a model of the power spectrum as a combination of two distinct functional processes:

  • An aperiodic component, reflecting 1/f like characteristics, with

  • A variable number of periodic components (putative oscillations), as peaks rising above the aperiodic component

This model driven approach can be used to measure periodic and aperiodic properties of electrophysiological data, including EEG, MEG, ECoG and LFP data.

The benefit of fitting a model in order to measure putative oscillations, is that peaks in the power spectrum are characterized in terms of their specific center frequency, power and bandwidth without requiring predefining specific bands of interest and controlling for the aperiodic component. The model also returns a measure of this aperiodic components of the signal, allowing for measuring and comparison of 1/f-like components of the signal within and between subjects.

specparam (upcoming version)

We are currently in the process of a major update to this tool, that includes a name changes (fooof -> specparam), and full rewrite of the code. This means that the new version will be incompatible with prior versions (in terms of the code having different names, and previous code no longer running as written), though note that the exact same procedures will be available (spectra can be fit in a way expected to give the same results), as well many new features.

The new version is called specparam (spectral parameterization). There is a release candidate available for testing (see installation instructions).

fooof (stable version)

The fooof naming scheme, with most recent stable version 1.1 is the current main release, and is fully functional and stable, including everything that was introduced under the fooof name.

Which version should I use?

The previous release version, fooof, is fully functional, and projects that are already using it might as well stick with that, unless any of the new functionality in specparam is particularly important. For projects that are just starting, the new specparam version may be of interest if some of the new features are of interest (e.g. time-resolved estimations), though note that as release candidates, the release are not guaranteed to be stable (future updates may make breaking changes). Note that for the same model and settings, fooof and specparam should be exactly equivalent, so in terms of outputs there should be no difference in choosing one or the other.

Documentation

The specparam package includes a full set of code documentation.

specparam (upcoming version)

To see the documentation for the candidate 2.0 release, see here.

fooof (stable version)

Documentation is available on the documentation site.

This documentation includes:

  • Motivations: with motivating examples of why we recommend parameterizing neural power spectra

  • Tutorials: with a step-by-step guide through the model and how to apply it

  • Examples: demonstrating example analyses and use cases, and other functionality

  • API list: which lists and describes all the code and functionality available in the module

  • FAQ: answering frequency asked questions

  • Glossary: which defines all the key terms used in the module

  • Reference: with information for how to reference and report on using the module

Dependencies

specparam is written in Python, and requires Python >= 3.7 to run.

It has the following required dependencies:

There are also optional dependencies, which are not required for model fitting itself, but offer extra functionality:

  • matplotlib is needed to visualize data and model fits

  • tqdm is needed to print progress bars when fitting many models

  • pandas is needed for exporting model fit results to dataframes

  • pytest is needed to run the test suite locally

We recommend using the Anaconda distribution to manage these requirements.

Installation

specparam / fooof can be installed using pip.

specparam (test version)

To install the current release candidate version for the new 2.0 version, you can do:

$ pip install specparam

The above will install the most recent release candidate.

NOTE: specparam is currently available as a ‘release candidate’, meaning it is not finalized and fully released yet. This means it may not yet have all features that the ultimate 2.0 version will include, and things are not strictly guaranteed to stay the same (there may be further breaking changes in the ultimate 2.0 release).

fooof (stable version)

The current major release is the 1.X.X series, which is a breaking change from the prior 0.X.X series.

Check the changelog for notes on updating to the new version.

Stable Version

To install the latest stable release, use pip:

$ pip install fooof

The module can also be installed with conda, from the conda-forge channel:

$ conda install -c conda-forge fooof

Development Version

To get the current development version, first clone this repository:

$ git clone https://github.com/fooof-tools/fooof

To install this cloned copy, move into the directory you just cloned, and run:

$ pip install .

Editable Version

To install an editable version, download the development version as above, and run:

$ pip install -e .

Other Language Support

The original implementation of specparam, available in this repository, is implemented in Python.

If you wish to run specparam from another language, there are a couple potential options:

  • a wrapper, which allows for running the Python code from another language

  • a reimplementation, which reflects a new implementation of the specparam algorithm in another language

Below are listed some examples of wrappers and/or re-implementations in other languages (non-exhaustive).

Matlab

In Matlab, there is a reimplementation available in common toolboxes: - The Brainstorm toolbox has a reimplementation of specparam (see the Brainstorm fooof tutorial) - The Fieldtrip toolbox also uses the same reimplementation (see the Fieldtrip fooof tutorial)

There is also a Matlab wrapper in the fooof_mat repository.

Note that another option is to use Python FOOOF within a Matlab pipeline, as explored in the mat_py_mat repository.

Other Languages

Other languages with wrappers include:

Reference

If you use this code in your project, please cite:

Donoghue T, Haller M, Peterson EJ, Varma P, Sebastian P, Gao R, Noto T, Lara AH, Wallis JD,
Knight RT, Shestyuk A, & Voytek B (2020). Parameterizing neural power spectra into periodic
and aperiodic components. Nature Neuroscience, 23, 1655-1665.
DOI: 10.1038/s41593-020-00744-x

Direct link: https://doi.org/10.1038/s41593-020-00744-x

More information for how to cite this method can be found on the reference page.

Code and analyses from the paper are also available in the paper repository.

Contribute

This project welcomes and encourages contributions from the community!

To file bug reports and/or ask questions about this project, please use the Github issue tracker.

To see and get involved in discussions about the module, check out:

  • the issues board for topics relating to code updates, bugs, and fixes

  • the development page for discussion of potential major updates to the module

When interacting with this project, please use the contribution guidelines and follow the code of conduct.

Quickstart

This module is object oriented, and uses a similar approach as used in scikit-learn.

The algorithm works on frequency representations, that is power spectra in linear space.

Fitting a Single Power Spectrum

With a power spectrum loaded (with ‘freqs’ storing frequency values, and ‘spectrum’ storing the power spectrum, both as 1D arrays in linear space) parameterization can be done as follows:

# Import the model object
from specparam import SpectralModel

# Initialize model object
fm = SpectralModel()

# Define frequency range across which to model the spectrum
freq_range = [3, 40]

# Parameterize the power spectrum, and print out a report
fm.report(freqs, spectrum, freq_range)

SpectralModel.report() fits the model, plots the original power spectrum with the associated model fit, and prints out the parameters of the model fit for both the aperiodic component, and parameters for any identified peaks, reflecting periodic components.

Example output for the report of a parameterized fit on an individual power spectrum:

https://raw.githubusercontent.com/fooof-tools/fooof/main/doc/img/FOOOF_report.png

Defining the model Settings

The settings for the algorithm are:

  • peak_width_limits sets the possible lower- and upper-bounds for the fitted peak widths.

  • max_n_peaks sets the maximum number of peaks to fit.

  • min_peak_height sets an absolute limit on the minimum height (above aperiodic) for any extracted peak.

  • peak_threshold sets a relative threshold above which a peak height must cross to be included in the model.

  • aperiodic_mode defines the approach to use to parameterize the aperiodic component.

These settings can be defined when initializing the model, for example:

# Initialize a model object with defined settings
fm = SpectralModel(peak_width_limits=[1.0, 8.0], max_n_peaks=6, min_peak_height=0.1,
                   peak_threshold=2.0, aperiodic_mode='fixed')

Fitting a Group of Power Spectra

Next is an example workflow for fitting a group of neural power spectra. In this case, ‘freqs’ is again a 1D array of frequency values, and ‘spectra’ is a 2D array of power spectra. We can fit the group of power spectra by doing:

# Initialize a SpectralGroupModel object, specifying some parameters
fg = SpectralGroupModel(peak_width_limits=[1.0, 8.0], max_n_peaks=8)

# Fit models across the matrix of power spectra
fg.fit(freqs, spectra)

# Create and save out a report summarizing the results across the group of power spectra
fg.save_report()

# Save out results for further analysis later
fg.save(file_name='group_results', save_results=True)

Example output from using SpectralGroupModel across a group of power spectra:

https://raw.githubusercontent.com/fooof-tools/fooof/main/doc/img/FOOOFGroup_report.png

Other Functionality

The module also includes functionality for fitting the model to matrices of multiple power spectra, saving and loading results, creating reports describing model fits, analyzing model outputs, plotting models and parameters, and simulating power spectra, all of which is described in the documentation.

Funding

Supported by NIH award R01 GM134363 from the NIGMS.

https://www.nih.gov/sites/all/themes/nih/images/nih-logo-color.png

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

specparam-2.0.0rc2.tar.gz (128.2 kB view details)

Uploaded Source

Built Distribution

specparam-2.0.0rc2-py3-none-any.whl (167.8 kB view details)

Uploaded Python 3

File details

Details for the file specparam-2.0.0rc2.tar.gz.

File metadata

  • Download URL: specparam-2.0.0rc2.tar.gz
  • Upload date:
  • Size: 128.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.3

File hashes

Hashes for specparam-2.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 ea9a38ad8b698ebf076433b0955996b4295aa7354df83925507c00431654d619
MD5 d4828eb0f0738c5ca29422cfa4a8c761
BLAKE2b-256 5af10406e3984e0923076310161fa2a3ff8df0e93a755f18a470ae9565c3e81c

See more details on using hashes here.

File details

Details for the file specparam-2.0.0rc2-py3-none-any.whl.

File metadata

  • Download URL: specparam-2.0.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 167.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.3

File hashes

Hashes for specparam-2.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 8e3961813c14f893728aa8380e5c77b7c55b26ac95ab3ee11a912b91b0004bbd
MD5 95bb5c28e439209480e13c1c57971737
BLAKE2b-256 fb8dd71d6108f14c13999be642ffa18582481f36264cfcd2121471b5571fc97f

See more details on using hashes here.

Supported by

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