MouseLand / Kilosort

Fast spike sorting with drift correction
https://kilosort.readthedocs.io/en/latest/
GNU General Public License v3.0
488 stars 247 forks source link

Question about 'nearest_chans' parameter #792

Closed rachelmcassidy closed 4 weeks ago

rachelmcassidy commented 2 months ago

I have previously found sorting parameters for KS4 that worked well for a 64 channel, single column probe geometry. When I use those parameters for a 2 column probe with similarly spaced contacts, the channels on which spike features are calculated do not cover the whole waveform, similar to issue #782.

I often have cortical pyramidal cells whose waveforms extend farther vertically than they do horizontally. Does the 'nearest_chans' parameter use euclidean distance to select the channels? I'm wondering if I should double this parameter to cover the same distance on the 2 column probe. How does 'nearest_chans' compare to 'template_sizes', 'nearest_templates', and 'max_channel_distance' for this issue? Would it be appropriate to change those as well?

Thanks for your help!

jacobpennington commented 1 month ago

@rachelmcassidy nearest_chans uses euclidean distance, yes. nearest_templates also uses euclidean distance, so you may need to increase it as well, but I wouldn't recommend doing that unless you still see problems with the sorting results after changing nearest_chans. template_sizes and min_template_size jointly determine the distribution of universal template sizes, but again I would not change those unless you have reason to believe that spikes are being missed because their waveforms fall outside expected range of sizes. max_channel_distance controls the placement of universal templates around contacts, it is not likely to impact this issue.

Keep in mind that increasing any of these parameters, with the exception of min_template_size, will impact performance since, so I would only change nearest_chans for now and then see how the results look before changing anything else.

jacobpennington commented 1 month ago

One other thing to keep in mind is that the extra channels won't necessarily be needed. There is generally enough information already in the largest channels, so you should only bother with tweaking these settings if you're seeing some problem with the results that you think is caused by those channels being left out.

rachelmcassidy commented 1 month ago

Thanks for your advice, Jacob! It sounds like nearest_chans is the main issue then. For cells whose waveforms extend beyond the default nearest_chans range (which is about +/- 40 um for the probe geometry), I will find a main cluster around the spike center, and then other clusters 4-5 channels above with spikes that are mostly duplicates of the main spike.

I'm guessing that when the main template is subtracted off, the waveform on distant channels is still in the residual and gets matched with other templates? Unfortunately, not all of them are duplicates and some get clustered with real units on those channels, so it's not straightforward to just throw them out.