Skip to content

Issue with setting probe groups when processing Intan electrophysiological data using spikeinterface #3777

Closed

Description

@cuowunimei

Problem: When reading Intan electrophysiological data using spikeinterface, I noticed that the channel_ids are not integers but strings like 'A-001', 'A-002', etc. This causes an issue when trying to link channels to probes via the set_device_channel_indices function, which expects integer indices. How can I resolve this mismatch?

import matplotlib.pyplot as plt
from pprint import pprint
from pathlib import Path
import numpy as np

import spikeinterface.full as si
global_job_kwargs = dict(n_jobs=4, chunk_duration="1s")
si.set_global_job_kwargs(**global_job_kwargs)
data_path = Path("D:/students/WWX/SpikeDataComparison/KD20250222/KD20250222_WWX009_250222_175030/KD20250222_WWX009_250222_175230.rhd")
# intan amplifier data is stored in stream_id = '0'
recording = si.read_intan(data_path, stream_id='0',all_annotations=True,use_names_as_ids=True)
# recording = si.read_binary(data_path,sampling_frequency=20000,num_channels=16,dtype='int16')
print(recording)
IntanRecordingExtractor: 16 channels - 20.0kHz - 1 segments - 1,200,000 samples 
                         60.00s (1.00 minutes) - uint16 dtype - 36.62 MiB
  file_path: D:\students\WWX\SpikeDataComparison\KD20250222\KD20250222_WWX009_250222_175030\KD20250222_WWX009_250222_175230.rhd
channels = recording.get_channel_ids()
device_channel_indices = np.arange(16)
fs = recording.get_sampling_frequency()
num_chan = recording.get_num_channels()
num_seg = recording.get_num_segments()

print("Channel ids:", channels)
print("Sampling frequency:", fs)
print("Number of channels:", num_chan)
print("Number of segments:", num_seg)
print("Recording proerty:", recording.get_property_keys())
w_ts = si.plot_traces(recording, channel_ids=channels,time_range=(0, 5), mode='auto',return_scaled=True,show_channel_ids=True,color='Blue')
Channel ids: ['A-001' 'A-002' 'A-003' 'A-004' 'A-005' 'A-006' 'A-007' 'A-008' 'A-009'
 'A-010' 'A-011' 'A-012' 'A-013' 'A-014' 'A-015' 'A-016']
Sampling frequency: 20000.0
Number of channels: 16
Number of segments: 1
Recording proerty: ['gain_to_uV', 'offset_to_uV', 'channel_names', 'channel_ids', 'electrode_impedance_magnitude', 'electrode_impedance_phase', 'custom_order', 'spike_scope_digital_trigger_channel', 'spike_scope_digital_edge_polarity', 'native_order', 'board_stream_num', 'chip_channel_num', 'spike_scope_trigger_mode', 'spike_scope_voltage_thresh']

Activity

  1. alejoe91 commented on Mar 17, 2025

    @alejoe91
    Member

    Hi @cuowunimei

    device_channel_indices are indeed integers, representing the index of the trace corresponding to a certain contact. This is totally independent of the channel_ids, which can be either int or strings.

  2. added
    question
    on Mar 17, 2025
  3. cuowunimei commented on Mar 17, 2025

    @cuowunimei
    Author

    Thank you for clarifying this! 🙌 I appreciate your help. However,I am attempting to split channels into four groups via set_probegroup, but the channels remain grouped as a single group. Here is the code.

    num_channels = recording.get_num_channels()
    
    groups = [0] * num_channels
    
    recording.set_property(key = 'group', values=groups)
    print(recording.get_channel_groups())
    
    from probeinterface import Probe, ProbeGroup, write_prb
    from probeinterface.plotting import plot_probe, plot_probe_group
    
    from probeinterface import generate_tetrode
    
    probegroup = ProbeGroup()
    
    channel_groups = [[14, 12, 10, 8], [6, 4, 2, 0], [15, 13, 11, 9], [7, 5, 3, 1]]
    # channel_groups = [['A-015', 'A-013', 'A-011', 'A-009'], ['A-007', 'A-005', 'A-003', 'A-001'], ['A-016', 'A-014', 'A-012', 'A-010'], ['A-008', 'A-006', 'A-004', 'A-002']]
    tetrode_A = generate_tetrode()
    tetrode_A.move([50, 0])
    tetrode_A.set_device_channel_indices(channel_groups[0])
    probegroup.add_probe(tetrode_A)
    
    tetrode_B = generate_tetrode()
    tetrode_B.move([100, 0])
    tetrode_B.set_device_channel_indices(channel_groups[1])
    probegroup.add_probe(tetrode_B)
    
    tetrode_C = generate_tetrode()
    tetrode_C.move([50, -50])
    tetrode_C.set_device_channel_indices(channel_groups[2])
    probegroup.add_probe(tetrode_C)
    
    tetrode_D = generate_tetrode()
    tetrode_D.move([100, -50])
    tetrode_D.set_device_channel_indices(channel_groups[3])
    probegroup.add_probe(tetrode_D)
    
    print(probegroup.get_global_device_channel_indices())
    # set this to the recording
    recording.set_probegroup(probegroup, group_mode='by_probe')
    # get group
    print(recording.get_channel_groups())
    # similar to this
    print(recording.get_property('group'))
    
    plot_probe_group(probegroup, with_contact_id=True, with_device_index=True)
    [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    [(0, 14) (0, 12) (0, 10) (0,  8) (1,  6) (1,  4) (1,  2) (1,  0) (2, 15)
     (2, 13) (2, 11) (2,  9) (3,  7) (3,  5) (3,  3) (3,  1)]
    [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
    
    C:\Users\DELL\AppData\Local\Temp\ipykernel_33764\1028705765.py:49: DeprecationWarning: `plot_probe_group` is deprecated and will be removed in 2.23. Use plot_probegroup instead
      plot_probe_group(probegroup, with_contact_id=True, with_device_index=True)
    
    
  4. alejoe91 commented on Mar 17, 2025

    @alejoe91
    Member

    The set_probegroup returns a new object.

    recording = recording.set_probegroup(probegroup, group_mode='by_probe')
    
  5. zm711 commented on Mar 17, 2025

    @zm711
    Member

    For me this another argument for getting rid of any reference to in_place, and ideally change the terminology from set which is too loaded a term. But I guess we never settled on a better term for attaching without making it sound like it is inplace. Probes are the only place where sometimes things are set in place and sometimes they return an object which makes things confusing for end users.

  6. cuowunimei commented on Mar 18, 2025

    @cuowunimei
    Author

    The set_probegroup returns a new object.

    recording = recording.set_probegroup(probegroup, group_mode='by_probe')
    

    Thank you so much for pointing this out! This resolved my issue, and I can now confirm that recording.get_channel_groups() correctly returns four distinct groups.

    For me this another argument for getting rid of any reference to in_place, and ideally change the terminology from set which is too loaded a term. But I guess we never settled on a better term for attaching without making it sound like it is inplace. Probes are the only place where sometimes things are set in place and sometimes they return an object which makes things confusing for end users.

    I fully agree with your observation about the terminology being potentially confusing. As a user, the difference between "set"and methods returning a new object was not immediately clear.

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