From 6c2e221595c179de4674f43c86320f0f41dd4b05 Mon Sep 17 00:00:00 2001 From: Ivan Usov Date: Thu, 27 May 2021 15:40:59 +0200 Subject: [PATCH] Add option to restore original scan after merging --- pyzebra/app/panel_ccl_integrate.py | 9 ++++++++- pyzebra/ccl_process.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pyzebra/app/panel_ccl_integrate.py b/pyzebra/app/panel_ccl_integrate.py index 12b8727..60aec47 100644 --- a/pyzebra/app/panel_ccl_integrate.py +++ b/pyzebra/app/panel_ccl_integrate.py @@ -343,6 +343,13 @@ def create(): merge_button = Button(label="Merge scans", width=145) merge_button.on_click(merge_button_callback) + def restore_button_callback(): + pyzebra.restore_scan(_get_selected_scan()) + _update_plot(_get_selected_scan()) + + restore_button = Button(label="Restore scan", width=145) + restore_button.on_click(restore_button_callback) + def fit_from_spinner_callback(_attr, _old, new): fit_from_span.location = new @@ -567,7 +574,7 @@ def create(): scan_layout = column( scan_table, - monitor_spinner, + row(monitor_spinner, column(Spacer(height=19), restore_button)), row(column(Spacer(height=19), merge_button), merge_into_select, merge_from_select), ) diff --git a/pyzebra/ccl_process.py b/pyzebra/ccl_process.py index 07ded47..b428157 100644 --- a/pyzebra/ccl_process.py +++ b/pyzebra/ccl_process.py @@ -76,6 +76,10 @@ def merge_datasets(dataset_into, dataset_from): def merge_scans(scan_into, scan_from): # TODO: does it need to be "scan_motor" instead of omega for a generalized solution? + if "init_omega" not in scan_into: + scan_into["init_omega"] = scan_into["omega"] + scan_into["init_counts"] = scan_into["counts"] + omega = np.concatenate((scan_into["omega"], scan_from["omega"])) counts = np.concatenate((scan_into["counts"], scan_from["counts"])) @@ -91,6 +95,14 @@ def merge_scans(scan_into, scan_from): print(f'Merging scans: {scan_into["idx"]} ({fname1}) <-- {scan_from["idx"]} ({fname2})') +def restore_scan(scan): + if "init_omega" in scan: + scan["omega"] = scan["init_omega"] + scan["counts"] = scan["init_counts"] + del scan["init_omega"] + del scan["init_counts"] + + def fit_scan(scan, model_dict, fit_from=None, fit_to=None): if fit_from is None: fit_from = -np.inf