error message "Bytes in binary file did not divide evenly, incorrect n_chan_bin"
Describe the issue:
Hello!
We have encountered recent path issue and installed kilosort 4.0.37 as advised. However, previously unseen problem has emerged, which is related to issue #672
We have recorded the data using Spikegadgets' Trodes software and NET's flexible probes from Chong Xie's lab at Rice University. We had established protocol for ks4 to spike sort the data. New dataset was recently recorded, and we have encountered the same issue as in the old posts at issue #672 :
We have used the same 128 channel probes as we've used before, and it seems that the .dat file does have 128 channels:
Reproduce the bug:
Error message:
Version information:
Python version 3.9, Kilosort 4.0.37
Please attach kilosort4.log from the results directory.
2025-05-15 15:44:08,166 kilosort.run_kilosort INFO Kilosort version 4.0.35
2025-05-15 15:44:08,167 kilosort.run_kilosort INFO Python version 3.9.21
2025-05-15 15:44:08,167 kilosort.run_kilosort INFO ----------------------------------------
2025-05-15 15:44:08,167 kilosort.run_kilosort INFO System information:
2025-05-15 15:44:08,180 kilosort.run_kilosort INFO Linux-4.18.0-372.9.1.el8.x86_64-x86_64-with-glibc2.28 x86_64
2025-05-15 15:44:08,180 kilosort.run_kilosort INFO x86_64
2025-05-15 15:44:27,515 kilosort.run_kilosort INFO Using GPU for PyTorch computations. Specify device to change this.
2025-05-15 15:44:27,551 kilosort.run_kilosort INFO Using CUDA device: Tesla V100-SXM2-32GB 31.74GB
2025-05-15 15:44:27,551 kilosort.run_kilosort INFO ----------------------------------------
2025-05-15 15:44:27,552 kilosort.run_kilosort ERROR Encountered error in run_kilosort:
Traceback (most recent call last):
File "/home/vrevenam/.conda/envs/kilosort/lib/python3.9/site-packages/kilosort/run_kilosort.py", line 232, in _sort
if len(filename) == 1:
TypeError: object of type 'PosixPath' has no len()
This was a bug introduced in a recent version, related to using the data_dir setting. It's fixed in the latest release. Updating with pip install --upgrade kilosort should resolve it. The output you posted indicates you have 4.0.35 installed, not 4.0.37.
Hello,
I have just reinstalled kilosort by removing it from the envronment and then following the installation instructions here on github anew. If I check the kilosort version (both via pip list or inside python), it is clear that the correct version is installed:
However, when I run the spike sorting job, the same error happens, and withing the log file I have version 4.0.35
That sounds like it's either not being run in the correct environment, or something about the package management got messed up. I would recommend double checking whatever script/interface you're using to run kilosort to make sure that it's pointing to the correct python executable for the enviroment you re-installed in. If that's already set correctly, you may just need to create a fresh environment.
Hey @jacobpennington , First things first, you were right: we had some discrepancies on our cluster which resulted in wrong version initialization. See the log attached.
However, in the same log we still observe the save error:
ValueError: Bytes in binary file did not divide evenly, incorrect n_chan_bin ('number of channels' in GUI).
Are you sure there aren't any other channels in the data that aren't included in the 128 you highlighted, like ground channels that aren't included in that number? I can't see any reason why this error would happen unless the number of channels isn't correct.
One way to check for sure is you can load the data yourself with numpy and divide the size of the array by the number of time samples. For example, our small test dataset is exactly 45 seconds long, so the following confirms the correct number of channels is 385:
import numpy as np
n_samples = 30000*45 # 30,000 samples per second for 45 seconds
f = 'path/to/data.bin'
a = np.memmap(f, mode='r', dtype='int16')
print(a.shape[0]/n_samples)