open_hdf5#

gwpy.io.hdf5.open_hdf5(
source: FileLike | h5py.HLObject,
mode: str = 'r',
**kwargs,
) h5py.HLObject[source]#

Open a h5py.File from disk, gracefully handling corner cases.

If source is already an HDF5 object, it is simply returned. Otherwise, it is opened as an HDF5 file in the given mode.

Parameters:
sourcefile-like, h5py.Group, h5py.Dataset

The file path or file-like object to open, or an existing HDF5 object to return as-is.

modestr

The mode in which to open the file, default: 'r'.

kwargs

Any additional keyword arguments are passed directly to h5py.File.

Returns:
h5objh5py.File, h5py.Group, h5py.Dataset

The opened HDF5 file object, or the original object if it was already an HDF5 object.