diff --git a/src/probeinterface/neuropixels_tools.py b/src/probeinterface/neuropixels_tools.py index e575ce5..cedc513 100644 --- a/src/probeinterface/neuropixels_tools.py +++ b/src/probeinterface/neuropixels_tools.py @@ -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, @@ -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"]) diff --git a/tests/test_io/test_openephys.py b/tests/test_io/test_openephys.py index 3700235..1ffbf69 100644 --- a/tests/test_io/test_openephys.py +++ b/tests/test_io/test_openephys.py @@ -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