Skip to main content

Spectral parametrization based on IRASA

Project description

PyRASA - Spectral parametrization in python based on IRASA

Project Status: Active – The project has reached a stable, usable state and is being actively developed. License Checked with mypy Coverage Status

PyRASA is a Python library designed to separate and parametrize aperiodic (fractal) and periodic (oscillatory) components in time series data based on the IRASA algorithm (Wen & Liu, 2016).

Features

  • Aperiodic and Periodic Decomposition: Utilize the IRASA algorithm to decompose power spectra into aperiodic and periodic components, enabling better interpretation of neurophysiological signals.
  • Time Resolved Spectral Parametrization: Perform time resolved spectral parametrizazion, allowing you to track changes in spectral components over time.
  • Support for Raw and Epoched MNE Objects: PyRASA provides functions designed for both continuous (Raw) and event-related (Epochs) data, making it versatile for various types of EEG/MEG analyses.
  • Consistent Ontology: PyRASA uses the same jargon to label parameters as specparam, the most commonly used tool to parametrize power spectra, to allow users to easily switch between tools depending on their needs, while keeping the labeling of features consistent.
  • Custom Aperiodic Fit Models: In addition to the built-in "fixed" and "knee" models for aperiodic fitting, users can specify their custom aperiodic fit functions, offering flexibility in how aperiodic components are modeled.

Documentation

Documentation for PyRASA, including detailed descriptions of functions, parameters, and tutorials is available here.

Installation

To install the latest stable version of PyRASA, you can soon use pip:

$ pip install pyrasa

or conda

$ conda install -c conda-forge pyrasa 

Dependencies

PyRASA has the following dependencies:

  • Core Dependencies:

  • Optional Dependencies for Full Functionality:

    • mne: Required for directly working with EEG/MEG data in Raw or Epochs formats.

Example Usage

Decompose spectra in periodic and aperiodic components If you want to reproduce the example below checkout example

from pyrasa.irasa import irasa

irasa_out = irasa(sig, 
                    fs=fs, 
                    band=(.1, 200), 
                    nperseg=duration*fs, 
                    noverlap=duration*fs*overlap,
                    hset_info=(1, 2, 0.05))

image info

Extract periodic parameters

irasa_out.get_peaks()
ch_name cf bw pw
0 10.0 1.1887 0.4950

Extract aperiodic parameters

irasa_out.fit_aperiodic_model(fit_func='knee').aperiodic_params
Offset Knee Exponent_1 Exponent_2 fit_type Knee Frequency (Hz) tau ch_name
4.3299e-17 62.1060 0.0552 1.4602 knee 13.8547 0.0115 0

And the goodness of fit

irasa_out.fit_aperiodic_model(fit_func='knee').gof
mse r_squared BIC AIC fit_type ch_name
0.000088 0.999303 -31.9892 -47.9550 knee 0

How to Contribute

Contributions to PyRASA are welcome! Whether it's raising issues, improving documentation, fixing bugs, or adding new features, your help is appreciated.

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

Please refer to the CONTRIBUTING.md file for more information on how to get involved.

Reference

If you are using IRASA please cite the smart people who came up with the algorithm:

Wen, H., & Liu, Z. (2016). Separating fractal and oscillatory components in the power spectrum of neurophysiological signal. Brain topography, 29, 13-26. https://doi.org/10.1007/s10548-015-0448-0

If you are using PyRASA it would be nice, if you could additionally cite us (whenever the paper is finally ready):

Schmidt F., Hartmann T., & Weisz, N. (2025). PyRASA - Spectral parametrization in python based on IRASA.

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

pyrasa-1.1.1.tar.gz (3.6 MB view details)

Uploaded Source

Built Distribution

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

pyrasa-1.1.1-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

Details for the file pyrasa-1.1.1.tar.gz.

File metadata

  • Download URL: pyrasa-1.1.1.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyrasa-1.1.1.tar.gz
Algorithm Hash digest
SHA256 d76df78eae4cfb04998fb0fd68edca4208b580f077900036f22ac18cb83e5c68
MD5 356fe07ff624f693a44920ab08768ecb
BLAKE2b-256 a5886b6000caa836b9c478c0609b76ecfb9118ae5ba442c5572e425335134012

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrasa-1.1.1.tar.gz:

Publisher: test.yml on schmidtfa/pyrasa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrasa-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyrasa-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 43.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyrasa-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12d4bd20cffbc70169c45373cb8444ef656e5efa2d9543c085b5ed417712048a
MD5 78e069c468f5399f5c531e0360bbc157
BLAKE2b-256 2a3a1f099e3cba6adceae885619047323d155971fab4c39c5d4826bc128e32fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrasa-1.1.1-py3-none-any.whl:

Publisher: test.yml on schmidtfa/pyrasa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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