silx
silx copied to clipboard
save a NXdata group using links to existing data
Allow to save a NXdata group with links to existing datasets for signal, axes, errors. The current save_as_NXdata take numpy array as signal and axes, and does not allow to create links to data that already exists in the output file.
Idea: if filename is an HDF5 handle, and signal, axes... are HDF5 datasets, it should be possible to create links without data duplication. Accept external links ?
I strongly support creating a NXdata group in every scan with NeXus links to the default plottable data. (see my comments under https://github.com/prjemian/spec2nexus/issues/141#issuecomment-515782804 for more of this motivation)
From the NeXus documentation
Use NeXus links liberally in data files to reduce duplication of data.
Basic overview of NeXus links is given in the FAQ, also the introduction. The procedure to write a NeXus link is described in the manual.
A python example that creates NeXus links in NXdata (https://github.com/prjemian/spec2nexus/blob/master/src/spec2nexus/eznx_example.py#L43-L46) uses routines from spec2nexus:
nxdata = eznx.makeGroup(scan_group, 'data', 'NXdata', signal="counts", axes='tth')
eznx.makeLink(measurement_group, tth, nxdata.name+'/tth')
eznx.makeLink(measurement_group, counts, nxdata.name+'/counts')
Of course, replace tth and counts with the proper datasets from the measurement group. Also, add an attribute to the scan_group: default="data" which identifies this NXdata group as the default to be plotted.