Skip to content

Instantly share code, notes, and snippets.

@keitaroyam
Created June 10, 2016 11:56
Show Gist options
  • Save keitaroyam/42957a61f831a432948c35e37fb4fd82 to your computer and use it in GitHub Desktop.
Save keitaroyam/42957a61f831a432948c35e37fb4fd82 to your computer and use it in GitHub Desktop.
Add reverse-phi information to master h5 file of Eiger
# This code will be unnecessary when new Eiger firmware offically writes this information
import h5py
def run(h5in):
h5 = h5py.File(h5in, "a")
if "/entry/sample/depends_on" not in h5:
h5["/entry/sample/depends_on"] = "/entry/sample/transformations/omega"
if "/entry/sample/transformations" not in h5:
grp = h5.create_group("/entry/sample/transformations")
else:
grp = h5["/entry/sample/transformations"]
grp.attrs['NX_class'] = "NXtransformations"
if "omega" not in grp:
omega = h5["/entry/sample/goniometer/omega"]
ds = grp.create_dataset("omega", omega.shape, dtype=omega.dtype, data=omega)
else:
ds = grp["omega"]
ds.attrs['units'] = 'degree'
ds.attrs['transformation_type'] = 'rotation'
ds.attrs['vector'] = (-1., 0., 0.)
ds.attrs['offset'] = (0., 0., 0.)
ds.attrs['depends_on'] = '.'
h5.close()
if __name__ == "__main__":
import sys
h5in = sys.argv[1]
run(h5in)
@keitaroyam
Copy link
Author

>     if "/entry/sample/transformations" not in h5:
>        grp = h5.create_group("/entry/sample/transformations")
>    else:
>        grp = h5["/entry/sample/transformations"]

This can be simplified by h5.require_group(). Thanks Takanori.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment