Exemple #1
0
def test_pac_signals_dtrials():
    """Definition of artificially coupled signals using dPha/dAmp."""
    assert pac_signals_tort(fpha=5,
                            famp=130,
                            sf=512,
                            ntrials=23,
                            chi=0.9,
                            noise=2,
                            dpha=35,
                            damp=46)
Exemple #2
0
def test_pac_signals_bandwidth():
    """Definition of artificially coupled signals using bandwidth."""
    assert pac_signals_tort(fpha=[5, 7],
                            famp=[30, 60],
                            sf=200.,
                            ntrials=100,
                            chi=0.5,
                            noise=3.,
                            npts=1000)
    assert pac_signals_wavelet(fpha=10,
                               famp=57.,
                               npts=1240,
                               sf=256,
                               noise=.7,
                               ntrials=33,
                               pp=np.pi / 4,
                               rnd_state=23)
For the visualization, we used a comodulogram.
"""
import matplotlib.pyplot as plt
from tensorpac.utils import pac_signals_tort
from tensorpac import Pac
plt.style.use('seaborn-poster')

# First, we generate a dataset of signals artificially coupled between 10hz
# and 100hz. By default, this dataset is organized as (ntrials, npts) where
# npts is the number of time points.
n = 10  # number of datasets
npts = 4000  # number of time points
data, time = pac_signals_tort(fpha=10,
                              famp=100,
                              noise=3.,
                              ntrials=n,
                              npts=npts,
                              dpha=10,
                              damp=5,
                              chi=.8)

# First, let's use the MVL, without any further correction by surrogates :
p = Pac(idpac=(1, 0, 0), fpha=(2, 30, 1, .5), famp=(60, 150, 10, 1))
xpac = p.filterfit(1024, data, axis=1)
t1 = p.method + '\n' + p.surro + '\n' + p.norm

# Now, we still use the MVL method, but in addition we shuffle amplitude time
# series and then, subtract then divide by the mean of surrogates :
p.idpac = (1, 1, 1)
xpac_corr = p.filterfit(1024, data, data, axis=1, nperm=10)
t2 = p.method + '\n' + p.surro + '\n' + p.norm
# Now, we plot the result by taking the mean across the dataset dimension.
Exemple #4
0
def test_default_args():
    """Test default aurguments for pac_vec."""
    assert pac_signals_tort(chi=2., noise=11., dpha=120., damp=200.)
Exemple #5
0
"""
=====================================
Generate artificially coupled signals
=====================================

Use the pac_signals_tort function to generate artificial PAC.
"""
import matplotlib.pyplot as plt
from tensorpac.utils import pac_signals_tort

# Generate one signal containing PAC. By default, this signal present a
# coupling between a 2hz phase and a 100hz amplitude (2 <-> 100) :
sig, time = pac_signals_tort(ntrials=1, npts=1000)

# Now, we generate a longer and weaker 4 <-> 60 coupling using the chi
#  parameter. In addition, we increase the amount of noise :
sig2, time2 = pac_signals_tort(fpha=4,
                               famp=60,
                               ntrials=1,
                               chi=.9,
                               noise=3,
                               npts=3000)

# Alternatively, you can generate multiple coupled signals :
sig3, time3 = pac_signals_tort(fpha=10, famp=150, ntrials=3, chi=0.5, noise=2)

# Finally, if you want to add variability across generated signals, use the
# dpha and damp parameters :
sig4, time4 = pac_signals_tort(fpha=10,
                               famp=50,
                               ntrials=3,
Exemple #6
0
signal to extract the phase (xpha) and the second, the amplitude (xamp).
If you want to extract local coupling (i.e. on a source/electrode) both xpha
and xamp have to be set to data.
"""
import matplotlib.pyplot as plt
from tensorpac.utils import pac_signals_tort
from tensorpac import Pac
# plt.style.use('seaborn-poster')

# First, we generate 2 datasets of signals artificially coupled between 10hz
# and 100hz. By default, those datasets are organized as (n_epochs, n_times)
# where n_times is the number of time points.
n_epochs = 20  # number of datasets
d1, time = pac_signals_tort(f_pha=10,
                            f_amp=100,
                            noise=1,
                            n_epochs=n_epochs,
                            n_times=3000)
d2, time = pac_signals_tort(f_pha=10,
                            f_amp=100,
                            noise=3,
                            n_epochs=n_epochs,
                            dpha=20,
                            damp=5,
                            chi=.3,
                            n_times=3000)

# Define the model of PAC to use :
p = Pac(idpac=(4, 0, 0),
        f_pha=(2, 30, 1, 1),
        f_amp=(60, 150, 5, 5),
One thing you may have noticed, both the fit() and filterfit() methods take as
inputs data and again data. The reason is that the first data refer to the
signal to extract the phase (xpha) and the second, the amplitude (xamp).
If you want to extract local coupling (i.e. on a source/electrode) both xpha
and xamp have to be set to data.
"""
import matplotlib.pyplot as plt
from tensorpac.utils import pac_signals_tort
from tensorpac import Pac
# plt.style.use('seaborn-poster')

# First, we generate 2 datasets of signals artificially coupled between 10hz
# and 100hz. By default, those datasets are organized as (ntrials, npts)
# where npts is the number of time points.
n = 20  # number of datasets
d1, time = pac_signals_tort(fpha=10, famp=100, noise=1, ntrials=n, npts=3000)
d2, time = pac_signals_tort(fpha=10,
                            famp=100,
                            noise=3,
                            ntrials=n,
                            dpha=20,
                            damp=5,
                            chi=.3,
                            npts=3000)

# Define the model of PAC to use :
p = Pac(idpac=(4, 0, 0),
        fpha=(2, 30, 1, 1),
        famp=(60, 150, 5, 5),
        dcomplex='wavelet',
        width=12)
Exemple #8
0
==============

Reproduced the figure in the README.
"""
from tensorpac.utils import pac_signals_tort
from tensorpac import Pac

# Dataset of signals artificially coupled between 10hz and 100hz :
n = 20  # number of datasets
sf = 512.  # sampling frequency

# Create artificially coupled signals using Tort method :
data, time = pac_signals_tort(fpha=10,
                              famp=100,
                              noise=2,
                              ntrials=n,
                              dpha=10,
                              damp=10,
                              sf=sf)

# Define a PAC object :
p = Pac(idpac=(4, 0, 0),
        fpha=(2, 20, 1, 1),
        famp=(60, 150, 5, 5),
        dcomplex='wavelet',
        width=12)
# Filter the data and extract PAC :
xpac = p.filterfit(sf, data, axis=1)

# Plot your Phase-Amplitude Coupling :
p.comodulogram(xpac.mean(-1),
Generate a coupling between specific bands
==========================================

Alternativerly, you can create coupling not between centered frequences, but
between frequency bands. In this example, we illustrate a [5, 7]<->[60, 80]hz
coupling.
"""
import numpy as np
import matplotlib.pyplot as plt

from tensorpac.utils import pac_signals_tort
from tensorpac import Pac

data, time = pac_signals_tort(fpha=[5, 7],
                              famp=[60, 80],
                              chi=0.5,
                              ntrials=10,
                              noise=3.,
                              npts=2000)

p = Pac(idpac=(3, 1, 1),
        fpha=(1, 15, 1, .2),
        famp=(40, 100, 5, 2),
        dcomplex='wavelet',
        width=6)
pac = np.squeeze(p.filterfit(1024, data, axis=1, nperm=10))

plt.figure(figsize=(12, 9))
p.comodulogram(pac.mean(-1),
               title=str(p),
               plotas='contour',
               ncontours=10,
from __future__ import print_function
import matplotlib.pyplot as plt
from tensorpac.utils import pac_signals_tort
from tensorpac import Pac
plt.style.use('seaborn-paper')

# First, we generate a dataset of signals artificially coupled between 10hz
# and 100hz. By default, this dataset is organized as (ntrials, npts) where
# npts is the number of time points.
n = 10  # number of datasets
sf = 256.  # sampling frequency
npts = 3000  # Number of time points
data, time = pac_signals_tort(sf=sf,
                              fpha=[4, 6],
                              famp=[90, 110],
                              noise=3,
                              ntrials=n,
                              dpha=10,
                              damp=10,
                              npts=npts)

# First, let's use the MVL, without any further correction by surrogates :
p = Pac(fpha=(1, 10, 1, .1), famp=(60, 140, 1, 1), dcomplex='wavelet', width=6)

# Now, we want to compare PAC methods, hence it's useless to systematically
# filter the data. So we extract the phase and the amplitude only once :
phases = p.filter(sf, data, axis=1, ftype='phase')
amplitudes = p.filter(sf, data, axis=1, ftype='amplitude')

plt.figure(figsize=(18, 9))
for i, k in enumerate([1, 2, 3, 4, 5]):
    # Change the pac method :