add option for test plot in get_bustiness

This commit is contained in:
alexanderott 2020-06-01 12:17:04 +02:00
parent a2da22cd76
commit 8fc99a356d

View File

@ -27,18 +27,18 @@ class Baseline:
def get_coefficient_of_variation(self):
raise NotImplementedError("NOT YET OVERRIDDEN FROM ABSTRACT CLASS")
def get_burstiness(self):
def get_burstiness(self, test_plot=False):
isis = np.array(self.get_interspike_intervals()) * 1000 # change unit to ms
if len(isis) <= 10:
return 0
step = 0.1
bins = np.arange(0, min(isis) * 3, step)
bins = np.arange(0, max(isis), step)
num_spikes_per_bin = np.zeros(bins.shape)
for i, bin in enumerate(bins):
num_of_spikes = np.sum(isis[(isis >= bin) & (isis < bin + step)])
num_of_spikes = len((isis[(isis >= bin) & (isis < bin + step)]))
num_spikes_per_bin[i] = num_of_spikes
max_found = -1
@ -58,19 +58,25 @@ class Baseline:
else:
if num_spikes_per_bin[i + 1] > num:
end_of_peak = i +1
end_of_peak = i + 1
break
burstiness = sum(num_spikes_per_bin[:end_of_peak]) / len(isis)
# bins = np.arange(0, max(isis) * 1.01, 0.1)
#
# plt.title('Baseline ISIs - burstiness {:.2f}'.format(burstiness))
# plt.xlabel('ISI in ms')
# plt.ylabel('Count')
# plt.hist(isis, bins=bins)
# plt.plot((0.5*step, bins[end_of_peak-1] + 0.5*step,), (0, 0), 'o')
# plt.show()
if test_plot:
print("burst peak:", sum(num_spikes_per_bin[:end_of_peak]))
print("sum num per bin:", sum(num_spikes_per_bin))
print("len isis:", len(isis))
bins = np.arange(0, max(isis) * 1.01, 0.1)
plt.title('Baseline ISIs - burstiness {:.2f}'.format(burstiness))
plt.xlabel('ISI in ms')
plt.ylabel('Count')
plt.hist(isis, bins=bins)
plt.plot([step*(i+0.5) for i in range(len(num_spikes_per_bin))], num_spikes_per_bin, 'o', alpha=0.5)
plt.plot((0.5 * step, bins[end_of_peak - 1] + 0.5 * step,), (0, 0), 'o')
plt.show()
return burstiness