def test_locate_h5_objects(simple_h5): matcher_cb = functools.partial(h5_utilities.h5_object_matcher_relname_in, ['c', 'e']) matches = h5_utilities.locate_h5_objects(matcher_cb, simple_h5) match_names = [ match.name for match in matches ] assert( set(match_names) == set(['/a/e', '/a/b/c']) )
def test_locate_h5_objects(simple_h5): matcher_cb = functools.partial(h5_utilities.h5_object_matcher_relname_in, ['c', 'e']) matches = h5_utilities.locate_h5_objects(matcher_cb, simple_h5) match_names = [match.name for match in matches] assert (set(match_names) == set(['/a/e', '/a/b/c']))
def _find_stimulus_presentation_group( nwb_file, stimulus_name, base_path=_STIMULUS_PRESENTATION_PATH, group_patterns=_STIMULUS_PRESENTATION_PATTERNS): ''' Searches an NWB file for a stimulus presentation group. Parameters ---------- nwb_file : h5py.File File to search stimulus_name : str Identifier for this stimulus. Corresponds to the relative name of its h5 group. base_path : str, optional Begin the search from here. Defaults to 'stimulus/presentation' group_patterns : array-like of str, optional Patterns for the relative name of the stimulus' h5 group. Defaults to the name, and the name suffixed by '_stimulus' Returns ------- h5py.Group, h5py.Dataset : h5 object found ''' group_candidates = [ pattern.format(stimulus_name) for pattern in group_patterns ] matcher = functools.partial(h5_utilities.h5_object_matcher_relname_in, group_candidates) matches = h5_utilities.locate_h5_objects(matcher, nwb_file, base_path) if len(matches) == 0: raise MissingStimulusException( 'Unable to locate stimulus: {}. ' 'Looked for this stimulus under the names: {} '.format( stimulus_name, group_candidates)) if len(matches) > 1: raise MissingStimulusException( 'Unable to locate stimulus: {}. ' 'Found multiple matching stimuli: {}'.format( stimulus_name, [match.name for match in matches])) return matches[0]
def _find_stimulus_presentation_group(nwb_file, stimulus_name, base_path=_STIMULUS_PRESENTATION_PATH, group_patterns=_STIMULUS_PRESENTATION_PATTERNS): ''' Searches an NWB file for a stimulus presentation group. Parameters ---------- nwb_file : h5py.File File to search stimulus_name : str Identifier for this stimulus. Corresponds to the relative name of its h5 group. base_path : str, optional Begin the search from here. Defaults to 'stimulus/presentation' group_patterns : array-like of str, optional Patterns for the relative name of the stimulus' h5 group. Defaults to the name, and the name suffixed by '_stimulus' Returns ------- h5py.Group, h5py.Dataset : h5 object found ''' group_candidates = [ pattern.format(stimulus_name) for pattern in group_patterns ] matcher = functools.partial(h5_utilities.h5_object_matcher_relname_in, group_candidates) matches = h5_utilities.locate_h5_objects(matcher, nwb_file, base_path) if len(matches) == 0: raise MissingStimulusException( 'Unable to locate stimulus: {}. ' 'Looked for this stimulus under the names: {} '.format(stimulus_name, group_candidates) ) if len(matches) > 1: raise MissingStimulusException( 'Unable to locate stimulus: {}. ' 'Found multiple matching stimuli: {}'.format(stimulus_name, [match.name for match in matches]) ) return matches[0]