Skip to content

Commit

Permalink
Merge pull request NeuralEnsemble#1594 from alejoe91/open-ephys-partial
Browse files Browse the repository at this point in the history
OpenEphysBinary: Skip streams if folder doesn't exist
  • Loading branch information
zm711 authored Nov 4, 2024
2 parents e6ddc2e + dbed8f4 commit c96250a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions neo/rawio/openephysbinaryrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import json
from pathlib import Path
from warnings import warn

import numpy as np

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions neo/test/rawiotest/test_openephysbinaryrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit c96250a

Please sign in to comment.