Add manual scan merging

This commit is contained in:
usov_i 2021-02-11 14:47:37 +01:00
parent b418fb8300
commit 96eaa27e55
3 changed files with 33 additions and 5 deletions

View File

@ -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"

View File

@ -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),
)

View File

@ -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"]))