diff --git a/pyzebra/app/panel_ccl_integrate.py b/pyzebra/app/panel_ccl_integrate.py index e5b9b47..34bb672 100644 --- a/pyzebra/app/panel_ccl_integrate.py +++ b/pyzebra/app/panel_ccl_integrate.py @@ -172,7 +172,7 @@ def create(): peak_pos_textinput_lock = True 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)) @@ -180,11 +180,11 @@ def create(): if num_of_peaks is not None and num_of_peaks > 0: peak_indexes = scan["peak_indexes"] 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: - 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"]) else: peak_pos_textinput.value = None @@ -314,7 +314,7 @@ def create(): if new is not None and not peak_pos_textinput_lock: 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_heights"] = np.array([scan["smooth_peaks"][peak_ind]]) _update_table() diff --git a/pyzebra/app/panel_param_study.py b/pyzebra/app/panel_param_study.py index 9cf643b..bdab893 100644 --- a/pyzebra/app/panel_param_study.py +++ b/pyzebra/app/panel_param_study.py @@ -194,7 +194,7 @@ def create(): peak_pos_textinput_lock = True 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)) @@ -267,10 +267,10 @@ def create(): par = [] for s, p in enumerate(scan_table_source.data["param"]): if p: - xs.append(np.array(det_data[s]["om"])) - x.extend(det_data[s]["om"]) + xs.append(np.array(det_data[s]["omega"])) + x.extend(det_data[s]["omega"]) 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)) par.extend(det_data[s]["Counts"]) @@ -412,7 +412,7 @@ def create(): if new is not None and not peak_pos_textinput_lock: 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_heights"] = np.array([scan["smooth_peaks"][peak_ind]]) _update_table() diff --git a/pyzebra/ccl_findpeaks.py b/pyzebra/ccl_findpeaks.py index 43054ee..bbf9069 100644 --- a/pyzebra/ccl_findpeaks.py +++ b/pyzebra/ccl_findpeaks.py @@ -11,7 +11,7 @@ def ccl_findpeaks( smooth=False, window_size=7, poly_order=3, - variable="om", + variable="omega", ): """function iterates through the dictionary created by load_cclv2 and locates peaks for each scan diff --git a/pyzebra/ccl_io.py b/pyzebra/ccl_io.py index 297f8db..34a4446 100644 --- a/pyzebra/ccl_io.py +++ b/pyzebra/ccl_io.py @@ -144,11 +144,18 @@ def parse_1D(fileobj, data_type): for param, (param_name, param_type) in zip(next_line.split(), ccl_second_line): 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["n_points"], ) + # overwrite metadata, because it only refers to the scan center + s["omega"] = s["variable"] # subsequent lines with counts counts = [] @@ -182,6 +189,15 @@ def parse_1D(fileobj, data_type): for name in col_names: 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") for param in ("mf", "temp"): diff --git a/pyzebra/ccl_process.py b/pyzebra/ccl_process.py index 555f210..68689af 100644 --- a/pyzebra/ccl_process.py +++ b/pyzebra/ccl_process.py @@ -9,7 +9,7 @@ PARAM_PRECISIONS = { "chi": 0.1, "nu": 0.1, "phi": 0.05, - "omega": 5, + "omega": 0.05, "gamma": 0.05, "temp": 1, "mf": 0.001, @@ -36,7 +36,14 @@ def _parameters_match(scan1, scan2): return False 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 True @@ -53,12 +60,12 @@ def merge_datasets(dataset1, dataset2): 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"])) - index = np.argsort(om) + index = np.argsort(omega) - scan1["om"] = om[index] + scan1["omega"] = omega[index] scan1["Counts"] = counts[index] print(f'Scan {scan2["idx"]} merged into {scan1["idx"]}') diff --git a/pyzebra/fit2.py b/pyzebra/fit2.py index 5bfb0ad..7bdfe71 100644 --- a/pyzebra/fit2.py +++ b/pyzebra/fit2.py @@ -67,7 +67,7 @@ def fitccl( return if binning is None or binning == 0 or binning == 1: - x = list(scan["om"]) + x = list(scan["omega"]) y = list(scan["Counts"]) y_err = list(np.sqrt(y)) if scan.get("sigma", None) is None else list(scan["sigma"]) if not scan["peak_indexes"]: @@ -75,7 +75,7 @@ def fitccl( else: centre = x[int(scan["peak_indexes"])] else: - x = list(scan["om"]) + x = list(scan["omega"]) if not scan["peak_indexes"]: centre = np.mean(x) else: diff --git a/pyzebra/fitvol3.py b/pyzebra/fitvol3.py index e3cf6e4..e171e72 100644 --- a/pyzebra/fitvol3.py +++ b/pyzebra/fitvol3.py @@ -39,13 +39,13 @@ def find_nearest(array, value): # peaks = [6.2, 8.1, 9.9, 11.5] peaks = [23.5, 24.5] # 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]) y = list(scan["Counts"]) peak_centre = np.mean(x) if binning is None or binning == 0 or binning == 1: - x = list(scan["om"]) + x = list(scan[variable]) y = list(scan["Counts"]) y_err = list(np.sqrt(y)) if scan.get("sigma", None) is None else list(scan["sigma"]) print(scan["peak_indexes"]) @@ -54,7 +54,7 @@ def fitccl(scan, variable="om", peak_type="gauss", binning=None): else: centre = x[int(scan["peak_indexes"])] else: - x = list(scan["om"]) + x = list(scan[variable]) if not scan["peak_indexes"]: peak_centre = np.mean(x) else: