Skip to content

seqasim/tensorpac

 
 

Repository files navigation

Tensorpac

https://travis-ci.org/EtienneCmb/tensorpac.svg?branch=master https://circleci.com/gh/EtienneCmb/tensorpac/tree/master.svg?style=svg https://ci.appveyor.com/api/projects/status/0arxtw05583gc3e2/branch/master?svg=true https://pepy.tech/badge/tensorpac
https://github.com/EtienneCmb/tensorpac/blob/master/docs/source/picture/tp.png

Description

Tensorpac is an Python open-source toolbox for computing Phase-Amplitude Coupling (PAC) using tensors and parallel computing for an efficient, and highly flexible modular implementation of PAC metrics both known and novel. Check out our documentation for details.

Installation

Tensorpac uses NumPy, SciPy and joblib for parallel computing. To get started, just open your terminal and run :

$ pip install tensorpac

Code snippet & illustration

from tensorpac import Pac
from tensorpac.signals import pac_signals_tort

# Dataset of signals artificially coupled between 10hz and 100hz :
n_epochs = 20   # number of trials
n_times = 4000  # number of time points
sf = 512.       # sampling frequency

# Create artificially coupled signals using Tort method :
data, time = pac_signals_tort(f_pha=10, f_amp=100, noise=2, n_epochs=n_epochs,
                              dpha=10, damp=10, sf=sf, n_times=n_times)

# Define a Pac object
p = Pac(idpac=(6, 0, 0), f_pha='hres', f_amp='hres')
# Filter the data and extract pac
xpac = p.filterfit(sf, data)

# plot your Phase-Amplitude Coupling :
p.comodulogram(xpac.mean(-1), cmap='Spectral_r', plotas='contour', ncontours=5,
               title=r'10hz phase$\Leftrightarrow$100Hz amplitude coupling',
               fz_title=14, fz_labels=13)

p.show()
https://github.com/EtienneCmb/tensorpac/blob/master/docs/source/picture/readme.png

Multivariate gc-PAC

Tensorpac also supports multivariate Gaussian-Copula PAC through the existing :class:`tensorpac.Pac` API. When idpac[0] == 6, both :meth:`fit` and :meth:`filterfit` accept phase and amplitude groups shaped (n_epochs, n_channels, n_times) and return one group-level PAC estimate per phase / amplitude frequency pair and epoch.

For a phase group with channels \phi_c(t) and an amplitude group with channels a_k(t), the multivariate estimator builds the vector-valued variables :

X(t) = [\sin(\phi_1(t)), \cos(\phi_1(t)), \dots,
\sin(\phi_P(t)), \cos(\phi_P(t))]
Y(t) = [a_1(t), \dots, a_A(t)]

After copula-normalizing each component, Tensorpac computes the Gaussian-Copula mutual information I(X; Y). This extends gc-PAC from a single phase / amplitude pair to a group-to-group dependence measure without arbitrary channel averaging, while keeping the same surrogate statistics and plotting workflow. See examples/pac/plot_multivariate_gc_pac.py for a complete example.

Cite Tensorpac

Tensorpac software has been published in PLoS Computational Biology

Use the following Bibtex entry to cite it :

@article{combrisson_tensorpac_2020,
    title = {Tensorpac: {An} open-source {Python} toolbox for tensor-based phase-amplitude coupling measurement in electrophysiological brain signals},
    volume = {16},
    issn = {1553-7358},
    shorttitle = {Tensorpac},
    doi = {10.1371/journal.pcbi.1008302},
    language = {eng},
    number = {10},
    journal = {PLoS computational biology},
    author = {Combrisson, Etienne and Nest, Timothy and Brovelli, Andrea and Ince, Robin A. A. and Soto, Juan L. P. and Guillot, Aymeric and Jerbi, Karim},
    month = oct,
    year = {2020},
    pmid = {33119593},
    pmcid = {PMC7654762},
    pages = {e1008302},
}

About

Phase-Amplitude Coupling under Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 99.8%
  • Other 0.2%