Ejemplo n.º 1
0
 def test_polar_plot(self):
     """Test the polar plot."""
     matplotlib.use('agg')
     p = PreferredPhase(f_pha=[5, 7], f_amp=(60, 200, 10, 1))
     x_pha = np.random.rand(100, 1000)
     x_amp = np.random.rand(100, 1000)
     ampbin, pp, vecbin = p.filterfit(256, x_pha, x_amp=x_amp)
     pp = np.squeeze(pp).T
     ampbin = np.squeeze(ampbin).mean(-1)
     p.polar(ampbin.T, vecbin, p.yvec, cmap='RdBu_r', interp=.1,
             cblabel='Amplitude bins')
     matplotlib.pyplot.close('all')
Ejemplo n.º 2
0
 def test_fit(self):
     """Test function fit."""
     data = np.random.rand(100, 1000)
     p = PreferredPhase()
     pha = p.filter(256, data, 'phase')
     amp = p.filter(256, data, 'amplitude')
     p.fit(pha, amp)
Ejemplo n.º 3
0
sf = 1024.
n_epochs = 100
n_times = 2000
pp = np.pi / 2
data, time = pac_signals_wavelet(f_pha=6,
                                 f_amp=100,
                                 n_epochs=n_epochs,
                                 sf=sf,
                                 noise=1,
                                 n_times=n_times,
                                 pp=pp)

###############################################################################
# Extract phases, amplitudes and compute the preferred phase
###############################################################################
p = PreferredPhase(f_pha=[5, 7], f_amp=(60, 200, 10, 1))

# Extract the phase and the amplitude :
pha = p.filter(sf, data, ftype='phase', n_jobs=1)
amp = p.filter(sf, data, ftype='amplitude', n_jobs=1)

# Now, compute the PP :
ampbin, pp, vecbin = p.fit(pha, amp, n_bins=72)

###############################################################################
# Plot the preferred phase
###############################################################################
# Here, we first plot the preferred phase across trials according to
# amplitudes. Then, the distribution of 100hz amplitudes is first plotted
# according to the 72 phase bins and also using a polar representation
Ejemplo n.º 4
0
                                 n_epochs=n_epochs,
                                 sf=sf,
                                 noise=3,
                                 n_times=n_times,
                                 pp=pp)

# compute the binned amplitude
b_obj = BinAmplitude(data,
                     sf,
                     f_pha=[5, 7],
                     f_amp=[90, 110],
                     n_jobs=1,
                     n_bins=18)

# compute the preferred phase
p = PreferredPhase(f_pha=[5, 7], f_amp='hres')
pha = p.filter(sf, data, ftype='phase', n_jobs=1)
amp = p.filter(sf, data, ftype='amplitude', n_jobs=1)
ampbin, pp, vecbin = p.fit(pha, amp, n_bins=72)
pp = np.squeeze(pp).T
ampbin = np.squeeze(ampbin).mean(-1)

plt.figure(figsize=(18, 8))

plt.subplot(121)
ax = b_obj.plot(color='#34495e', alpha=.5, unit='deg')
plt.ylim(40, 140)
plt.title("Binned 100hz amplitude according to the 6hz phase")
# plt.autoscale(tight=True)
ax = plt.gca()
ax.text(*tuple(cfg["nb_pos"]), 'A', transform=ax.transAxes, **cfg["nb_cfg"])
Ejemplo n.º 5
0
# As you can see, the amplitude is modulated inside the resting and even more
# inside the planning phase. On the other hand, during the execution, the
# distribution stays flat. Note also that the amplitude is maximum arround
# -150° (or 210°) during the planning phase

###############################################################################
# Identify the preferred phase
###############################################################################
# The preferred phase is given by the phase bin at which the amplitude is
# maximum. Said differently, the gamma amplitude is binned according to the
# alpha phase. The preferred-phase is computed as the maximum of this
# histogram. To identify this preferred-phase, we propose here a polar plotting
# method to visualize retrieve the previous result using the histogram method

# define the preferred phase object
pp_obj = PreferredPhase(f_pha=[8, 12])
# only extract the alpha phase
pp_pha = pp_obj.filter(sf, data, ftype='phase')
pp_pha_rest = pp_pha[..., time_rest]
pp_pha_prep = pp_pha[..., time_prep]
pp_pha_exec = pp_pha[..., time_exec]
# compute the preferred phase (reuse the amplitude computed above)
ampbin_rest, _, vecbin = pp_obj.fit(pp_pha_rest, amp_rest, n_bins=72)
ampbin_prep, _, vecbin = pp_obj.fit(pp_pha_prep, amp_prep, n_bins=72)
ampbin_exec, _, vecbin = pp_obj.fit(pp_pha_exec, amp_exec, n_bins=72)
# mean binned amplitude across trials
ampbin_rest = np.squeeze(ampbin_rest).mean(-1).T
ampbin_prep = np.squeeze(ampbin_prep).mean(-1).T
ampbin_exec = np.squeeze(ampbin_exec).mean(-1).T

###############################################################################
Ejemplo n.º 6
0
 def test_filterfit(self):
     """Test function filterfit."""
     p = PreferredPhase()
     x_pha = np.random.rand(100, 1000)
     x_amp = np.random.rand(100, 1000)
     p.filterfit(256, x_pha, x_amp=x_amp)
Ejemplo n.º 7
0
 def test_filter(self):
     """Test function filter."""
     data = np.random.rand(7, 1000)
     p = PreferredPhase()
     p.filter(256, data, 'phase')
     p.filter(256, data, 'amplitude')