Skip to content

Commit 5757336

Browse files
committed
Re-order ADC contact annotations to match device_channel_index
1 parent 149f53a commit 5757336

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/probeinterface/neuropixels_tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,12 @@ def read_openephys(
17521752
if oebin_file is not None:
17531753
device_channel_indices = _compute_wiring_from_oebin(probe, oebin_file, stream_name, settings_file)
17541754
probe.set_device_channel_indices(device_channel_indices)
1755+
1756+
# re-order contact annotations to match device channel order
1757+
ordered_adc_groups = [probe.contact_annotations["adc_group"][i] for i in device_channel_indices]
1758+
probe.annotate_contacts(adc_group=ordered_adc_groups)
1759+
ordered_adc_sample_orders = [probe.contact_annotations["adc_sample_order"][i] for i in device_channel_indices]
1760+
probe.annotate_contacts(adc_sample_order=ordered_adc_sample_orders)
17551761
else:
17561762
probe.set_device_channel_indices(np.arange(probe.get_contact_count()))
17571763
return probe

tests/test_io/test_openephys.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,9 @@ def _read_oebin_electrode_indices(oebin_file, stream_name):
499499
"""Read electrode_index metadata from an oebin file for a given stream."""
500500
with open(oebin_file) as f:
501501
oebin = json.load(f)
502-
is_neo_stream = "#" in stream_name
503-
oebin_stream_name = stream_name.split("#")[-1] if is_neo_stream else stream_name
504502
for cs in oebin.get("continuous", []):
505503
folder_name = cs.get("folder_name", "").rstrip("/")
506-
if folder_name == oebin_stream_name:
504+
if folder_name == stream_name:
507505
indices = []
508506
for ch in cs.get("channels", []):
509507
for m in ch.get("channel_metadata", []):
@@ -526,6 +524,8 @@ def test_read_openephys_with_oebin_wiring():
526524

527525
assert probe.get_contact_count() == 384
528526
assert probe.device_channel_indices is not None
527+
assert "adc_group" in probe.contact_annotations
528+
assert "adc_sample_order" in probe.contact_annotations
529529

530530
# Wiring invariant
531531
oebin_electrode_indices = _read_oebin_electrode_indices(oebin, stream_name)
@@ -708,7 +708,6 @@ def test_read_openephys_onebox_nonsequential_wiring():
708708
f"at column {column}, got {oebin_electrode_indices[column]}"
709709
)
710710

711-
712711
if __name__ == "__main__":
713712
# test_multiple_probes()
714713
# test_NP_Ultra()

0 commit comments

Comments
 (0)