1'''Virtual datasets: the 'Percival Frame Builder' use case.
2
3https://support.hdfgroup.org/HDF5/docNewFeatures/VDS/HDF5-VDS-requirements-use-cases-2014-12-10.pdf
4'''
5import h5py
6
7in_key = 'data' # where is the data at the input?
8dtype = h5py.File('raw_file_1.h5')['data'].dtype
9outshape = (799,2000,2000)
10
11# Virtual target is a representation of the output dataset
12layout = h5py.VirtualLayout(shape=outshape, dtype=dtype)
13
14# Sources represent the input datasets
15vsource1 = h5py.VirtualSource('raw_file_1.h5', 'data', shape=(200, 2000, 2000))
16vsource2 = h5py.VirtualSource('raw_file_2.h5', 'data', shape=(200, 2000, 2000))
17vsource3 = h5py.VirtualSource('raw_file_3.h5', 'data', shape=(200, 2000, 2000))
18vsource4 = h5py.VirtualSource('raw_file_4.h5', 'data', shape=(199, 2000, 2000))
19
20# Map the inputs into the virtual dataset
21layout[0:799:4, :, :] = vsource1
22layout[1:799:4, :, :] = vsource2
23layout[2:799:4, :, :] = vsource3
24layout[3:799:4, :, :] = vsource4
25
26# Create an output file
27with h5py.File('full_time_series.h5', 'w', libver='latest') as f:
28    f.create_virtual_dataset(in_key, layout, fillvalue=0x1)
29