Skip to content

Commit c96250a

Browse files
authored
Merge pull request #1594 from alejoe91/open-ephys-partial
OpenEphysBinary: Skip streams if folder doesn't exist
2 parents e6ddc2e + dbed8f4 commit c96250a

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

neo/rawio/openephysbinaryrawio.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import json
1414
from pathlib import Path
15+
from warnings import warn
1516

1617
import numpy as np
1718

@@ -570,6 +571,15 @@ def explore_folder(dirname, experiment_names=None):
570571
stream_name = node_name + "#" + oe_stream_name
571572
else:
572573
stream_name = oe_stream_name
574+
575+
# skip streams if folder is on oebin, but doesn't exist
576+
if not (recording_folder / "continuous" / info["folder_name"]).is_dir():
577+
warn(
578+
f"For {recording_folder} the folder continuous/{info['folder_name']} is missing. "
579+
f"Skipping {stream_name} continuous stream."
580+
)
581+
continue
582+
573583
raw_filename = recording_folder / "continuous" / info["folder_name"] / "continuous.dat"
574584

575585
# Updates for OpenEphys v0.6:
@@ -604,6 +614,14 @@ def explore_folder(dirname, experiment_names=None):
604614
else:
605615
stream_name = oe_stream_name
606616

617+
# skip streams if folder is on oebin, but doesn't exist
618+
if not (recording_folder / "events" / info["folder_name"]).is_dir():
619+
warn(
620+
f"For {recording_folder} the folder events/{info['folder_name']} is missing. "
621+
f"Skipping {stream_name} event stream."
622+
)
623+
continue
624+
607625
event_stream = info.copy()
608626
for name in _possible_event_stream_names:
609627
npy_filename = root / "events" / info["folder_name"] / f"{name}.npy"

neo/test/rawiotest/test_openephysbinaryrawio.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class TestOpenEphysBinaryRawIO(BaseTestRawIO, unittest.TestCase):
1313
"openephysbinary/v0.5.x_two_nodes",
1414
"openephysbinary/v0.6.x_neuropixels_multiexp_multistream",
1515
"openephysbinary/v0.6.x_neuropixels_with_sync",
16+
"openephysbinary/v0.6.x_neuropixels_missing_folders"
1617
]
1718

1819
def test_sync(self):
@@ -48,6 +49,14 @@ def test_no_sync(self):
4849
)
4950
rawio_no_sync.parse_header()
5051

52+
def test_missing_folders(self):
53+
# missing folders should raise an error
54+
with self.assertWarns(UserWarning):
55+
rawio = OpenEphysBinaryRawIO(
56+
self.get_local_path("openephysbinary/v0.6.x_neuropixels_missing_folders"), load_sync_channel=False
57+
)
58+
rawio.parse_header()
59+
5160

5261
if __name__ == "__main__":
5362
unittest.main()

0 commit comments

Comments
 (0)