From 96eaa27e557cd27bf1adc80551e8d58e681ace2b Mon Sep 17 00:00:00 2001 From: Ivan Usov Date: Thu, 11 Feb 2021 14:47:37 +0100 Subject: [PATCH] Add manual scan merging --- pyzebra/__init__.py | 2 +- pyzebra/app/panel_ccl_integrate.py | 30 +++++++++++++++++++++++++++++- pyzebra/ccl_process.py | 6 +++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/pyzebra/__init__.py b/pyzebra/__init__.py index 06a3edb..6954149 100644 --- a/pyzebra/__init__.py +++ b/pyzebra/__init__.py @@ -4,6 +4,6 @@ from pyzebra.ccl_io import export_1D, load_1D, parse_1D from pyzebra.fit2 import fitccl from pyzebra.h5 import * from pyzebra.xtal import * -from pyzebra.ccl_process import normalize_dataset, merge_duplicates, merge_datasets +from pyzebra.ccl_process import normalize_dataset, merge_duplicates, merge_datasets, merge_scans __version__ = "0.2.2" diff --git a/pyzebra/app/panel_ccl_integrate.py b/pyzebra/app/panel_ccl_integrate.py index 34bb672..77b81cc 100644 --- a/pyzebra/app/panel_ccl_integrate.py +++ b/pyzebra/app/panel_ccl_integrate.py @@ -99,6 +99,12 @@ def create(): scan_table_source.selected.indices = [] scan_table_source.selected.indices = [0] + merge_options = [(str(i), f"{i} ({idx})") for i, idx in enumerate(scan_list)] + merge_source_select.options = merge_options + merge_source_select.value = merge_options[0][0] + merge_dest_select.options = merge_options + merge_dest_select.value = merge_options[0][0] + def ccl_file_select_callback(_attr, _old, _new): pass @@ -310,6 +316,23 @@ def create(): def _get_selected_scan(): return det_data[scan_table_source.selected.indices[0]] + merge_dest_select = Select(title="destination:", width=100) + merge_source_select = Select(title="source:", width=100) + + def merge_button_callback(): + scan_dest_ind = int(merge_dest_select.value) + scan_source_ind = int(merge_source_select.value) + + if scan_dest_ind == scan_source_ind: + print("WARNING: Selected scans for merging are identical") + return + + pyzebra.merge_scans(det_data[scan_dest_ind], det_data[scan_source_ind]) + _update_plot(_get_selected_scan()) + + merge_button = Button(label="Merge scans", width=145) + merge_button.on_click(merge_button_callback) + def peak_pos_textinput_callback(_attr, _old, new): if new is not None and not peak_pos_textinput_lock: scan = _get_selected_scan() @@ -593,6 +616,11 @@ def create(): ), ) + scan_layout = column( + scan_table, + row(column(Spacer(height=19), merge_button), merge_dest_select, merge_source_select), + ) + export_layout = column( preview_output_textinput, row( @@ -609,7 +637,7 @@ def create(): column(upload_div, upload_button), column(append_upload_div, append_upload_button), ), - row(scan_table, plot, Spacer(width=30), fit_output_textinput, export_layout), + row(scan_layout, plot, Spacer(width=30), fit_output_textinput, export_layout), row(findpeak_controls, Spacer(width=30), fitpeak_controls), ) diff --git a/pyzebra/ccl_process.py b/pyzebra/ccl_process.py index 47d84b0..e54b68b 100644 --- a/pyzebra/ccl_process.py +++ b/pyzebra/ccl_process.py @@ -31,7 +31,7 @@ def normalize_dataset(dataset, monitor=100_000): def merge_duplicates(dataset): for scan_i, scan_j in itertools.combinations(dataset, 2): if _parameters_match(scan_i, scan_j): - _merge_scans(scan_i, scan_j) + merge_scans(scan_i, scan_j) def _parameters_match(scan1, scan2): @@ -59,13 +59,13 @@ def merge_datasets(dataset1, dataset2): for scan_j in dataset2: for scan_i in dataset1: if _parameters_match(scan_i, scan_j): - _merge_scans(scan_i, scan_j) + merge_scans(scan_i, scan_j) break else: dataset1.append(scan_j) -def _merge_scans(scan1, scan2): +def merge_scans(scan1, scan2): omega = np.concatenate((scan1["omega"], scan2["omega"])) counts = np.concatenate((scan1["Counts"], scan2["Counts"]))