Utility functions#
RosettaSciIO provides certain utility functions that are applicable for multiple formats, e.g. for the HDF5-format on which a number of plugins are based.
HDF5 utility functions#
HDF5 file inspection.
- rsciio.utils.hdf5.list_datasets_in_file(filename, dataset_key=None, hardlinks_only=False, verbose=True)#
Read from a NeXus or
.hdffile and return a list of the dataset paths.This method is used to inspect the contents of an hdf5 file. The method iterates through group attributes and returns NXdata or hdf datasets of size >=2 if they’re not already NXdata blocks and returns a list of the entries. This is a convenience method to inspect a file to list datasets present rather than loading all the datasets in the file as signals.
- Parameters:
filename (str, pathlib.Path) – Filename of the file to read or corresponding pathlib.Path.
dataset_key (str, list of strings or None , default: None) – If a str or list of strings is provided only return items whose path contain the strings. For example, dataset_key = [“instrument”, “Fe”] will only return hdf entries with “instrument” or “Fe” somewhere in their hdf path.
hardlinks_only (bool, default : False) – If true any links (soft or External) will be ignored when loading.
verbose (boolean, default : True) – Prints the results to screen
- Returns:
List of paths to datasets.
- Return type:
list
See also
file_reader()file_writer()read_metadata_from_file()
- rsciio.utils.hdf5.read_metadata_from_file(filename, metadata_key=None, lazy=False, verbose=False, skip_array_metadata=False)#
Read the metadata from a NeXus or
.hdffile.This method iterates through the hdf5 file and returns a dictionary of the entries. This is a convenience method to inspect a file for a value rather than loading the file as a signal.
- Parameters:
filename (str, pathlib.Path) – Filename of the file to read or corresponding pathlib.Path.
metadata_key (None,str or list_of_strings , default : None) – None will return all datasets found including linked data. Providing a string or list of strings will only return items which contain the string(s). For example, search_keys = [“instrument”,”Fe”] will return hdf entries with “instrument” or “Fe” in their hdf path.
verbose (bool, default : False) – Pretty Print the results to screen
skip_array_metadata (bool, default : False) – Whether to skip loading array metadata. This is useful as a lot of large array may be present in the metadata and it is redundant with dataset itself.
- Returns:
Metadata dictionary.
- Return type:
dict
See also
file_reader()file_writer()list_datasets_in_file()