From 802b37863b55927799cea1bc5606d3689569aa56 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 4 Nov 2024 11:24:04 +0100 Subject: [PATCH 1/3] Skip streams if folder doesn't exist --- neo/rawio/openephysbinaryrawio.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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" From fa3f508e8a9dbae759e7893a62eb128cc7a0aaa8 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 4 Nov 2024 12:37:17 +0100 Subject: [PATCH 2/3] Add test on missing folders --- neo/test/rawiotest/test_openephysbinaryrawio.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/neo/test/rawiotest/test_openephysbinaryrawio.py b/neo/test/rawiotest/test_openephysbinaryrawio.py index c4a5bff3b..8e18347b7 100644 --- a/neo/test/rawiotest/test_openephysbinaryrawio.py +++ b/neo/test/rawiotest/test_openephysbinaryrawio.py @@ -1,4 +1,5 @@ import unittest +import pytest from neo.rawio.openephysbinaryrawio import OpenEphysBinaryRawIO from neo.test.rawiotest.common_rawio_test import BaseTestRawIO @@ -13,6 +14,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 +50,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() From dbed8f49dff094e49249b45adb00e98d8d2bd398 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 4 Nov 2024 15:40:14 +0100 Subject: [PATCH 3/3] Update neo/test/rawiotest/test_openephysbinaryrawio.py --- neo/test/rawiotest/test_openephysbinaryrawio.py | 1 - 1 file changed, 1 deletion(-) diff --git a/neo/test/rawiotest/test_openephysbinaryrawio.py b/neo/test/rawiotest/test_openephysbinaryrawio.py index 8e18347b7..bcb609104 100644 --- a/neo/test/rawiotest/test_openephysbinaryrawio.py +++ b/neo/test/rawiotest/test_openephysbinaryrawio.py @@ -1,5 +1,4 @@ import unittest -import pytest from neo.rawio.openephysbinaryrawio import OpenEphysBinaryRawIO from neo.test.rawiotest.common_rawio_test import BaseTestRawIO