MouseLand / Kilosort

Fast spike sorting with drift correction for up to a thousand channels
https://kilosort.readthedocs.io/en/latest/
GNU General Public License v3.0
469 stars 245 forks source link

issue with whitening when electrode locations are duplicated #567

Closed magland closed 8 months ago

magland commented 1 year ago

I realize it should never happen that two electrodes have identical location. However, unless I am making an error in reading the data file, I have come across an example of this in an IBL dataset on the DANDI archive. I still need to double check and confirm that this is the case.

But in any event, here's what happens when you have a duplicated location - and I think this is something that should be fixed.

Here's the relevant code

https://github.com/MouseLand/Kilosort/blob/d55179f4bed45d4f17e5481283bc3f260212c1c7/preProcess/whiteningLocal.m#L1-L14

Note the comment "First channel in this list will always be the primary channel." This is not the case when you have duplicates. And so what ends up happening is that two rows (or maybe columns) of the whitening matrix end up being identical. This in turn causes two channels to be identical signal in the filtered data. And this causes a problem with detection where all spikes are considered non-isolated. Finally this in turn causes the crash of #566

magland commented 1 year ago

As a follow-up. It seems the IBL dataset is actually okay... you just need to read the rel_x, rel_y fields from the NWB file and not the x, y, z. Still investigating.