def __init__(self, dataset, hdf=None, dtype=None, shape=None):
super(Hdf5Data, self).__init__()
raise Exception("Hdf5Data is under-maintanance!")
# default chunks size is 32 (reduce complexity of the works)
self._chunk_size = 32
if isinstance(hdf, str):
hdf = open_hdf5(hdf)
if hdf is None and not isinstance(dataset, h5py.Dataset):
raise ValueError('Cannot initialize dataset without hdf file')
if isinstance(dataset, h5py.Dataset):
self._data = dataset
self._hdf = dataset.file
else:
if dataset not in hdf: # not created dataset
if dtype is None or shape is None:
raise ValueError('dtype and shape must be specified if '
'dataset has not created in hdf5 file.')
shape = tuple([0 if i is None else i for i in shape])
hdf.create_dataset(dataset, dtype=dtype,
chunks=_get_chunk_size(shape, self._chunk_size),
shape=shape, maxshape=(None, ) + shape[1:])
self._data = hdf[dataset]
if shape is not None and self._data[0].shape[1:] != shape[1:]:
raise ValueError('Shape mismatch between predefined dataset '
'and given shape, {} != {}'
''.format(shape, self._data[0].shape))
self._hdf = hdf
# ==================== properties ==================== #
评论列表
文章目录