Examples#

Copy part of a file#

Suppose that you want to copy all but some dataset from a file. In that case you can use

Consider the following example.

import h5py
import numpy as np

import GooseHDF5 as g5

with h5py.File("foo.h5", "w") as file:
    file["/a"] = np.arange(5)
    file["/b/c"] = np.arange(5)
    file["/d/e/f"] = np.arange(5)

with h5py.File("foo.h5", "r") as file:
    paths = list(g5.getdatasets(file))
    paths.remove("/d/e/f")

    with h5py.File("bar.h5", "w") as ret:
        g5.copy(file, ret, paths)
        ret["/d/e/f"] = file["/d/e/f"][...] * 2

        print(g5.compare(file, ret, paths))

The last line includes an example on how to verify if a set of datasets is indeed the same.