From 047af1b9f12c0c2d4235a552a67188f6c3a9768a Mon Sep 17 00:00:00 2001 From: Ivan Usov Date: Tue, 31 Mar 2020 11:30:38 +0200 Subject: [PATCH] Pack detector data/metadata into a dict --- pyzebra/app.py | 3 ++- pyzebra/h5.py | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pyzebra/app.py b/pyzebra/app.py index d7f2508..043ed9d 100644 --- a/pyzebra/app.py +++ b/pyzebra/app.py @@ -67,7 +67,8 @@ def update_image(): def filelist_callback(_attr, _old, new): global curent_h5_data, current_index - data, _, _, _ = pyzebra.read_detector_data(new) + det_data = pyzebra.read_detector_data(new) + data = det_data["data"] curent_h5_data = data current_index = 0 update_image() diff --git a/pyzebra/h5.py b/pyzebra/h5.py index 7d8ce21..56440e3 100644 --- a/pyzebra/h5.py +++ b/pyzebra/h5.py @@ -38,22 +38,24 @@ def read_detector_data(filepath): ndarray: A 3D array of data, rot_angle, pol_angle, tilt_angle. """ with h5py.File(filepath, "r") as h5f: - detector_data = h5f["/entry1/area_detector2/data"][:] + data = h5f["/entry1/area_detector2/data"][:] # reshape data to a correct shape (2006 issue) - n, cols, rows = detector_data.shape - detector_data = detector_data.reshape(n, rows, cols) + n, cols, rows = data.shape + data = data.reshape(n, rows, cols) - rot_angle = h5f["/entry1/area_detector2/rotation_angle"][:] # om, sometimes ph - pol_angle = h5f["/entry1/ZEBRA/area_detector2/polar_angle"][:] # gammad - tlt_angle = h5f["/entry1/ZEBRA/area_detector2/tilt_angle"][:] # nud - ddist = h5f["/entry1/ZEBRA/area_detector2/distance"][:] - wave = h5f["/entry1/ZEBRA/monochromator/wavelength"][:] - chi_angle = h5f["/entry1/sample/chi"][:] # ch - phi_angle = h5f["/entry1/sample/phi"][:] # ph - UB = h5f["/entry1/sample/UB"][:] + det_data = {"data": data} - return detector_data,pol_angle,rot_angle,tlt_angle,chi_angle,phi_angle,ddist,wave,UB + det_data["rot_angle"] = h5f["/entry1/area_detector2/rotation_angle"][:] # om, sometimes ph + det_data["pol_angle"] = h5f["/entry1/ZEBRA/area_detector2/polar_angle"][:] # gammad + det_data["tlt_angle"] = h5f["/entry1/ZEBRA/area_detector2/tilt_angle"][:] # nud + det_data["ddist"] = h5f["/entry1/ZEBRA/area_detector2/distance"][:] + det_data["wave"] = h5f["/entry1/ZEBRA/monochromator/wavelength"][:] + det_data["chi_angle"] = h5f["/entry1/sample/chi"][:] # ch + det_data["phi_angle"] = h5f["/entry1/sample/phi"][:] # ph + det_data["UB"] = h5f["/entry1/sample/UB"][:] + + return det_data def open_h5meta(filepath): """Open h5meta file like *.cami