Apply black formatter

This commit is contained in:
usov_i 2020-09-11 12:00:50 +02:00 committed by Ivan Usov
parent ddebcc305f
commit 661014ad73

View File

@ -1,12 +1,57 @@
import re
import numpy as np
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')
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):
"""
@ -17,16 +62,15 @@ 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": {}}
with open(filepath, 'r') as infile:
with open(filepath, "r") as infile:
for line in infile:
det_variables["Measurements"] = {}
if '=' in line:
variable, value = line.split('=')
if "=" in line:
variable, value = line.split("=")
variable = variable.strip()
try:
if variable in META_VARS_FLOAT:
@ -34,34 +78,41 @@ def load_1D(filepath):
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))
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:
if det_variables["file_type"] == 'ccl':
print(
"Some values are not in expected format (str or float), error:", str(error)
)
elif "#data" in line:
if det_variables["file_type"] == "ccl":
data = infile.readlines()
position = - 1
position = -1
for lines in data:
position = position + 1
if bool(re.match('(\s\s\s\d)', lines[0:4])) == True or bool(
re.match('(\s\s\d\d)', lines[0:4])) == True or bool(
re.match('(\s\d\d\d)', lines[0:4])) == True or bool(
re.match('(\d\d\d\d)', lines[0:4])) == True:
if (
bool(re.match("(\s\s\s\d)", lines[0:4])) == True
or bool(re.match("(\s\s\d\d)", lines[0:4])) == True
or bool(re.match("(\s\d\d\d)", lines[0:4])) == True
or bool(re.match("(\d\d\d\d)", lines[0:4])) == True
):
counts = []
measurement_number = int(lines.split()[0])
d = {}
d["h_index"] = float(lines.split()[1])
d["k_index"] = float(lines.split()[2])
d["l_index"] = float(lines.split()[3])
if det_variables["meta"]["zebra_mode"] == 'bi':
d["twotheta_angle"] = float(lines.split()[4]) # gamma
d["omega_angle"] = float(lines.split()[5]) # omega
d["chi_angle"] = float(lines.split()[6]) # nu
d["phi_angle"] = float(lines.split()[7]) # doesnt matter
elif det_variables["meta"]["zebra_mode"] == 'nb':
d["gamma_angle"] = float(lines.split()[4]) # gamma
d["omega_angle"] = float(lines.split()[5]) # omega
d["nu_angle"] = float(lines.split()[6]) # nu
if det_variables["meta"]["zebra_mode"] == "bi":
d["twotheta_angle"] = float(lines.split()[4]) # gamma
d["omega_angle"] = float(lines.split()[5]) # omega
d["chi_angle"] = float(lines.split()[6]) # nu
d["phi_angle"] = float(lines.split()[7]) # doesnt matter
elif det_variables["meta"]["zebra_mode"] == "nb":
d["gamma_angle"] = float(lines.split()[4]) # gamma
d["omega_angle"] = float(lines.split()[5]) # omega
d["nu_angle"] = float(lines.split()[6]) # nu
next_line = data[position + 1]
d["number_of_measurements"] = int(next_line.split()[0])
@ -73,18 +124,23 @@ def load_1D(filepath):
d["time"] = str(next_line.split()[6])
d["scan_type"] = str(next_line.split()[7])
for i in range(
int(int(next_line.split()[0]) / 10) + (int(next_line.split()[0]) % 10 > 0)):
int(int(next_line.split()[0]) / 10)
+ (int(next_line.split()[0]) % 10 > 0)
):
fileline = data[position + 2 + i].split()
numbers = [int(w) for w in fileline]
counts = counts + numbers
d["omega"] = np.linspace(
float(lines.split()[5]) - (int(next_line.split()[0]) / 2) * float(
next_line.split()[1]),
float(lines.split()[5]) + (int(next_line.split()[0]) / 2) * float(
next_line.split()[1]), int(next_line.split()[0]))
float(lines.split()[5])
- (int(next_line.split()[0]) / 2) * float(next_line.split()[1]),
float(lines.split()[5])
+ (int(next_line.split()[0]) / 2) * float(next_line.split()[1]),
int(next_line.split()[0]),
)
d["counts"] = counts
det_variables["Measurements"][str('M' + str(measurement_number))] = d
elif det_variables["file_type"] == 'dat':
det_variables["Measurements"][str("M" + str(measurement_number))] = d
elif det_variables["file_type"] == "dat":
data = infile.readlines()
num_of_points = int(data[1].split()[0])
omega = []
@ -107,5 +163,6 @@ def load_1D(filepath):
det_variables["Measurements"]["Monitor3"] = monitor3
det_variables["Measurements"]["time"] = time
else:
print('Unknown file extention')
print("Unknown file extention")
return det_variables