You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Making order = np.argsort(device_channel_indices) optional #4565
Dear Spikeinterface community,
I am asking for this feature in the _set_probes() as I would like to feed my previous dataset sorted by kilosort standalone into an analyser with the new function read_kilosort_as_analyzer#4366
The problem is that my probe map, coming from probe_interface library is not sorted by channels. While using spikeinterface to do spike sorting, it is fine to sort them by channels. However, when using read_kilosort_as_analyzer, it will check whether channels location used in the kilosort4 phy folder matches with its counterpart in the Recording (e.g. OpenEphysBinaryRecordingExtractor). Since kilosort4 does not sort the map, there is always a mismatch between the two.
or
I can certainly create a set of probe maps and sort them by channels first before using kilosort standalone to do spike sorting so that I will never to worry about this mismatch. However, would it be possible to make order = np.argsort(device_channel_indices) an option to skip so that both Recording and either my original probe.prb or kilosort's channel_map.npy, channel_locations.npy, and channel_shanks.npy are equally unsorted?
Or if you have any suggestion about circuvment the mismatch in channels location when using read_kilosort_as_analyzer?
Hi @chiyu1203 , sorry I've been meaning to look at this. It's possible that I'm using channel_map incorrectly in the kilosort PR. I'll take a closer look next week!
@chrishalcrow thank you! Take your time! I was thinking either doing some work in _set_probes() or in read_kilosort_as_analyzer to ensure the channels are sorted the same way but yeah you probably know what I meant.
Hello, I tried to update PR #4529 so that the probe attached to the recording gets rewired to whatever is in the probe.prb file. Can you check if this solves the problem?
Hello, Thank you very much for the update! I have tried that with and without .prb file in the phy folder. Both worked fine (I have not valided the final output of the sorting analyser, but I think that part is fixed).
On the other hand, there is a minor issue related to recording.get_probe().set_device_channel_indices(new_device_channel_indices) in the read_kilosort_as_analyzer (Line 394).
I would received this following error if I attached 2-shanked probe information to the recording from a .prb file, instead of a .json file.
Exception has occurred: AssertionError
there are several probe use .get_probes() or get_probegroup()
File "C:\Users\neuroPC\Documents\GitHub\spikeinterface\src\spikeinterface\core\baserecordingsnippets.py", line 245, in get_probe
assert len(probes) == 1, "there are several probe use .get_probes() or get_probegroup()"
^^^^^^^^^^^^^^^^
File "C:\Users\neuroPC\Documents\GitHub\spikeinterface\src\spikeinterface\extractors\phykilosortextractors.py", line 394, in read_kilosort_as_analyzer
recording.get_probe().set_device_channel_indices(new_device_channel_indices)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\neuroPC\Documents\GitHub\ephys\spike_curation.py", line 357, in si2phy
sorting_analyzer=se.read_kilosort_as_analyzer(kilosort_result_folder_name,recording_for_analysis)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\neuroPC\Documents\GitHub\ephys\spike_curation.py", line 500, in
_=si2phy(thisDir, json_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: there are several probe use .get_probes() or get_probegroup()
The foundamental mechanism behind that seems to because of the API read_prb. Here is a discussion about that.
In my code, this is how I read 2-shanked probe information from the .prb file
These codes, together with additional lines to add shank id to the probegroup, are fine to group my recording without a problem.
For me, the way to get around that error is to use recording.get_probegroup().set_global_device_channel_indices(new_device_channel_indices) at Line 394 in the read_kilosort_as_analyzer
However, I am not familiar with .set_global_device_channel_indices() so not sure if this is the right way to fix this.
Note: in the case where the 2-shanked information comes from .json file, I use
No error returned, no matter if I changed the Line 394 from recording.get_probe().set_device_channel_indices(new_device_channel_indices) to recording.get_probegroup().set_global_device_channel_indices(new_device_channel_indices) or not
This type of error is what I am talking about when I have argued against silently setting device_channel_indices to arange(N) in #4397: the code should not have this type of side effects. It is an undeclared modification of the probe that we do for the internal benefit of SpikeInterface (which is actually not really necessary, see #4553), but it is surprising to the user. The user had their own mapping that they wanted to keep, and we are losing that information here.
@h-mayorquin thanks for the insight! I do not have any idea how to solve this issue, either working on a quick fix for this particular function or re-organising those basis in the Spikeinterface. @chrishalcrow Do you have any preference?
Hello, I've updated the PR with @h-mayorquin's recommendation. Let us know if it works!
We will probably need to come back to this after the other probe issues are resolved.
We realised there was a much easier way to get the recording to use the right channel map: we now apply the channel map to the spikeinterface recording using select_channels. This is simpler and doesn't touch the probe wiring (which can get complicated internally).
Activity
chrishalcrow commentedon May 1, 2026
Hi @chiyu1203 , sorry I've been meaning to look at this. It's possible that I'm using
channel_mapincorrectly in the kilosort PR. I'll take a closer look next week!chiyu1203 commentedon May 4, 2026
@chrishalcrow thank you! Take your time! I was thinking either doing some work in _set_probes() or in read_kilosort_as_analyzer to ensure the channels are sorted the same way but yeah you probably know what I meant.
chrishalcrow commentedon May 11, 2026
Hello, I tried to update PR #4529 so that the probe attached to the recording gets rewired to whatever is in the probe.prb file. Can you check if this solves the problem?
chiyu1203 commentedon May 11, 2026
Hello, Thank you very much for the update! I have tried that with and without .prb file in the phy folder. Both worked fine (I have not valided the final output of the sorting analyser, but I think that part is fixed).
On the other hand, there is a minor issue related to
recording.get_probe().set_device_channel_indices(new_device_channel_indices)in theread_kilosort_as_analyzer(Line 394).I would received this following error if I attached 2-shanked probe information to the recording from a .prb file, instead of a .json file.
The foundamental mechanism behind that seems to because of the API
read_prb. Here is a discussion about that.In my code, this is how I read 2-shanked probe information from the .prb file
These codes, together with additional lines to add shank id to the probegroup, are fine to group my recording without a problem.
For me, the way to get around that error is to use
recording.get_probegroup().set_global_device_channel_indices(new_device_channel_indices)at Line 394 in theread_kilosort_as_analyzerHowever, I am not familiar with
.set_global_device_channel_indices()so not sure if this is the right way to fix this.Note: in the case where the 2-shanked information comes from .json file, I use
No error returned, no matter if I changed the Line 394 from
recording.get_probe().set_device_channel_indices(new_device_channel_indices)torecording.get_probegroup().set_global_device_channel_indices(new_device_channel_indices)or noth-mayorquin commentedon May 18, 2026
This type of error is what I am talking about when I have argued against silently setting
device_channel_indicestoarange(N)in #4397: the code should not have this type of side effects. It is an undeclared modification of the probe that we do for the internal benefit of SpikeInterface (which is actually not really necessary, see #4553), but it is surprising to the user. The user had their own mapping that they wanted to keep, and we are losing that information here.chiyu1203 commentedon May 22, 2026
@h-mayorquin thanks for the insight! I do not have any idea how to solve this issue, either working on a quick fix for this particular function or re-organising those basis in the Spikeinterface. @chrishalcrow Do you have any preference?
chrishalcrow commentedon May 25, 2026
Hello, I've updated the PR with @h-mayorquin's recommendation. Let us know if it works!
We will probably need to come back to this after the other probe issues are resolved.
chiyu1203 commentedon May 26, 2026
Thank you so much!! I have tested the updated PR already. It worked well and fixed my problem so I will close this issue for now.
chrishalcrow commentedon May 26, 2026
Great!! We'll try and get the PR merged into main soon
chrishalcrow commentedon Jul 22, 2026
Hi @chiyu1203
We realised there was a much easier way to get the recording to use the right channel map: we now apply the channel map to the spikeinterface recording using
select_channels. This is simpler and doesn't touch the probe wiring (which can get complicated internally).Can you re-try the open PR (https://github.com/SpikeInterface/spikeinterface/pull/4529/changes) on your data?
Sorry this has taken a while, I just keep forgetting about it. Feel free to tag me any time to try and hurry me up!
chiyu1203 commentedon Jul 22, 2026
@chrishalcrow No worries! I have tested the new 4529 with the code
This returned the following error at the step of set_temporary_recording
Do you know where the bug might come from? I have lost the track of this PR 4529 already.