From 28f53df019f0c7c1cd2aff887d001bcafd55c568 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 3 Apr 2023 16:11:59 +0200 Subject: [PATCH 1/2] Allow folders without events/continuous streams to be loaded --- neo/rawio/openephysbinaryrawio.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/neo/rawio/openephysbinaryrawio.py b/neo/rawio/openephysbinaryrawio.py index 650c96672..5495f5d04 100644 --- a/neo/rawio/openephysbinaryrawio.py +++ b/neo/rawio/openephysbinaryrawio.py @@ -77,9 +77,16 @@ def _parse_header(self): check_folder_consistency(folder_structure, possible_experiments) self.folder_structure = folder_structure - # all streams are consistent across blocks and segments - sig_stream_names = sorted(list(all_streams[0][0]['continuous'].keys())) - event_stream_names = sorted(list(all_streams[0][0]['events'].keys())) + # all streams are consistent across blocks and segments. + # also checks that 'continuous' and 'events' folder are present + if 'continuous' in all_streams[0][0]: + sig_stream_names = sorted(list(all_streams[0][0]['continuous'].keys())) + else: + sig_stream_names = [] + if 'events' in all_streams[0][0]: + event_stream_names = sorted(list(all_streams[0][0]['events'].keys())) + else: + event_stream_names = [] # first loop to reassign stream by "stream_index" instead of "stream_name" self._sig_streams = {} @@ -563,7 +570,13 @@ def explore_folder(dirname, experiment_names=None): # nested dictionary: block_index > seg_index > data_type > stream_name all_streams = {} nb_segment_per_block = {} - recording_node = folder_structure[list(folder_structure.keys())[0]] + record_nodes = list(folder_structure.keys()) + if len(record_nodes) == 0: + raise ValueError( + f"{dirname} is not a valid Open Ephys binary folder. No 'structure.oebin' " + f"files were found in sub-folders." + ) + recording_node = folder_structure[record_nodes[0]] # nb_block needs to be consistent across record nodes. Use the first one nb_block = len(recording_node['experiments']) @@ -609,7 +622,8 @@ def check_folder_consistency(folder_structure, possible_experiment_names=None): ("Inconsistent experiments across recording nodes!") # check that "continuous" streams are the same across multiple segments (recordings) - experiments = folder_structure[list(folder_structure.keys())[0]]['experiments'] + record_nodes = list(folder_structure.keys()) + experiments = folder_structure[record_nodes[0]]['experiments'] for exp_id, experiment in experiments.items(): segment_stream_names = None if len(experiment['recordings']) > 1: From 28697b66f781dce9588cc67c64d50f8914dd4e1d Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 3 Apr 2023 16:14:20 +0200 Subject: [PATCH 2/2] record_nodes -> record_node_names --- neo/rawio/openephysbinaryrawio.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neo/rawio/openephysbinaryrawio.py b/neo/rawio/openephysbinaryrawio.py index 5495f5d04..74534ac7d 100644 --- a/neo/rawio/openephysbinaryrawio.py +++ b/neo/rawio/openephysbinaryrawio.py @@ -570,13 +570,13 @@ def explore_folder(dirname, experiment_names=None): # nested dictionary: block_index > seg_index > data_type > stream_name all_streams = {} nb_segment_per_block = {} - record_nodes = list(folder_structure.keys()) - if len(record_nodes) == 0: + record_node_names = list(folder_structure.keys()) + if len(record_node_names) == 0: raise ValueError( f"{dirname} is not a valid Open Ephys binary folder. No 'structure.oebin' " f"files were found in sub-folders." ) - recording_node = folder_structure[record_nodes[0]] + recording_node = folder_structure[record_node_names[0]] # nb_block needs to be consistent across record nodes. Use the first one nb_block = len(recording_node['experiments']) @@ -622,8 +622,8 @@ def check_folder_consistency(folder_structure, possible_experiment_names=None): ("Inconsistent experiments across recording nodes!") # check that "continuous" streams are the same across multiple segments (recordings) - record_nodes = list(folder_structure.keys()) - experiments = folder_structure[record_nodes[0]]['experiments'] + record_node_names = list(folder_structure.keys()) + experiments = folder_structure[record_node_names[0]]['experiments'] for exp_id, experiment in experiments.items(): segment_stream_names = None if len(experiment['recordings']) > 1: