def test_spectral(self): """Test filtering using the provided filters.""" data = np.random.rand(3, 1000) p = Pac() dcomplex = ['hilbert', 'wavelet'] for k in dcomplex: p.dcomplex = k p.filter(1024, data, n_jobs=1)
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)
def test_pac_meth(): """Test all Pac methods.""" pha = np.random.rand(2, 7, 1024) amp = np.random.rand(3, 7, 1024) nmeth, nsuro, nnorm = 5, 5, 5 p = Pac() for k in range(nmeth): for i in range(nsuro): for j in range(nnorm): p.idpac = (k + 1, i, j) p.fit(pha, amp, axis=2, traxis=1, njobs=1, nperm=2)
def test_fit(self): """Test all Pac methods.""" pha = np.random.rand(2, 7, 1024) amp = np.random.rand(3, 7, 1024) nmeth, nsuro, nnorm = 5, 4, 5 p = Pac() for k in range(nmeth): for i in range(nsuro): for j in range(nnorm): p.idpac = (k + 1, i, j) p.fit(pha, amp, n_jobs=1, n_perm=10)
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')
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 test_functional_pac(self): """Test functionnal pac.""" # generate a 10<->100hz ground truth coupling n_epochs, sf, n_times = 1, 512., 4000 data, time = pac_signals_wavelet(f_pha=10, f_amp=100, noise=.8, n_epochs=n_epochs, n_times=n_times, sf=sf) # phase / amplitude extraction (single time) p = Pac(f_pha='lres', f_amp='lres', dcomplex='wavelet', width=12) phases = p.filter(sf, data, ftype='phase', n_jobs=1) amplitudes = p.filter(sf, data, ftype='amplitude', n_jobs=1) # ground truth array construction n_pha, n_amp = len(p.xvec), len(p.yvec) n_pix = int(n_pha * n_amp) gt = np.zeros((n_amp, n_pha), dtype=bool) b_pha = np.abs(p.xvec.reshape(-1, 1) - np.array([[9, 11]])).argmin(0) b_amp = np.abs(p.yvec.reshape(-1, 1) - np.array([[95, 105]])).argmin(0) gt[b_amp[0]:b_amp[1] + 1, b_pha[0]:b_pha[1] + 1] = True plt.figure(figsize=(12, 9)) plt.subplot(2, 3, 1) p.comodulogram(gt, title='Gound truth', cmap='magma', colorbar=False) # loop over implemented methods for i, k in enumerate([1, 2, 3, 5, 6]): # compute only the pac p.idpac = (k, 2, 3) xpac = p.fit(phases, amplitudes, n_perm=200).squeeze() pval = p.pvalues.squeeze() is_coupling = pval <= .05 # count the number of correct pixels. This includes both true # positives and true negatives acc = 100 * (is_coupling == gt).sum() / n_pix assert acc > 95. # build title of the figure (for sanity check) meth = p.method.replace(' (', '\n(') title = f"Method={meth}\nAccuracy={np.around(acc, 2)}%" # set to nan everywhere it's not significant xpac[~is_coupling] = np.nan vmin, vmax = np.nanmin(xpac), np.nanmax(xpac) # plot the results plt.subplot(2, 3, i + 2) p.comodulogram(xpac, colorbar=False, vmin=vmin, vmax=vmax, title=title) plt.ylabel(''), plt.xlabel('') plt.tight_layout() plt.show() # show on demand
def test_filter(self): """Test filter method.""" data = np.random.rand(2, 1000) p = Pac() p.filter(256, data, 'phase') p.filter(256, data, 'phase', edges=2) p.filter(256, data, 'amplitude')
def test_filtering_definition(self): """Test filtering defintion.""" dcomplex = ['hilbert', 'wavelet'] cycle = (12, 24) width = 12 for k in dcomplex: Pac(dcomplex=k, cycle=cycle, width=width)
def test_id_pac_definition(self): """Test Pac object definition.""" nmeth, nsuro, nnorm = 6, 4, 5 for k in range(nmeth): for i in range(nsuro): for j in range(nnorm): p = Pac(idpac=(k + 1, i, j)) str(p)
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 test_erpac(): """Test the ERPAC.""" data = np.random.rand(2, 1024) p = Pac(idpac=(4, 0, 0)) pha = p.filter(1024, data, axis=1, ftype='phase') amp = p.filter(1024, data, axis=1, ftype='amplitude') p.erpac(pha, amp, traxis=1)
def test_preferred_phase(): """Test the prefered phase.""" data = np.random.rand(2, 1024) p = Pac(idpac=(4, 0, 0)) pha = p.filter(1024, data, axis=1, ftype='phase') amp = p.filter(1024, data, axis=1, ftype='amplitude') p.pp(pha, amp, axis=2)
def test_filtering_definition(self): """Test filtering defintion.""" dcomplex = ['hilbert', 'wavelet'] filt = ['butter', 'fir1', 'bessel'] cycle = (12, 24) filtorder = 4 width = 12 for k in dcomplex: for i in filt: Pac(dcomplex=k, filt=i, filtorder=filtorder, cycle=cycle, width=width)
def test_fit(self): """Test all Pac methods.""" pha = np.random.rand(2, 7, 1024) amp = np.random.rand(3, 7, 1024) nmeth, nsuro, nnorm = 5, 4, 5 p = Pac(verbose=False) for k in range(nmeth): for i in range(nsuro): for j in range(nnorm): p.idpac = (k + 1, i, j) p.fit(pha, amp, n_jobs=1, n_perm=10) if (i >= 1) and (k + 1 != 4): for mcp in ['maxstat', 'fdr', 'bonferroni']: p.infer_pvalues(mcp=mcp)
def test_spectral(): """Test filtering using the provided filters.""" data = np.random.rand(3, 1000) p = Pac() dcomplex = ['hilbert', 'wavelet'] filt = ['butter', 'fir1', 'bessel'] for k in dcomplex: for i in filt: p.dcomplex = k p.filt = i p.filter(1024, data, axis=1, njobs=1)
def test_properties(self): """Test Pac properties.""" p = Pac() # Idpac : p.idpac p.idpac = (2, 1, 1) # Filt : p.filt p.filt = 'butter' # Dcomplex : p.dcomplex p.dcomplex = 'wavelet' # Cycle : p.cycle p.cycle = (12, 24) # Filtorder : p.filtorder p.filtorder = 6 # Width : p.width p.width = 12
def test_properties(self): """Test Pac properties.""" p = Pac() # Idpac : p.idpac p.idpac = (2, 1, 1) # Dcomplex : p.dcomplex p.dcomplex = 'wavelet' # Cycle : p.cycle p.cycle = (12, 24) # Width : p.width p.width = 12
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
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, n_times) where # n_times is the number of time points. n_epochs = 5 # number of datasets n_times = 4000 # number of time points data, time = pac_signals_wavelet(f_pha=10, 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 : 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')
""" import numpy as np import matplotlib.pyplot as plt from tensorpac import pac_signals_wavelet, Pac plt.style.use('seaborn-poster') # Generate 100 datasets with a 6<->100hz coupling : sf = 1024. ntrials = 100 data, time = pac_signals_wavelet(fpha=6, famp=100, ntrials=ntrials, sf=sf, noise=.7, npts=2000, pp=np.pi/2) # Define a Pac object. Here, we are not going to use the idpac variable : p = Pac(fpha=[5, 7], famp=(60, 200, 10, 1)) # Extract the phase and the amplitude : pha = p.filter(sf, data, axis=1, ftype='phase') amp = p.filter(sf, data, axis=1, ftype='amplitude') # Now, compute the PP : ambin, pp, vecbin = p.pp(pha, amp, axis=2, nbins=72) # Reshape the PP to be (ntrials, namp) : pp = np.squeeze(pp).T # Reshape the amplitude to be (nbins, namp, ntrials) and take the mean across # datasets : ambin = np.squeeze(ambin).mean(-1)
# 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. 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)
a=str(famp), 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()
sf = 1024 n_epochs = 1 n_times = 100000 n_bins = 30 ############################################################################### data, time = pac_signals_wavelet(sf=sf, f_pha=10, f_amp=100, noise=2., n_epochs=n_epochs, n_times=n_times, rnd_state=0) # extract the phase and the amplitude p = Pac(idpac=(1, 0, 0), f_pha=[8, 12], f_amp=[60, 140]) pha = p.filter(sf, data, ftype='phase', n_jobs=1).squeeze() amp = p.filter(sf, data, ftype='amplitude', n_jobs=1).squeeze() # z-score normalize the amplitude amp_n = (amp - amp.mean()) / amp.std() plt.figure(figsize=(18, 5)) plt.subplot(131) plt.hist(pha, n_bins, color='blue') plt.title('Binned phase') plt.subplot(132) plt.hist(amp, n_bins, color='red') plt.title('Binned amplitude')
from __future__ import print_function import matplotlib.pyplot as plt from tensorpac import Pac, pac_signals_wavelet plt.style.use('seaborn-paper') # First, we generate a delta <-> low-gamma coupling. By default, this dataset # is organized as (n_epochs, n_times) where n_times is the number of time # points. n_epochs = 20 # number of datasets sf = 512. # sampling frequency data, time = pac_signals_wavelet(sf=sf, f_pha=6, f_amp=70, noise=3., n_epochs=n_epochs, n_times=4000) # First, let's use the MVL, without any further correction by surrogates : p = Pac(f_pha=(3, 10, 1, .2), f_amp=(50, 90, 5, 1), dcomplex='wavelet', width=12) # 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, ftype='phase') amplitudes = p.filter(sf, data, ftype='amplitude') plt.figure(figsize=(16, 12)) for i, k in enumerate(range(4)): # Change the pac method : p.idpac = (5, k, 1) # Compute only the PAC without filtering : xpac = p.fit(phases, amplitudes, n_perm=10) # Plot : plt.subplot(2, 2, k + 1) p.comodulogram(xpac.mean(-1), title=p.str_surro, cmap='Reds', vmin=0)
n_epochs = 100 n_times = 3000 res = 'hres' titles = ["MVL", "KLD", "HR", "ndPAC", "PS"] methods = dict(MVL=[0, slice(0, 2)], KLD=[0, slice(2, 4)], HR=[0, slice(4, 6)], ndPAC=[1, slice(1, 3)], PS=[1, slice(3, 5)]) ############################################################################### METHODS = dict(MVL=mvl, KLD=kld, HR=hr, ndPAC=ndpac, PS=ps) data, time = pac_signals_wavelet(sf=sf, f_pha=10, f_amp=100, noise=2., n_epochs=n_epochs, n_times=n_times) # p = Pac(idpac=(1, 0, 0), f_pha=cfg["phres"], f_amp=cfg["ahres"]) # p = Pac(idpac=(1, 0, 0), f_pha=(1, 30, 1, 1), f_amp=(60, 160, 5, 5)) p = Pac(idpac=(1, 0, 0), f_pha=res, f_amp=res) pha = p.filter(sf, data, ftype='phase', n_jobs=1) amp = p.filter(sf, data, ftype='amplitude', n_jobs=1) n_pha, n_amp = pha.shape[0], amp.shape[0] print(f'Vector-based dimensions : ({n_times}, {n_epochs}, {n_pha}, {n_amp})') elapsed, name, ctype, ratio, ratio_names = [], [], [], [], [] for n_m, (meth_name, meth) in enumerate(METHODS.items()): # tensor-based computations t_start = tst() meth(pha, amp) t_end = tst() t_tensor = t_end - t_start elapsed += [t_tensor] name += [meth_name]
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()
data, time = pac_signals_wavelet(sf=sf, f_pha=f_pha, f_amp=f_amp, noise=.8, n_epochs=n_epochs, n_times=n_times) ############################################################################### # Extract phases and amplitudes ############################################################################### # Since we're going to compute PAC using several methods, we're first going # to extract all of the phases and amplitudes only once # define a pac object and extract high-resolution phases and amplitudes using # Morlet's wavelets p = Pac(f_pha='hres', f_amp='hres', dcomplex='wavelet') # etract all of the phases and amplitudes phases = p.filter(sf, data, ftype='phase', n_jobs=1) amplitudes = p.filter(sf, data, ftype='amplitude', n_jobs=1) ############################################################################### # Compute, plot and compare PAC ############################################################################### # Once all of the phases and amplitudes extracted we can compute PAC by # ietrating over the implemented methods. plt.figure(figsize=(14, 8)) for i, k in enumerate([1, 2, 3, 4, 5, 6]): # switch method of PAC p.idpac = (k, 0, 0) # compute only the pac without filtering
sf=sf) ############################################################################### # 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))
# 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 = 10 # number of datasets sf = 512. # sampling frequency n_times = 4000 # Number of time points data, time = pac_signals_tort(sf=sf, f_pha=5, f_amp=100, noise=2., n_epochs=n_epochs, n_times=n_times) # First, let's use the MVL, without any further correction by surrogates : p = Pac(f_pha=(2, 20, 1, 1), f_amp=(60, 150, 5, 5)) # 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, ftype='phase') amplitudes = p.filter(sf, data, ftype='amplitude') plt.figure(figsize=(18, 9)) for i, k in enumerate([1, 2, 3, 4, 5, 6]): # Change the pac method : p.idpac = (k, 0, 0) print('-> PAC using ' + str(p)) # Compute only the PAC without filtering : xpac = p.fit(phases, amplitudes) # Plot : plt.subplot(2, 3, k)
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), 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]')