SpikeInterface / spikeinterface

A Python-based module for creating flexible and robust spike sorting pipelines.
https://spikeinterface.readthedocs.io
MIT License
533 stars 187 forks source link

Kilosort 4 writes present working directory to params.py instead of path to binary file. #2733

Closed gkBCCN closed 7 months ago

gkBCCN commented 7 months ago

Because Kilosort doesn't know about the binary file, when automatically writing the params.py file it enters the present working directory (of the calling script) instead. It would be nice to be able to pass a string that is written at the top of params.py instead.

zm711 commented 7 months ago

@gkBCCN , but if you don't have a binary file written yet then how would spikeinterface write that path? It would technically be just as easy to open params.py and edit it after the fact. My biggest concern is that if the KS4 wrapper lets you pass in a dir argument then KS4 might actually search for the bfile in the wrong place rather than just use the spikeinterface location. Our own export_to_phy gives you the ability to autowrite in the relative or absolute path to the binary, but in the past we let the native KS write whatever it wants to their version of the params.py.

alejoe91 commented 7 months ago

I think that on the spikeinterface wrapper we could check if it's a binary compatible recording and modify the params.py with the dat/bin location after ks is done

zm711 commented 7 months ago

You mean we write the binary to requested dir and name it after all the sorting is done? Or switch the wrapper to just write a binary at the beginning in a location and use that if the user requests it?

alejoe91 commented 7 months ago

No, to let ks run using the SI wrapper and then just uodate the params.py if the input SI recording is binary with the location to the file

gkBCCN commented 7 months ago

Hey guys. I appreciate the discussion, but I see that @zm711 has a point. Instead of a simple fix, this would be a tough problem to solve in general since it depends on the user's convention for storing the raw binary, etc. and might cause new problems. Plus, in the end it doesn't save that much time. I can just replace that line myself after writing the binary:

binary_path = sorting_folder/f"{group}"/"sorter_output"
si.write_binary_recording(sub_recording, file_paths=binary_path / "recording.dat", dtype='int16', **job_kwargs)
with open(binary_path / "params.py", "r") as params_file:
    lines = params_file.readlines()
lines[0] = "dat_path = 'recording.dat'\n"
with open(binary_path / "params.py", "w") as params_file:
    params_file.writelines(lines)