def get_nested_dict_from_shot(filepath): row = runmanager.get_shot_globals(filepath) with h5py.File(filepath, 'r') as h5_file: if 'results' in h5_file: for groupname in h5_file['results']: resultsgroup = h5_file['results'][groupname] row[groupname] = get_attributes(resultsgroup) if 'images' in h5_file: for orientation in h5_file['images'].keys(): if isinstance(h5_file['images'][orientation], h5py.Group): row[orientation] = get_attributes( h5_file['images'][orientation]) for label in h5_file['images'][orientation]: row[orientation][label] = {} group = h5_file['images'][orientation][label] for image in group: row[orientation][label][image] = {} for key, val in get_attributes( group[image]).items(): if not isinstance(val, h5py.Reference): row[orientation][label][image][key] = val row['filepath'] = _ensure_str(filepath) row['agnostic_path'] = labscript_utils.shared_drive.path_to_agnostic( filepath) seq_id = _ensure_str(h5_file.attrs['sequence_id']) row['sequence'] = asdatetime(seq_id.split('_')[0]) try: row['sequence_index'] = h5_file.attrs['sequence_index'] except KeyError: row['sequence_index'] = None if 'script' in h5_file: row['labscript'] = _ensure_str(h5_file['script'].attrs['name']) try: row['run time'] = asdatetime(_ensure_str( h5_file.attrs['run time'])) except KeyError: row['run time'] = float('nan') try: row['run number'] = h5_file.attrs['run number'] except KeyError: row['run number'] = float('nan') try: row['run repeat'] = h5_file.attrs['run repeat'] except KeyError: row['run repeat'] = 0 try: row['n_runs'] = h5_file.attrs['n_runs'] except KeyError: row['n_runs'] = float('nan') return row
def get_image_attributes(self, orientation): with h5py.File(self.h5_path, 'r') as h5_file: if not 'images' in h5_file: raise Exception('File does not contain any images') if not orientation in h5_file['images']: raise Exception('File does not contain any images with orientation \'%s\''%orientation) return get_attributes(h5_file['images'][orientation])
def get_attrs(self, group): """Returns all attributes of the specified group as a dictionary. Args: group (str): Group for which attributes are desired. Raises: Exception: If the `group` does not exist. Returns: dict: Dictionary of attributes. """ with h5py.File(self.h5_path, 'r') as h5_file: if not group in h5_file: raise Exception('The group \'%s\' does not exist' % group) return get_attributes(h5_file[group])
def get_image_attributes(self, orientation): """Return the attributes of a saved orientation image group. Args: orientation (str): Orientation label to get attributes of. Raises: Exception: If images or orientation group do not exist. Returns: dict: Dictionary of attributes and their values. """ with h5py.File(self.h5_path, 'r') as h5_file: if not 'images' in h5_file: raise Exception('File does not contain any images') if not orientation in h5_file['images']: raise Exception( 'File does not contain any images with orientation \'%s\'' % orientation) return get_attributes(h5_file['images'][orientation])
def get_attrs(self, group): """Returns all attributes of the specified group as a dictionary.""" with h5py.File(self.h5_path) as h5_file: if not group in h5_file: raise Exception('The group \'%s\' does not exist' % group) return get_attributes(h5_file[group])
def get_attrs(self, group, h5_file=None): """Returns all attributes of the specified group as a dictionary.""" if not group in h5_file: raise Exception('The group \'%s\' does not exist' % group) return get_attributes(h5_file[group])