Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@keitaroyam

keitaroyam Mar 15, 2017

>     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.

Owner

keitaroyam commented Mar 15, 2017

>     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