API reference¶
-
h5py_wrapper.
save
(filename, d, write_mode='a', overwrite_dataset=False, resize=False, path=None, dict_label='', compression=None)[source]¶ Save a dictionary to an hdf5 file.
- filename : string
- The file name of the hdf5 file.
- d : dict
- The dictionary to be stored.
- write_mode : {‘a’, ‘w’}, optional
- Analog to normal file handling in python. Defaults to ‘a’.
- overwrite_dataset : bool, optional
- Whether datasets should be overwritten if already existing. Defaults to False.
- resize : bool, optional
- If True, the hdf5 file is resized after writing all data, may reduce file size. Uses h5repack (see https://www.hdfgroup.org/HDF5/doc/RM/Tools.html#Tools-Repack). Caution: slows down writing. Defaults to False.
- path : string, optional
- If not empty, the dictionary is stored under the given path in the hdf5 file, with levels separated by ‘/’. For instance, path=’test/trial/spiketrains’. Defaults to None.
- compression : {‘gzip’, ‘szip’,’lzf’, 0,…,10}, optional
- Compression strategy to reduce file size. An integer >0, <=10 leads to usage of gzip,indicating the level of compression. ‘gzip’ is recommended. See http://docs.h5py.org/en/latest/high/dataset.html for details. Caution: This slows down writing and loading of data. Attention: Will be ignored for scalar data.
None
>>> d = {} >>> d['a'] = {'a1': [1, 2, 3], 'a2': 4., 'a3': {'a31': 'Test'}} >>> d['b'] = 'string' >>> import h5py_wrapper as h5w >>> h5w.save('example.h5', d)
-
h5py_wrapper.
load
(filename, path='', lazy=False)[source]¶ Loads a dictionary from an hdf5 file.
- filename : string
- The file name of the hdf5 file.
- path : string, optional
- If not empty, specifies a path to access deeper levels in the hdf5 file.
- lazy : boolean, optional
- If True, only keys from all levels of the dictionary are loaded with values. Defaults to False.
- dictionary : dict
- Dictionary from the hdf5 file.
>>> d = {} >>> d['a'] = {'a1': [1, 2, 3], 'a2': 4., 'a3': {'a31': 'Test'}} >>> d['b'] = 'string' >>> import h5py_wrapper as h5w >>> h5w.save('example_load.h5', d, overwrite_dataset=True) >>> h5w.load('example_load.h5') {u'a': {u'a1': array([1, 2, 3]), u'a3': {u'a31': 'Test'}, u'a2': 4.0}, u'b': 'string'}