Add a possiblity to select a measurement
This commit is contained in:
parent
8d397a819b
commit
fd769106b7
@ -14,6 +14,7 @@ from bokeh.models import (
|
|||||||
LinearAxis,
|
LinearAxis,
|
||||||
Panel,
|
Panel,
|
||||||
Plot,
|
Plot,
|
||||||
|
Select,
|
||||||
Spacer,
|
Spacer,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,20 +22,22 @@ import pyzebra
|
|||||||
|
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
|
det_data = {}
|
||||||
|
|
||||||
def upload_button_callback(_attr, _old, new):
|
def upload_button_callback(_attr, _old, new):
|
||||||
|
nonlocal det_data
|
||||||
with io.StringIO(base64.b64decode(new).decode()) as file:
|
with io.StringIO(base64.b64decode(new).decode()) as file:
|
||||||
_, ext = os.path.splitext(upload_button.filename)
|
_, ext = os.path.splitext(upload_button.filename)
|
||||||
res = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
for _, meas in res["Measurements"].items():
|
|
||||||
y = meas["Counts"]
|
|
||||||
x = list(range(len(y)))
|
|
||||||
break
|
|
||||||
|
|
||||||
plot_line_source.data.update(x=x, y=y)
|
meas_list = list(det_data["Measurements"].keys())
|
||||||
|
meas_select.options = meas_list
|
||||||
|
meas_select.value = meas_list[0]
|
||||||
|
|
||||||
upload_button = FileInput(accept=".ccl")
|
upload_button = FileInput(accept=".ccl")
|
||||||
upload_button.on_change("value", upload_button_callback)
|
upload_button.on_change("value", upload_button_callback)
|
||||||
|
|
||||||
|
# Main plot
|
||||||
plot = Plot(
|
plot = Plot(
|
||||||
x_range=DataRange1d(),
|
x_range=DataRange1d(),
|
||||||
y_range=DataRange1d(),
|
y_range=DataRange1d(),
|
||||||
@ -52,7 +55,17 @@ def create():
|
|||||||
plot_line_source = ColumnDataSource(dict(x=[0], y=[0]))
|
plot_line_source = ColumnDataSource(dict(x=[0], y=[0]))
|
||||||
plot.add_glyph(plot_line_source, Line(x="x", y="y", line_color="steelblue"))
|
plot.add_glyph(plot_line_source, Line(x="x", y="y", line_color="steelblue"))
|
||||||
|
|
||||||
|
# Measurement select
|
||||||
|
def meas_select_callback(_attr, _old, new):
|
||||||
|
y = det_data["Measurements"][new]["Counts"]
|
||||||
|
x = list(range(len(y)))
|
||||||
|
|
||||||
|
plot_line_source.data.update(x=x, y=y)
|
||||||
|
|
||||||
|
meas_select = Select()
|
||||||
|
meas_select.on_change("value", meas_select_callback)
|
||||||
|
|
||||||
upload_div = Div(text="Upload .ccl file:")
|
upload_div = Div(text="Upload .ccl file:")
|
||||||
tab_layout = column(row(column(Spacer(height=5), upload_div), upload_button), plot)
|
tab_layout = column(row(column(Spacer(height=5), upload_div), upload_button, meas_select), plot)
|
||||||
|
|
||||||
return Panel(child=tab_layout, title="1D Detector")
|
return Panel(child=tab_layout, title="1D Detector")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user