plotting, psth, sta lecture
This commit is contained in:
@@ -44,13 +44,13 @@ def get_instantaneous_rate(times, max_t=30., dt=1e-4):
|
||||
|
||||
|
||||
def plot_isi_rate(spike_times, max_t=30, dt=1e-4):
|
||||
times = np.squeeze(spike_times[0][0])[:100000]
|
||||
time, rate = get_instantaneous_rate(times, max_t=100000*dt)
|
||||
times = np.squeeze(spike_times[0][0])[:50000]
|
||||
time, rate = get_instantaneous_rate(times, max_t=50000*dt)
|
||||
|
||||
rates = np.zeros((len(rate), len(spike_times)))
|
||||
for i in range(len(spike_times)):
|
||||
_, rates[:, i] = get_instantaneous_rate(np.squeeze(spike_times[i][0])[:100000],
|
||||
max_t=100000*dt)
|
||||
_, rates[:, i] = get_instantaneous_rate(np.squeeze(spike_times[i][0])[:50000],
|
||||
max_t=50000*dt)
|
||||
avg_rate = np.mean(rates, axis=1)
|
||||
rate_std = np.std(rates, axis=1)
|
||||
|
||||
@@ -59,7 +59,7 @@ def plot_isi_rate(spike_times, max_t=30, dt=1e-4):
|
||||
ax2 = fig.add_subplot(312)
|
||||
ax3 = fig.add_subplot(313)
|
||||
|
||||
ax1.vlines(times[times < (100000*dt)], ymin=0, ymax=1, color="dodgerblue", lw=1.5)
|
||||
ax1.vlines(times[times < (50000*dt)], ymin=0, ymax=1, color="dodgerblue", lw=1.5)
|
||||
ax1.set_ylabel("skpikes", fontsize=12)
|
||||
set_axis_fontsize(ax1, 12)
|
||||
|
||||
@@ -112,13 +112,13 @@ def plot_bin_rate(spike_times, bin_width, max_t=30, dt=1e-4):
|
||||
|
||||
ax1.vlines(times[times < (100000*dt)], ymin=0, ymax=1, color="dodgerblue", lw=1.5)
|
||||
ax1.set_ylabel("skpikes", fontsize=12)
|
||||
ax1.set_xlim([0, 10])
|
||||
ax1.set_xlim([0, 5])
|
||||
set_axis_fontsize(ax1, 12)
|
||||
|
||||
ax2.plot(time, rate, label="binned rate, trial 1")
|
||||
ax2.set_ylabel("firing rate [Hz]", fontsize=12)
|
||||
ax2.legend(fontsize=12)
|
||||
ax2.set_xlim([0, 10])
|
||||
ax2.set_xlim([0, 5])
|
||||
set_axis_fontsize(ax2, 12)
|
||||
|
||||
ax3.fill_between(time, avg_rate+rate_std, avg_rate-rate_std, color="dodgerblue",
|
||||
@@ -127,7 +127,7 @@ def plot_bin_rate(spike_times, bin_width, max_t=30, dt=1e-4):
|
||||
ax3.set_xlabel("times [s]", fontsize=12)
|
||||
ax3.set_ylabel("firing rate [Hz]", fontsize=12)
|
||||
ax3.legend(fontsize=12)
|
||||
ax3.set_xlim([0, 10])
|
||||
ax3.set_xlim([0, 5])
|
||||
ax3.set_ylim([0, 450])
|
||||
set_axis_fontsize(ax3, 12)
|
||||
|
||||
@@ -165,13 +165,13 @@ def plot_conv_rate(spike_times, sigma=0.05, max_t=30, dt=1e-4):
|
||||
|
||||
ax1.vlines(times[times < (100000*dt)], ymin=0, ymax=1, color="dodgerblue", lw=1.5)
|
||||
ax1.set_ylabel("skpikes", fontsize=12)
|
||||
ax1.set_xlim([0, 10])
|
||||
ax1.set_xlim([0, 5])
|
||||
set_axis_fontsize(ax1, 12)
|
||||
|
||||
ax2.plot(time, rate, label="convolved rate, trial 1")
|
||||
ax2.set_ylabel("firing rate [Hz]", fontsize=12)
|
||||
ax2.legend(fontsize=12)
|
||||
ax2.set_xlim([0, 10])
|
||||
ax2.set_xlim([0, 5])
|
||||
set_axis_fontsize(ax2, 12)
|
||||
|
||||
ax3.fill_between(time, avg_rate+rate_std, avg_rate-rate_std, color="dodgerblue",
|
||||
@@ -180,19 +180,19 @@ def plot_conv_rate(spike_times, sigma=0.05, max_t=30, dt=1e-4):
|
||||
ax3.set_xlabel("times [s]", fontsize=12)
|
||||
ax3.set_ylabel("firing rate [Hz]", fontsize=12)
|
||||
ax3.legend(fontsize=12)
|
||||
ax3.set_xlim([0, 10])
|
||||
ax3.set_xlim([0, 5])
|
||||
ax3.set_ylim([0, 450])
|
||||
set_axis_fontsize(ax3, 12)
|
||||
|
||||
fig.set_size_inches(15, 10)
|
||||
fig.subplots_adjust(left=0.1, bottom=0.125, top=0.95, right=0.95)
|
||||
fig.set_facecolor("white")
|
||||
fig.savefig("../lectures/images/concolved_rate.png")
|
||||
fig.savefig("../lectures/images/convolved_rate.png")
|
||||
plt.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
spike_times = spio.loadmat('lifoustim.mat')["spikes"]
|
||||
# plot_isi_rate(spike_times)
|
||||
# plot_bin_rate(spike_times, 0.05)
|
||||
plot_conv_rate(spike_times, 0.05)
|
||||
plot_isi_rate(spike_times)
|
||||
plot_bin_rate(spike_times, 0.05)
|
||||
plot_conv_rate(spike_times, 0.025)
|
||||
|
||||
Reference in New Issue
Block a user