1'''Virtual datasets: The 'Eiger' use case
2
3https://support.hdfgroup.org/HDF5/docNewFeatures/VDS/HDF5-VDS-requirements-use-cases-2014-12-10.pdf
4'''
5
6import h5py
7import numpy as np
8
9
10files = ['1.h5', '2.h5', '3.h5', '4.h5', '5.h5']
11entry_key = 'data' # where the data is inside of the source files.
12sh = h5py.File(files[0], 'r')[entry_key].shape # get the first ones shape.
13
14layout = h5py.VirtualLayout(shape=(len(files) * sh[0], ) + sh[1:], dtype=np.float64)
15M_start = 0
16for i, filename in enumerate(files):
17    M_end = M_start + sh[0]
18    vsource = h5py.VirtualSource(filename, entry_key, shape=sh)
19    layout[M_start:M_end:1, :, :] = vsource
20    M_start = M_end
21
22with h5py.File("eiger_vds.h5", 'w', libver='latest') as f:
23    f.create_virtual_dataset('data', layout, fillvalue=0)
24