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), 
                    psd_kwargs={'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. SOME JOURNAL THAT LIKES US

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.0.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.0-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyrasa-1.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 5aa8de5ef9e7cef46ab1388dae8ffb480fbdb1082bd846db40cf2cf1bcc3f185
MD5 6daf9fa057a4878233c0bf26271a15a9
BLAKE2b-256 863816dfc92a67126a59f8fcda0f47f6ef1f0a3e6e4088cbb96e64e736e305ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrasa-1.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: pyrasa-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e5d2fd3992bbb1b6eec2e2208afe751a3c8e3632690e77bf86f4f5de8b4bf08
MD5 92fff8f7c1304ff980b4a3893e9c3400
BLAKE2b-256 ba5e905cfc5b2f523a977b3ab092560be923b956a2c65eea0bafd88212f916ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrasa-1.1.0-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