@@ -77,9 +77,16 @@ def _parse_header(self):
7777 check_folder_consistency (folder_structure , possible_experiments )
7878 self .folder_structure = folder_structure
7979
80- # all streams are consistent across blocks and segments
81- sig_stream_names = sorted (list (all_streams [0 ][0 ]['continuous' ].keys ()))
82- event_stream_names = sorted (list (all_streams [0 ][0 ]['events' ].keys ()))
80+ # all streams are consistent across blocks and segments.
81+ # also checks that 'continuous' and 'events' folder are present
82+ if 'continuous' in all_streams [0 ][0 ]:
83+ sig_stream_names = sorted (list (all_streams [0 ][0 ]['continuous' ].keys ()))
84+ else :
85+ sig_stream_names = []
86+ if 'events' in all_streams [0 ][0 ]:
87+ event_stream_names = sorted (list (all_streams [0 ][0 ]['events' ].keys ()))
88+ else :
89+ event_stream_names = []
8390
8491 # first loop to reassign stream by "stream_index" instead of "stream_name"
8592 self ._sig_streams = {}
@@ -563,7 +570,13 @@ def explore_folder(dirname, experiment_names=None):
563570 # nested dictionary: block_index > seg_index > data_type > stream_name
564571 all_streams = {}
565572 nb_segment_per_block = {}
566- recording_node = folder_structure [list (folder_structure .keys ())[0 ]]
573+ record_nodes = list (folder_structure .keys ())
574+ if len (record_nodes ) == 0 :
575+ raise ValueError (
576+ f"{ dirname } is not a valid Open Ephys binary folder. No 'structure.oebin' "
577+ f"files were found in sub-folders."
578+ )
579+ recording_node = folder_structure [record_nodes [0 ]]
567580
568581 # nb_block needs to be consistent across record nodes. Use the first one
569582 nb_block = len (recording_node ['experiments' ])
@@ -609,7 +622,8 @@ def check_folder_consistency(folder_structure, possible_experiment_names=None):
609622 ("Inconsistent experiments across recording nodes!" )
610623
611624 # check that "continuous" streams are the same across multiple segments (recordings)
612- experiments = folder_structure [list (folder_structure .keys ())[0 ]]['experiments' ]
625+ record_nodes = list (folder_structure .keys ())
626+ experiments = folder_structure [record_nodes [0 ]]['experiments' ]
613627 for exp_id , experiment in experiments .items ():
614628 segment_stream_names = None
615629 if len (experiment ['recordings' ]) > 1 :
0 commit comments