Utility cleanup

This commit is contained in:
usov_i 2021-09-08 16:07:04 +02:00
parent 4b9f0a8c36
commit a73c34b06f
5 changed files with 23 additions and 35 deletions

View File

@ -38,7 +38,6 @@ from bokeh.models import (
Spinner, Spinner,
TableColumn, TableColumn,
TextAreaInput, TextAreaInput,
TextInput,
WheelZoomTool, WheelZoomTool,
Whisker, Whisker,
) )
@ -202,7 +201,7 @@ def create():
def monitor_spinner_callback(_attr, old, new): def monitor_spinner_callback(_attr, old, new):
if det_data: if det_data:
pyzebra.normalize_dataset(det_data, new) pyzebra.normalize_dataset(det_data, new)
_update_plot(_get_selected_scan()) _update_plot()
monitor_spinner = Spinner(title="Monitor:", mode="int", value=100_000, low=1, width=145) monitor_spinner = Spinner(title="Monitor:", mode="int", value=100_000, low=1, width=145)
monitor_spinner.on_change("value", monitor_spinner_callback) monitor_spinner.on_change("value", monitor_spinner_callback)
@ -212,7 +211,8 @@ def create():
export = [scan.get("active", True) for scan in det_data] export = [scan.get("active", True) for scan in det_data]
scan_table_source.data.update(fit=fit_ok, export=export) scan_table_source.data.update(fit=fit_ok, export=export)
def _update_plot(scan): def _update_plot():
scan = _get_selected_scan()
scan_motor = scan["scan_motor"] scan_motor = scan["scan_motor"]
y = scan["counts"] y = scan["counts"]
@ -322,13 +322,14 @@ def create():
# skip unnecessary update caused by selection drop # skip unnecessary update caused by selection drop
return return
_update_plot(det_data[new[0]]) _update_plot()
def scan_table_source_callback(_attr, _old, _new): def scan_table_source_callback(_attr, _old, _new):
_update_preview() _update_preview()
scan_table_source = ColumnDataSource(dict(scan=[], hkl=[], fit=[], export=[])) scan_table_source = ColumnDataSource(dict(scan=[], hkl=[], fit=[], export=[]))
scan_table_source.on_change("data", scan_table_source_callback) scan_table_source.on_change("data", scan_table_source_callback)
scan_table_source.selected.on_change("indices", scan_table_select_callback)
scan_table = DataTable( scan_table = DataTable(
source=scan_table_source, source=scan_table_source,
@ -344,8 +345,6 @@ def create():
editable=True, editable=True,
) )
scan_table_source.selected.on_change("indices", scan_table_select_callback)
def _get_selected_scan(): def _get_selected_scan():
return det_data[scan_table_source.selected.indices[0]] return det_data[scan_table_source.selected.indices[0]]
@ -361,7 +360,7 @@ def create():
pyzebra.merge_scans(scan_into, scan_from) pyzebra.merge_scans(scan_into, scan_from)
_update_datatable() _update_datatable()
_update_plot(_get_selected_scan()) _update_plot()
merge_button = Button(label="Merge into current", width=145) merge_button = Button(label="Merge into current", width=145)
merge_button.on_click(merge_button_callback) merge_button.on_click(merge_button_callback)
@ -369,7 +368,7 @@ def create():
def restore_button_callback(): def restore_button_callback():
pyzebra.restore_scan(_get_selected_scan()) pyzebra.restore_scan(_get_selected_scan())
_update_datatable() _update_datatable()
_update_plot(_get_selected_scan()) _update_plot()
restore_button = Button(label="Restore scan", width=145) restore_button = Button(label="Restore scan", width=145)
restore_button.on_click(restore_button_callback) restore_button.on_click(restore_button_callback)
@ -505,7 +504,7 @@ def create():
lorentz=lorentz_checkbox.active, lorentz=lorentz_checkbox.active,
) )
_update_plot(_get_selected_scan()) _update_plot()
_update_datatable() _update_datatable()
proc_all_button = Button(label="Process All", button_type="primary", width=145) proc_all_button = Button(label="Process All", button_type="primary", width=145)
@ -522,7 +521,7 @@ def create():
lorentz=lorentz_checkbox.active, lorentz=lorentz_checkbox.active,
) )
_update_plot(scan) _update_plot()
_update_datatable() _update_datatable()
proc_button = Button(label="Process Current", width=145) proc_button = Button(label="Process Current", width=145)

View File

@ -33,7 +33,6 @@ from bokeh.models import (
Spinner, Spinner,
TableColumn, TableColumn,
Tabs, Tabs,
TextInput,
Title, Title,
WheelZoomTool, WheelZoomTool,
) )
@ -198,7 +197,16 @@ def create():
else: # zebra_mode == "bi" else: # zebra_mode == "bi"
metadata_table_source.data.update(geom=["bisecting"]) metadata_table_source.data.update(geom=["bisecting"])
update_image(0) if "mf" in det_data:
metadata_table_source.data.update(mf=[det_data["mf"][0]])
else:
metadata_table_source.data.update(mf=[None])
if "temp" in det_data:
metadata_table_source.data.update(temp=[det_data["temp"][0]])
else:
metadata_table_source.data.update(temp=[None])
update_overview_plot() update_overview_plot()
def scan_table_source_callback(_attr, _old, _new): def scan_table_source_callback(_attr, _old, _new):
@ -247,17 +255,6 @@ def create():
) )
param_select.on_change("value", param_select_callback) param_select.on_change("value", param_select_callback)
def update_image(index=None):
if "mf" in det_data:
metadata_table_source.data.update(mf=[det_data["mf"][index]])
else:
metadata_table_source.data.update(mf=[None])
if "temp" in det_data:
metadata_table_source.data.update(temp=[det_data["temp"][index]])
else:
metadata_table_source.data.update(temp=[None])
def update_overview_plot(): def update_overview_plot():
h5_data = det_data["data"] h5_data = det_data["data"]
n_im, n_y, n_x = h5_data.shape n_im, n_y, n_x = h5_data.shape

View File

@ -37,7 +37,6 @@ from bokeh.models import (
Spacer, Spacer,
Spinner, Spinner,
TableColumn, TableColumn,
TextInput,
Title, Title,
WheelZoomTool, WheelZoomTool,
) )

View File

@ -42,7 +42,6 @@ from bokeh.models import (
TableColumn, TableColumn,
Tabs, Tabs,
TextAreaInput, TextAreaInput,
TextInput,
WheelZoomTool, WheelZoomTool,
Whisker, Whisker,
) )
@ -237,10 +236,11 @@ def create():
scan_table_source.data.update(fit=fit_ok) scan_table_source.data.update(fit=fit_ok)
def _update_plot(): def _update_plot():
_update_single_scan_plot(_get_selected_scan()) _update_single_scan_plot()
_update_overview() _update_overview()
def _update_single_scan_plot(scan): def _update_single_scan_plot():
scan = _get_selected_scan()
scan_motor = scan["scan_motor"] scan_motor = scan["scan_motor"]
y = scan["counts"] y = scan["counts"]
@ -488,6 +488,7 @@ def create():
scan_table_source = ColumnDataSource(dict(file=[], scan=[], param=[], fit=[], export=[])) scan_table_source = ColumnDataSource(dict(file=[], scan=[], param=[], fit=[], export=[]))
scan_table_source.on_change("data", scan_table_source_callback) scan_table_source.on_change("data", scan_table_source_callback)
scan_table_source.selected.on_change("indices", scan_table_select_callback)
scan_table = DataTable( scan_table = DataTable(
source=scan_table_source, source=scan_table_source,
@ -503,13 +504,6 @@ def create():
autosize_mode="none", autosize_mode="none",
) )
def scan_table_source_callback(_attr, _old, _new):
if scan_table_source.selected.indices:
_update_plot()
scan_table_source.selected.on_change("indices", scan_table_select_callback)
scan_table_source.on_change("data", scan_table_source_callback)
def _get_selected_scan(): def _get_selected_scan():
return det_data[scan_table_source.selected.indices[0]] return det_data[scan_table_source.selected.indices[0]]

View File

@ -1,4 +1,3 @@
import itertools
import os import os
import numpy as np import numpy as np