PyRASA


NamePyRASA JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummarySpectral parametrization based on IRASA
upload_time2024-10-09 10:47:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseBSD-3-Clause
keywords 1/f oscillations power spectra spectral parametrization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # PyRASA - Spectral parameterization in python based on IRASA

[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![License](https://img.shields.io/badge/License-BSD_2--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
[![Coverage Status](https://coveralls.io/repos/github/schmidtfa/pyrasa/badge.svg?branch=main)](https://coveralls.io/github/schmidtfa/pyrasa?branch=main)


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](https://schmidtfa.github.io/pyrasa/index.html).


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

```bash
$ pip install pyrasa
```

or conda

```bash
$ conda install pyrasa 
```

### Dependencies

PyRASA has the following dependencies:
- **Core Dependencies:**
  - [numpy](https://github.com/numpy/numpy)
  - [scipy](https://github.com/scipy/scipy)
  - [pandas](https://github.com/pandas-dev/pandas)

- **Optional Dependencies for Full Functionality:**
  - [mne](https://github.com/mne-tools/mne-python): Required for directly working with EEG/MEG data in `Raw` or `Epochs` formats.


### Example Usage

Decompose spectra in periodic and aperiodic ccomponents

```python
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](./simulations/example_knee.png)

Extract periodic parameters

```python

irasa_out.get_peaks()

```
|   ch_name |   cf |      bw |     pw |
|----------:|-----:|--------:|-------:|
|         0 |  9.5 | 1.4426 | 0.4178 |

Extract aperiodic parameters

```python

irasa_out.fit_aperiodic_model(fit_func='knee').aperiodic_params

```

|   Offset |   Knee |   Exponent_1 |   Exponent_2 | fit_type   |   Knee Frequency (Hz) |   tau |   ch_name |
|---------:|-------:|-------------:|-------------:|:-----------|----------------------:|----------:|----------:|
|  	1.737402e-16 | 60.942144 |     0.039556 |      1.472746	 | knee       |               14.131277 |         0.011263 |         0 |

And the goodness of fit

```python

irasa_out.fit_aperiodic_model(fit_func='knee').gof

```

|         mse |   r_squared |      BIC |      AIC | fit_type   |   ch_name |
|------------:|------------:|---------:|---------:|:-----------|----------:|
| 0.000051 |    0.999751 | -3931.840246 | -3947.806104 | 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](https://github.com/schmidtfa/pyrasa/issues).

Please refer to the [CONTRIBUTING.md](https://github.com/schmidtfa/pyrasa/blob/main/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. (2049). PyRASA - Spectral parameterization in python based on IRASA. SOME JOURNAL THAT LIKES US
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "PyRASA",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "1/f, oscillations, power spectra, spectral parametrization",
    "author": null,
    "author_email": "Fabian Schmidt <schmidtfa91@gmail.com>, Thomas Hartmann <thomas.hartmann@th-ht.de>",
    "download_url": "https://files.pythonhosted.org/packages/b7/dd/3a5cbf0afc94c3175c10508d6835084ee298162e75f1bb5bd73d8cecb655/pyrasa-1.0.0.tar.gz",
    "platform": null,
    "description": "# PyRASA - Spectral parameterization in python based on IRASA\n\n[![Project Status: WIP \u2013 Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)\n[![License](https://img.shields.io/badge/License-BSD_2--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause)\n[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n[![Coverage Status](https://coveralls.io/repos/github/schmidtfa/pyrasa/badge.svg?branch=main)](https://coveralls.io/github/schmidtfa/pyrasa?branch=main)\n\n\nPyRASA 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).\n\n### Features\n- **Aperiodic and Periodic Decomposition:** Utilize the IRASA algorithm to decompose power spectra into aperiodic and periodic components, enabling better interpretation of neurophysiological signals.\n- **Time Resolved Spectral Parametrization:** Perform time resolved spectral parametrizazion, allowing you to track changes in spectral components over time.\n- **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.\n- **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.\n- **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.\n\n\n## Documentation\nDocumentation for PyRASA, including detailed descriptions of functions, parameters, and tutorials is available [here](https://schmidtfa.github.io/pyrasa/index.html).\n\n\n### Installation\nTo install the latest stable version of PyRASA, you can soon use pip:\n\n```bash\n$ pip install pyrasa\n```\n\nor conda\n\n```bash\n$ conda install pyrasa \n```\n\n### Dependencies\n\nPyRASA has the following dependencies:\n- **Core Dependencies:**\n  - [numpy](https://github.com/numpy/numpy)\n  - [scipy](https://github.com/scipy/scipy)\n  - [pandas](https://github.com/pandas-dev/pandas)\n\n- **Optional Dependencies for Full Functionality:**\n  - [mne](https://github.com/mne-tools/mne-python): Required for directly working with EEG/MEG data in `Raw` or `Epochs` formats.\n\n\n### Example Usage\n\nDecompose spectra in periodic and aperiodic ccomponents\n\n```python\nfrom pyrasa.irasa import irasa\n\nirasa_out = irasa(sig, \n                    fs=fs, \n                    band=(.1, 200), \n                    psd_kwargs={'nperseg': duration*fs, \n                                'noverlap': duration*fs*overlap\n                                },\n                    hset_info=(1, 2, 0.05))\n\n```\n\n![image info](./simulations/example_knee.png)\n\nExtract periodic parameters\n\n```python\n\nirasa_out.get_peaks()\n\n```\n|   ch_name |   cf |      bw |     pw |\n|----------:|-----:|--------:|-------:|\n|         0 |  9.5 | 1.4426 | 0.4178 |\n\nExtract aperiodic parameters\n\n```python\n\nirasa_out.fit_aperiodic_model(fit_func='knee').aperiodic_params\n\n```\n\n|   Offset |   Knee |   Exponent_1 |   Exponent_2 | fit_type   |   Knee Frequency (Hz) |   tau |   ch_name |\n|---------:|-------:|-------------:|-------------:|:-----------|----------------------:|----------:|----------:|\n|  \t1.737402e-16 | 60.942144 |     0.039556 |      1.472746\t | knee       |               14.131277 |         0.011263 |         0 |\n\nAnd the goodness of fit\n\n```python\n\nirasa_out.fit_aperiodic_model(fit_func='knee').gof\n\n```\n\n|         mse |   r_squared |      BIC |      AIC | fit_type   |   ch_name |\n|------------:|------------:|---------:|---------:|:-----------|----------:|\n| 0.000051 |    0.999751 | -3931.840246 | -3947.806104 | knee       |         0 |\n\n\n### How to Contribute\n\nContributions to PyRASA are welcome! Whether it's raising issues, improving documentation, fixing bugs, or adding new features, your help is appreciated. \n\nTo file bug reports and/or ask questions about this project, please use the [Github issue tracker](https://github.com/schmidtfa/pyrasa/issues).\n\nPlease refer to the [CONTRIBUTING.md](https://github.com/schmidtfa/pyrasa/blob/main/CONTRIBUTING.md) file for more information on how to get involved.\n\n\n### Reference\n\nIf you are using IRASA please cite the smart people who came up with the algorithm:\n\nWen, 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\n\nIf you are using PyRASA it would be nice, if you could additionally cite us (whenever the paper is finally ready):\n\nSchmidt F., Hartmann T., & Weisz, N. (2049). PyRASA - Spectral parameterization in python based on IRASA. SOME JOURNAL THAT LIKES US",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Spectral parametrization based on IRASA",
    "version": "1.0.0",
    "project_urls": {
        "repository": "https://github.com/schmidtfa/pyrasa"
    },
    "split_keywords": [
        "1/f",
        " oscillations",
        " power spectra",
        " spectral parametrization"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50e47769338f87ea51e599856d07eb0049d757745d53f9fbbd166255bf0fd74b",
                "md5": "00a38323a8323f0e828dc2395ee53066",
                "sha256": "dd981129fa71d409883ca9ad88a23b9646684b0be0cbe2f8944a54036895ee3b"
            },
            "downloads": -1,
            "filename": "pyrasa-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "00a38323a8323f0e828dc2395ee53066",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 37566,
            "upload_time": "2024-10-09T10:47:13",
            "upload_time_iso_8601": "2024-10-09T10:47:13.763175Z",
            "url": "https://files.pythonhosted.org/packages/50/e4/7769338f87ea51e599856d07eb0049d757745d53f9fbbd166255bf0fd74b/pyrasa-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7dd3a5cbf0afc94c3175c10508d6835084ee298162e75f1bb5bd73d8cecb655",
                "md5": "b913c333c597e64e9b4238e1c7568f3b",
                "sha256": "338fb9709cd0c2c7baa2536b12894df33d7333f8f8775a222a8bedf83956aa48"
            },
            "downloads": -1,
            "filename": "pyrasa-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b913c333c597e64e9b4238e1c7568f3b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 3368604,
            "upload_time": "2024-10-09T10:47:15",
            "upload_time_iso_8601": "2024-10-09T10:47:15.914090Z",
            "url": "https://files.pythonhosted.org/packages/b7/dd/3a5cbf0afc94c3175c10508d6835084ee298162e75f1bb5bd73d8cecb655/pyrasa-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-09 10:47:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "schmidtfa",
    "github_project": "pyrasa",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "pyrasa"
}
        
Elapsed time: 0.86431s