diff --git a/neo/rawio/openephysbinaryrawio.py b/neo/rawio/openephysbinaryrawio.py index 957c195c9..27e3a80c9 100644 --- a/neo/rawio/openephysbinaryrawio.py +++ b/neo/rawio/openephysbinaryrawio.py @@ -12,6 +12,7 @@ import os import json from pathlib import Path +from warnings import warn import numpy as np @@ -570,6 +571,15 @@ def explore_folder(dirname, experiment_names=None): stream_name = node_name + "#" + oe_stream_name else: stream_name = oe_stream_name + + # skip streams if folder is on oebin, but doesn't exist + if not (recording_folder / "continuous" / info["folder_name"]).is_dir(): + warn( + f"For {recording_folder} the folder continuous/{info['folder_name']} is missing. " + f"Skipping {stream_name} continuous stream." + ) + continue + raw_filename = recording_folder / "continuous" / info["folder_name"] / "continuous.dat" # Updates for OpenEphys v0.6: @@ -604,6 +614,14 @@ def explore_folder(dirname, experiment_names=None): else: stream_name = oe_stream_name + # skip streams if folder is on oebin, but doesn't exist + if not (recording_folder / "events" / info["folder_name"]).is_dir(): + warn( + f"For {recording_folder} the folder events/{info['folder_name']} is missing. " + f"Skipping {stream_name} event stream." + ) + continue + event_stream = info.copy() for name in _possible_event_stream_names: npy_filename = root / "events" / info["folder_name"] / f"{name}.npy" diff --git a/neo/test/rawiotest/test_openephysbinaryrawio.py b/neo/test/rawiotest/test_openephysbinaryrawio.py index c4a5bff3b..bcb609104 100644 --- a/neo/test/rawiotest/test_openephysbinaryrawio.py +++ b/neo/test/rawiotest/test_openephysbinaryrawio.py @@ -13,6 +13,7 @@ class TestOpenEphysBinaryRawIO(BaseTestRawIO, unittest.TestCase): "openephysbinary/v0.5.x_two_nodes", "openephysbinary/v0.6.x_neuropixels_multiexp_multistream", "openephysbinary/v0.6.x_neuropixels_with_sync", + "openephysbinary/v0.6.x_neuropixels_missing_folders" ] def test_sync(self): @@ -48,6 +49,14 @@ def test_no_sync(self): ) rawio_no_sync.parse_header() + def test_missing_folders(self): + # missing folders should raise an error + with self.assertWarns(UserWarning): + rawio = OpenEphysBinaryRawIO( + self.get_local_path("openephysbinary/v0.6.x_neuropixels_missing_folders"), load_sync_channel=False + ) + rawio.parse_header() + if __name__ == "__main__": unittest.main()