Nexus writer: save user metadata at the start
Requested by @tvincent
Current scan metadata provided by the user is saved at the end of the scan for 2 reasons:
- If there is a collision between bliss data and user metadata (meaning the same dataset name) then Bliss data has to priority
- The user metadata could in principle be added/changed after the scan starts
For example the user wants to add metadata to the "diode1" NXdetector group in the HDF5 file:
loopscan(10, 0.1, diode1, scan_info={"instrument": {"diode1": {"custom": 123.456}}})
However Bliss already puts datasets in the "diode1" group. For example there is a dataset called "data". If the user does this
loopscan(10, 0.1, diode1, scan_info={"instrument": {"diode1": {"data": 123.456}}})
then the writer would raise an exception when saving the user metadata before saving the Bliss data. You currently don't have this problem because the user metadata is saved after saving the Bliss data and this operation skips all existing datasets (see http://www.silx.org/doc/silx/latest/modules/io/dictdump.html#silx.io.dictdump.dicttoh5).
So the solutions if we need to save user metadata at the start are
- When creating datasets for Bliss data, always check whether the dataset already exists and delete it if it does.
- Have a special "pre_write_info" section (or whether we call in)
scan_info={"pre_write_info": {"instrument": "diode1": {"data": 123.456}}})
and then the user should know that if he uses a name that collides with Bliss, the writer with raise an error. - Simply ignore the possible collisions and let the writer raise an exception, in which case the user knows he needs to rename the metadata he is adding.
Edited by Wout De Nolf