Esempio n. 1
0
 def test_filterfit(self):
     """Test filtering test computing PAC."""
     data = np.random.rand(2, 1024)
     p = Pac(idpac=(4, 0, 0))
     p.filterfit(1024, data, n_jobs=1)
     p.idpac = (1, 1, 1)
     p.filterfit(1024, data, data, n_jobs=1, n_perm=2)
     p.dcomplex = 'wavelet'
     p.filter(1024, data, n_jobs=1)
Esempio n. 2
0
def test_kargs():
    """Test filtering test computing PAC."""
    data = np.random.rand(2, 1024)
    p = Pac(idpac=(1, 2, 4))
    karg1 = p.filterfit(1024, data, data, njobs=1)
    karg2 = p.filterfit(1024, data, data, njobs=1, get_pval=True)
    karg3 = p.filterfit(1024, data, data, njobs=1, get_surro=True)
    karg4 = p.filterfit(1024,
                        data,
                        data,
                        njobs=1,
                        get_surro=True,
                        get_pval=True)
    assert len(karg1) == 1
    assert len(karg2) == 2
    assert len(karg3) == 2
    assert len(karg4) == 3
Esempio n. 3
0
    def set_data(self,
                 data,
                 sf=1.,
                 f_pha=[(2, 4), (5, 7), (8, 13)],
                 f_amp=[(40, 60), (60, 100)],
                 idpac=(4, 0, 0),
                 n_window=None,
                 clim=None,
                 cmap=None,
                 vmin=None,
                 under=None,
                 vmax=None,
                 over=None,
                 **kwargs):
        """Compute pacmap and set data to the ImageObj."""
        # ======================= CHECKING =======================
        is_tensorpac_installed(raise_error=True)
        from tensorpac import Pac
        data = np.squeeze(data)
        assert isinstance(data, np.ndarray) and data.ndim == 1
        assert isinstance(sf, (int, float))
        time = np.arange(len(data))
        # Switch between several plotting capabilities :
        _pha = len(f_pha) == 2 and all(
            [isinstance(k, (int, float)) for k in f_pha])
        _amp = len(f_amp) == 2 and all(
            [isinstance(k, (int, float)) for k in f_amp])
        if _pha or _amp:
            assert isinstance(n_window, int)
            sections = time.copy()[::n_window][1::]
            time = np.array(np.array_split(time, sections)[0:-1]).mean(1).T
            time /= sf
            data = np.array(np.array_split(data, sections)[0:-1]).T
        # Define the pac object and compute pac :
        p = Pac(idpac=idpac, fpha=f_pha, famp=f_amp, **kwargs)
        pac = np.squeeze(p.filterfit(sf, data, njobs=1, axis=0))
        pac[np.isnan(pac)] = 0.
        assert pac.ndim == 2
        # Get x-axis and y-axis :
        if _pha:
            xaxis, yaxis = time, p.yvec
        elif _amp:
            xaxis, yaxis = time, p.xvec
        else:
            xaxis, yaxis = p.xvec, p.yvec
        # Update color arguments :
        self._update_cbar_args(cmap, clim, vmin, vmax, under, over)

        # Set data to the image object :
        ImageObj.set_data(self,
                          pac,
                          xaxis=xaxis,
                          yaxis=yaxis,
                          **self.to_kwargs())
def compute_pt_tp(n_jobs, n_perm, title=''):
    """Compute Pactools and Tensorpac."""
    cpt, meth_comp, soft = [], [], []
    for meth in ['MVL', 'MI', 'PLV']:
        # ---------------------------------------------------------------------
        # get the method name
        meth_pt = METH['PACTOOLS'][meth]
        meth_tp = METH['TENSORPAC'][meth]

        if n_perm > 0:
            idpac = (meth_tp, 2, 4)
        else:
            idpac = (meth_tp, 0, 0)

        # ---------------------------------------------------------------------
        # PACTOOLS
        pt_start = tst()
        estimator = Comodulogram(fs=sf,
                                 low_fq_range=f_pha_pt,
                                 low_fq_width=f_pha_pt_width,
                                 high_fq_range=f_amp_pt,
                                 high_fq_width=f_amp_pt_width,
                                 method=meth_pt,
                                 progress_bar=False,
                                 n_jobs=n_jobs,
                                 n_surrogates=n_perm)
        estimator.fit(data)
        pt_end = tst()
        # ---------------------------------------------------------------------
        # TENSORPAC
        tp_start = tst()
        p_obj = Pac(idpac=idpac,
                    f_pha=f_pha_tp,
                    f_amp=f_amp_tp,
                    verbose='error')
        pac = p_obj.filterfit(sf, data, n_jobs=n_jobs, n_perm=n_perm).mean(-1)
        tp_end = tst()

        # ---------------------------------------------------------------------
        # shape shape checking
        assert estimator.comod_.shape == pac.T.shape
        # saving the results
        cpt += [pt_end - pt_start, tp_end - tp_start]
        meth_comp += [meth] * 2
        soft += ['Pactools', 'Tensorpac']

    # -------------------------------------------------------------------------
    df = pd.DataFrame({
        "Computing time": cpt,
        "PAC method": meth_comp,
        "Software": soft
    })
    sns.barplot(x="PAC method", y="Computing time", hue="Software", data=df)
    plt.title(title, fontsize=14, fontweight='bold')
Esempio n. 5
0
    def set_data(self, data, sf=1., f_pha=[(2, 4), (5, 7), (8, 13)],
                 f_amp=[(40, 60), (60, 100)], idpac=(4, 0, 0), n_window=None,
                 clim=None, cmap=None, vmin=None, under=None, vmax=None,
                 over=None, **kwargs):
        """Compute pacmap and set data to the ImageObj."""
        # ======================= CHECKING =======================
        is_tensorpac_installed(raise_error=True)
        from tensorpac import Pac
        data = np.squeeze(data)
        assert isinstance(data, np.ndarray) and data.ndim == 1
        assert isinstance(sf, (int, float))
        time = np.arange(len(data))
        # Switch between several plotting capabilities :
        _pha = len(f_pha) == 2 and all([isinstance(k, (int,
                                                       float)) for k in f_pha])
        _amp = len(f_amp) == 2 and all([isinstance(k, (int,
                                                       float)) for k in f_amp])
        if _pha or _amp:
            assert isinstance(n_window, int)
            sections = time.copy()[::n_window][1::]
            time = np.array(np.array_split(time, sections)[0:-1]).mean(1).T
            time /= sf
            data = np.array(np.array_split(data, sections)[0:-1]).T
        # Define the pac object and compute pac :
        p = Pac(idpac=idpac, fpha=f_pha, famp=f_amp, **kwargs)
        pac = np.squeeze(p.filterfit(sf, data, njobs=1, axis=0))
        pac[np.isnan(pac)] = 0.
        assert pac.ndim == 2
        # Get x-axis and y-axis :
        if _pha:
            xaxis, yaxis = time, p.yvec
        elif _amp:
            xaxis, yaxis = time, p.xvec
        else:
            xaxis, yaxis = p.xvec, p.yvec
        # Update color arguments :
        self._update_cbar_args(cmap, clim, vmin, vmax, under, over)

        # Set data to the image object :
        ImageObj.set_data(self, pac, xaxis=xaxis, yaxis=yaxis,
                          **self.to_kwargs())
Esempio n. 6
0
                        n=str(noise))
        info.append(inf)
        # Generate coupling :
        data[i, k, ...], time = pac_signals_wavelet(fpha=fpha,
                                                    famp=famp,
                                                    noise=noise,
                                                    npts=n_pts,
                                                    ntrials=n_trials,
                                                    sf=sf)

# ----------------- Compute PAC -----------------
# Define the PAC object :
p = Pac(idpac=(4, 0, 0),
        fpha=(1, 15, 1, .3),
        famp=(25, 130, 5, 1),
        dcomplex='wavelet',
        width=12)
# Compute PAC along the time axis and take the mean across trials :
pac = p.filterfit(sf, data, axis=3).mean(-1)

# ----------------- Visualization -----------------
q = 1
plt.figure(figsize=(20, 19))
for i in range(n_subject):
    for k in range(n_elec):
        plt.subplot(n_subject, n_elec, q)
        p.comodulogram(pac[:, :, i, k], title=info[q - 1], interp=(.2, .2))
        q += 1

p.show()
Esempio n. 7
0
# Compute true PAC estimation and surrogates distribution
###############################################################################
# Now, we compute the PAC using multiple phases and amplitudes such as the
# distribution of surrogates. In this example, we used the method proposed by
# Bahramisharif et al. 2013 :cite:`bahramisharif2013propagating` and also
# recommended by Aru et al. 2015 :cite:`aru2015untangling`. This method
# consists in swapping two time blocks of amplitudes cut at a random time
# point. Then, we used the method :class:`tensorpac.Pac.infer_pvalues` in order
# to get the corrected p-values across all possible (phase, amplitude)
# frequency pairs.

# define the Pac object
p = Pac(idpac=(2, 2, 0), f_pha=(2, 15, 2, .2), f_amp=(60, 120, 5, 1))
# compute true pac and surrogates
n_perm = 200  # number of permutations
xpac = p.filterfit(sf, data, n_perm=n_perm, n_jobs=-1,
                   random_state=0).squeeze()
# get the corrected p-values
pval = p.infer_pvalues(p=0.05)
# get the mean pac values where it's detected as significant
xpac_smean = xpac[pval < .05].mean()

# if you want to see how the surrogates looks like, you can have to access
# using :class:`tensorpac.Pac.surrogates`
surro = p.surrogates.squeeze()
print(f"Surrogates shape (n_perm, n_amp, n_pha) : {surro.shape}")
# get the maximum of the surrogates across (phase, amplitude) pairs
surro_max = surro.max(axis=(1, 2))

plt.figure(figsize=(16, 5))
plt.subplot(131)
p.comodulogram(xpac,
Esempio n. 8
0
import numpy as np
import matplotlib.pyplot as plt
from tensorpac import Pac, pac_signals_wavelet
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 (n_epochs, n_times) where
# n_times is the number of time points.
n_epochs = 1  # number of datasets
sf = 512.  # sampling frequency
data, time = pac_signals_wavelet(f_pha=6,
                                 f_amp=90,
                                 noise=.8,
                                 n_epochs=n_epochs,
                                 n_times=4000,
                                 sf=sf)

# First, let's use the MVL, without any further correction by surrogates :
p = Pac(idpac=(1, 2, 0), f_pha=(2, 15, 2, .2), f_amp=(60, 120, 10, 1))
xpac = p.filterfit(sf, data, n_perm=200, p=.05)
pval = p.pvalues

p.comodulogram(xpac.mean(-1),
               title=str(p),
               cmap='Spectral_r',
               vmin=0.,
               pvalues=pval,
               levels=.05)

p.show()
Esempio n. 9
0
from tensorpac.signals import pac_signals_tort

# Dataset of signals artificially coupled between 10hz and 100hz :
n_epochs = 20
n_times = 4000
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=(2, 20, 1, 1), f_amp=(60, 150, 5, 5))
# Filter the data and extract PAC :
xpac = p.filterfit(sf, data)

# Plot your Phase-Amplitude Coupling :
p.comodulogram(xpac.mean(-1),
               title='Contour plot with 5 regions',
               cmap='Spectral_r',
               plotas='contour',
               ncontours=5)

p.show()
                            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),
        dcomplex='wavelet',
        width=12)
# Now, compute PAC by taking the phase of the first dataset and the amplitude
# of the second
xpac12 = p.filterfit(1024, d1, d2)
# Invert by taking the phase of the second dataset and the amplitude of the
#  first one :
xpac21 = p.filterfit(1024, d2, d1)

# Plot signals and PAC :
plt.figure(figsize=(18, 12))
plt.subplot(2, 2, 1)
plt.plot(time, d1.mean(0), color='k')
plt.xlabel('Time')
plt.ylabel('Amplitude [uV]')
plt.title('Mean across trials of the first dataset')
plt.axis('tight')

plt.subplot(2, 2, 2)
plt.plot(time, d2.mean(0), color='k')
"""
from tensorpac import Pac, pac_trivec, pac_signals_tort

sf = 256.
data, time = pac_signals_tort(fpha=[5, 7],
                              famp=[60, 80],
                              noise=2,
                              ntrials=5,
                              npts=3000,
                              sf=sf,
                              dpha=10)

trif, tridx = pac_trivec(fstart=30, fend=140, fwidth=3)

p = Pac(idpac=(1, 0, 0), fpha=[5, 7], famp=trif)
pac = p.filterfit(sf, data, axis=1)

p.triplot(pac.mean(-1),
          trif,
          tridx,
          cmap='Spectral_r',
          rmaxis=True,
          title=r'Optimal $[Fmin; Fmax]hz$ band for amplitude')

# In this example, we generated a coupling with a phase between [5, 7]hz and an
# amplitude between [60, 80]hz. To interpret the figure, the best starting
# frequency is around 50hz and the best ending frequency is around 90hz. In
# conclusion, the optimal amplitude bandwidth for this [5, 7]hz phase is
# [50, 90]hz.

# plt.savefig('triplot.png', dpi=600, bbox_inches='tight')
Esempio n. 12
0
n_epochs = 50
n_times = 3000
n_perm = 20
###############################################################################

data, time = pac_signals_wavelet(sf=sf,
                                 f_pha=10,
                                 f_amp=100,
                                 noise=3.,
                                 n_epochs=n_epochs,
                                 n_times=n_times)

p = Pac(idpac=(1, 2, 3), f_pha=cfg["phres"], f_amp=cfg["ahres"])
# p = Pac(idpac=(1, 2, 3), f_pha=(1, 30, 1, 1), f_amp=(60, 160, 5, 5))
# p = Pac(idpac=(1, 2, 3), f_pha='lres', f_amp='lres')
xpac = p.filterfit(sf, data, n_perm=n_perm, p=.05, n_jobs=-1)

pacn = p.pac.mean(-1)
pac = xpac.mean(-1)
surro = p.surrogates.mean(0).max(-1)  # mean(perm).max(epochs)

plt.figure(figsize=(22, 6))

plt.subplot(1, 3, 1)
p.comodulogram(pacn,
               cblabel="",
               title="Uncorrected PAC",
               cmap=cfg["cmap"],
               vmin=0)
ax = plt.gca()
ax.text(*tuple(cfg["nb_pos"]), 'A', transform=ax.transAxes, **cfg["nb_cfg"])
###############################################################################
sf = 1024
n_epochs = 50
n_times = 3000
n_perm = 20
###############################################################################

data, time = pac_signals_wavelet(sf=sf,
                                 f_pha=10,
                                 f_amp=100,
                                 noise=3.,
                                 n_epochs=n_epochs,
                                 n_times=n_times)

p = Pac(idpac=(1, 2, 3), f_pha='hres', f_amp='hres')
xpac = p.filterfit(sf, data, n_perm=n_perm, p=.05, n_jobs=-1, random_state=0)

pacn = p.pac.mean(-1)
pac = xpac.mean(-1)
surro = p.surrogates.mean(0).max(-1)  # mean(perm).max(epochs)

kw_plt = dict(fz_labels=20, fz_title=22, fz_cblabel=20)

plt.figure(figsize=(20, 6))

plt.subplot(1, 3, 1)
p.comodulogram(pacn,
               cblabel="",
               title="Uncorrected PAC",
               cmap=cfg["cmap"],
               vmin=0,
# and 100hz. By default, this dataset is organized as (ntrials, npts) where
# npts is the number of time points.
n = 10  # number of datasets
data, time = pac_signals_wavelet(fpha=10,
                                 famp=100,
                                 noise=1.,
                                 ntrials=n,
                                 npts=4000)

# First, let's use the MVL, without any further correction by surrogates :
p = Pac(idpac=(5, 3, 3),
        fpha=(4, 18, 1, .3),
        famp=(60, 150, 5, 2),
        dcomplex='wavelet',
        width=7)
xpac, pval = p.filterfit(1024, data, axis=1, nperm=110, get_pval=True)

# Now, we plot the result by taking the mean across the dataset dimension.
plt.figure(figsize=(20, 15))
plt.subplot(3, 3, 1)
p.comodulogram(xpac.mean(-1), title='Default plotting')

plt.subplot(3, 3, 2)
p.comodulogram(xpac.mean(-1),
               title='Peaking between [5, 20]',
               vmin=5,
               vmax=20,
               cmap='gnuplot2_r')

plt.subplot(3, 3, 3)
# Ideally, the p-values should be corrected across trials because taking the
Esempio n. 15
0
# 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.
plt.figure(figsize=(20, 7))
plt.subplot(1, 2, 1)
p.comodulogram(xpac.mean(-1), title=t1)

plt.subplot(1, 2, 2)
p.comodulogram(xpac_corr.mean(-1), title=t2)
plt.show()
                                n_epochs=n_epochs,
                                n_times=n_times)
# create a second random dataset without any coupling
x_2 = np.random.rand(n_epochs, n_times)

###############################################################################
# Compute the single trial PAC on both datasets
###############################################################################
# once the datasets created, we can now extract the PAC, computed across
# time-points for each trials and across several phase and amplitude
# frequencies

# create the pac object. Use the Gaussian-Copula PAC
p = Pac(idpac=(6, 0, 0), f_pha='hres', f_amp='hres', dcomplex='wavelet')
# compute pac for both dataset
pac_1 = p.filterfit(sf, x_1, n_jobs=-1)
pac_2 = p.filterfit(sf, x_2, n_jobs=-1)

###############################################################################
# Correct for multiple-comparisons using a cluster-based approach
###############################################################################
# Then, we perform the cluster-based correction for multiple comparisons
# between the PAC coming from the two conditions. To this end we use the
# Python package MNE-Python and in particular, the function
# :func:`mne.stats.permutation_cluster_test`

# mne requires that the first is represented by the number of trials (n_epochs)
# Therefore, we transpose the output PACs of both conditions
pac_r1 = np.transpose(pac_1, (2, 0, 1))
pac_r2 = np.transpose(pac_2, (2, 0, 1))
Esempio n. 17
0
###############################################################################
# Compute true PAC estimation and surrogates distribution
###############################################################################
# Now, we compute the PAC using multiple phases and amplitudes such as the
# distribution of surrogates. In this example, we used the method proposed by
# Tort et al. 2010 :cite:`tort2010measuring`. This method consists in swapping
# phase and amplitude trials. Then, we used the method
# :class:`tensorpac.Pac.infer_pvalues` in order to get the corrected p-values
# across all possible (phase, amplitude) frequency pairs.

# define the Pac object
p = Pac(idpac=(1, 1, 0), f_pha='mres', f_amp='mres')
# compute true pac and surrogates
n_perm = 200  # number of permutations
xpac = p.filterfit(sf, data, n_perm=n_perm, n_jobs=-1).squeeze()

plt.figure(figsize=(16, 5))
for n_mcp, mcp in enumerate(['maxstat', 'fdr', 'bonferroni']):
    # get the corrected p-values
    pval = p.infer_pvalues(p=0.05, mcp=mcp)
    # set to gray non significant p-values and in color significant values
    pac_ns = xpac.copy()
    pac_ns[pval <= .05] = np.nan
    pac_s = xpac.copy()
    pac_s[pval > .05] = np.nan

    plt.subplot(1, 3, n_mcp + 1)
    p.comodulogram(pac_ns, cmap='gray', colorbar=False, vmin=np.nanmin(pac_ns),
                   vmax=np.nanmax(pac_ns))
    p.comodulogram(pac_s, title=f'MCP={mcp}', cmap='viridis',
Esempio n. 18
0
                                 f_amp=100,
                                 noise=1.,
                                 n_epochs=n_epochs,
                                 n_times=n_times)

# First, let's use the MVL, without any further correction by surrogates :
p = Pac(idpac=(4, 0, 0),
        f_pha=(5, 14, 2, .3),
        f_amp=(80, 120, 2, 1),
        verbose=False)

plt.figure(figsize=(18, 9))
# Define several cycle options for the fir1 (eegfilt like) filter :
print('Filtering with fir1 filter')
for i, k in enumerate([(1, 3), (2, 4), (3, 6)]):
    p.cycle = k
    xpac = p.filterfit(1024, data, n_jobs=1)
    plt.subplot(2, 3, i + 1)
    p.comodulogram(xpac.mean(-1), title='Fir1 - cycle ' + str(k))

# Define several wavelet width :
p.dcomplex = 'wavelet'
print('Filtering with wavelets')
for i, k in enumerate([7, 9, 12]):
    p.width = k
    xpac = p.filterfit(1024, data)
    plt.subplot(2, 3, i + 4)
    p.comodulogram(xpac.mean(-1), title='Wavelet - width ' + str(k))

plt.show()
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,
               cmap='plasma',
               vmin=0)
plt.show()
                            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)
# Now, compute PAC by taking the phase of the first dataset and the amplitude
# of the second
xpac12 = p.filterfit(1024, d1, d2, axis=1)
# Invert by taking the phase of the second dataset and the amplitude of the
#  first one :
xpac21 = p.filterfit(1024, d2, d1, axis=1)

# Plot signals and PAC :
plt.figure(figsize=(18, 12))
plt.subplot(2, 2, 1)
plt.plot(time, d1.mean(0), color='k')
plt.xlabel('Time')
plt.ylabel('Amplitude [uV]')
plt.title('Mean across trials of the first dataset')
plt.axis('tight')

plt.subplot(2, 2, 2)
plt.plot(time, d2.mean(0), color='k')
Esempio n. 21
0
f_pha, f_amp = 5, 120
n_epochs = 5
n_times = 1000
###############################################################################


# generate the random dataset
sig_t, time = pac_signals_tort(f_pha=f_pha, f_amp=f_amp, n_epochs=n_epochs,
                               noise=2, n_times=n_times, sf=sf)
sig_w, time = pac_signals_wavelet(sf=sf, f_pha=f_pha, f_amp=f_amp, noise=.5,
                                  n_epochs=n_epochs, n_times=n_times)

# compute pac
p = Pac(idpac=(6, 0, 0), f_pha=cfg["phres"], f_amp=cfg["ahres"],
        dcomplex='wavelet', width=12)
xpac_t = p.filterfit(sf, sig_t, n_jobs=1).mean(-1)
xpac_w = p.filterfit(sf, sig_w, n_jobs=1).mean(-1)

plt.figure(figsize=(17, 14))

# ----------------------------------------- Tort et al. 2010
plt.subplot(221)
plt.plot(time, sig_t[0, :], color='black', lw=.8)
plt.ylabel("Amplitude (V)")
plt.title("pac_signals_tort (Tort et al. 2010)")
plt.autoscale(axis='both', tight=True)
plt.tick_params(axis='x', which='both', labelbottom=False)
ax = plt.gca()
ax.text(*tuple(cfg["nb_pos"]), 'A', transform=ax.transAxes, **cfg["nb_cfg"])

plt.subplot(222)
Esempio n. 22
0
                                 noise=1.,
                                 n_epochs=n_epochs,
                                 n_times=n_times)

# First, let's use the MVL, without any further correction by surrogates :
p = Pac(idpac=(4, 0, 0),
        f_pha=(5, 14, 2, .3),
        f_amp=(80, 120, 2, 1),
        verbose=False)

plt.figure(figsize=(18, 9))
# Define several cycle options for the fir1 (eegfilt like) filter :
p.filt = 'fir1'
print('Filtering with fir1 filter')
for i, k in enumerate([(1, 3), (2, 4), (3, 6)]):
    p.cycle = k
    xpac = p.filterfit(1024, data)
    plt.subplot(2, 3, i + 1)
    p.comodulogram(xpac.mean(-1), title='Fir1 - cycle ' + str(k))

# Define several wavelet width :
p.dcomplex = 'wavelet'
print('Filtering with wavelets')
for i, k in enumerate([7, 9, 12]):
    p.width = k
    xpac = p.filterfit(1024, data)
    plt.subplot(2, 3, i + 4)
    p.comodulogram(xpac.mean(-1), title='Wavelet - width ' + str(k))

plt.show()
Esempio n. 23
0
npts = 2000  # number of time points
data, time = pac_signals_wavelet(fpha=10,
                                 famp=100,
                                 noise=1.,
                                 ntrials=n,
                                 npts=npts)

# First, let's use the MVL, without any further correction by surrogates :
p = Pac(idpac=(1, 0, 0), fpha=(5, 14, 2, .3), famp=(80, 120, 2, 1))

plt.figure(figsize=(18, 9))
# Define several cycle options for the fir1 (eegfilt like) filter :
p.filt = 'fir1'
print('Filtering with fir1 filter')
for i, k in enumerate([(1, 3), (3, 6), (6, 12)]):
    p.cycle = k
    xpac = p.filterfit(1024, data, axis=1)
    plt.subplot(2, 3, i + 1)
    p.comodulogram(xpac.mean(-1), title='Fir1 - cycle ' + str(k))

# Define several wavelet width :
p.dcomplex = 'wavelet'
print('Filtering with wavelets')
for i, k in enumerate([7, 12, 24]):
    p.width = k
    xpac = p.filterfit(1024, data, axis=1)
    plt.subplot(2, 3, i + 4)
    p.comodulogram(xpac.mean(-1), title='Wavelet - width ' + str(k))

plt.show()