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

BUG: Error when running kilosort on a previously acceptable file (RuntimeWarning: divide by zero encountered in scalar divide) #626

Closed JacobKelley101 closed 7 months ago

JacobKelley101 commented 7 months ago

Describe the issue:

Kilosort throws the below error when I try to analyze my data. I used a datafile that ran without errors in Kilosort2.5. I included the main error text as well as a picture of the GUI and enlarged python read-out.

C:\Users\kelley.j\AppData\Local\anaconda3\envs\kilosort\lib\site-packages\kilosort\spikedetect.py:92: RuntimeWarning: divide by zero encountered in scalar divide ops['yup'] = np.arange(ymin, ymax+.00001, dmin//2)

image

Reproduce the bug:

No response

Error message:

No response

Version information:

Kilosort 4

Context for the issue:

No response

Experiment information:

No response

jacobpennington commented 7 months ago

Are you by chance using something other than micron values for 'xc' and 'yc'? This error came up for another user because their xc and yc values were on a different scale, probably mm, so dmin was set to something very small which will cause dmin // 2 to round down to 0.

JacobKelley101 commented 7 months ago

I updated my probe configuration from xc = [2,2,1,3] yc = [3,1,2,2] (worked with Kilosort2.5) to xc = [50,50,25,75], yc = [75,25,50,50] (roughly um dimensions of neuronexus tetrode probe) and that got rid of the previous error but a new one is appearing. Now there is a broadcasting error. Thanks for continuing to help! image

jacobpennington commented 7 months ago

You'll have to change nearest_chans in the "extra settings" window to 4 (or less), it can't be larger than the number of channels in the data. I'll add a fix for that to the todo list, to check that automatically.

JacobKelley101 commented 7 months ago

Awesome, now the program runs (or at least the progress bar gets to 100% and figures are generated) but nothing appears to be getting saved. I posted the error messages again (this time in text bc it wouldn't fit on the screen). I am using datafiles that have produced at least 1 cluster with Kilosort2.5. Generated Figures: ![image](https://github.com/MouseLand/Kilosort/assets/164085482/3b421cf4-e40a-4ab8-80ee-0305ff3b7898

If continuously commenting in this thread for you/others to help me debug my own version of kilosort is frowned upon please let me know. This is my first time using GitHub and I am not familiar with best practices.

Error message text (below):

Preprocessing filters computed in 0.06s; total 0.06s

computing drift

nblocks = 0, skipping drift correction

drift computed in 0.00s; total 0.06s

Extracting spikes using templates

Re-computing universal templates from data.

0%| | 0/600 [00:00<?, ?it/s]

0%| | 0/600 [00:19<?, ?it/s]

81%|################################################################9 | 487/600 [01:00<00:13, 8.11it/s]

100%|################################################################################| 600/600 [01:14<00:00, 8.11it/s]

7885 spikes extracted in 74.10s; total 74.16s

First clustering

0%| | 0/1 [00:00<?, ?it/s]

100%|############################################################################################| 1/1 [00:00<?, ?it/s]

1 clusters found, in 0.03s; total 74.19s

Extracting spikes using cluster waveforms

0%| | 0/600 [00:00<?, ?it/s]

100%|###############################################################################| 600/600 [00:01<00:00, 452.25it/s]

225 spikes extracted in 1.33s; total 75.52s

Final clustering

0%| | 0/1 [00:00<?, ?it/s]

100%|############################################################################################| 1/1 [00:00<?, ?it/s]

Traceback (most recent call last):

File "C:\Users\kelley.j\AppData\Local\anaconda3\envs\kilosort\lib\site-packages\kilosort\gui\sorter.py", line 90, in run

clu, Wall = cluster_spikes(st, tF, ops, self.device, bfile, tic0=tic0,

File "C:\Users\kelley.j\AppData\Local\anaconda3\envs\kilosort\lib\site-packages\kilosort\run_kilosort.py", line 420, in cluster_spikes

clu, Wall = clustering_qr.run(ops, st, tF, mode = 'template', device=device,

File "C:\Users\kelley.j\AppData\Local\anaconda3\envs\kilosort\lib\site-packages\kilosort\clustering_qr.py", line 317, in run

raise ValueError(

ValueError : get_data_cpu never found suitable channels in clustering_qr.run. dmin, dminx, and xcenter are: (25.0, 1.0, 50.0)

Traceback (most recent call last):

File "C:\Users\kelley.j\AppData\Local\anaconda3\envs\kilosort\lib\site-packages\kilosort\gui\main.py", line 158, in keyPressEvent

self.toggle_mode("prediction")

File "C:\Users\kelley.j\AppData\Local\anaconda3\envs\kilosort\lib\site-packages\kilosort\gui\main.py", line 280, in toggle_mode

raise ValueError("Invalid mode requested!")

ValueError : Invalid mode requested!

jacobpennington commented 7 months ago

Continuing to comment here is fine, someone else with single tetrode data will likely run into the same problems and find this helpful.

The fact that dminx is being set to 1 (reported by that second to last error) means it's not parsing the probe layout very well, probably because there are so few channels. You could try manually setting dminx to 25 or 50 instead, which will adjust where templates are positioned for spike detection.

If that doesn't work, @marius10p might have other ideas.

JacobKelley101 commented 7 months ago

That did the trick! I set dminx to 25 and the outputs generated and files were saved. I will have to validate that the program is working as intended (comparing to Kilosort2.5) but I believe that is the natural conclusion to this thread. If I encounter any issues with validation I will open a new Issue. Thanks for your continued support, it is greatly appreciated. I will close this issue.