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)
# 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) plt.figure(figsize=(20, 35)) # Plot the prefered phase : plt.subplot(221) plt.pcolormesh(p.yvec, np.arange(100), np.rad2deg(pp), cmap='Spectral_r') cb = plt.colorbar() plt.clim(vmin=-180., vmax=180.) plt.axis('tight')