Skip to main content

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.

Metadata

Release files for PyRASA 1.1.1

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

Source distribution (sdist)

Source distribution for PyRASA 1.1.1
File Size Uploaded
pyrasa-1.1.1.tar.gz 3.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyRASA 1.1.1
File Interpreter ABI Platform
pyrasa-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 3.6 MB

Release files / pyrasa-1.1.1.tar.gz

Download URL pyrasa-1.1.1.tar.gz
Size 3.6 MB
Tags Source
SHA-256 checksum
How to use checksums
d76df78eae4cfb04998fb0fd68edca4208b580f077900036f22ac18cb83e5c68
BLAKE2b-256 checksum
How to use checksums
a5886b6000caa836b9c478c0609b76ecfb9118ae5ba442c5572e425335134012
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 2, 2025.

Transparency log

Release files / pyrasa-1.1.1-py3-none-any.whl

Download URL pyrasa-1.1.1-py3-none-any.whl
Size 43.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12d4bd20cffbc70169c45373cb8444ef656e5efa2d9543c085b5ed417712048a
BLAKE2b-256 checksum
How to use checksums
2a3a1f099e3cba6adceae885619047323d155971fab4c39c5d4826bc128e32fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 2, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 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