Skip to content

Commit

Permalink
Merge pull request #37 from zm711/ref-dur-refactor
Browse files Browse the repository at this point in the history
calculate refractory period violations with samples
  • Loading branch information
zm711 authored Aug 25, 2023
2 parents 1104ebe + 8c5b95d commit 721355f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/spikeanalysis/spike_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,19 @@ def refractory_violation(self, ref_dur_ms: float):
"""
print("calculating refractory period violation fraction")
self._goto_file_path()
ref_dur = ref_dur_ms / 1000
ref_dur_samples = ref_dur_ms / 1000 * self._sampling_rate
spike_clusters = np.squeeze(np.load("spike_clusters.npy"))
violations = np.zeros((len(set(spike_clusters))))
violations[:] = np.nan

try:
spike_times = self.spike_times
except AttributeError:
spike_times = self.raw_spike_times / self._sampling_rate
spike_times = self.raw_spike_times

for idx, cluster in enumerate(tqdm(set(spike_clusters))):
spikes = spike_times[self.spike_clusters == cluster]
# print(len(spikes))
if len(spikes) < 10:
continue
else:
num_violations = float(len(np.where(np.diff(spikes) <= ref_dur)[0]))
num_violations = float(len(np.where(np.diff(spikes) <= ref_dur_samples)[0]))
total_spikes = len(spikes)
violations[idx] = num_violations / total_spikes

Expand Down

0 comments on commit 721355f

Please sign in to comment.