cortex-lab / phy

phy: interactive visualization and manual spike sorting of large-scale ephys data
BSD 3-Clause "New" or "Revised" License
304 stars 155 forks source link

Help with understanding ISIview and finding the number of spikes in each bin #1215

Closed ryoiwata closed 1 month ago

ryoiwata commented 11 months ago

Hey all!

Quick question with the ISI view. What are the numbers on the Y-axis in the ISI view?

We are trying to find a way to count the number of spikes that occurred within the two center bins/bars for refractory period violations. Currently, we are counting the smallest difference between adjacent bins as one spike. And then counting the number of spikes in other bins based on how many multiples of the smallest difference in terms of height that the bin's height is. Please let us know if there's a simpler way to find the number of spikes in the different bins. Thank you so much for any help!

image

zm711 commented 11 months ago

@ryoiwata

It would be pretty easy to do that outside of Phy. You just load in spike_times.npy and spike_clusters.npy. Then to get the ISI you just do something like:

spike_clusters = np.squeeze(np.load('spike_clusters.npy'))
spike_times = np.squeeze(np.load('spike_times.npy')) # these are raw will need sample rate later
for cluster in np.unique(spike_clusters):
    current_spike_times = spike_times[spike_clusters==cluster]
    total_spikes = len(current_spike_times)
    current_isi = np.diff(current_spike_times) * sample_rate # this is stored in the params.py file
    number_violations= len(current_isi[current_isi<refractory_period]) # you put in whatever refractory period you want as written in seconds

Then you save the number_violations for each cluster and total_spikes for each cluster.

There are some more sophisticated approaches. You can check out spikeinterface which can load Phy directories and do some of the math for you or you could read up on the different types of more statistical-like tests for doing refractory period violations.

Or you could check out sortingQuality if you prefer Matlab.

Hope that helps :)