Skip to content

Error in the set_probes function in spikeinterface ? #2435

Closed

Description

@Kayv-cmb

Hi Spikeinterface,

There seems to be an issue in the spikeinterface set_probes function in the core packages.

I am trying to set a probes to a recording but I get this error :


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], [line 50](vscode-notebook-cell:?execution_count=1&line=50)
     [48](vscode-notebook-cell:?execution_count=1&line=48) recording_b = recording.remove_channels(remove_channel_ids=missing_numbers)
     [49](vscode-notebook-cell:?execution_count=1&line=49) #probe.set_device_channel_indices(recording_b.get_channel_ids())
---> [50](vscode-notebook-cell:?execution_count=1&line=50) recording_clean = recording_b.set_probe(probe)
     [51](vscode-notebook-cell:?execution_count=1&line=51) #recording = recording.remove_channels(remove_channel_ids=bad_channel['index_pixels'])
     [52](vscode-notebook-cell:?execution_count=1&line=52) # setting the channel location
     [53](vscode-notebook-cell:?execution_count=1&line=53) #recording.set_channel_locations(positions) to check...
     [54](vscode-notebook-cell:?execution_count=1&line=54) rec_dict = dict(filt=recording_clean)

File [~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:96](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:96), in BaseRecordingSnippets.set_probe(self, probe, group_mode, in_place)
     [94](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:94) probegroup = ProbeGroup()
     [95](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:95) probegroup.add_probe(probe)
---> [96](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:96) return self.set_probes(probegroup, group_mode=group_mode, in_place=in_place)

File [~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:170](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:170), in BaseRecordingSnippets.set_probes(self, probe_or_probegroup, group_mode, in_place)
    [163](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:163) if number_of_device_channel_indices >= self.get_num_channels():
    [164](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:164)     error_msg = (
    [165](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:165)         f"The given Probe have 'device_channel_indices' that do not match channel count \n"
    [166](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:166)         f"{number_of_device_channel_indices} vs {self.get_num_channels()} \n"
    [167](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:167)         f"device_channel_indices are the following: {device_channel_indices} \n"
    [168](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:168)         f"recording channels are the following: {self.get_channel_ids()} \n"
    [169](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:169)     )
--> [170](https://vscode-remote+ssh-002dremote-002bvis-005fnode2.vscode-resource.vscode-cdn.net/camp/home/combadk/working/combadk/ScriptKC/CHIME_script/~/.conda/envs/CHIME_kayvan/lib/python3.9/site-packages/spikeinterface/core/baserecordingsnippets.py:170)     raise ValueError(error_msg)
...
ValueError: The given Probe have 'device_channel_indices' that do not match channel count 
110 vs 52 
device_channel_indices are the following: [  1   2   4   5   6   7   9  10  11  13  18  19  20  24  28  35  37  38  39  40  41  44  47  49  50  52  54  58  59  63  68  70  72  79  81  83  84  86  87  88  89  90  91  92  94  97 100 104 106 107 108 110] 
recording channels are the following: [  1   2   4   5   6   7   9  10  11  13  18  19  20  24  28  35  37  38  39  40  41  44  47  49  50  52  54  58  59  63  68  70  72  79  81  83  84  86  87  88  89  90  91  92  94  97 100 104 106 107 108 110]

When I had a look at the code, it seems to check the max of the device_channel_indices against the number of channel in the recording should it be comparing size?

        number_of_device_channel_indices = np.max(list(device_channel_indices) + [0])
        if number_of_device_channel_indices >= self.get_num_channels():
            error_msg = (
                f"The given Probe have 'device_channel_indices' that do not match channel count \n"
                f"{number_of_device_channel_indices} vs {self.get_num_channels()} \n"
                f"device_channel_indices are the following: {device_channel_indices} \n"
                f"recording channels are the following: {self.get_channel_ids()} \n"
            )
            raise ValueError(error_msg)

Activity

  1. alejoe91 commented on Jan 24, 2024

    @alejoe91
    Member

    Hi @Kayv-cmb

    The device_channel_indices is an index, so it's maximum value cannot exceed num_channels - 1

    How are you setting the device_channel_indices? Can you paste your script?

  2. added
    question
    on Jan 24, 2024
  3. Kayv-cmb commented on Jan 24, 2024

    @Kayv-cmb
    Author

    I am setting it like this, but basically I have a lot of preprocessing before actually creating a recording and which end up of
    with having a positions array (x,y,z) for the probe with channel indices like this
    array([ 74, 99, 25, 58, 72, 107, 91, 59, 63, 35, 90, 44, 42, 108, 97, 41, 87, 66, 19, 84, 37, 43, 88, 81, 104, 110, 57, 93, 106, 89, 24, 48, 2, 5, 52, 111, 28, 61, 102, 9, 68, 4, 11, 70, 40, 6, 75, 47, 79, 86, 94, 13, 49, 100, 92, 20, 7, 10, 1, 39, 18, 38, 50, 54, 83])

    exp = Experiment(directory, ct= dic)
    
    recording = extractor.read_chime(exp)
    num_channel = recording.get_num_channels()
    tip_min_um = exp.ct.tip_min*exp.ct.voxel[0]
    
    positions,bad_channel,df_min_noises = exp.channel_map(exp.wire_map,tip_min_um)
    missing_numbers = find_missing_numbers(df_min_noises['index_pixels'],num_channel)
    
    #positions,bad_channel = exp.channel_map(exp.wire_map,exp.ct.tip_min)
    # Creation of a custom prob linked to the channel map
    if positions.shape[1]==3:
        probe = Probe(ndim = 3, si_units='um')
        # Setting the position of the probes
        plane_axes_xy = np.zeros((len(positions), 2, 3))
        # xy axis will be:
        plane_axes_xy[:, 0, 0] = 1
        plane_axes_xy[:, 1, 1] = 1
        probe.set_contacts(positions=positions, shapes='circle', shape_params={'radius': 8}, plane_axes =plane_axes_xy)
        #probe.set_global_device_channel_indices(np.arrange(position.shape[0]))
        #probe.set_device_channel_indices(np.arange(positions.shape[0]))
        probe.set_device_channel_indices(df_min_noises['index_pixels'])
    
    # removing channel that got higher noise level
    recording_b = recording.remove_channels(remove_channel_ids=missing_numbers)
    #probe.set_device_channel_indices(recording_b.get_channel_ids())
    recording_clean = recording_b.set_probe(probe)
    
  4. Kayv-cmb commented on Jan 24, 2024

    @Kayv-cmb
    Author

    and when I compare this

    ValueError: The given Probe have 'device_channel_indices' that do not match channel count 
    110 vs 52 
    device_channel_indices are the following: [  1   2   4   5   6   7   9  10  11  13  18  19  20  24  28  35  37  38  39  40  41  44  47  49  50  52  54  58  59  63  68  70  72  79  81  83  84  86  87  88  89  90  91  92  94  97 100 104 106 107 108 110] 
    recording channels are the following: [  1   2   4   5   6   7   9  10  11  13  18  19  20  24  28  35  37  38  39  40  41  44  47  49  50  52  54  58  59  63  68  70  72  79  81  83  84  86  87  88  89  90  91  92  94  97 100 104 106 107 108 110]
    
    

    I have exactly the same channel inside both and the same number of channel but the match check give different output

  5. Kayv-cmb commented on Jan 25, 2024

    @Kayv-cmb
    Author

    I changed my way of doing it so that it would not trigger this error so I will close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions