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
Shuffled channels when concatenating sliced recordings #1691
I tried to concatenate recording slices (subselection of channels) and realized that my sorting (Kilosort2.5) did not find consistent units across the recordings:
My workflow is as follows: I have several recordings with some core electrodes that stay constant throughout all recordings, while I sample from the rest of the electrodes "at random". I match the core electrodes and concatenate the recordings over the matching channels, which I then spike sort to subsequently extract footprints from the randomly selected channels.
I went back and checked how the traces looked like after concatenating and filtering. Interestingly, the channels are only shuffled across recordings, when I plot (si.plot_timeseries) or retrieve (si.get_traces) several traces at a time, but not when I look at individual ones:
vs
I tried to backtrace the error but could not figure out where the difference was between retrieving one vs many traces. One thing that I found, however, was that the shuffling did not take place, when the original channel ids (before concatenating) matched.
I realize that this is a pretty niche issue, but I would appreciate any help, as I would like to keep my workflow within the spikeinterface environment.
When I try to run your code I get the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[13], line 1
----> 1 trace_one_channel_only = multirecording.get_traces(channel_ids=multirecording.channel_ids[0])[:, 0]
2 trace_multi_channels = multirecording.get_traces(channel_ids=multirecording.channel_ids[:2])[:, 0]
File ~/miniconda3/envs/si_env/lib/python3.9/site-packages/spikeinterface/core/baserecording.py:158, in BaseRecording.get_traces(self, segment_index, start_frame, end_frame, channel_ids, order, return_scaled, cast_unsigned)
126 """Returns traces from recording.
127
128 Parameters
(...)
155 If return_scaled is True, but recording does not have scaled traces
156 """
157 segment_index = self._check_segment_index(segment_index)
--> 158 channel_indices = self.ids_to_indices(channel_ids, prefer_slice=True)
159 rs = self._recording_segments[segment_index]
160 traces = rs.get_traces(start_frame=start_frame, end_frame=end_frame, channel_indices=channel_indices)
File ~/miniconda3/envs/si_env/lib/python3.9/site-packages/spikeinterface/core/base.py:102, in BaseExtractor.ids_to_indices(self, ids, prefer_slice)
100 else:
101 _main_ids = self._main_ids.tolist()
--> 102 indices = np.array([_main_ids.index(id) for id in ids], dtype=int)
103 if prefer_slice:
104 if np.all(np.diff(indices) == 1):
TypeError: 'numpy.int64' object is not iterable
I I replace channel_ids[0] by channel_ids[0:1] it works and the assertion does not fail.
Regarding this:
One thing that I found, however, was that the shuffling did not take place, when the original channel ids (before concatenating) matched.
I checked again and this seems to have been a concidence, but instead I now found that also retrieving 2 traces does not shuffle them, but only if it is >=3:
can you try to plot the traces for the single recordings separately for the same channels? Thanks for helping out here! Trying to understand what's going on
Thanks. I think I need to ask you to share the data with me! Otherwise we can try to have a debugging by the end of next week. Let me know what you prefer!
Activity
alejoe91 commentedon Jun 7, 2023
Hi Philipp!
Thanks for all the info, this is helpful. I guess something is buggy when re-sorting the channels..can you run this to double check?
Can I ask you some clarification on?
hornauerp commentedon Jun 7, 2023
Hi Alessio!
When I try to run your code I get the following error:
I I replace
channel_ids[0]bychannel_ids[0:1]it works and the assertion does not fail.Regarding this:
I checked again and this seems to have been a concidence, but instead I now found that also retrieving 2 traces does not shuffle them, but only if it is >=3:

alejoe91 commentedon Jun 7, 2023
Ok, getting closer!
So basically the same example above but with the secon line being:
fails? That is interesting!
hornauerp commentedon Jun 7, 2023
Yes exactly, this gives this shuffled trace:

alejoe91 commentedon Jun 7, 2023
ok..what are the channel_ids of the individual recordings?
hornauerp commentedon Jun 7, 2023
Those should be:

alejoe91 commentedon Jun 7, 2023
can you try to plot the traces for the single recordings separately for the same channels? Thanks for helping out here! Trying to understand what's going on
hornauerp commentedon Jun 7, 2023
So what I tried before was:
If I plot those it is still shuffled:

Would that answer your question?
Ah, sorry I misread your question, one second.
So I guess you are referring to something like this?
This seems to look fine:

alejoe91 commentedon Jun 7, 2023
I would try this 2 options:
Could you also share the code you used for selecting and sorting the channels and to concatenate them?
hornauerp commentedon Jun 7, 2023
Your first option produces:

The second one:

To select and concatenate the channels I do the following:
I just do the filtering here to get rid of the offset and it is actually faster than si.center().
alejoe91 commentedon Jun 7, 2023
And the second option seems to work well for all 4 channels, right?
hornauerp commentedon Jun 7, 2023
Yes, it works for all 4 individually.
alejoe91 commentedon Jun 7, 2023
Thanks. I think I need to ask you to share the data with me! Otherwise we can try to have a debugging by the end of next week. Let me know what you prefer!
alejoe91 commentedon Nov 6, 2023
Fixed by @hornauerp