Beispiel #1
0
def plot_spectrum(x, dt, shift, ax=None, color=None, label=None):
    """ 
        Plots the power-frequency spectrum of a simulation in a semilog plot.
    """
    #dt, shift = 75, 10
    if not ax:
        _, ax = plt.subplots()

    start, end = 1000, max(x)
    f, pxx = psd.power_spectrum(x, dt, shift, start, end)
    ax.semilogy(f, pxx, color=color, label=label)
    ax.set_xlabel('Frequency (Hz)')
    ax.set_ylabel('Power')
ma = psd.moving_average(X, dt, shift, total_steps)
time_scale = np.arange(0, duration / ms, shift)
time_scale = time_scale[100:-100]
plt.plot(time_scale, ma[100:-100])
plt.title('All Neurons')
plt.xlabel('Simulation Time (ms)')
plt.ylabel('Mean firing rate')

ma1 = psd.moving_average(X1, dt, shift, total_steps)
ma2 = psd.moving_average(X2, dt, shift, total_steps)

plt.figure(2)
plt.plot(time_scale, ma1[100:-100])
plt.title('Excitatory Neurons')
plt.xlabel('Simulation Time (ms)')
plt.ylabel('Mean firing rate')

plt.figure(3)
plt.plot(time_scale, ma2[100:-100])
plt.title('Inhibitory Neurons')
plt.xlabel('Simulation Time (ms)')
plt.ylabel('Mean firing rate')

plt.figure(4)
f, pxx = psd.power_spectrum(X, dt, shift, total_steps)
plt.semilogy(f, pxx)
plt.xlabel('Frequency (Hz)')
plt.ylabel('Power Spectrum')

plt.show()
plt.plot(M_EX.t / ms, M_EX.i, '.b')
ax2.set_xlim(0, duration / ms)
ax2.set_xlabel("Time (ms)")
ax2.set_ylabel("Excitatory Neuron Index")

ax3 = plt.subplot(312)
plt.plot(M_IN.t / ms, M_IN.i, '.k')
ax3.set_xlim(0, duration / ms)
ax3.set_xlabel("Time (ms)")
ax3.set_ylabel("Inhibitory Neuron Index")

ax1.legend()

plt.figure(2)
ax1 = plt.subplot(211)
f, pxx = psd.power_spectrum(times, dt, shift, int((duration / ms) / shift))
ax1.set_xlabel('Frequency (Hz)')
ax1.set_ylabel('Power Spectrum')
plt.plot(f, pxx, label="All excitatory spikes")
ax1.legend()

ax2 = plt.subplot(212)
for i, ss in enumerate(spikes_per_module):
    f, pxx = psd.power_spectrum(ss, dt, shift, int((duration / ms) / shift))
    plt.plot(f, pxx, color="C{}".format(i), label="Module {}".format(i))
ax2.set_xlabel('Frequency (Hz)')
ax2.set_ylabel('Power Spectrum')
ax2.legend()
plt.tight_layout()

plt.show()
Beispiel #4
0
# )
#
#
#with open(fname, 'wb') as f:
#    print('Writing output data to \'{}\''.format(fname))
#    pickle.dump(PICKLE_OUT_DATA, f)

# Discard initial transient signal
transient_thres = 1000  # ms
X = np.concatenate([M_EX.t / ms, M_IN.t / ms])
Y = np.concatenate([M_EX.i, M_IN.i + N_EX])

XY = [(t, s) for (t, s) in zip(X, Y) if t >= transient_thres]
X, Y = zip(*XY)

plt.figure(1)
plt.plot(X, Y, '.b')
plt.xlabel("Time (ms)")
plt.ylabel("Excitatory Neuron Index")

plt.figure(2)
dt = 75  # ms
shift = 10  # ms
total_steps = int(duration / (shift * ms))
f, pxx = psd.power_spectrum(X, dt, shift, int((duration / ms) / shift))
plt.semilogy(f, pxx)
plt.xlabel('Frequency (Hz)')
plt.ylabel('Power Spectrum')

plt.show()