Hdf5Loader
full name: tenpy.tools.hdf5_io.Hdf5Loader
parent module:
tenpy.tools.hdf5_io
type: class
Inheritance Diagram
Methods
|
|
|
Recursively display all keys in the given h5_group. |
|
Return attribute |
|
Load a Python |
|
Load objects converted to string during save, in particular int > 2^64. |
|
Load a h5py |
|
Load a dictionary in the format according to type_info. |
|
Load a |
|
Load a dictionary with general keys. |
|
Load a global object like a class or function from its qualified name and module. |
|
Load an instance of a userdefined class. |
|
Ignore the group to be loaded. |
|
Load a list. |
|
Load a masked array. |
|
Load the |
|
Load a range. |
|
Load an object where the return values of |
|
Load a set. |
|
Load a dictionary with simple keys. |
|
Load a string from a h5py |
|
Load a tuple. |
|
Store objects already loaded in the |
Class Attributes and Properties
- class tenpy.tools.hdf5_io.Hdf5Loader(h5group, ignore_unknown=True, exclude=None)[source]
Bases:
object
Class to load and import object from a HDF5 file.
The intended use of this class is through
load_from_hdf5()
, which is simply an alias forHdf5Loader(h5group).load(path)
.It can load data exported with
save_to_hdf5()
or theHdf5Saver
, respectively.The basic structure of this class is similar as the Unpickler from
pickle
.See Saving to disk: input/output for a specification of what can be saved and what the resulting datastructure is.
- Parameters:
h5group (
Group
) – The HDF5 group (or file) where to save the data.ignore_unknown (bool) – Whether to just warn (True) or raise an Error (False) if a class to be loaded is not found.
exclude (list of str) – List of paths (possibly relative to h5group) for objects to be excluded from loading. References to the corresponding object are replaced by an instance of
Hdf5Ignored
. Of course, this might break other functions expecting correctly loaded data.
- h5group
The HDF5 group (or HDF5
File
) where to save the data.- Type:
Group
- ignore_unknown
Whether to just warn (True) or raise an Error (False) if a class to be loaded is not found.
- Type:
- dispatch_load
Mapping from one of the global
REPR_*
variables to (unbound) methods f of this class. The method is called asf(self, h5gr, type_info, subpath)
. The call to f should load and return an object obj from the h5pyGroup
orDataset
h5gr; and memorize the loaded obj withmemorize_load()
. subpath is just the name of h5gr with a guaranteed'/'
in the end. type_info is often theREPR_*
variable of the type or some other information about the type, which allows to use a single dispatch_load function for different datatypes.- Type:
- memo_load
A dictionary to remember all the objects which we already loaded from
h5group
. The dictionary key is a h5py group- or datasetid
; the value is the loaded object. Seememorize_load()
.- Type:
- load(path=None)[source]
Load a Python
object
from the dataset.See
load_from_hdf5()
for more details.
- memorize_load(h5gr, obj)[source]
Store objects already loaded in the
memo_load
.This allows to avoid copies, if the same dataset appears multiple times in the hdf5 group of obj. Examples can be shared
LegCharge
objects or even sharedArray
.To handle cyclic references correctly, this function should be called before loading data from subgroups with new calls of
load()
.
- static get_attr(h5gr, attr_name)[source]
Return attribute
h5gr.attrs[attr_name]
, if existent.- Raises:
Hdf5ImportError – If the attribute does not exist.
- load_dataset(h5gr, type_info, subpath)[source]
Load a h5py
Dataset
and convert it into the desired type.
- load_converted_to_str(h5gr, type_info, subpath)[source]
Load objects converted to string during save, in particular int > 2^64.
- load_dict(h5gr, type_info, subpath)[source]
Load a dictionary in the format according to type_info.
- load_dtype(h5gr, type_info, subpath)[source]
Load a
numpy.dtype
.