Revert "Update load_1D.py"

This reverts commit cc3f1d28a5670dad6fdaec83a19edbee0b1a09ce.
This commit is contained in:
usov_i 2020-09-15 15:53:24 +02:00
parent cc3f1d28a5
commit ab002be606

View File

@ -2,22 +2,7 @@ import re
import numpy as np
from decimal import Decimal
def load_1D(filepath):
"""
Loads *.ccl or *.dat file (Distinguishes them based on last 3 chars in string of filepath
to add more variables to read, extend the elif list
the file must include '#data' and number of points in right place to work properly
: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
"""
det_variables = {"file_type": str(filepath)[-3:], "meta": {}}
meta_vars_str = (
META_VARS_STR = (
"instrument",
"title",
"sample",
@ -31,7 +16,7 @@ def load_1D(filepath):
"proposal_title",
"proposal_email",
)
meta_vars_float = (
META_VARS_FLOAT = (
"mf",
"2-theta",
"chi",
@ -66,28 +51,35 @@ def load_1D(filepath):
"s2hr",
"s2hl",
)
meta_ub_matrix = ("ub1j", "ub2j", "ub3j")
META_UB_MATRIX = ("ub1j", "ub2j", "ub3j")
def load_1D(filepath):
"""
Loads *.ccl or *.dat file (Distinguishes them based on last 3 chars in string of filepath
to add more variables to read, extend the elif list
the file must include '#data' and number of points in right place to work properly
: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
"""
det_variables = {"file_type": str(filepath)[-3:], "meta": {}}
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:
if variable in META_VARS_FLOAT:
det_variables["meta"][variable] = float(value)
elif variable in meta_vars_str:
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),
)
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