Table Of Contents

Previous topic

Module H5A

Next topic

Module H5E

This Page

Module H5D

Provides access to the low-level HDF5 “H5D” dataset interface.

class h5py.h5d.DatasetID

Represents an HDF5 dataset identifier.

Objects of this class may be used in any HDF5 function which expects a dataset identifier. Also, all H5D* functions which take a dataset instance as their first argument are presented as methods of this class.

Properties: dtype: Numpy dtype representing the dataset type shape: Numpy-style shape tuple representing the dataspace rank: Integer giving dataset rank

  • Hashable: Yes, unless anonymous
  • Equality: True HDF5 identity if unless anonymous
dtype
Numpy dtype object representing the dataset type
extend(TUPLE shape)
Extend the given dataset so it’s at least as big as “shape”. Note that a dataset may only be extended up to the maximum dimensions of its dataspace, which are fixed when the dataset is created.
get_create_plist() → PropDCID
Create an return a new copy of the dataset creation property list used when this dataset was created.
get_offset() → LONG offset or None
Get the offset of this dataset in the file, in bytes, or None if it doesn’t have one. This is always the case for datasets which use chunked storage, compact datasets, and datasets for which space has not yet been allocated in the file.
get_space() → SpaceID
Create and return a new copy of the dataspace for this dataset.
get_space_status() → INT space_status_code

Determine if space has been allocated for a dataset. Return value is one of:

  • SPACE_STATUS_NOT_ALLOCATED
  • SPACE_STATUS_PART_ALLOCATED
  • SPACE_STATUS_ALLOCATED
get_storage_size() → LONG storage_size
Determine the amount of file space required for a dataset. Note this only counts the space which has actually been allocated; it may even be zero.
get_type() → TypeID
Create and return a new copy of the datatype for this dataset.
rank
Integer giving the dataset rank (0 = scalar)
read(SpaceID mspace, SpaceID fspace, NDARRAY arr_obj, TypeID mtype=None, PropDXID dxpl=None)

Read data from an HDF5 dataset into a Numpy array. For maximum flexibility, you can specify dataspaces for the file and the Numpy object. Keyword dxpl may be a dataset transfer property list.

The provided Numpy array must be writable and C-contiguous. If this is not the case, ValueError will be raised and the read will fail.

It is your responsibility to ensure that the memory dataspace provided is compatible with the shape of the Numpy array. Since a wide variety of dataspace configurations are possible, this is not checked. You can easily crash Python by reading in data from too large a dataspace.

The GIL is released during the read. Modifying the contents of the array from another thread has undefined results.

set_extent(TUPLE shape)
Set the size of the dataspace to match the given shape. If the new size is larger in any dimension, it must be compatible with the maximum dataspace size.
shape
Numpy-style shape tuple representing the dataspace
write(SpaceID mspace, SpaceID fspace, NDARRAY arr_obj, TypeID mtype=None, PropDXID dxpl=None)

Write data from a Numpy array to an HDF5 dataset. Keyword dxpl may be a dataset transfer property list.

The provided Numpy array must be C-contiguous. If this is not the case, ValueError will be raised and the read will fail.

The GIL is released during the write. Modifying the contents of the array from another thread has undefined results.

h5py.h5d.create(objectID loc, STRING name or None, TypeID tid, SpaceID space, PropDCID dcpl=None, PropID lcpl=None) → DatasetID
Create a new dataset. If “name” is None, the dataset will be anonymous.
h5py.h5d.open(ObjectID loc, STRING name) → DatasetID
Open an existing dataset attached to a group or file object, by name.

Module constants

Allocation times

h5py.h5d.ALLOC_TIME_DEFAULT
h5py.h5d.ALLOC_TIME_LATE
h5py.h5d.ALLOC_TIME_EARLY
h5py.h5d.ALLOC_TIME_INCR