Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing Cf amplitude in st[:,3] #844

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

ryan-ressmeyer
Copy link

Hi! I've been working on some quality control metrics for KS4 and made a small change that I thought others might benefit from. I explain below:

A commonly used quality control metric for previous versions of Kilosort has been to quantify the truncation of the amplitude distribution as an estimate of the percentage of spikes missing in a given cluster (i.e. prevalence of type 2 errors). Such methods are implemented in bombcell and the IBL spike sorting pipeline. In the current version of Kilosort4, amplitudes.npy always returns an approximately gaussian distribution for amplitudes, making it impossible to estimate the degree of truncation. The amplitudes column in st[:,2] often shows a truncation, but occasionally appears to superimpose two truncated distributions with different truncation thresholds points (I believe due to normalization and merges, but I am not certain). This PR makes a small change to template_matching.py to append an extra column to st. This column contains the raw value of Cf for each spike, which is the value used to determine spike inclusion. This is the value that is directly compared to Th_learned, and always shows the truncation clearly. This makes the spike inclusion criteria clear to the user, and allows previously developed QC methods to be used with KS4.

I'm also including a figure below to help demonstrate this point. The top row is the a cluster identified by KS2.5, while the bottom 3 rows show the same cluster (high % of coincident spikes) identified by KS4. The top row plots amplitudes.npy from KS2.5 with a clear truncation after the red line (amplitude histograms in the right column). The second row shows amplitudes.npy from KS4 with no clear truncation. The third row shows st[:,2], which matches KS2.5 amplitudes.npy more closely, but seemly has two superimposed truncated distributions. The final row shows the proposed st[:,3] with a clearly truncated distribution that matches (roughly) the KS2.5 distribution. The truncation is also at the Th_learned = 8 value, which makes it clear to the user that this is the amplitude value used for spike inclusion.

ks4_amplitudes

Thanks for your time!
Ryan Ressmeyer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants