Add smooth option as an example

This commit is contained in:
usov_i 2020-09-24 15:35:53 +02:00
parent c977d3c58e
commit 8bcbba5e31

View File

@ -18,6 +18,7 @@ from bokeh.models import (
Plot, Plot,
Select, Select,
Spacer, Spacer,
Toggle,
) )
import pyzebra import pyzebra
@ -49,8 +50,10 @@ def create():
num_of_peaks = meas.get("num_of_peaks") num_of_peaks = meas.get("num_of_peaks")
if num_of_peaks is not None and num_of_peaks > 0: if num_of_peaks is not None and num_of_peaks > 0:
plot_circle_source.data.update(x=meas["peak_indexes"], y=meas["peak_heights"]) plot_circle_source.data.update(x=meas["peak_indexes"], y=meas["peak_heights"])
plot_smooth_source.data.update(x=x, y=meas["smooth_peaks"])
else: else:
plot_circle_source.data.update(x=[], y=[]) plot_circle_source.data.update(x=[], y=[])
plot_smooth_source.data.update(x=[], y=[])
# Main plot # Main plot
plot = Plot( plot = Plot(
@ -70,6 +73,9 @@ 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"))
plot_smooth_source = ColumnDataSource(dict(x=[0], y=[0]))
plot.add_glyph(plot_smooth_source, Line(x="x", y="y", line_color="red"))
plot_circle_source = ColumnDataSource(dict(x=[], y=[])) plot_circle_source = ColumnDataSource(dict(x=[], y=[]))
plot.add_glyph(plot_circle_source, Circle(x="x", y="y")) plot.add_glyph(plot_circle_source, Circle(x="x", y="y"))
@ -80,10 +86,12 @@ def create():
meas_select = Select() meas_select = Select()
meas_select.on_change("value", meas_select_callback) meas_select.on_change("value", meas_select_callback)
smooth_toggle = Toggle(label="Smooth curve")
def process_button_callback(): def process_button_callback():
nonlocal det_data nonlocal det_data
for meas in det_data["Measurements"]: for meas in det_data["Measurements"]:
det_data = pyzebra.ccl_findpeaks(det_data, meas) det_data = pyzebra.ccl_findpeaks(det_data, meas, smooth=smooth_toggle.active)
_update_plot(meas_select.value) _update_plot(meas_select.value)
@ -94,6 +102,7 @@ def create():
tab_layout = column( tab_layout = column(
row(column(Spacer(height=5), upload_div), upload_button, meas_select), row(column(Spacer(height=5), upload_div), upload_button, meas_select),
plot, plot,
row(smooth_toggle),
row(process_button), row(process_button),
) )