From 20527e8d2bd706092fa8b18ad9e53cc4d719d597 Mon Sep 17 00:00:00 2001 From: Ivan Usov Date: Fri, 5 Feb 2021 15:15:40 +0100 Subject: [PATCH] Consolidate hkl and ub --- pyzebra/app/panel_ccl_integrate.py | 2 +- pyzebra/app/panel_hdf_viewer.py | 2 +- pyzebra/ccl_io.py | 35 ++++++++++++++---------------- pyzebra/h5.py | 2 +- pyzebra/merge_function.py | 15 +------------ pyzebra/param_study_moduls.py | 6 ++--- 6 files changed, 23 insertions(+), 39 deletions(-) diff --git a/pyzebra/app/panel_ccl_integrate.py b/pyzebra/app/panel_ccl_integrate.py index a70b480..305a1ae 100644 --- a/pyzebra/app/panel_ccl_integrate.py +++ b/pyzebra/app/panel_ccl_integrate.py @@ -88,7 +88,7 @@ def create(): def _init_datatable(): scan_list = [s["idx"] for s in det_data["scan"]] - hkl = [f'{s["h_index"]} {s["k_index"]} {s["l_index"]}' for s in det_data["scan"]] + hkl = [f'{s["h"]} {s["k"]} {s["l"]}' for s in det_data["scan"]] scan_table_source.data.update( scan=scan_list, hkl=hkl, diff --git a/pyzebra/app/panel_hdf_viewer.py b/pyzebra/app/panel_hdf_viewer.py index 4278438..43baa7a 100644 --- a/pyzebra/app/panel_hdf_viewer.py +++ b/pyzebra/app/panel_hdf_viewer.py @@ -618,7 +618,7 @@ def calculate_hkl(det_data, index): gammad = det_data["gamma"][index] om = det_data["omega"][index] nud = det_data["nu"] - ub = det_data["UB"] + ub = det_data["ub"] geometry = det_data["zebra_mode"] if geometry == "bi": diff --git a/pyzebra/ccl_io.py b/pyzebra/ccl_io.py index 40f3786..ba8213f 100644 --- a/pyzebra/ccl_io.py +++ b/pyzebra/ccl_io.py @@ -1,5 +1,4 @@ import os -import re from collections import defaultdict import numpy as np @@ -58,12 +57,7 @@ META_VARS_FLOAT = ( META_UB_MATRIX = ("ub1j", "ub2j", "ub3j") -CCL_FIRST_LINE = ( - ("idx", int), - ("h_index", float), - ("k_index", float), - ("l_index", float), -) +CCL_FIRST_LINE = (("idx", int), ("h", float), ("k", float), ("l", float)) CCL_ANGLES = { "bi": (("twotheta", float), ("omega", float), ("chi", float), ("phi", float)), @@ -111,14 +105,20 @@ def parse_1D(fileobj, data_type): variable, value = line.split("=") variable = variable.strip() value = value.strip() - if variable in META_VARS_FLOAT: + + if variable in META_VARS_STR: + metadata[variable] = value + + elif variable in META_VARS_FLOAT: if variable == "2-theta": # fix that angle name not to be an expression variable = "twotheta" metadata[variable] = float(value) - elif variable in META_VARS_STR: - metadata[variable] = value + elif variable in META_UB_MATRIX: - metadata[variable] = re.findall(r"[-+]?\d*\.\d+|\d+", value) + if "ub" not in metadata: + metadata["ub"] = np.zeros((3, 3)) + row = int(variable[-2]) - 1 + metadata["ub"][row, :] = list(map(float, value.split())) if "#data" in line: # this is the end of metadata and the start of data section @@ -172,10 +172,9 @@ def parse_1D(fileobj, data_type): s[name].append(float(val)) try: - s["h_index"] = float(metadata["title"].split()[-3]) - s["k_index"] = float(metadata["title"].split()[-2]) - s["l_index"] = float(metadata["title"].split()[-1]) + s["h"], s["k"], s["l"] = map(float, metadata["title"].split()[-3:]) except (ValueError, IndexError): + s["h"] = s["k"] = s["l"] = float("nan") print("seems hkl is not in title") s["om"] = np.array(s["om"]) @@ -201,10 +200,8 @@ def parse_1D(fileobj, data_type): print("Unknown file extention") for s in scan: - if s["h_index"].is_integer() and s["k_index"].is_integer() and s["l_index"].is_integer(): - s["h_index"] = int(s["h_index"]) - s["k_index"] = int(s["k_index"]) - s["l_index"] = int(s["l_index"]) + if s["h"].is_integer() and s["k"].is_integer() and s["l"].is_integer(): + s["h"], s["k"], s["l"] = map(int, (s["h"], s["k"], s["l"])) s["indices"] = "hkl" else: s["indices"] = "real" @@ -229,7 +226,7 @@ def export_1D(data, path, area_method=AREA_METHODS[0], lorentz=False, hkl_precis idx_str = f"{scan['idx']:6}" - h, k, l = scan["h_index"], scan["k_index"], scan["l_index"] + h, k, l = scan["h"], scan["k"], scan["l"] if scan["indices"] == "hkl": hkl_str = f"{h:6}{k:6}{l:6}" else: # scan["indices"] == "real" diff --git a/pyzebra/h5.py b/pyzebra/h5.py index 4fc86ef..821f152 100644 --- a/pyzebra/h5.py +++ b/pyzebra/h5.py @@ -69,7 +69,7 @@ def read_detector_data(filepath): det_data["wave"] = h5f["/entry1/ZEBRA/monochromator/wavelength"][:] det_data["chi"] = h5f["/entry1/sample/chi"][:] # ch det_data["phi"] = h5f["/entry1/sample/phi"][:] # ph - det_data["UB"] = h5f["/entry1/sample/UB"][:].reshape(3, 3) + det_data["ub"] = h5f["/entry1/sample/UB"][:].reshape(3, 3) for var in ("omega", "gamma", "nu", "chi", "phi"): if abs(det_data[var][0] - det_data[var][-1]) > 0.1: diff --git a/pyzebra/merge_function.py b/pyzebra/merge_function.py index b81172c..d5e1e97 100644 --- a/pyzebra/merge_function.py +++ b/pyzebra/merge_function.py @@ -77,20 +77,7 @@ def merge(scan1, scan2): def check_UB(dict1, dict2, precision=0.01): - truth_list = list() - for i in ["ub1j", "ub2j", "ub3j"]: - for j in range(3): - if abs(abs(float(dict1["meta"][i][j])) - abs(float(dict2["meta"][i][j]))) < precision: - - truth_list.append(True) - else: - truth_list.append(False) - - # print(truth_list) - if all(truth_list): - return True - else: - return False + return np.max(np.abs(dict1["meta"]["ub"] - dict2["meta"]["ub"])) < precision def check_zebramode(dict1, dict2): diff --git a/pyzebra/param_study_moduls.py b/pyzebra/param_study_moduls.py index afa7c19..14dd8fe 100644 --- a/pyzebra/param_study_moduls.py +++ b/pyzebra/param_study_moduls.py @@ -416,9 +416,9 @@ def variables(dictionary): "Monitor1", "Monitor2", "Monitor3", - "h_index", - "l_index", - "k_index", + "h", + "k", + "l", "n_points", "monitor", "Time",