Skip to content

Commit 48b855f

Browse files
authored
Merge pull request #1661 from h-mayorquin/fix_spikeglx
Fix spikeglx stream for isolated folder from multi probe case.
2 parents d265dc6 + 9d39fe8 commit 48b855f

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

neo/rawio/spikeglxrawio.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -376,28 +376,16 @@ def get_segment_tuple(info):
376376
for info in info_list:
377377
info["seg_index"] = segment_tuple_to_segment_index[get_segment_tuple(info)]
378378

379-
# Probe index calculation
380-
# The calculation is ordered by slot, port, dock in that order, this is the number that appears in the filename
381-
# after imec when using native names (e.g. imec0, imec1, etc.)
382-
def get_probe_tuple(info):
383-
slot = normalize(info.get("probe_slot"))
384-
port = normalize(info.get("probe_port"))
385-
dock = normalize(info.get("probe_dock"))
386-
return (slot, port, dock)
387-
388-
# TODO: handle one box case
389-
info_list_imec = [info for info in info_list if info.get("device") != "nidq"]
390-
unique_probe_tuples = {get_probe_tuple(info) for info in info_list_imec}
391-
sorted_probe_keys = sorted(unique_probe_tuples)
392-
probe_tuple_to_probe_index = {key: idx for idx, key in enumerate(sorted_probe_keys)}
393379

394380
for info in info_list:
395-
if info.get("device") == "nidq":
396-
info["device_index"] = "" # TODO: Handle multi nidq case, maybe use meta["typeNiEnabled"]
381+
# device_kind is imec, nidq
382+
if info.get("device_kind") == "imec":
383+
info["device_index"] = info["device"].split("imec")[-1]
397384
else:
398-
info["device_index"] = probe_tuple_to_probe_index[get_probe_tuple(info)]
385+
info["device_index"] = "" # TODO: Handle multi nidq case, maybe use meta["typeNiEnabled"]
399386

400-
# Define stream base on device [imec|nidq], device_index and stream_kind [ap|lf] for imec
387+
# Define stream base on device_kind [imec|nidq], device_index and stream_kind [ap|lf] for imec
388+
# Stream format is "{device_kind}{device_index}.{stream_kind}"
401389
for info in info_list:
402390
device_kind = info["device_kind"]
403391
device_index = info["device_index"]
@@ -524,6 +512,7 @@ def extract_stream_info(meta_file, meta):
524512
# NIDQ case
525513
has_sync_trace = False
526514

515+
# This is the original name that the file had. It might not match the current name if the user changed it
527516
bin_file_path = meta["fileName"]
528517
fname = Path(bin_file_path).stem
529518

neo/test/rawiotest/test_spikeglxrawio.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ class TestSpikeGLXRawIO(BaseTestRawIO, unittest.TestCase):
4343
"spikeglx/multi_trigger_multi_gate/CatGT/Supercat-A",
4444
]
4545

46+
def test_loading_only_one_probe_in_multi_probe_scenario(self):
47+
from pathlib import Path
48+
local_path_multi_probe_path = Path(self.get_local_path("spikeglx/multi_trigger_multi_gate/SpikeGLX/5-19-2022-CI0"))
49+
gate_folder_path = local_path_multi_probe_path / "5-19-2022-CI0_g0"
50+
probe_folder_path = gate_folder_path / "5-19-2022-CI0_g0_imec1"
51+
52+
rawio = SpikeGLXRawIO(probe_folder_path)
53+
rawio.parse_header()
54+
55+
expected_stream_names = ["imec1.ap", "imec1.lf"]
56+
actual_stream_names = rawio.header["signal_streams"]["name"].tolist()
57+
assert actual_stream_names == expected_stream_names, f"Expected {expected_stream_names}, but got {actual_stream_names}"
58+
4659
def test_with_location(self):
4760
rawio = SpikeGLXRawIO(self.get_local_path("spikeglx/Noise4Sam_g0"), load_channel_location=True)
4861
rawio.parse_header()

0 commit comments

Comments
 (0)