Revert "Update load_1D.py"
This reverts commit cc3f1d28a5670dad6fdaec83a19edbee0b1a09ce.
This commit is contained in:
parent
cc3f1d28a5
commit
ab002be606
@ -2,6 +2,57 @@ import re
|
||||
import numpy as np
|
||||
from decimal import Decimal
|
||||
|
||||
META_VARS_STR = (
|
||||
"instrument",
|
||||
"title",
|
||||
"sample",
|
||||
"user",
|
||||
"ProposalID",
|
||||
"original_filename",
|
||||
"date",
|
||||
"zebra_mode",
|
||||
"proposal",
|
||||
"proposal_user",
|
||||
"proposal_title",
|
||||
"proposal_email",
|
||||
)
|
||||
META_VARS_FLOAT = (
|
||||
"mf",
|
||||
"2-theta",
|
||||
"chi",
|
||||
"phi",
|
||||
"nu",
|
||||
"temp",
|
||||
"wavelenght",
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"alpha",
|
||||
"beta",
|
||||
"gamma",
|
||||
"cex1",
|
||||
"cex2",
|
||||
"mexz",
|
||||
"moml",
|
||||
"mcvl",
|
||||
"momu",
|
||||
"mcvu",
|
||||
"detectorDistance",
|
||||
"snv",
|
||||
"snh",
|
||||
"snvm",
|
||||
"snhm",
|
||||
"s1vt",
|
||||
"s1vb",
|
||||
"s1hr",
|
||||
"s1hl",
|
||||
"s2vt",
|
||||
"s2vb",
|
||||
"s2hr",
|
||||
"s2hl",
|
||||
)
|
||||
META_UB_MATRIX = ("ub1j", "ub2j", "ub3j")
|
||||
|
||||
|
||||
def load_1D(filepath):
|
||||
"""
|
||||
@ -12,82 +63,23 @@ def load_1D(filepath):
|
||||
:arg filepath
|
||||
:returns det_variables
|
||||
- dictionary of all detector/scan variables and dictinionary for every measurement.
|
||||
Names of these dictionaries are M + measurement number. They include HKL indeces, angles, monitors,
|
||||
stepsize and array of counts
|
||||
Names of these dictionaries are M + measurement number. They include HKL indeces, angles,
|
||||
monitors, stepsize and array of counts
|
||||
"""
|
||||
|
||||
det_variables = {"file_type": str(filepath)[-3:], "meta": {}}
|
||||
meta_vars_str = (
|
||||
"instrument",
|
||||
"title",
|
||||
"sample",
|
||||
"user",
|
||||
"ProposalID",
|
||||
"original_filename",
|
||||
"date",
|
||||
"zebra_mode",
|
||||
"proposal",
|
||||
"proposal_user",
|
||||
"proposal_title",
|
||||
"proposal_email",
|
||||
)
|
||||
meta_vars_float = (
|
||||
"mf",
|
||||
"2-theta",
|
||||
"chi",
|
||||
"phi",
|
||||
"nu",
|
||||
"temp",
|
||||
"wavelenght",
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"alpha",
|
||||
"beta",
|
||||
"gamma",
|
||||
"cex1",
|
||||
"cex2",
|
||||
"mexz",
|
||||
"moml",
|
||||
"mcvl",
|
||||
"momu",
|
||||
"mcvu",
|
||||
"detectorDistance",
|
||||
"snv",
|
||||
"snh",
|
||||
"snvm",
|
||||
"snhm",
|
||||
"s1vt",
|
||||
"s1vb",
|
||||
"s1hr",
|
||||
"s1hl",
|
||||
"s2vt",
|
||||
"s2vb",
|
||||
"s2hr",
|
||||
"s2hl",
|
||||
)
|
||||
meta_ub_matrix = ("ub1j", "ub2j", "ub3j")
|
||||
|
||||
with open(filepath, "r") as infile:
|
||||
for line in infile:
|
||||
det_variables["Measurements"] = {}
|
||||
if "=" in line:
|
||||
variable, value = line.split("=")
|
||||
variable = variable.strip()
|
||||
try:
|
||||
if variable in meta_vars_float:
|
||||
det_variables["meta"][variable] = float(value)
|
||||
elif variable in meta_vars_str:
|
||||
det_variables["meta"][variable] = str(value)[:-1].strip()
|
||||
elif variable in meta_ub_matrix:
|
||||
det_variables["meta"][variable] = re.findall(
|
||||
r"[-+]?\d*\.\d+|\d+", str(value)
|
||||
)
|
||||
except ValueError as error:
|
||||
print(
|
||||
"Some values are not in expected format (str or float), error:",
|
||||
str(error),
|
||||
)
|
||||
if variable in META_VARS_FLOAT:
|
||||
det_variables["meta"][variable] = float(value)
|
||||
elif variable in META_VARS_STR:
|
||||
det_variables["meta"][variable] = str(value)[:-1].strip()
|
||||
elif variable in META_UB_MATRIX:
|
||||
det_variables["meta"][variable] = re.findall(r"[-+]?\d*\.\d+|\d+", str(value))
|
||||
|
||||
elif "#data" in line:
|
||||
if det_variables["file_type"] == "ccl":
|
||||
decimal = list()
|
||||
@ -119,7 +111,6 @@ def load_1D(filepath):
|
||||
d["gamma_angle"] = float(lines.split()[4]) # gamma
|
||||
d["omega_angle"] = float(lines.split()[5]) # omega
|
||||
d["nu_angle"] = float(lines.split()[6]) # nu
|
||||
d["unkwn_angle"] = float(lines.split()[7])
|
||||
|
||||
next_line = data[position + 1]
|
||||
d["number_of_measurements"] = int(next_line.split()[0])
|
||||
@ -146,12 +137,6 @@ def load_1D(filepath):
|
||||
)
|
||||
d["counts"] = counts
|
||||
det_variables["Measurements"][str("M" + str(measurement_number))] = d
|
||||
if all(decimal):
|
||||
det_variables["meta"]["indices"] = "hkl"
|
||||
else:
|
||||
det_variables["meta"]["indices"] = "real"
|
||||
print("indeces:", det_variables["meta"]["indices"])
|
||||
|
||||
|
||||
elif det_variables["file_type"] == "dat":
|
||||
data = infile.readlines()
|
||||
@ -177,6 +162,9 @@ def load_1D(filepath):
|
||||
det_variables["Measurements"]["time"] = time
|
||||
else:
|
||||
print("Unknown file extention")
|
||||
if all(decimal):
|
||||
det_variables["meta"]["indices"] = "hkl"
|
||||
else:
|
||||
det_variables["meta"]["indices"] = "real"
|
||||
|
||||
return det_variables
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user