Module H5F
Low-level operations on HDF5 file objects.
Functional API
-
h5py.h5f.open(STRING name, UINT flags=ACC_RDWR, PropFAID fapl=None) → FileID
Open an existing HDF5 file. Keyword “flags” may be:
- ACC_RDWR
- Open in read-write mode
- ACC_RDONLY
- Open in readonly mode
Keyword fapl may be a file access property list.
-
h5py.h5f.create(STRING name, INT flags=ACC_TRUNC, PropFCID fcpl=None, PropFAID fapl=None) → FileID
Create a new HDF5 file. Keyword “flags” may be:
- ACC_TRUNC
- Truncate an existing file, discarding its data
- ACC_EXCL
- Fail if a conflicting file exists
To keep the behavior in line with that of Python’s built-in functions,
the default is ACC_TRUNC. Be careful!
-
h5py.h5f.flush(ObjectID obj, INT scope=SCOPE_LOCAL)
Tell the HDF5 library to flush file buffers to disk. “obj” may
be the file identifier, or the identifier of any object residing in
the file. Keyword “scope” may be:
- SCOPE_LOCAL
- Flush only the given file
- SCOPE_GLOBAL
- Flush the entire virtual file
-
h5py.h5f.is_hdf5(STRING name) → BOOL
- Determine if a given file is an HDF5 file. Note this raises an
exception if the file doesn’t exist.
-
h5py.h5f.mount(ObjectID loc, STRING name, FileID fid)
- Mount an open file on the group “name” under group loc_id. Note that
“name” must already exist.
-
h5py.h5f.unmount(ObjectID loc, STRING name)
- Unmount a file, mounted at “name” under group loc_id.
-
h5py.h5f.get_name(ObjectID obj) → STRING
- Determine the name of the file in which the specified object resides.
-
h5py.h5f.get_obj_count(OBJECT where=OBJ_ALL, types=OBJ_ALL) → INT
Get the number of open objects.
- where
- Either a FileID instance representing an HDF5 file, or the
special constant OBJ_ALL, to count objects in all files.
- type
Specify what kinds of object to include. May be one of OBJ*,
or any bitwise combination (e.g. OBJ_FILE | OBJ_ATTR).
The special value OBJ_ALL matches all object types, and
OBJ_LOCAL will only match objects opened through a specific
identifier.
-
h5py.h5f.get_obj_ids(OBJECT where=OBJ_ALL, types=OBJ_ALL) → LIST
Get a list of identifier instances for open objects.
- where
- Either a FileID instance representing an HDF5 file, or the
special constant OBJ_ALL, to list objects in all files.
- type
Specify what kinds of object to include. May be one of OBJ*,
or any bitwise combination (e.g. OBJ_FILE | OBJ_ATTR).
The special value OBJ_ALL matches all object types, and
OBJ_LOCAL will only match objects opened through a specific
identifier.
File objects
-
class h5py.h5f.FileID
Represents an HDF5 file identifier.
These objects wrap a small portion of the H5F interface; all the
H5F functions which can take arbitrary objects in addition to
file identifiers are provided as functions in the h5f module.
Properties:
Behavior:
- Hashable: Yes, unique to the file (but not the access mode)
- Equality: Hash comparison
-
close()
- Terminate access through this identifier. Note that depending on
what property list settings were used to open the file, the
physical file might not be closed until all remaining open
identifiers are freed.
-
get_access_plist() → PropFAID
- Retrieve a copy of the file access property list which manages access
to this file.
-
get_create_plist() → PropFCID
- Retrieve a copy of the file creation property list used to
create this file.
-
get_filesize() → LONG size
- Determine the total size (in bytes) of the HDF5 file,
including any user block.
-
get_freespace() → LONG freespace
- Determine the amount of free space in this file. Note that this
only tracks free space until the file is closed.
-
get_intent() → INT
- Determine the file’s write intent, either of:
- H5F_ACC_RDONLY
- H5F_ACC_RDWR
-
name
- File name on disk (according to h5f.get_name())
-
reopen() → FileID
- Retrieve another identifier for a file (which must still be open).
The new identifier is guaranteed to neither be mounted nor contain
a mounted file.
Module constants
File access flags
-
h5py.h5f.ACC_TRUNC
- Create/truncate file
-
h5py.h5f.ACC_EXCL
- Create file if it doesn’t exist; fail otherwise
-
h5py.h5f.ACC_RDWR
- Open in read/write mode
-
h5py.h5f.ACC_RDONLY
- Open in read-only mode
File close strength
-
h5py.h5f.CLOSE_WEAK
-
h5py.h5f.CLOSE_SEMI
-
h5py.h5f.CLOSE_STRONG
-
h5py.h5f.CLOSE_DEFAULT
File scope
-
h5py.h5f.SCOPE_LOCAL
-
h5py.h5f.SCOPE_GLOBAL
Object types
-
h5py.h5f.OBJ_FILE
-
h5py.h5f.OBJ_DATASET
-
h5py.h5f.OBJ_GROUP
-
h5py.h5f.OBJ_DATATYPE
-
h5py.h5f.OBJ_ATTR
-
h5py.h5f.OBJ_ALL
-
h5py.h5f.OBJ_LOCAL