Skip to content

Commit 4c3a6f9

Browse files
authored
Open Ephys: find root folder to correctly look for timestamps (#4500)
1 parent da9be0e commit 4c3a6f9

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

src/spikeinterface/extractors/neoextractors/openephys.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def __init__(
224224
experiment_names: str | list | None = None,
225225
all_annotations: bool = False,
226226
):
227+
folder_path = Path(folder_path)
228+
227229
# Handle experiment_names deprecation
228230
if experiment_names is not None:
229231
warnings.warn(
@@ -336,8 +338,15 @@ def __init__(
336338
if sample_shifts is not None:
337339
self.set_property("inter_sample_shift", sample_shifts)
338340

339-
# load synchronized timestamps and set_times to recording
340-
recording_folder = Path(folder_path) / record_node
341+
# folder_path can point to different levels of the OE folder structure
342+
# (root, record node, experiment, or recording). We need to find the root folder
343+
# in order to load the sync timestamps and set them as times to the recording.
344+
if record_node in folder_path.parts:
345+
root_index = len(folder_path.parts) - folder_path.parts.index(record_node) - 1
346+
root_folder = folder_path.parents[root_index]
347+
else:
348+
root_folder = folder_path
349+
recording_folder = root_folder / record_node
341350
stream_folders = []
342351
for segment_index, rec_id in enumerate(rec_ids):
343352
stream_folder = (

src/spikeinterface/extractors/tests/test_neoextractors.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,38 @@ def test_non_trivial_wiring(self):
156156
probe = recording.get_probe()
157157
np.testing.assert_array_equal(recording.channel_ids, probe.contact_annotations["settings_channel_key"])
158158

159+
def test_timestamp_loading_multi_level(self):
160+
"""
161+
Test that we can load the sync timestamps from different levels of the folder structure and
162+
that they are the same.
163+
"""
164+
recording_folder = (
165+
local_folder / "openephysbinary/v0.6.x_neuropixels_with_sync/Record Node 104/experiment1/recording1"
166+
)
167+
stream_name = "Record Node 104#Neuropix-PXI-100.ProbeA-AP"
168+
block_index = 0
169+
170+
recording_from_recording_folder = self.ExtractorClass(
171+
recording_folder,
172+
stream_name=stream_name,
173+
block_index=block_index,
174+
load_sync_timestamps=True,
175+
)
176+
assert recording_from_recording_folder.has_time_vector()
177+
timestamps_recording = recording_from_recording_folder.get_times()
178+
parent_folder = recording_folder
179+
for _ in range(3):
180+
parent_folder = parent_folder.parent
181+
recording_from_parent = self.ExtractorClass(
182+
parent_folder,
183+
stream_name=stream_name,
184+
block_index=block_index,
185+
load_sync_timestamps=True,
186+
)
187+
assert recording_from_parent.has_time_vector()
188+
timestamps_parent = recording_from_parent.get_times()
189+
np.testing.assert_array_equal(timestamps_recording, timestamps_parent)
190+
159191

160192
class OpenEphysBinaryEventTest(EventCommonTestSuite, unittest.TestCase):
161193
ExtractorClass = OpenEphysBinaryEventExtractor

0 commit comments

Comments
 (0)