Rename "Measurements" to "meas"
This commit is contained in:
parent
306958b02a
commit
3f8900bf87
@ -75,7 +75,7 @@ def create():
|
|||||||
_, ext = os.path.splitext(new)
|
_, ext = os.path.splitext(new)
|
||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
|
|
||||||
meas_list = list(det_data["Measurements"].keys())
|
meas_list = list(det_data["meas"].keys())
|
||||||
meas_table_source.data.update(measurement=meas_list, peaks=[0] * len(meas_list))
|
meas_table_source.data.update(measurement=meas_list, peaks=[0] * len(meas_list))
|
||||||
meas_table_source.selected.indices = []
|
meas_table_source.selected.indices = []
|
||||||
meas_table_source.selected.indices = [0]
|
meas_table_source.selected.indices = [0]
|
||||||
@ -89,7 +89,7 @@ def create():
|
|||||||
_, ext = os.path.splitext(upload_button.filename)
|
_, ext = os.path.splitext(upload_button.filename)
|
||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
|
|
||||||
meas_list = list(det_data["Measurements"].keys())
|
meas_list = list(det_data["meas"].keys())
|
||||||
meas_table_source.data.update(measurement=meas_list, peaks=[0] * len(meas_list))
|
meas_table_source.data.update(measurement=meas_list, peaks=[0] * len(meas_list))
|
||||||
meas_table_source.selected.indices = []
|
meas_table_source.selected.indices = []
|
||||||
meas_table_source.selected.indices = [0]
|
meas_table_source.selected.indices = [0]
|
||||||
@ -98,14 +98,14 @@ def create():
|
|||||||
upload_button.on_change("value", upload_button_callback)
|
upload_button.on_change("value", upload_button_callback)
|
||||||
|
|
||||||
def _update_table():
|
def _update_table():
|
||||||
num_of_peaks = [meas.get("num_of_peaks", 0) for meas in det_data["Measurements"].values()]
|
num_of_peaks = [meas.get("num_of_peaks", 0) for meas in det_data["meas"].values()]
|
||||||
meas_table_source.data.update(peaks=num_of_peaks)
|
meas_table_source.data.update(peaks=num_of_peaks)
|
||||||
|
|
||||||
def _update_plot(ind):
|
def _update_plot(ind):
|
||||||
nonlocal peak_pos_textinput_lock
|
nonlocal peak_pos_textinput_lock
|
||||||
peak_pos_textinput_lock = True
|
peak_pos_textinput_lock = True
|
||||||
|
|
||||||
meas = det_data["Measurements"][ind]
|
meas = det_data["meas"][ind]
|
||||||
y = meas["Counts"]
|
y = meas["Counts"]
|
||||||
x = meas["om"]
|
x = meas["om"]
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ def create():
|
|||||||
if new is not None and not peak_pos_textinput_lock:
|
if new is not None and not peak_pos_textinput_lock:
|
||||||
sel_ind = meas_table_source.selected.indices[-1]
|
sel_ind = meas_table_source.selected.indices[-1]
|
||||||
meas_name = meas_table_source.data["measurement"][sel_ind]
|
meas_name = meas_table_source.data["measurement"][sel_ind]
|
||||||
meas = det_data["Measurements"][meas_name]
|
meas = det_data["meas"][meas_name]
|
||||||
|
|
||||||
meas["num_of_peaks"] = 1
|
meas["num_of_peaks"] = 1
|
||||||
peak_ind = (np.abs(meas["om"] - float(new))).argmin()
|
peak_ind = (np.abs(meas["om"] - float(new))).argmin()
|
||||||
@ -296,7 +296,7 @@ def create():
|
|||||||
fit_output_textinput = TextAreaInput(title="Fit results:", width=450, height=400)
|
fit_output_textinput = TextAreaInput(title="Fit results:", width=450, height=400)
|
||||||
|
|
||||||
def peakfind_all_button_callback():
|
def peakfind_all_button_callback():
|
||||||
for meas in det_data["Measurements"].values():
|
for meas in det_data["meas"].values():
|
||||||
pyzebra.ccl_findpeaks(
|
pyzebra.ccl_findpeaks(
|
||||||
meas,
|
meas,
|
||||||
int_threshold=peak_int_ratio_spinner.value,
|
int_threshold=peak_int_ratio_spinner.value,
|
||||||
@ -318,7 +318,7 @@ def create():
|
|||||||
sel_ind = meas_table_source.selected.indices[-1]
|
sel_ind = meas_table_source.selected.indices[-1]
|
||||||
meas = meas_table_source.data["measurement"][sel_ind]
|
meas = meas_table_source.data["measurement"][sel_ind]
|
||||||
pyzebra.ccl_findpeaks(
|
pyzebra.ccl_findpeaks(
|
||||||
det_data["Measurements"][meas],
|
det_data["meas"][meas],
|
||||||
int_threshold=peak_int_ratio_spinner.value,
|
int_threshold=peak_int_ratio_spinner.value,
|
||||||
prominence=peak_prominence_spinner.value,
|
prominence=peak_prominence_spinner.value,
|
||||||
smooth=smooth_toggle.active,
|
smooth=smooth_toggle.active,
|
||||||
@ -333,7 +333,7 @@ def create():
|
|||||||
peakfind_button.on_click(peakfind_button_callback)
|
peakfind_button.on_click(peakfind_button_callback)
|
||||||
|
|
||||||
def fit_all_button_callback():
|
def fit_all_button_callback():
|
||||||
for meas in det_data["Measurements"].values():
|
for meas in det_data["meas"].values():
|
||||||
num_of_peaks = meas.get("num_of_peaks")
|
num_of_peaks = meas.get("num_of_peaks")
|
||||||
if num_of_peaks is not None and num_of_peaks == 1:
|
if num_of_peaks is not None and num_of_peaks == 1:
|
||||||
pyzebra.fitccl(
|
pyzebra.fitccl(
|
||||||
@ -380,10 +380,10 @@ def create():
|
|||||||
sel_ind = meas_table_source.selected.indices[-1]
|
sel_ind = meas_table_source.selected.indices[-1]
|
||||||
meas = meas_table_source.data["measurement"][sel_ind]
|
meas = meas_table_source.data["measurement"][sel_ind]
|
||||||
|
|
||||||
num_of_peaks = det_data["Measurements"][meas].get("num_of_peaks")
|
num_of_peaks = det_data["meas"][meas].get("num_of_peaks")
|
||||||
if num_of_peaks is not None and num_of_peaks == 1:
|
if num_of_peaks is not None and num_of_peaks == 1:
|
||||||
pyzebra.fitccl(
|
pyzebra.fitccl(
|
||||||
det_data["Measurements"][meas],
|
det_data["meas"][meas],
|
||||||
guess=[
|
guess=[
|
||||||
centre_guess.value,
|
centre_guess.value,
|
||||||
sigma_guess.value,
|
sigma_guess.value,
|
||||||
|
@ -12,19 +12,17 @@ def add_dict(dict1, dict2):
|
|||||||
:return dict1 : combined dictionary
|
:return dict1 : combined dictionary
|
||||||
Note: dict1 must be made from ccl, otherwise we would have to change the structure of loaded
|
Note: dict1 must be made from ccl, otherwise we would have to change the structure of loaded
|
||||||
dat file"""
|
dat file"""
|
||||||
max_measurement_dict1 = max([int(str(keys)[1:]) for keys in dict1["Measurements"]])
|
max_measurement_dict1 = max([int(str(keys)[1:]) for keys in dict1["meas"]])
|
||||||
if dict2["meta"]["data_type"] == ".ccl":
|
if dict2["meta"]["data_type"] == ".ccl":
|
||||||
new_filenames = [
|
new_filenames = [
|
||||||
"M" + str(x + max_measurement_dict1)
|
"M" + str(x + max_measurement_dict1)
|
||||||
for x in [int(str(keys)[1:]) for keys in dict2["Measurements"]]
|
for x in [int(str(keys)[1:]) for keys in dict2["meas"]]
|
||||||
]
|
]
|
||||||
new_meta_name = "meta" + str(dict2["meta"]["original_filename"])
|
new_meta_name = "meta" + str(dict2["meta"]["original_filename"])
|
||||||
if new_meta_name not in dict1:
|
if new_meta_name not in dict1:
|
||||||
for keys, name in zip(dict2["Measurements"], new_filenames):
|
for keys, name in zip(dict2["meas"], new_filenames):
|
||||||
dict2["Measurements"][keys]["file_of_origin"] = str(
|
dict2["meas"][keys]["file_of_origin"] = str(dict2["meta"]["original_filename"])
|
||||||
dict2["meta"]["original_filename"]
|
dict1["meas"][name] = dict2["meas"][keys]
|
||||||
)
|
|
||||||
dict1["Measurements"][name] = dict2["Measurements"][keys]
|
|
||||||
|
|
||||||
dict1[new_meta_name] = dict2["meta"]
|
dict1[new_meta_name] = dict2["meta"]
|
||||||
|
|
||||||
@ -42,14 +40,14 @@ def add_dict(dict1, dict2):
|
|||||||
d["h_index"] = float(hkl.split()[-3])
|
d["h_index"] = float(hkl.split()[-3])
|
||||||
d["k_index"] = float(hkl.split()[-2])
|
d["k_index"] = float(hkl.split()[-2])
|
||||||
d["l_index"] = float(hkl.split()[-1])
|
d["l_index"] = float(hkl.split()[-1])
|
||||||
d["number_of_measurements"] = len(dict2["Measurements"]["NP"])
|
d["number_of_measurements"] = len(dict2["meas"]["NP"])
|
||||||
d["om"] = dict2["Measurements"]["om"]
|
d["om"] = dict2["meas"]["om"]
|
||||||
d["Counts"] = dict2["Measurements"]["Counts"]
|
d["Counts"] = dict2["meas"]["Counts"]
|
||||||
d["monitor"] = dict2["Measurements"]["Monitor1"][0]
|
d["monitor"] = dict2["meas"]["Monitor1"][0]
|
||||||
d["temperature"] = dict2["meta"]["temp"]
|
d["temperature"] = dict2["meta"]["temp"]
|
||||||
d["mag_field"] = dict2["meta"]["mf"]
|
d["mag_field"] = dict2["meta"]["mf"]
|
||||||
d["omega_angle"] = dict2["meta"]["omega"]
|
d["omega_angle"] = dict2["meta"]["omega"]
|
||||||
dict1["Measurements"][new_name] = d
|
dict1["meas"][new_name] = d
|
||||||
print(hkl.split())
|
print(hkl.split())
|
||||||
for keys in d:
|
for keys in d:
|
||||||
print(keys)
|
print(keys)
|
||||||
@ -82,18 +80,18 @@ def scan_dict(dict):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
d = {}
|
d = {}
|
||||||
for i in dict["Measurements"]:
|
for i in dict["meas"]:
|
||||||
for j in dict["Measurements"]:
|
for j in dict["meas"]:
|
||||||
if dict["Measurements"][str(i)] != dict["Measurements"][str(j)]:
|
if dict["meas"][str(i)] != dict["meas"][str(j)]:
|
||||||
itup = (
|
itup = (
|
||||||
dict["Measurements"][str(i)]["h_index"],
|
dict["meas"][str(i)]["h_index"],
|
||||||
dict["Measurements"][str(i)]["k_index"],
|
dict["meas"][str(i)]["k_index"],
|
||||||
dict["Measurements"][str(i)]["l_index"],
|
dict["meas"][str(i)]["l_index"],
|
||||||
)
|
)
|
||||||
jtup = (
|
jtup = (
|
||||||
dict["Measurements"][str(j)]["h_index"],
|
dict["meas"][str(j)]["h_index"],
|
||||||
dict["Measurements"][str(j)]["k_index"],
|
dict["meas"][str(j)]["k_index"],
|
||||||
dict["Measurements"][str(j)]["l_index"],
|
dict["meas"][str(j)]["l_index"],
|
||||||
)
|
)
|
||||||
if itup != jtup:
|
if itup != jtup:
|
||||||
pass
|
pass
|
||||||
@ -119,47 +117,44 @@ def compare_hkl(dict1, dict2):
|
|||||||
first dict and M9 in second"""
|
first dict and M9 in second"""
|
||||||
d = {}
|
d = {}
|
||||||
dupl = 0
|
dupl = 0
|
||||||
for keys in dict1["Measurements"]:
|
for keys in dict1["meas"]:
|
||||||
for key in dict2["Measurements"]:
|
for key in dict2["meas"]:
|
||||||
if (
|
if (
|
||||||
dict1["Measurements"][str(keys)]["h_index"]
|
dict1["meas"][str(keys)]["h_index"] == dict2["meas"][str(key)]["h_index"]
|
||||||
== dict2["Measurements"][str(key)]["h_index"]
|
and dict1["meas"][str(keys)]["k_index"] == dict2["meas"][str(key)]["k_index"]
|
||||||
and dict1["Measurements"][str(keys)]["k_index"]
|
and dict1["meas"][str(keys)]["l_index"] == dict2["meas"][str(key)]["l_index"]
|
||||||
== dict2["Measurements"][str(key)]["k_index"]
|
|
||||||
and dict1["Measurements"][str(keys)]["l_index"]
|
|
||||||
== dict2["Measurements"][str(key)]["l_index"]
|
|
||||||
):
|
):
|
||||||
|
|
||||||
if (
|
if (
|
||||||
str(
|
str(
|
||||||
(
|
(
|
||||||
str(dict1["Measurements"][str(keys)]["h_index"])
|
str(dict1["meas"][str(keys)]["h_index"])
|
||||||
+ " "
|
+ " "
|
||||||
+ str(dict1["Measurements"][str(keys)]["k_index"])
|
+ str(dict1["meas"][str(keys)]["k_index"])
|
||||||
+ " "
|
+ " "
|
||||||
+ str(dict1["Measurements"][str(keys)]["l_index"])
|
+ str(dict1["meas"][str(keys)]["l_index"])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
not in d
|
not in d
|
||||||
):
|
):
|
||||||
d[
|
d[
|
||||||
str(
|
str(
|
||||||
str(dict1["Measurements"][str(keys)]["h_index"])
|
str(dict1["meas"][str(keys)]["h_index"])
|
||||||
+ " "
|
+ " "
|
||||||
+ str(dict1["Measurements"][str(keys)]["k_index"])
|
+ str(dict1["meas"][str(keys)]["k_index"])
|
||||||
+ " "
|
+ " "
|
||||||
+ str(dict1["Measurements"][str(keys)]["l_index"])
|
+ str(dict1["meas"][str(keys)]["l_index"])
|
||||||
)
|
)
|
||||||
] = (str(keys), str(key))
|
] = (str(keys), str(key))
|
||||||
else:
|
else:
|
||||||
dupl = dupl + 1
|
dupl = dupl + 1
|
||||||
d[
|
d[
|
||||||
str(
|
str(
|
||||||
str(dict1["Measurements"][str(keys)]["h_index"])
|
str(dict1["meas"][str(keys)]["h_index"])
|
||||||
+ " "
|
+ " "
|
||||||
+ str(dict1["Measurements"][str(keys)]["k_index"])
|
+ str(dict1["meas"][str(keys)]["k_index"])
|
||||||
+ " "
|
+ " "
|
||||||
+ str(dict1["Measurements"][str(keys)]["l_index"])
|
+ str(dict1["meas"][str(keys)]["l_index"])
|
||||||
+ "_dupl"
|
+ "_dupl"
|
||||||
+ str(dupl)
|
+ str(dupl)
|
||||||
)
|
)
|
||||||
@ -188,13 +183,9 @@ def normalize(dict, key, monitor):
|
|||||||
:return counts - normalized counts
|
:return counts - normalized counts
|
||||||
:return sigma - normalized sigma"""
|
:return sigma - normalized sigma"""
|
||||||
|
|
||||||
counts = np.array(dict["Measurements"][key]["Counts"])
|
counts = np.array(dict["meas"][key]["Counts"])
|
||||||
sigma = (
|
sigma = np.sqrt(counts) if "sigma" not in dict["meas"][key] else dict["meas"][key]["sigma"]
|
||||||
np.sqrt(counts)
|
monitor_ratio = monitor / dict["meas"][key]["monitor"]
|
||||||
if "sigma" not in dict["Measurements"][key]
|
|
||||||
else dict["Measurements"][key]["sigma"]
|
|
||||||
)
|
|
||||||
monitor_ratio = monitor / dict["Measurements"][key]["monitor"]
|
|
||||||
scaled_counts = counts * monitor_ratio
|
scaled_counts = counts * monitor_ratio
|
||||||
scaled_sigma = np.array(sigma) * monitor_ratio
|
scaled_sigma = np.array(sigma) * monitor_ratio
|
||||||
|
|
||||||
@ -212,11 +203,11 @@ def merge(dict1, dict2, keys, auto=True, monitor=100000):
|
|||||||
note: dict1 and dict2 can be same dict
|
note: dict1 and dict2 can be same dict
|
||||||
:return dict1 with merged scan"""
|
:return dict1 with merged scan"""
|
||||||
if auto:
|
if auto:
|
||||||
if dict1["Measurements"][keys[0]]["monitor"] == dict2["Measurements"][keys[1]]["monitor"]:
|
if dict1["meas"][keys[0]]["monitor"] == dict2["meas"][keys[1]]["monitor"]:
|
||||||
monitor = dict1["Measurements"][keys[0]]["monitor"]
|
monitor = dict1["meas"][keys[0]]["monitor"]
|
||||||
|
|
||||||
# load om and Counts
|
# load om and Counts
|
||||||
x1, x2 = dict1["Measurements"][keys[0]]["om"], dict2["Measurements"][keys[1]]["om"]
|
x1, x2 = dict1["meas"][keys[0]]["om"], dict2["meas"][keys[1]]["om"]
|
||||||
cor_y1, y_err1 = normalize(dict1, keys[0], monitor=monitor)
|
cor_y1, y_err1 = normalize(dict1, keys[0], monitor=monitor)
|
||||||
cor_y2, y_err2 = normalize(dict2, keys[1], monitor=monitor)
|
cor_y2, y_err2 = normalize(dict2, keys[1], monitor=monitor)
|
||||||
# creates touples (om, Counts, sigma) for sorting and further processing
|
# creates touples (om, Counts, sigma) for sorting and further processing
|
||||||
@ -246,21 +237,21 @@ def merge(dict1, dict2, keys, auto=True, monitor=100000):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if dict1 == dict2:
|
if dict1 == dict2:
|
||||||
del dict1["Measurements"][keys[1]]
|
del dict1["meas"][keys[1]]
|
||||||
|
|
||||||
note = (
|
note = (
|
||||||
f"This measurement was merged with measurement {keys[1]} from "
|
f"This measurement was merged with measurement {keys[1]} from "
|
||||||
f'file {dict2["meta"]["original_filename"]} \n'
|
f'file {dict2["meta"]["original_filename"]} \n'
|
||||||
)
|
)
|
||||||
if "notes" not in dict1["Measurements"][str(keys[0])]:
|
if "notes" not in dict1["meas"][str(keys[0])]:
|
||||||
dict1["Measurements"][str(keys[0])]["notes"] = note
|
dict1["meas"][str(keys[0])]["notes"] = note
|
||||||
else:
|
else:
|
||||||
dict1["Measurements"][str(keys[0])]["notes"] += note
|
dict1["meas"][str(keys[0])]["notes"] += note
|
||||||
|
|
||||||
dict1["Measurements"][keys[0]]["om"] = om
|
dict1["meas"][keys[0]]["om"] = om
|
||||||
dict1["Measurements"][keys[0]]["Counts"] = Counts
|
dict1["meas"][keys[0]]["Counts"] = Counts
|
||||||
dict1["Measurements"][keys[0]]["sigma"] = sigma
|
dict1["meas"][keys[0]]["sigma"] = sigma
|
||||||
dict1["Measurements"][keys[0]]["monitor"] = monitor
|
dict1["meas"][keys[0]]["monitor"] = monitor
|
||||||
print("merging done")
|
print("merging done")
|
||||||
return dict1
|
return dict1
|
||||||
|
|
||||||
@ -274,12 +265,12 @@ def substract_measurement(dict1, dict2, keys, auto=True, monitor=100000):
|
|||||||
:arg monitor : final monitor after merging
|
:arg monitor : final monitor after merging
|
||||||
:returns d : dict1 with substracted Counts from dict2 and sigma that comes from the substraction"""
|
:returns d : dict1 with substracted Counts from dict2 and sigma that comes from the substraction"""
|
||||||
|
|
||||||
if len(dict1["Measurements"][keys[0]]["om"]) != len(dict2["Measurements"][keys[1]]["om"]):
|
if len(dict1["meas"][keys[0]]["om"]) != len(dict2["meas"][keys[1]]["om"]):
|
||||||
raise ValueError("Omegas have different lengths, cannot be substracted")
|
raise ValueError("Omegas have different lengths, cannot be substracted")
|
||||||
|
|
||||||
if auto:
|
if auto:
|
||||||
if dict1["Measurements"][keys[0]]["monitor"] == dict2["Measurements"][keys[1]]["monitor"]:
|
if dict1["meas"][keys[0]]["monitor"] == dict2["meas"][keys[1]]["monitor"]:
|
||||||
monitor = dict1["Measurements"][keys[0]]["monitor"]
|
monitor = dict1["meas"][keys[0]]["monitor"]
|
||||||
|
|
||||||
cor_y1, y_err1 = normalize(dict1, keys[0], monitor=monitor)
|
cor_y1, y_err1 = normalize(dict1, keys[0], monitor=monitor)
|
||||||
cor_y2, y_err2 = normalize(dict2, keys[1], monitor=monitor)
|
cor_y2, y_err2 = normalize(dict2, keys[1], monitor=monitor)
|
||||||
@ -301,17 +292,17 @@ def substract_measurement(dict1, dict2, keys, auto=True, monitor=100000):
|
|||||||
f"{len([num for num in res_nom if num < 0]) / len(res_nom)}"
|
f"{len([num for num in res_nom if num < 0]) / len(res_nom)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
dict1["Measurements"][str(keys[0])]["Counts"] = res_nom
|
dict1["meas"][str(keys[0])]["Counts"] = res_nom
|
||||||
dict1["Measurements"][str(keys[0])]["sigma"] = res_err
|
dict1["meas"][str(keys[0])]["sigma"] = res_err
|
||||||
dict1["Measurements"][str(keys[0])]["monitor"] = monitor
|
dict1["meas"][str(keys[0])]["monitor"] = monitor
|
||||||
note = (
|
note = (
|
||||||
f'Measurement {keys[1]} from file {dict2["meta"]["original_filename"]} '
|
f'Measurement {keys[1]} from file {dict2["meta"]["original_filename"]} '
|
||||||
f"was substracted from this measurement \n"
|
f"was substracted from this measurement \n"
|
||||||
)
|
)
|
||||||
if "notes" not in dict1["Measurements"][str(keys[0])]:
|
if "notes" not in dict1["meas"][str(keys[0])]:
|
||||||
dict1["Measurements"][str(keys[0])]["notes"] = note
|
dict1["meas"][str(keys[0])]["notes"] = note
|
||||||
else:
|
else:
|
||||||
dict1["Measurements"][str(keys[0])]["notes"] += note
|
dict1["meas"][str(keys[0])]["notes"] += note
|
||||||
return dict1
|
return dict1
|
||||||
|
|
||||||
|
|
||||||
@ -380,24 +371,24 @@ def compare_dict(dict1, dict2):
|
|||||||
# compare Measurements
|
# compare Measurements
|
||||||
S.append(
|
S.append(
|
||||||
"Number of measurements in %s = %s \n"
|
"Number of measurements in %s = %s \n"
|
||||||
% (dict1["meta"]["original_filename"], len(dict1["Measurements"]))
|
% (dict1["meta"]["original_filename"], len(dict1["meas"]))
|
||||||
)
|
)
|
||||||
S.append(
|
S.append(
|
||||||
"Number of measurements in %s = %s \n"
|
"Number of measurements in %s = %s \n"
|
||||||
% (dict2["meta"]["original_filename"], len(dict2["Measurements"]))
|
% (dict2["meta"]["original_filename"], len(dict2["meas"]))
|
||||||
)
|
)
|
||||||
S.append("Different values in Measurements:\n")
|
S.append("Different values in Measurements:\n")
|
||||||
select_set = ["om", "Counts", "sigma"]
|
select_set = ["om", "Counts", "sigma"]
|
||||||
exlude_set = ["time", "Counts", "date", "notes"]
|
exlude_set = ["time", "Counts", "date", "notes"]
|
||||||
for keys1 in comp:
|
for keys1 in comp:
|
||||||
for key2 in dict1["Measurements"][str(comp[str(keys1)][0])]:
|
for key2 in dict1["meas"][str(comp[str(keys1)][0])]:
|
||||||
if key2 in exlude_set:
|
if key2 in exlude_set:
|
||||||
continue
|
continue
|
||||||
if key2 not in select_set:
|
if key2 not in select_set:
|
||||||
try:
|
try:
|
||||||
if (
|
if (
|
||||||
dict1["Measurements"][comp[str(keys1)][0]][str(key2)]
|
dict1["meas"][comp[str(keys1)][0]][str(key2)]
|
||||||
!= dict2["Measurements"][str(comp[str(keys1)][1])][str(key2)]
|
!= dict2["meas"][str(comp[str(keys1)][1])][str(key2)]
|
||||||
):
|
):
|
||||||
S.append(
|
S.append(
|
||||||
"Measurement value "
|
"Measurement value "
|
||||||
@ -407,21 +398,21 @@ def compare_dict(dict1, dict2):
|
|||||||
)
|
)
|
||||||
S.append(
|
S.append(
|
||||||
" dict1: %s \n"
|
" dict1: %s \n"
|
||||||
% str(dict1["Measurements"][comp[str(keys1)][0]][str(key2)])
|
% str(dict1["meas"][comp[str(keys1)][0]][str(key2)])
|
||||||
)
|
)
|
||||||
S.append(
|
S.append(
|
||||||
" dict2: %s \n"
|
" dict2: %s \n"
|
||||||
% str(dict2["Measurements"][comp[str(keys1)][1]][str(key2)])
|
% str(dict2["meas"][comp[str(keys1)][1]][str(key2)])
|
||||||
)
|
)
|
||||||
if key2 not in conflicts:
|
if key2 not in conflicts:
|
||||||
conflicts[key2] = {}
|
conflicts[key2] = {}
|
||||||
conflicts[key2]["amount"] = 1
|
conflicts[key2]["amount"] = 1
|
||||||
conflicts[key2]["measurements"] = str(comp[str(keys1)])
|
conflicts[key2]["meas"] = str(comp[str(keys1)])
|
||||||
else:
|
else:
|
||||||
|
|
||||||
conflicts[key2]["amount"] = conflicts[key2]["amount"] + 1
|
conflicts[key2]["amount"] = conflicts[key2]["amount"] + 1
|
||||||
conflicts[key2]["measurements"] = (
|
conflicts[key2]["meas"] = (
|
||||||
conflicts[key2]["measurements"] + " " + (str(comp[str(keys1)]))
|
conflicts[key2]["meas"] + " " + (str(comp[str(keys1)]))
|
||||||
)
|
)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print("Missing keys, some files were probably merged or substracted")
|
print("Missing keys, some files were probably merged or substracted")
|
||||||
@ -429,11 +420,11 @@ def compare_dict(dict1, dict2):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
comparison = list(
|
comparison = list(dict1["meas"][comp[str(keys1)][0]][str(key2)]) == list(
|
||||||
dict1["Measurements"][comp[str(keys1)][0]][str(key2)]
|
dict2["meas"][comp[str(keys1)][1]][str(key2)]
|
||||||
) == list(dict2["Measurements"][comp[str(keys1)][1]][str(key2)])
|
)
|
||||||
if len(list(dict1["Measurements"][comp[str(keys1)][0]][str(key2)])) != len(
|
if len(list(dict1["meas"][comp[str(keys1)][0]][str(key2)])) != len(
|
||||||
list(dict2["Measurements"][comp[str(keys1)][1]][str(key2)])
|
list(dict2["meas"][comp[str(keys1)][1]][str(key2)])
|
||||||
):
|
):
|
||||||
if str("different length of %s" % key2) not in warnings:
|
if str("different length of %s" % key2) not in warnings:
|
||||||
warnings[str("different length of %s" % key2)] = list()
|
warnings[str("different length of %s" % key2)] = list()
|
||||||
@ -453,20 +444,20 @@ def compare_dict(dict1, dict2):
|
|||||||
)
|
)
|
||||||
S.append(
|
S.append(
|
||||||
" dict1: %s \n"
|
" dict1: %s \n"
|
||||||
% str(list(dict1["Measurements"][comp[str(keys1)][0]][str(key2)]))
|
% str(list(dict1["meas"][comp[str(keys1)][0]][str(key2)]))
|
||||||
)
|
)
|
||||||
S.append(
|
S.append(
|
||||||
" dict2: %s \n"
|
" dict2: %s \n"
|
||||||
% str(list(dict2["Measurements"][comp[str(keys1)][1]][str(key2)]))
|
% str(list(dict2["meas"][comp[str(keys1)][1]][str(key2)]))
|
||||||
)
|
)
|
||||||
if key2 not in conflicts:
|
if key2 not in conflicts:
|
||||||
conflicts[key2] = {}
|
conflicts[key2] = {}
|
||||||
conflicts[key2]["amount"] = 1
|
conflicts[key2]["amount"] = 1
|
||||||
conflicts[key2]["measurements"] = str(comp[str(keys1)])
|
conflicts[key2]["meas"] = str(comp[str(keys1)])
|
||||||
else:
|
else:
|
||||||
conflicts[key2]["amount"] = conflicts[key2]["amount"] + 1
|
conflicts[key2]["amount"] = conflicts[key2]["amount"] + 1
|
||||||
conflicts[key2]["measurements"] = (
|
conflicts[key2]["meas"] = (
|
||||||
conflicts[key2]["measurements"] + " " + (str(comp[str(keys1)]))
|
conflicts[key2]["meas"] + " " + (str(comp[str(keys1)]))
|
||||||
)
|
)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print("Missing keys, some files were probably merged or substracted")
|
print("Missing keys, some files were probably merged or substracted")
|
||||||
@ -474,7 +465,7 @@ def compare_dict(dict1, dict2):
|
|||||||
|
|
||||||
for keys in conflicts:
|
for keys in conflicts:
|
||||||
try:
|
try:
|
||||||
conflicts[str(keys)]["measurements"] = conflicts[str(keys)]["measurements"].split(" ")
|
conflicts[str(keys)]["meas"] = conflicts[str(keys)]["meas"].split(" ")
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
report_string = "".join(S)
|
report_string = "".join(S)
|
||||||
@ -489,18 +480,18 @@ def guess_next(dict1, dict2, comp):
|
|||||||
if (
|
if (
|
||||||
abs(
|
abs(
|
||||||
(
|
(
|
||||||
dict1["Measurements"][str(comp[keys][0])]["temperature"]
|
dict1["meas"][str(comp[keys][0])]["temperature"]
|
||||||
- dict2["Measurements"][str(comp[keys][1])]["temperature"]
|
- dict2["meas"][str(comp[keys][1])]["temperature"]
|
||||||
)
|
)
|
||||||
/ dict2["Measurements"][str(comp[keys][1])]["temperature"]
|
/ dict2["meas"][str(comp[keys][1])]["temperature"]
|
||||||
)
|
)
|
||||||
< threshold
|
< threshold
|
||||||
and abs(
|
and abs(
|
||||||
(
|
(
|
||||||
dict1["Measurements"][str(comp[keys][0])]["mag_field"]
|
dict1["meas"][str(comp[keys][0])]["mag_field"]
|
||||||
- dict2["Measurements"][str(comp[keys][1])]["mag_field"]
|
- dict2["meas"][str(comp[keys][1])]["mag_field"]
|
||||||
)
|
)
|
||||||
/ dict2["Measurements"][str(comp[keys][1])]["mag_field"]
|
/ dict2["meas"][str(comp[keys][1])]["mag_field"]
|
||||||
)
|
)
|
||||||
< threshold
|
< threshold
|
||||||
):
|
):
|
||||||
|
@ -30,7 +30,7 @@ def export_comm(data, path, lorentz=False):
|
|||||||
padding = [4, 6, 10, 8]
|
padding = [4, 6, 10, 8]
|
||||||
|
|
||||||
with open(str(path + extension), "w") as out_file:
|
with open(str(path + extension), "w") as out_file:
|
||||||
for keys, meas in data["Measurements"].items():
|
for keys, meas in data["meas"].items():
|
||||||
if "fit" not in meas:
|
if "fit" not in meas:
|
||||||
print("Measurement skipped - no fit value for:", keys)
|
print("Measurement skipped - no fit value for:", keys)
|
||||||
continue
|
continue
|
||||||
|
@ -183,4 +183,4 @@ def parse_1D(fileobj, data_type):
|
|||||||
metadata["data_type"] = data_type
|
metadata["data_type"] = data_type
|
||||||
metadata["area_method"] = "fit"
|
metadata["area_method"] = "fit"
|
||||||
|
|
||||||
return {"meta": metadata, "Measurements": measurements}
|
return {"meta": metadata, "meas": measurements}
|
||||||
|
@ -38,12 +38,12 @@ def load_dats(filepath):
|
|||||||
dict1 = add_dict(dict1, load_1D(file_list[i][0]))
|
dict1 = add_dict(dict1, load_1D(file_list[i][0]))
|
||||||
else:
|
else:
|
||||||
dict1 = add_dict(dict1, load_1D(file_list[i]))
|
dict1 = add_dict(dict1, load_1D(file_list[i]))
|
||||||
dict1["Measurements"][str("M" + str(i + 1))]["params"] = {}
|
dict1["meas"][str("M" + str(i + 1))]["params"] = {}
|
||||||
if data_type == "txt":
|
if data_type == "txt":
|
||||||
for x in range(len(col_names) - 1):
|
for x in range(len(col_names) - 1):
|
||||||
dict1["Measurements"][str("M" + str(i + 1))]["params"][
|
dict1["meas"][str("M" + str(i + 1))]["params"][col_names[x + 1]] = file_list[i][
|
||||||
col_names[x + 1]
|
x + 1
|
||||||
] = file_list[i][x + 1]
|
]
|
||||||
|
|
||||||
return dict1
|
return dict1
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ def create_dataframe(dict1):
|
|||||||
# create dictionary to which we pull only wanted items before transforming it to pd.dataframe
|
# create dictionary to which we pull only wanted items before transforming it to pd.dataframe
|
||||||
pull_dict = {}
|
pull_dict = {}
|
||||||
pull_dict["filenames"] = list()
|
pull_dict["filenames"] = list()
|
||||||
for key in dict1["Measurements"]["M1"]["params"]:
|
for key in dict1["meas"]["M1"]["params"]:
|
||||||
pull_dict[key] = list()
|
pull_dict[key] = list()
|
||||||
pull_dict["temperature"] = list()
|
pull_dict["temperature"] = list()
|
||||||
pull_dict["mag_field"] = list()
|
pull_dict["mag_field"] = list()
|
||||||
@ -65,21 +65,19 @@ def create_dataframe(dict1):
|
|||||||
pull_dict["Counts"] = list()
|
pull_dict["Counts"] = list()
|
||||||
|
|
||||||
# populate the dict
|
# populate the dict
|
||||||
for keys in dict1["Measurements"]:
|
for keys in dict1["meas"]:
|
||||||
if "file_of_origin" in dict1["Measurements"][keys]:
|
if "file_of_origin" in dict1["meas"][keys]:
|
||||||
pull_dict["filenames"].append(
|
pull_dict["filenames"].append(dict1["meas"][keys]["file_of_origin"].split("/")[-1])
|
||||||
dict1["Measurements"][keys]["file_of_origin"].split("/")[-1]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
pull_dict["filenames"].append(dict1["meta"]["original_filename"].split("/")[-1])
|
pull_dict["filenames"].append(dict1["meta"]["original_filename"].split("/")[-1])
|
||||||
for key in dict1["Measurements"][keys]["params"]:
|
for key in dict1["meas"][keys]["params"]:
|
||||||
pull_dict[str(key)].append(float(dict1["Measurements"][keys]["params"][key]))
|
pull_dict[str(key)].append(float(dict1["meas"][keys]["params"][key]))
|
||||||
pull_dict["temperature"].append(dict1["Measurements"][keys]["temperature"])
|
pull_dict["temperature"].append(dict1["meas"][keys]["temperature"])
|
||||||
pull_dict["mag_field"].append(dict1["Measurements"][keys]["mag_field"])
|
pull_dict["mag_field"].append(dict1["meas"][keys]["mag_field"])
|
||||||
pull_dict["fit_area"].append(dict1["Measurements"][keys]["fit"]["fit_area"])
|
pull_dict["fit_area"].append(dict1["meas"][keys]["fit"]["fit_area"])
|
||||||
pull_dict["int_area"].append(dict1["Measurements"][keys]["fit"]["int_area"])
|
pull_dict["int_area"].append(dict1["meas"][keys]["fit"]["int_area"])
|
||||||
pull_dict["om"].append(dict1["Measurements"][keys]["om"])
|
pull_dict["om"].append(dict1["meas"][keys]["om"])
|
||||||
pull_dict["Counts"].append(dict1["Measurements"][keys]["Counts"])
|
pull_dict["Counts"].append(dict1["meas"][keys]["Counts"])
|
||||||
|
|
||||||
return pd.DataFrame(data=pull_dict)
|
return pd.DataFrame(data=pull_dict)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user