MCPcopy Create free account
hub / github.com/PyTTaMaster/PyTTa / _h5_load

Function _h5_load

pytta/functions.py:957–995  ·  view source on GitHub ↗

Load an hdf5 file and recreate the PyTTa objects.

(fileName: str)

Source from the content-addressed store, hash-verified

955
956
957def _h5_load(fileName: str):
958 """
959 Load an hdf5 file and recreate the PyTTa objects.
960 """
961 # Checking if the file is an hdf5 file
962 if fileName.split('.')[-1] != 'hdf5':
963 raise ValueError("_h5_load function only works with *.hdf5 files")
964 f = h5py.File(fileName, 'r')
965
966 # Check if it is a PyTTa-like hdf5 file
967 try:
968 if 'GENERATED_BY' not in f.attrs.keys() or \
969 f.attrs['GENERATED_BY'] != "PyTTa":
970 raise NotImplementedError
971 except:
972 # raise NotImplementedError("Only PyTTa-like hdf5 files can be loaded.")
973 warn(DeprecationWarning("'GENERATED_BY' tag couldn't be found in " +
974 "the .hdf5 file. Still trying to load " +
975 "because of legacy PyTTa HDF5 files."))
976
977 loadedObjects = {}
978 objCount = 0 # Counter for loaded objects
979 totCount = 0 # Counter for total groups
980 for PyTTaObjName, PyTTaObjH5Group in f.items():
981 totCount += 1
982 try:
983 loadedObjects[PyTTaObjName] = __h5_unpack(PyTTaObjH5Group)
984 objCount += 1
985 except NotImplementedError:
986 print("Skipping hdf5 group named {} as it ".format(PyTTaObjName) +
987 "isn't an PyTTa object group.")
988 f.close()
989 # Final message
990 plural1 = 's' if objCount > 1 else ''
991 plural2 = 's' if totCount > 1 else ''
992 print('Imported {} PyTTa object-like group'.format(objCount) + plural1 +
993 ' of {} group'.format(totCount) + plural2 +
994 ' inside the hdf5 file.')
995 return loadedObjects
996
997
998def __h5_unpack(objH5Group):

Callers 1

loadFunction · 0.70

Calls 2

__h5_unpackFunction · 0.85
splitMethod · 0.80

Tested by

no test coverage detected