pwtools.io.write_h5¶
- pwtools.io.write_h5(fn, dct, **kwds)[source]¶
Write dictionary with arrays (or whatever HDF5 handles) to h5 file.
Dict keys are supposed to be HDF group + dataset names like /a/b/c/dset. The leading slash can be skipped. Default file mode is ‘a’ (see below for details).
- Parameters:
fn (str) – filename (e.g. ‘foo.h5’, ‘bar.hdf’)
dct (dict)
**kwds – keywords to
h5py.File
(e.g.mode='w'
)
Notes
The default file opening mode is the (old?)
h5py.File
default value, which ismode='a'
, i.e. read+append mode. In this mode, existing keys cannot be reused (overwritten), only new ones can be appended. The file is created if nonexistent. To overwrite, usemode='w'
, but this is the same as deleting the file and writing a new one! If you want to overwrite some or all existing keys and add new ones, use smth like:>>> old = read_h5('file.h5') >>> old.update({'/old/key': new_value, '/new/key': some_more_data}) >>> write_h5('file.h5', old, mode='w')