MCPcopy Create free account
hub / github.com/dask/dask / to_hdf5

Function to_hdf5

dask/array/core.py:5704–5760  ·  view source on GitHub ↗

Store arrays in HDF5 file This saves several dask arrays into several datapaths in an HDF5 file. It creates the necessary datasets and handles clean file opening/closing. Parameters ---------- chunks: tuple or ``True`` Chunk shape, or ``True`` to pass the chunks from th

(filename, *args, chunks=True, **kwargs)

Source from the content-addressed store, hash-verified

5702
5703
5704def to_hdf5(filename, *args, chunks=True, **kwargs):
5705 """Store arrays in HDF5 file
5706
5707 This saves several dask arrays into several datapaths in an HDF5 file.
5708 It creates the necessary datasets and handles clean file opening/closing.
5709
5710 Parameters
5711 ----------
5712 chunks: tuple or ``True``
5713 Chunk shape, or ``True`` to pass the chunks from the dask array.
5714 Defaults to ``True``.
5715
5716 Examples
5717 --------
5718
5719 >>> da.to_hdf5('myfile.hdf5', '/x', x) # doctest: +SKIP
5720
5721 or
5722
5723 >>> da.to_hdf5('myfile.hdf5', {'/x': x, '/y': y}) # doctest: +SKIP
5724
5725 Optionally provide arguments as though to ``h5py.File.create_dataset``
5726
5727 >>> da.to_hdf5('myfile.hdf5', '/x', x, compression='lzf', shuffle=True) # doctest: +SKIP
5728
5729 >>> da.to_hdf5('myfile.hdf5', '/x', x, chunks=(10,20,30)) # doctest: +SKIP
5730
5731 This can also be used as a method on a single Array
5732
5733 >>> x.to_hdf5('myfile.hdf5', '/x') # doctest: +SKIP
5734
5735 See Also
5736 --------
5737 da.store
5738 h5py.File.create_dataset
5739 """
5740 if len(args) == 1 and isinstance(args[0], dict):
5741 data = args[0]
5742 elif len(args) == 2 and isinstance(args[0], str) and isinstance(args[1], Array):
5743 data = {args[0]: args[1]}
5744 else:
5745 raise ValueError("Please provide {'/data/path': array} dictionary")
5746
5747 import h5py
5748
5749 with h5py.File(filename, mode="a") as f:
5750 dsets = [
5751 f.require_dataset(
5752 dp,
5753 shape=x.shape,
5754 dtype=x.dtype,
5755 chunks=tuple(c[0] for c in x.chunks) if chunks is True else chunks,
5756 **kwargs,
5757 )
5758 for dp, x in data.items()
5759 ]
5760 store(list(data.values()), dsets)
5761

Callers 1

to_hdf5Method · 0.85

Calls 3

storeFunction · 0.85
itemsMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected