Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/probeinterface/neuropixels_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,7 @@ def read_openephys(
"shank_ids": shank_ids,
"elec_ids": elec_ids,
"channel_names": channel_names,
"channel_order": channel_order,
"pt_metadata": pt_metadata,
"slot": slot,
"port": port,
Expand Down Expand Up @@ -1429,6 +1430,9 @@ def read_openephys(
pt_metadata, probe_part_number, elec_ids, shank_ids=shank_ids, mux_info=mux_info
)

if "channel_order" in np_probe_info:
probe.set_device_channel_indices(np_probe_info["channel_order"])

if "channel_names" in np_probe_info:
probe.annotate_contacts(channel_name=np_probe_info["channel_names"])

Expand Down
22 changes: 22 additions & 0 deletions tests/test_io/test_openephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,28 @@ def test_older_than_06_format():
assert np.min(ypos) >= 0


def test_older_than_06_device_channel_indices():
"""Test that device_channel_indices correctly map sorted contacts to original XML order."""
import xml.etree.ElementTree as ET

settings_file = data_path / "OE_5_Neuropix-PXI-multi-probe" / "settings.xml"
tree = ET.parse(settings_file)
root = tree.getroot()

# Parse the original XML channel order for the first probe
np_probe = root.findall(".//NP_PROBE")[0]
channels = np_probe.find("CHANNELS")
channel_names = list(channels.attrib.keys())
channel_ids = np.array([int(ch[2:]) for ch in channel_names])
expected_channel_order = np.argsort(channel_ids)

probe = read_openephys(settings_file, probe_name="100.0")

# device_channel_indices should map sorted contacts back to original XML positions
assert probe.device_channel_indices is not None
np.testing.assert_array_equal(probe.device_channel_indices, expected_channel_order)


def test_multiple_signal_chains():
# tests that the probe information can be loaded even if the Neuropix-PXI plugin
# is not in the first signalchain
Expand Down
Loading