Add code for 1D detector #69
@ -2,7 +2,22 @@ import re
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
META_VARS_STR = (
|
|
||||||
|
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 = (
|
||||||
"instrument",
|
"instrument",
|
||||||
"title",
|
"title",
|
||||||
"sample",
|
"sample",
|
||||||
@ -15,8 +30,8 @@ META_VARS_STR = (
|
|||||||
"proposal_user",
|
"proposal_user",
|
||||||
"proposal_title",
|
"proposal_title",
|
||||||
"proposal_email",
|
"proposal_email",
|
||||||
)
|
)
|
||||||
META_VARS_FLOAT = (
|
meta_vars_float = (
|
||||||
"mf",
|
"mf",
|
||||||
"2-theta",
|
"2-theta",
|
||||||
"chi",
|
"chi",
|
||||||
@ -50,36 +65,29 @@ META_VARS_FLOAT = (
|
|||||||
"s2vb",
|
"s2vb",
|
||||||
"s2hr",
|
"s2hr",
|
||||||
"s2hl",
|
"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:
|
with open(filepath, "r") as infile:
|
||||||
for line in infile:
|
for line in infile:
|
||||||
det_variables["Measurements"] = {}
|
det_variables["Measurements"] = {}
|
||||||
if "=" in line:
|
if "=" in line:
|
||||||
variable, value = line.split("=")
|
variable, value = line.split("=")
|
||||||
variable = variable.strip()
|
variable = variable.strip()
|
||||||
if variable in META_VARS_FLOAT:
|
try:
|
||||||
|
if variable in meta_vars_float:
|
||||||
det_variables["meta"][variable] = float(value)
|
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()
|
det_variables["meta"][variable] = str(value)[:-1].strip()
|
||||||
elif variable in META_UB_MATRIX:
|
elif variable in meta_ub_matrix:
|
||||||
det_variables["meta"][variable] = re.findall(r"[-+]?\d*\.\d+|\d+", str(value))
|
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 "#data" in line:
|
elif "#data" in line:
|
||||||
if det_variables["file_type"] == "ccl":
|
if det_variables["file_type"] == "ccl":
|
||||||
decimal = list()
|
decimal = list()
|
||||||
@ -111,6 +119,7 @@ def load_1D(filepath):
|
|||||||
d["gamma_angle"] = float(lines.split()[4]) # gamma
|
d["gamma_angle"] = float(lines.split()[4]) # gamma
|
||||||
d["omega_angle"] = float(lines.split()[5]) # omega
|
d["omega_angle"] = float(lines.split()[5]) # omega
|
||||||
d["nu_angle"] = float(lines.split()[6]) # nu
|
d["nu_angle"] = float(lines.split()[6]) # nu
|
||||||
|
d["unkwn_angle"] = float(lines.split()[7])
|
||||||
|
|
||||||
next_line = data[position + 1]
|
next_line = data[position + 1]
|
||||||
d["number_of_measurements"] = int(next_line.split()[0])
|
d["number_of_measurements"] = int(next_line.split()[0])
|
||||||
@ -137,6 +146,12 @@ def load_1D(filepath):
|
|||||||
)
|
)
|
||||||
d["counts"] = counts
|
d["counts"] = counts
|
||||||
det_variables["Measurements"][str("M" + str(measurement_number))] = d
|
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":
|
elif det_variables["file_type"] == "dat":
|
||||||
data = infile.readlines()
|
data = infile.readlines()
|
||||||
@ -162,9 +177,6 @@ def load_1D(filepath):
|
|||||||
det_variables["Measurements"]["time"] = time
|
det_variables["Measurements"]["time"] = time
|
||||||
else:
|
else:
|
||||||
print("Unknown file extention")
|
print("Unknown file extention")
|
||||||
if all(decimal):
|
|
||||||
det_variables["meta"]["indices"] = "hkl"
|
|
||||||
else:
|
|
||||||
det_variables["meta"]["indices"] = "real"
|
|
||||||
|
|
||||||
return det_variables
|
return det_variables
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user