Merge based on variable parameter range overlap
This commit is contained in:
parent
3b1a2b1a0b
commit
12077dd5f3
@ -172,7 +172,7 @@ def create():
|
|||||||
peak_pos_textinput_lock = True
|
peak_pos_textinput_lock = True
|
||||||
|
|
||||||
y = scan["Counts"]
|
y = scan["Counts"]
|
||||||
x = scan["om"]
|
x = scan["omega"]
|
||||||
|
|
||||||
plot_scatter_source.data.update(x=x, y=y, y_upper=y + np.sqrt(y), y_lower=y - np.sqrt(y))
|
plot_scatter_source.data.update(x=x, y=y, y_upper=y + np.sqrt(y), y_lower=y - np.sqrt(y))
|
||||||
|
|
||||||
@ -180,11 +180,11 @@ def create():
|
|||||||
if num_of_peaks is not None and num_of_peaks > 0:
|
if num_of_peaks is not None and num_of_peaks > 0:
|
||||||
peak_indexes = scan["peak_indexes"]
|
peak_indexes = scan["peak_indexes"]
|
||||||
if len(peak_indexes) == 1:
|
if len(peak_indexes) == 1:
|
||||||
peak_pos_textinput.value = str(scan["om"][peak_indexes[0]])
|
peak_pos_textinput.value = str(scan["omega"][peak_indexes[0]])
|
||||||
else:
|
else:
|
||||||
peak_pos_textinput.value = str([scan["om"][ind] for ind in peak_indexes])
|
peak_pos_textinput.value = str([scan["omega"][ind] for ind in peak_indexes])
|
||||||
|
|
||||||
plot_peak_source.data.update(x=scan["om"][peak_indexes], y=scan["peak_heights"])
|
plot_peak_source.data.update(x=scan["omega"][peak_indexes], y=scan["peak_heights"])
|
||||||
plot_line_smooth_source.data.update(x=x, y=scan["smooth_peaks"])
|
plot_line_smooth_source.data.update(x=x, y=scan["smooth_peaks"])
|
||||||
else:
|
else:
|
||||||
peak_pos_textinput.value = None
|
peak_pos_textinput.value = None
|
||||||
@ -314,7 +314,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:
|
||||||
scan = _get_selected_scan()
|
scan = _get_selected_scan()
|
||||||
|
|
||||||
peak_ind = (np.abs(scan["om"] - float(new))).argmin()
|
peak_ind = (np.abs(scan["omega"] - float(new))).argmin()
|
||||||
scan["peak_indexes"] = np.array([peak_ind], dtype=np.int64)
|
scan["peak_indexes"] = np.array([peak_ind], dtype=np.int64)
|
||||||
scan["peak_heights"] = np.array([scan["smooth_peaks"][peak_ind]])
|
scan["peak_heights"] = np.array([scan["smooth_peaks"][peak_ind]])
|
||||||
_update_table()
|
_update_table()
|
||||||
|
@ -194,7 +194,7 @@ def create():
|
|||||||
peak_pos_textinput_lock = True
|
peak_pos_textinput_lock = True
|
||||||
|
|
||||||
y = scan["Counts"]
|
y = scan["Counts"]
|
||||||
x = scan["om"]
|
x = scan["omega"]
|
||||||
|
|
||||||
plot_scatter_source.data.update(x=x, y=y, y_upper=y + np.sqrt(y), y_lower=y - np.sqrt(y))
|
plot_scatter_source.data.update(x=x, y=y, y_upper=y + np.sqrt(y), y_lower=y - np.sqrt(y))
|
||||||
|
|
||||||
@ -267,10 +267,10 @@ def create():
|
|||||||
par = []
|
par = []
|
||||||
for s, p in enumerate(scan_table_source.data["param"]):
|
for s, p in enumerate(scan_table_source.data["param"]):
|
||||||
if p:
|
if p:
|
||||||
xs.append(np.array(det_data[s]["om"]))
|
xs.append(np.array(det_data[s]["omega"]))
|
||||||
x.extend(det_data[s]["om"])
|
x.extend(det_data[s]["omega"])
|
||||||
ys.append(np.array(det_data[s]["Counts"]))
|
ys.append(np.array(det_data[s]["Counts"]))
|
||||||
y.extend([float(p)] * len(det_data[s]["om"]))
|
y.extend([float(p)] * len(det_data[s]["omega"]))
|
||||||
param.append(float(p))
|
param.append(float(p))
|
||||||
par.extend(det_data[s]["Counts"])
|
par.extend(det_data[s]["Counts"])
|
||||||
|
|
||||||
@ -412,7 +412,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:
|
||||||
scan = _get_selected_scan()
|
scan = _get_selected_scan()
|
||||||
|
|
||||||
peak_ind = (np.abs(scan["om"] - float(new))).argmin()
|
peak_ind = (np.abs(scan["omega"] - float(new))).argmin()
|
||||||
scan["peak_indexes"] = np.array([peak_ind], dtype=np.int64)
|
scan["peak_indexes"] = np.array([peak_ind], dtype=np.int64)
|
||||||
scan["peak_heights"] = np.array([scan["smooth_peaks"][peak_ind]])
|
scan["peak_heights"] = np.array([scan["smooth_peaks"][peak_ind]])
|
||||||
_update_table()
|
_update_table()
|
||||||
|
@ -11,7 +11,7 @@ def ccl_findpeaks(
|
|||||||
smooth=False,
|
smooth=False,
|
||||||
window_size=7,
|
window_size=7,
|
||||||
poly_order=3,
|
poly_order=3,
|
||||||
variable="om",
|
variable="omega",
|
||||||
):
|
):
|
||||||
|
|
||||||
"""function iterates through the dictionary created by load_cclv2 and locates peaks for each scan
|
"""function iterates through the dictionary created by load_cclv2 and locates peaks for each scan
|
||||||
|
@ -144,11 +144,18 @@ def parse_1D(fileobj, data_type):
|
|||||||
for param, (param_name, param_type) in zip(next_line.split(), ccl_second_line):
|
for param, (param_name, param_type) in zip(next_line.split(), ccl_second_line):
|
||||||
s[param_name] = param_type(param)
|
s[param_name] = param_type(param)
|
||||||
|
|
||||||
s["om"] = np.linspace(
|
if s["variable_name"] != "om":
|
||||||
|
raise Exception("Unsupported variable name in ccl file.")
|
||||||
|
|
||||||
|
# "om" -> "omega"
|
||||||
|
s["variable_name"] = "omega"
|
||||||
|
s["variable"] = np.linspace(
|
||||||
s["omega"] - (s["n_points"] / 2) * s["angle_step"],
|
s["omega"] - (s["n_points"] / 2) * s["angle_step"],
|
||||||
s["omega"] + (s["n_points"] / 2) * s["angle_step"],
|
s["omega"] + (s["n_points"] / 2) * s["angle_step"],
|
||||||
s["n_points"],
|
s["n_points"],
|
||||||
)
|
)
|
||||||
|
# overwrite metadata, because it only refers to the scan center
|
||||||
|
s["omega"] = s["variable"]
|
||||||
|
|
||||||
# subsequent lines with counts
|
# subsequent lines with counts
|
||||||
counts = []
|
counts = []
|
||||||
@ -182,6 +189,15 @@ def parse_1D(fileobj, data_type):
|
|||||||
for name in col_names:
|
for name in col_names:
|
||||||
s[name] = np.array(s[name])
|
s[name] = np.array(s[name])
|
||||||
|
|
||||||
|
# "om" -> "omega"
|
||||||
|
if s["variable_name"] == "om":
|
||||||
|
s["variable_name"] = "omega"
|
||||||
|
s["variable"] = s["om"]
|
||||||
|
s["omega"] = s["om"]
|
||||||
|
del s["om"]
|
||||||
|
else:
|
||||||
|
s["variable"] = s[s["variable_name"]]
|
||||||
|
|
||||||
s["h"] = s["k"] = s["l"] = float("nan")
|
s["h"] = s["k"] = s["l"] = float("nan")
|
||||||
|
|
||||||
for param in ("mf", "temp"):
|
for param in ("mf", "temp"):
|
||||||
|
@ -9,7 +9,7 @@ PARAM_PRECISIONS = {
|
|||||||
"chi": 0.1,
|
"chi": 0.1,
|
||||||
"nu": 0.1,
|
"nu": 0.1,
|
||||||
"phi": 0.05,
|
"phi": 0.05,
|
||||||
"omega": 5,
|
"omega": 0.05,
|
||||||
"gamma": 0.05,
|
"gamma": 0.05,
|
||||||
"temp": 1,
|
"temp": 1,
|
||||||
"mf": 0.001,
|
"mf": 0.001,
|
||||||
@ -36,7 +36,14 @@ def _parameters_match(scan1, scan2):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
for param in ("ub", "temp", "mf", *(vars[0] for vars in CCL_ANGLES[zebra_mode])):
|
for param in ("ub", "temp", "mf", *(vars[0] for vars in CCL_ANGLES[zebra_mode])):
|
||||||
if np.max(np.abs(scan1[param] - scan2[param])) > PARAM_PRECISIONS[param]:
|
if param == scan1["variable_name"] == scan2["variable_name"]:
|
||||||
|
# check if ranges of variable parameter overlap
|
||||||
|
range1 = scan1["variable"]
|
||||||
|
range2 = scan2["variable"]
|
||||||
|
if range1[0] > range2[-1] or range2[0] > range1[-1]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
elif np.max(np.abs(scan1[param] - scan2[param])) > PARAM_PRECISIONS[param]:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@ -53,12 +60,12 @@ def merge_datasets(dataset1, dataset2):
|
|||||||
|
|
||||||
|
|
||||||
def _merge_scans(scan1, scan2):
|
def _merge_scans(scan1, scan2):
|
||||||
om = np.concatenate((scan1["om"], scan2["om"]))
|
omega = np.concatenate((scan1["omega"], scan2["omega"]))
|
||||||
counts = np.concatenate((scan1["Counts"], scan2["Counts"]))
|
counts = np.concatenate((scan1["Counts"], scan2["Counts"]))
|
||||||
|
|
||||||
index = np.argsort(om)
|
index = np.argsort(omega)
|
||||||
|
|
||||||
scan1["om"] = om[index]
|
scan1["omega"] = omega[index]
|
||||||
scan1["Counts"] = counts[index]
|
scan1["Counts"] = counts[index]
|
||||||
|
|
||||||
print(f'Scan {scan2["idx"]} merged into {scan1["idx"]}')
|
print(f'Scan {scan2["idx"]} merged into {scan1["idx"]}')
|
||||||
|
@ -67,7 +67,7 @@ def fitccl(
|
|||||||
return
|
return
|
||||||
|
|
||||||
if binning is None or binning == 0 or binning == 1:
|
if binning is None or binning == 0 or binning == 1:
|
||||||
x = list(scan["om"])
|
x = list(scan["omega"])
|
||||||
y = list(scan["Counts"])
|
y = list(scan["Counts"])
|
||||||
y_err = list(np.sqrt(y)) if scan.get("sigma", None) is None else list(scan["sigma"])
|
y_err = list(np.sqrt(y)) if scan.get("sigma", None) is None else list(scan["sigma"])
|
||||||
if not scan["peak_indexes"]:
|
if not scan["peak_indexes"]:
|
||||||
@ -75,7 +75,7 @@ def fitccl(
|
|||||||
else:
|
else:
|
||||||
centre = x[int(scan["peak_indexes"])]
|
centre = x[int(scan["peak_indexes"])]
|
||||||
else:
|
else:
|
||||||
x = list(scan["om"])
|
x = list(scan["omega"])
|
||||||
if not scan["peak_indexes"]:
|
if not scan["peak_indexes"]:
|
||||||
centre = np.mean(x)
|
centre = np.mean(x)
|
||||||
else:
|
else:
|
||||||
|
@ -39,13 +39,13 @@ def find_nearest(array, value):
|
|||||||
# peaks = [6.2, 8.1, 9.9, 11.5]
|
# peaks = [6.2, 8.1, 9.9, 11.5]
|
||||||
peaks = [23.5, 24.5]
|
peaks = [23.5, 24.5]
|
||||||
# peaks = [24]
|
# peaks = [24]
|
||||||
def fitccl(scan, variable="om", peak_type="gauss", binning=None):
|
def fitccl(scan, variable="omega", peak_type="gauss", binning=None):
|
||||||
|
|
||||||
x = list(scan[variable])
|
x = list(scan[variable])
|
||||||
y = list(scan["Counts"])
|
y = list(scan["Counts"])
|
||||||
peak_centre = np.mean(x)
|
peak_centre = np.mean(x)
|
||||||
if binning is None or binning == 0 or binning == 1:
|
if binning is None or binning == 0 or binning == 1:
|
||||||
x = list(scan["om"])
|
x = list(scan[variable])
|
||||||
y = list(scan["Counts"])
|
y = list(scan["Counts"])
|
||||||
y_err = list(np.sqrt(y)) if scan.get("sigma", None) is None else list(scan["sigma"])
|
y_err = list(np.sqrt(y)) if scan.get("sigma", None) is None else list(scan["sigma"])
|
||||||
print(scan["peak_indexes"])
|
print(scan["peak_indexes"])
|
||||||
@ -54,7 +54,7 @@ def fitccl(scan, variable="om", peak_type="gauss", binning=None):
|
|||||||
else:
|
else:
|
||||||
centre = x[int(scan["peak_indexes"])]
|
centre = x[int(scan["peak_indexes"])]
|
||||||
else:
|
else:
|
||||||
x = list(scan["om"])
|
x = list(scan[variable])
|
||||||
if not scan["peak_indexes"]:
|
if not scan["peak_indexes"]:
|
||||||
peak_centre = np.mean(x)
|
peak_centre = np.mean(x)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user