Break metadata and data reads
* fix decimal issue * add unkwn_angle
This commit is contained in:
parent
ab002be606
commit
8b3f1b568f
@ -68,6 +68,7 @@ def load_1D(filepath):
|
|||||||
"""
|
"""
|
||||||
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:
|
||||||
|
# read metadata
|
||||||
for line in infile:
|
for line in infile:
|
||||||
det_variables["Measurements"] = {}
|
det_variables["Measurements"] = {}
|
||||||
if "=" in line:
|
if "=" in line:
|
||||||
@ -80,91 +81,96 @@ def load_1D(filepath):
|
|||||||
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))
|
||||||
|
|
||||||
elif "#data" in line:
|
if "#data" in line:
|
||||||
if det_variables["file_type"] == "ccl":
|
# this is the end of metadata and the start of data section
|
||||||
decimal = list()
|
break
|
||||||
data = infile.readlines()
|
|
||||||
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
|
|
||||||
):
|
|
||||||
counts = []
|
|
||||||
measurement_number = int(lines.split()[0])
|
|
||||||
d = {}
|
|
||||||
d["h_index"] = float(lines.split()[1])
|
|
||||||
decimal.append(bool(Decimal(d["h_index"]) % 1 == 0))
|
|
||||||
d["k_index"] = float(lines.split()[2])
|
|
||||||
decimal.append(bool(Decimal(d["k_index"]) % 1 == 0))
|
|
||||||
d["l_index"] = float(lines.split()[3])
|
|
||||||
decimal.append(bool(Decimal(d["l_index"]) % 1 == 0))
|
|
||||||
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]
|
# read data
|
||||||
d["number_of_measurements"] = int(next_line.split()[0])
|
if det_variables["file_type"] == "ccl":
|
||||||
d["angle_step"] = float(next_line.split()[1])
|
decimal = list()
|
||||||
d["monitor"] = float(next_line.split()[2])
|
data = infile.readlines()
|
||||||
d["unkwn1"] = float(next_line.split()[3])
|
position = -1
|
||||||
d["unkwn2"] = float(next_line.split()[4])
|
for lines in data:
|
||||||
d["date"] = str(next_line.split()[5])
|
position = position + 1
|
||||||
d["time"] = str(next_line.split()[6])
|
if (
|
||||||
d["scan_type"] = str(next_line.split()[7])
|
bool(re.match("(\s\s\s\d)", lines[0:4])) == True
|
||||||
for i in range(
|
or bool(re.match("(\s\s\d\d)", lines[0:4])) == True
|
||||||
int(int(next_line.split()[0]) / 10)
|
or bool(re.match("(\s\d\d\d)", lines[0:4])) == True
|
||||||
+ (int(next_line.split()[0]) % 10 > 0)
|
or bool(re.match("(\d\d\d\d)", lines[0:4])) == True
|
||||||
):
|
):
|
||||||
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]),
|
|
||||||
)
|
|
||||||
d["counts"] = counts
|
|
||||||
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 = []
|
|
||||||
counts = []
|
counts = []
|
||||||
monitor1 = []
|
measurement_number = int(lines.split()[0])
|
||||||
monitor2 = []
|
d = {}
|
||||||
monitor3 = []
|
d["h_index"] = float(lines.split()[1])
|
||||||
time = []
|
decimal.append(bool(Decimal(d["h_index"]) % 1 == 0))
|
||||||
for position in range(num_of_points):
|
d["k_index"] = float(lines.split()[2])
|
||||||
omega.append(float(data[position + 3].split()[1]))
|
decimal.append(bool(Decimal(d["k_index"]) % 1 == 0))
|
||||||
counts.append(float(data[position + 3].split()[2]))
|
d["l_index"] = float(lines.split()[3])
|
||||||
monitor1.append(float(data[position + 3].split()[3]))
|
decimal.append(bool(Decimal(d["l_index"]) % 1 == 0))
|
||||||
monitor2.append(float(data[position + 3].split()[4]))
|
if det_variables["meta"]["zebra_mode"] == "bi":
|
||||||
monitor3.append(float(data[position + 3].split()[5]))
|
d["twotheta_angle"] = float(lines.split()[4]) # gamma
|
||||||
time.append(float(data[position + 3].split()[6]))
|
d["omega_angle"] = float(lines.split()[5]) # omega
|
||||||
det_variables["Measurements"]["omega"] = omega
|
d["chi_angle"] = float(lines.split()[6]) # nu
|
||||||
det_variables["Measurements"]["counts"] = counts
|
d["phi_angle"] = float(lines.split()[7]) # doesnt matter
|
||||||
det_variables["Measurements"]["Monitor1"] = monitor1
|
elif det_variables["meta"]["zebra_mode"] == "nb":
|
||||||
det_variables["Measurements"]["Monitor2"] = monitor2
|
d["gamma_angle"] = float(lines.split()[4]) # gamma
|
||||||
det_variables["Measurements"]["Monitor3"] = monitor3
|
d["omega_angle"] = float(lines.split()[5]) # omega
|
||||||
det_variables["Measurements"]["time"] = time
|
d["nu_angle"] = float(lines.split()[6]) # nu
|
||||||
else:
|
d["unkwn_angle"] = float(lines.split()[7])
|
||||||
print("Unknown file extention")
|
|
||||||
if all(decimal):
|
next_line = data[position + 1]
|
||||||
det_variables["meta"]["indices"] = "hkl"
|
d["number_of_measurements"] = int(next_line.split()[0])
|
||||||
else:
|
d["angle_step"] = float(next_line.split()[1])
|
||||||
det_variables["meta"]["indices"] = "real"
|
d["monitor"] = float(next_line.split()[2])
|
||||||
|
d["unkwn1"] = float(next_line.split()[3])
|
||||||
|
d["unkwn2"] = float(next_line.split()[4])
|
||||||
|
d["date"] = str(next_line.split()[5])
|
||||||
|
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)
|
||||||
|
):
|
||||||
|
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]),
|
||||||
|
)
|
||||||
|
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"
|
||||||
|
|
||||||
|
elif det_variables["file_type"] == "dat":
|
||||||
|
data = infile.readlines()
|
||||||
|
num_of_points = int(data[1].split()[0])
|
||||||
|
omega = []
|
||||||
|
counts = []
|
||||||
|
monitor1 = []
|
||||||
|
monitor2 = []
|
||||||
|
monitor3 = []
|
||||||
|
time = []
|
||||||
|
for position in range(num_of_points):
|
||||||
|
omega.append(float(data[position + 3].split()[1]))
|
||||||
|
counts.append(float(data[position + 3].split()[2]))
|
||||||
|
monitor1.append(float(data[position + 3].split()[3]))
|
||||||
|
monitor2.append(float(data[position + 3].split()[4]))
|
||||||
|
monitor3.append(float(data[position + 3].split()[5]))
|
||||||
|
time.append(float(data[position + 3].split()[6]))
|
||||||
|
det_variables["Measurements"]["omega"] = omega
|
||||||
|
det_variables["Measurements"]["counts"] = counts
|
||||||
|
det_variables["Measurements"]["Monitor1"] = monitor1
|
||||||
|
det_variables["Measurements"]["Monitor2"] = monitor2
|
||||||
|
det_variables["Measurements"]["Monitor3"] = monitor3
|
||||||
|
det_variables["Measurements"]["time"] = time
|
||||||
|
else:
|
||||||
|
print("Unknown file extention")
|
||||||
|
|
||||||
return det_variables
|
return det_variables
|
||||||
|
Loading…
x
Reference in New Issue
Block a user