principia_materia.io_interface.hdf5_wrapper module
- class principia_materia.io_interface.hdf5_wrapper.HDF5Wrapper(title=None)
- Bases: - BaseDataWrapper- Save/load data in/from HDF5 file. - A object oriented wrapper to save and load data in and from HDF5 files. This allows us to easily save some custom defined data types into HDF5 supported types. - Parameters:
- title (str, default to None) – A comment description for the file. The title is not used when saving/loading HDF5 files. 
 - add_item(key, choices=None, dtype=None, load_dtype=None, save_dtype=None, optional=False)
- Add an item of data to the container. - Parameters:
- key (str) – The name of the item to be save in the data file. 
- dtype (str, default to None) – Data type of the item. The corresponding save/load functions will be used to save/load the item. 
- load_dtype (str or callable, default to None) – The function to load the item. 
- save_dtype (str or callable, default to None) – The function to save the item. 
- optional (bool, default to False) – Whether the item is optional. 
- help (str, default to None) – The description of the item. 
- alias (list of str, default to None) – A list aliases of the item keyword. 
- depends (list of str, default to None) – The keywords that are required when the item is present. 
 
 
 - dump(data, filename, allow_missing=False, overwrite=False)
- Save data into HDF5 file. - Parameters:
- data (dict) – The dictionary containing data to be saved. 
- filename (str) – The name of the file to save the data into, 
- allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary. 
- overwrite (bool, optional, default to False) – When the file exists, whether to replace the content of the file with the content to be saved. 
 
 
 - dump_h5file(data, h5file, allow_missing=False)
- Save data into HDF5 through a h5py.File/h5py.Group object. - This allows us to save data into a HDF5 group within a HDF5 file. - Parameters:
- data (dict) – The dictionary containing data to be saved. 
- h5file (h5py.File/h5py.Group object) – The h5py.File/h5py.Group object to save the data into. 
- allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary. 
 
 
 - dumps(data, allow_missing=False)
- Dump the data into string - Parameters:
- data (dict) – The dictionary containing data to be saved. 
- allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary. 
 
 
 - load(filename, allow_missing=False)
- Load data from HDF5 file - Parameters:
- filename (str) – The name of the file to save the data into, 
- allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary. 
 
 
 - load_h5file(h5file, allow_missing=False)
- Load data from HDF5 through a h5py.File/h5py.Group object. - This allows us to load data from a HDF5 group within a HDF5 file. - Parameters:
- h5file (h5py.File/h5py.Group object) – The h5py.File/h5py.Group object to save the data into. 
- allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary. 
 
 
 - loads(text, allow_missing=False, allow_unknown=False, load_unknown=False)
- Load the data from a string - Parameters:
- text (str) – Data in text format, 
- allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary. 
- allow_unknown (bool, optional, default to False) – Whether to allow keys not declared in the container. Though even if allowed, those keys will not be loaded if load_unknown == False. 
- load_unknown (bool, optional, default to False) – Whether to load keys not declared in the container to be loaded in raw.