Updated load_1D.py #63
@ -1,12 +1,57 @@
|
|||||||
import re
|
import re
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
META_VARS_STR = ('instrument', 'title', 'sample', 'user', 'ProposalID', 'original_filename', 'date',
|
META_VARS_STR = (
|
||||||
'zebra_mode','proposal', 'proposal_user', 'proposal_title', 'proposal_email')
|
"instrument",
|
||||||
META_VARS_FLOAT = ('mf', '2-theta', 'chi', 'phi', 'nu', 'temp', 'wavelenght', 'a', 'b', 'c', 'alpha', 'beta',
|
"title",
|
||||||
'gamma', 'cex1', 'cex2', 'mexz', 'moml', 'mcvl', 'momu', 'mcvu', 'detectorDistance', 'snv',
|
"sample",
|
||||||
'snh', 'snvm', 'snhm', 's1vt', 's1vb', 's1hr', 's1hl', 's2vt', 's2vb', 's2hr', 's2hl')
|
"user",
|
||||||
META_UB_MATRIX = ('ub1j', 'ub2j', 'ub3j')
|
"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):
|
def load_1D(filepath):
|
||||||
"""
|
"""
|
||||||
@ -17,16 +62,15 @@ def load_1D(filepath):
|
|||||||
:arg filepath
|
:arg filepath
|
||||||
:returns det_variables
|
:returns det_variables
|
||||||
- dictionary of all detector/scan variables and dictinionary for every measurement.
|
- 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,
|
Names of these dictionaries are M + measurement number. They include HKL indeces, angles,
|
||||||
stepsize and array of counts
|
monitors, stepsize and array of counts
|
||||||
"""
|
"""
|
||||||
|
|
||||||
det_variables = {"file_type": str(filepath)[-3:], "meta": {}}
|
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()
|
||||||
try:
|
try:
|
||||||
if variable in META_VARS_FLOAT:
|
if variable in META_VARS_FLOAT:
|
||||||
@ -34,34 +78,41 @@ def load_1D(filepath):
|
|||||||
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:
|
except ValueError as error:
|
||||||
print('Some values are not in expected format (str or float), error:', str(error))
|
print(
|
||||||
elif '#data' in line:
|
"Some values are not in expected format (str or float), error:", str(error)
|
||||||
if det_variables["file_type"] == 'ccl':
|
)
|
||||||
|
|
||||||
|
elif "#data" in line:
|
||||||
|
if det_variables["file_type"] == "ccl":
|
||||||
data = infile.readlines()
|
data = infile.readlines()
|
||||||
position = - 1
|
position = -1
|
||||||
for lines in data:
|
for lines in data:
|
||||||
position = position + 1
|
position = position + 1
|
||||||
if bool(re.match('(\s\s\s\d)', lines[0:4])) == True or bool(
|
if (
|
||||||
re.match('(\s\s\d\d)', lines[0:4])) == True or bool(
|
bool(re.match("(\s\s\s\d)", lines[0:4])) == True
|
||||||
re.match('(\s\d\d\d)', lines[0:4])) == True or bool(
|
or bool(re.match("(\s\s\d\d)", lines[0:4])) == True
|
||||||
re.match('(\d\d\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 = []
|
counts = []
|
||||||
measurement_number = int(lines.split()[0])
|
measurement_number = int(lines.split()[0])
|
||||||
d = {}
|
d = {}
|
||||||
d["h_index"] = float(lines.split()[1])
|
d["h_index"] = float(lines.split()[1])
|
||||||
d["k_index"] = float(lines.split()[2])
|
d["k_index"] = float(lines.split()[2])
|
||||||
d["l_index"] = float(lines.split()[3])
|
d["l_index"] = float(lines.split()[3])
|
||||||
if det_variables["meta"]["zebra_mode"] == 'bi':
|
if det_variables["meta"]["zebra_mode"] == "bi":
|
||||||
d["twotheta_angle"] = float(lines.split()[4]) # gamma
|
d["twotheta_angle"] = float(lines.split()[4]) # gamma
|
||||||
d["omega_angle"] = float(lines.split()[5]) # omega
|
d["omega_angle"] = float(lines.split()[5]) # omega
|
||||||
d["chi_angle"] = float(lines.split()[6]) # nu
|
d["chi_angle"] = float(lines.split()[6]) # nu
|
||||||
d["phi_angle"] = float(lines.split()[7]) # doesnt matter
|
d["phi_angle"] = float(lines.split()[7]) # doesnt matter
|
||||||
elif det_variables["meta"]["zebra_mode"] == 'nb':
|
elif det_variables["meta"]["zebra_mode"] == "nb":
|
||||||
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
|
||||||
|
|
||||||
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])
|
||||||
@ -73,18 +124,23 @@ def load_1D(filepath):
|
|||||||
d["time"] = str(next_line.split()[6])
|
d["time"] = str(next_line.split()[6])
|
||||||
d["scan_type"] = str(next_line.split()[7])
|
d["scan_type"] = str(next_line.split()[7])
|
||||||
for i in range(
|
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()
|
fileline = data[position + 2 + i].split()
|
||||||
numbers = [int(w) for w in fileline]
|
numbers = [int(w) for w in fileline]
|
||||||
counts = counts + numbers
|
counts = counts + numbers
|
||||||
d["omega"] = np.linspace(
|
d["omega"] = np.linspace(
|
||||||
float(lines.split()[5]) - (int(next_line.split()[0]) / 2) * float(
|
float(lines.split()[5])
|
||||||
next_line.split()[1]),
|
- (int(next_line.split()[0]) / 2) * float(next_line.split()[1]),
|
||||||
float(lines.split()[5]) + (int(next_line.split()[0]) / 2) * float(
|
float(lines.split()[5])
|
||||||
next_line.split()[1]), int(next_line.split()[0]))
|
+ (int(next_line.split()[0]) / 2) * float(next_line.split()[1]),
|
||||||
|
int(next_line.split()[0]),
|
||||||
|
)
|
||||||
d["counts"] = counts
|
d["counts"] = counts
|
||||||
det_variables["Measurements"][str('M' + str(measurement_number))] = d
|
det_variables["Measurements"][str("M" + str(measurement_number))] = d
|
||||||
elif det_variables["file_type"] == 'dat':
|
|
||||||
|
elif det_variables["file_type"] == "dat":
|
||||||
data = infile.readlines()
|
data = infile.readlines()
|
||||||
num_of_points = int(data[1].split()[0])
|
num_of_points = int(data[1].split()[0])
|
||||||
omega = []
|
omega = []
|
||||||
@ -107,5 +163,6 @@ def load_1D(filepath):
|
|||||||
det_variables["Measurements"]["Monitor3"] = monitor3
|
det_variables["Measurements"]["Monitor3"] = monitor3
|
||||||
det_variables["Measurements"]["time"] = time
|
det_variables["Measurements"]["time"] = time
|
||||||
else:
|
else:
|
||||||
print('Unknown file extention')
|
print("Unknown file extention")
|
||||||
|
|
||||||
return det_variables
|
return det_variables
|
||||||
|
Reference in New Issue
Block a user