1'''Virtual datasets: The 'Excalibur' use case
2
3https://support.hdfgroup.org/HDF5/docNewFeatures/VDS/HDF5-VDS-requirements-use-cases-2014-12-10.pdf
4'''
5
6import h5py
7
8raw_files = ["stripe_%d.h5" % stripe for stripe in range(1,7)]# get these names
9in_key = 'data' # where is the data at the input?
10outfile = 'full_detector.h5'
11out_key = 'full_frame'
12
13in_sh = h5py.File(raw_files[0], 'r')[in_key].shape # get the input shape
14dtype = h5py.File(raw_files[0], 'r')[in_key].dtype # get the datatype
15
16# now generate the output shape
17vertical_gap = 10 # pixels spacing in the vertical
18nfiles = len(raw_files)
19nframes = in_sh[0]
20width = in_sh[2]
21height = (in_sh[1]*nfiles) + (vertical_gap*(nfiles-1))
22out_sh = (nframes, height, width)
23
24# Virtual target is a representation of the output dataset
25layout = h5py.VirtualLayout(shape=out_sh, dtype=dtype)
26offset = 0 # initial offset
27for i in range(nfiles):
28    print("frame_number is: %s" % str(i)) # for feedback
29    vsource = h5py.VirtualSource(raw_files[i], in_key, shape=in_sh) #a representation of the input dataset
30    layout[:, offset:(offset + in_sh[1]), :] = vsource
31    offset += in_sh[1]+vertical_gap # increment the offset
32
33# Create an output file.
34with h5py.File(outfile, 'w', libver='latest') as f:
35    f.create_virtual_dataset(out_key, layout, fillvalue=0x1)
36