예제 #1
0
    def test_pac_comodulogram(self):
        """Test Pac object definition.

        This test works locally but failed on travis...
        """
        matplotlib.use('agg')
        f, tridx = pac_trivec()
        pac = np.random.rand(20, 10)
        pval = np.random.rand(20, 10)
        p = Pac(f_pha=np.arange(11), f_amp=np.arange(21))
        p.comodulogram(np.random.rand(10, 10, 20))
        p.comodulogram(pac, rmaxis=True, dpaxis=True, interp=(.1, .1))
        p.comodulogram(pac, plotas='contour', pvalues=pval)
        p.comodulogram(pac,
                       plotas='pcolor',
                       pvalues=pval,
                       levels=[.5, .7],
                       under='gray',
                       over='red',
                       bad='orange')
        p = Pac(f_pha=np.arange(11), f_amp=f)
        pac = np.random.rand(len(f))
        p.triplot(pac, f, tridx)
        p.savefig('test_savefig.png')
        p.show()
        matplotlib.pyplot.close('all')
예제 #2
0
def test_pac_comodulogram():
    """Test Pac object definition.

    This test works locally but failed on travis...
    """
    matplotlib.use('agg')
    f, tridx = pac_trivec()
    pac = np.random.rand(20, 10)
    pval = np.random.rand(20, 10)
    p = Pac(fpha=np.arange(11), famp=np.arange(21))
    print(len(p.xvec), len(p.yvec))
    p.comodulogram(pac, rmaxis=True, dpaxis=True)
    p.comodulogram(pac, plotas='contour', pvalues=pval)
    p.comodulogram(pac,
                   plotas='pcolor',
                   pvalues=pval,
                   levels=[.5, .7],
                   under='gray',
                   over='red',
                   bad='orange')
    p = Pac(fpha=np.arange(11), famp=f)
    p.polar(pac, np.arange(10), np.arange(20), interp=.8)
    pac = np.random.rand(len(f))
    p.triplot(pac, f, tridx)
    matplotlib.pyplot.close('all')
예제 #3
0
sf = 256.
data, time = pac_signals_tort(f_pha=[5, 7],
                              f_amp=[60, 80],
                              noise=2,
                              n_epochs=5,
                              n_times=3000,
                              sf=sf,
                              dpha=10)

trif, tridx = pac_trivec(f_start=30, f_end=140, f_width=3)

p = Pac(idpac=(1, 0, 0), f_pha=[5, 7], f_amp=trif)
pac = p.filterfit(sf, data)

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')

p.show()
예제 #4
0
best_f = trif[pac.argmax()]

plt.figure(figsize=(16, 7))
plt.subplot(121)
ax = psd.plot(confidence=None, f_min=2, f_max=30, log=False, grid=True)
plt.ylim(0, .15)
plt.title("Power Spectrum Density (PSD)")
# plt.autoscale(enable=True, axis='y', tight=True)
ax = plt.gca()
ax.text(*tuple(cfg["nb_pos"]), 'A', transform=ax.transAxes, **cfg["nb_cfg"])

plt.subplot(122)
p.triplot(pac,
          trif,
          tridx,
          cmap=cfg["cmap"],
          rmaxis=True,
          title=r'Optimal $[Fmin; Fmax]hz$ band for amplitude',
          cblabel="")
plt.axvline(best_f[0], lw=1, color='w')
plt.axhline(best_f[1], lw=1, color='w')
ax = plt.gca()
ax.text(*tuple(cfg["nb_pos"]), 'B', transform=ax.transAxes, **cfg["nb_cfg"])

plt.tight_layout()
# plt.savefig(f"{cfg['path']}/Fig7.png", dpi=300, bbox_inches='tight')

print("*" * 79)
print(f"BEST FREQUENCY RANGE : {trif[pac.argmax()]}")
print("*" * 79)