From 6f83292d691b288f6d3429ea18ce415548798d39 Mon Sep 17 00:00:00 2001 From: Ivan Usov Date: Fri, 6 May 2022 15:54:12 +0200 Subject: [PATCH] Temporary resolve issues with new format metadata --- pyzebra/ccl_io.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pyzebra/ccl_io.py b/pyzebra/ccl_io.py index f6d4a13..770d938 100644 --- a/pyzebra/ccl_io.py +++ b/pyzebra/ccl_io.py @@ -109,24 +109,29 @@ def parse_1D(fileobj, data_type): variable = variable.strip() value = value.strip() - if variable in META_VARS_STR: - metadata[variable] = value + try: + 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" - if variable in ("a", "b", "c", "alpha", "beta", "gamma"): - variable += "_cell" - metadata[variable] = float(value) + elif variable in META_VARS_FLOAT: + if variable == "2-theta": # fix that angle name not to be an expression + variable = "twotheta" + if variable in ("a", "b", "c", "alpha", "beta", "gamma"): + variable += "_cell" + metadata[variable] = float(value) - elif variable in META_UB_MATRIX: - if variable == "UB": - metadata["ub"] = np.array(literal_eval(value)).reshape(3, 3) - else: - if "ub" not in metadata: - metadata["ub"] = np.zeros((3, 3)) - row = int(variable[-2]) - 1 - metadata["ub"][row, :] = list(map(float, value.split())) + elif variable in META_UB_MATRIX: + if variable == "UB": + metadata["ub"] = np.array(literal_eval(value)).reshape(3, 3) + else: + if "ub" not in metadata: + metadata["ub"] = np.zeros((3, 3)) + row = int(variable[-2]) - 1 + metadata["ub"][row, :] = list(map(float, value.split())) + + except Exception: + print(f"Error reading {variable} with value '{value}'") + metadata[variable] = 0 if "#data" in line: # this is the end of metadata and the start of data section