def create(self): self.sources['table'] = ColumnDataSource( dict(xStart=[], xStop=[], top=[], bottom=[], integral=[])) columns = [ TableColumn(field="xStart", title="start", editor=NumberEditor(step=0.01), formatter=NumberFormatter(format="0.00")), TableColumn(field="xStop", title="stop", editor=NumberEditor(step=0.01), formatter=NumberFormatter(format="0.00")), TableColumn(field="integral", title="integral", editor=NumberEditor(step=0.01), formatter=NumberFormatter(format="0.00")) ] self.dataTable = DataTable(source=self.sources['table'], columns=columns, reorderable=False, width=500, editable=True) self.sources['table'].on_change( 'selected', lambda attr, old, new: self.rowSelect(new['1d']['indices'])) self.sources['table'].on_change( 'data', lambda attr, old, new: self.changeData(old, new)) self.manual = CustomButton( label="Manual Integration", button_type="primary", width=250, error="Please select area using the integration tool.") self.manual.on_click(self.manualIntegration) self.createDeselectButton() self.createDeleteButton() callback = CustomJS(args=dict(button=self.manual), code=""" /// get BoxSelectTool dimensions from cb_data parameter of Callback var geometry = cb_data['geometry']; button.data = { x0: geometry['x0'], x1: geometry['x1'], y0: geometry['y0'], y1: geometry['y1'] }; // Callback to the backend button.clicks++; """) self.tool = CustomBoxSelectTool(tool_name="Integration", icon="my_icon_integration", dimensions="width", callback=callback, id="integrationTool")
def _get_columns(self, element, data): columns = [] for d in element.dimensions(): col = dimension_sanitizer(d.name) kind = data[col].dtype.kind if kind == 'i': formatter = NumberFormatter() editor = IntEditor() elif kind == 'f': formatter = NumberFormatter(format='0,0.0[00000]') editor = NumberEditor() elif kind == 'M' or (kind == 'O' and len(data[col]) and type(data[col][0]) in datetime_types): dimtype = element.get_dimension_type(0) dformat = Dimension.type_formatters.get( dimtype, '%Y-%m-%d %H:%M:%S') formatter = DateFormatter(format=dformat) editor = DateEditor() else: formatter = StringFormatter() editor = StringEditor() column = TableColumn(field=dimension_sanitizer(d.name), title=d.pprint_label, editor=editor, formatter=formatter) columns.append(column) return columns
def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): """ Initializes a new plot object with the last available frame. """ # Get element key and ranges for frame element = self.hmap.last key = self.keys[-1] self.current_frame = element self.current_key = key style = self.lookup_options(element, 'style')[self.cyclic_index] data, _, style = self.get_data(element, ranges, style) if source is None: source = self._init_datasource(data) self.handles['source'] = source columns = [] dims = element.dimensions() for d in dims: col = dimension_sanitizer(d.name) kind = data[col].dtype.kind if kind == 'i': formatter = NumberFormatter() editor = IntEditor() elif kind == 'f': formatter = NumberFormatter(format='0,0.0[00000]') editor = NumberEditor() elif kind == 'M' or (kind == 'O' and len(data[col]) and type(data[col][0]) in datetime_types): dimtype = element.get_dimension_type(0) dformat = Dimension.type_formatters.get( dimtype, '%Y-%m-%d %H:%M:%S') formatter = DateFormatter(format=dformat) editor = DateEditor() else: formatter = StringFormatter() editor = StringEditor() column = TableColumn(field=d.name, title=d.pprint_label, editor=editor, formatter=formatter) columns.append(column) style['reorderable'] = False table = DataTable(source=source, columns=columns, height=self.height, width=self.width, **style) self.handles['plot'] = table self.handles['glyph_renderer'] = table self._execute_hooks(element) self.drawn = True for cb in self.callbacks: cb.initialize() return table
def _get_columns(self): if self.value is None: return [] index = [self.value.index.name or 'index'] col_names = index + list(self.value.columns) columns = [] for col in col_names: if col in self.value.columns: data = self.value[col] else: data = self.value.index kind = data.dtype.kind if kind == 'i': formatter = NumberFormatter() editor = IntEditor() elif kind == 'f': formatter = NumberFormatter(format='0,0.0[00000]') editor = NumberEditor() elif isdatetime(data) or kind == 'M': formatter = DateFormatter(format='%Y-%m-%d %H:%M:%S') editor = DateEditor() else: formatter = StringFormatter() editor = StringEditor() if col in self.editors: editor = self.editors[col] if col in self.formatters: formatter = self.formatters[col] if str(col) != col: self._renamed_cols[str(col)] = col width = self.widths.get(str(col)) column = TableColumn(field=str(col), title=str(col), editor=editor, formatter=formatter, width=width) columns.append(column) return columns
from bokeh.resources import INLINE from bokeh.util.browser import view from bokeh.sampledata.autompg2 import autompg2 as mpg source = ColumnDataSource(mpg) manufacturers = sorted(mpg["manufacturer"].unique()) models = sorted(mpg["model"].unique()) transmissions = sorted(mpg["trans"].unique()) drives = sorted(mpg["drv"].unique()) classes = sorted(mpg["class"].unique()) columns = [ TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")), TableColumn(field="model", title="Model", editor=StringEditor(completions=models)), TableColumn(field="displ", title="Displacement", editor=NumberEditor(step=0.1), formatter=NumberFormatter(format="0.0")), TableColumn(field="year", title="Year", editor=IntEditor()), TableColumn(field="cyl", title="Cylinders", editor=IntEditor()), TableColumn(field="trans", title="Transmission", editor=SelectEditor(options=transmissions)), TableColumn(field="drv", title="Drive", editor=SelectEditor(options=drives)), TableColumn(field="class", title="Class", editor=SelectEditor(options=classes)), TableColumn(field="cty", title="City MPG", editor=IntEditor()), TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()), ] data_table = DataTable(source=source, columns=columns, editable=True, width=1000, index_position=-1, index_header="row index", index_width=60) plot = Plot(title=None, plot_width=1000, plot_height=300) # Set up x & y axis plot.add_layout(LinearAxis(), 'below')
], mode='vline', line_policy="interp", renderers=[line_regr], ) plot.add_tools(hover) data_table = DataTable(source=source, width=400, height=327, editable=True, columns=[ TableColumn( field="f", title="force (N)", editor=NumberEditor(step=0.001), formatter=NumberFormatter(format="0.000")), TableColumn(field="v", title="voltage (V/1023)", editor=IntEditor(step=1)), ]) ############################################################################## # Widgets _div = Div(text=""" """, height=4) checkbox = CheckboxGroup(labels=['', '', ''], active=[0]) device_slc = Select(title="Device ID:", value=g.device_id, options=DEVICES['code']) device_conn_btn = Toggle(label="Connect to device",
def create(self): print("running create...") manufacturers = sorted(mpg["manufacturer"].unique()) models = sorted(mpg["model"].unique()) transmissions = sorted(mpg["trans"].unique()) drives = sorted(mpg["drv"].unique()) classes = sorted(mpg["class"].unique()) manufacturer_select = Select(title="Manufacturer:", value="All", options=["All"] + manufacturers) manufacturer_select.on_change('value', self.on_manufacturer_change) model_select = Select(title="Model:", value="All", options=["All"] + models) model_select.on_change('value', self.on_model_change) transmission_select = Select(title="Transmission:", value="All", options=["All"] + transmissions) transmission_select.on_change('value', self.on_transmission_change) drive_select = Select(title="Drive:", value="All", options=["All"] + drives) drive_select.on_change('value', self.on_drive_change) class_select = Select(title="Class:", value="All", options=["All"] + classes) class_select.on_change('value', self.on_class_change) columns = [ TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")), TableColumn(field="model", title="Model", editor=StringEditor(completions=models)), TableColumn(field="displ", title="Displacement", editor=NumberEditor(step=0.1), formatter=NumberFormatter(format="0.0")), TableColumn(field="year", title="Year", editor=IntEditor()), TableColumn(field="cyl", title="Cylinders", editor=IntEditor()), TableColumn(field="trans", title="Transmission", editor=SelectEditor(options=transmissions)), TableColumn(field="drv", title="Drive", editor=SelectEditor(options=drives)), TableColumn(field="class", title="Class", editor=SelectEditor(options=classes)), TableColumn(field="cty", title="City MPG", editor=IntEditor()), TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()), ] data_table = DataTable(source=self.source, columns=columns, editable=True, width=1300) plot = Plot(title=None, x_range=DataRange1d(), y_range=DataRange1d(), plot_width=1000, plot_height=300) # Set up x & y axis plot.add_layout(LinearAxis(), 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) # Add Glyphs cty_glyph = Circle(x="index", y="cty", fill_color="#396285", size=8, fill_alpha=0.5, line_alpha=0.5) hwy_glyph = Circle(x="index", y="hwy", fill_color="#CE603D", size=8, fill_alpha=0.5, line_alpha=0.5) cty = plot.add_glyph(self.source, cty_glyph) hwy = plot.add_glyph(self.source, hwy_glyph) # Add the tools tooltips = [ ("Manufacturer", "@manufacturer"), ("Model", "@model"), ("Displacement", "@displ"), ("Year", "@year"), ("Cylinders", "@cyl"), ("Transmission", "@trans"), ("Drive", "@drv"), ("Class", "@class"), ] cty_hover_tool = HoverTool(renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")]) hwy_hover_tool = HoverTool(renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")]) select_tool = BoxSelectTool(renderers=[cty, hwy], dimensions='width') plot.add_tools(cty_hover_tool, hwy_hover_tool, select_tool) controls = WidgetBox(manufacturer_select, model_select, transmission_select, drive_select, class_select) top_panel = Row(controls, plot) layout = Column(top_panel, data_table) return layout
def create(self): manufacturers = sorted(mpg["manufacturer"].unique()) models = sorted(mpg["model"].unique()) transmissions = sorted(mpg["trans"].unique()) drives = sorted(mpg["drv"].unique()) classes = sorted(mpg["class"].unique()) manufacturer_select = Select(title="Manufacturer:", value="All", options=["All"] + manufacturers) manufacturer_select.on_change('value', self.on_manufacturer_change) model_select = Select(title="Model:", value="All", options=["All"] + models) model_select.on_change('value', self.on_model_change) transmission_select = Select(title="Transmission:", value="All", options=["All"] + transmissions) transmission_select.on_change('value', self.on_transmission_change) drive_select = Select(title="Drive:", value="All", options=["All"] + drives) drive_select.on_change('value', self.on_drive_change) class_select = Select(title="Class:", value="All", options=["All"] + classes) class_select.on_change('value', self.on_class_change) columns = [ TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")), TableColumn(field="model", title="Model", editor=StringEditor(completions=models)), TableColumn(field="displ", title="Displacement", editor=NumberEditor(step=0.1), formatter=NumberFormatter(format="0.0")), TableColumn(field="year", title="Year", editor=IntEditor()), TableColumn(field="cyl", title="Cylinders", editor=IntEditor()), TableColumn(field="trans", title="Transmission", editor=SelectEditor(options=transmissions)), TableColumn(field="drv", title="Drive", editor=SelectEditor(options=drives)), TableColumn(field="class", title="Class", editor=SelectEditor(options=classes)), TableColumn(field="cty", title="City MPG", editor=IntEditor()), TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()), ] data_table = DataTable(source=self.source, columns=columns, editable=True) xdr = DataRange1d() ydr = DataRange1d() plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300) xaxis = LinearAxis(plot=plot) plot.below.append(xaxis) yaxis = LinearAxis(plot=plot) ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker) plot.left.append(yaxis) cty_glyph = Circle(x="index", y="cty", fill_color="#396285", size=8, fill_alpha=0.5, line_alpha=0.5) hwy_glyph = Circle(x="index", y="hwy", fill_color="#CE603D", size=8, fill_alpha=0.5, line_alpha=0.5) cty = GlyphRenderer(data_source=self.source, glyph=cty_glyph) hwy = GlyphRenderer(data_source=self.source, glyph=hwy_glyph) tooltips = [ ("Manufacturer", "@manufacturer"), ("Model", "@model"), ("Displacement", "@displ"), ("Year", "@year"), ("Cylinders", "@cyl"), ("Transmission", "@trans"), ("Drive", "@drv"), ("Class", "@class"), ] cty_hover_tool = HoverTool(plot=plot, renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")]) hwy_hover_tool = HoverTool(plot=plot, renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")]) select_tool = BoxSelectTool(plot=plot, renderers=[cty, hwy], dimensions=['width']) plot.tools.extend([cty_hover_tool, hwy_hover_tool, select_tool]) plot.renderers.extend([cty, hwy, ygrid]) controls = VBox(children=[ manufacturer_select, model_select, transmission_select, drive_select, class_select ], width=200) top_panel = HBox(children=[controls, plot]) layout = VBox(children=[top_panel, data_table]) return layout
models = sorted(mpg["model"].unique()) transmissions = sorted(mpg["trans"].unique()) drives = sorted(mpg["drv"].unique()) classes = sorted(mpg["class"].unique()) columns = [ TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")), TableColumn(field="model", title="Model", editor=StringEditor(completions=models)), TableColumn(field="displ", title="Displacement", editor=NumberEditor(step=0.1), formatter=NumberFormatter(format="0.0")), TableColumn(field="year", title="Year", editor=IntEditor()), TableColumn(field="cyl", title="Cylinders", editor=IntEditor()), TableColumn(field="trans", title="Transmission", editor=SelectEditor(options=transmissions)), TableColumn(field="drv", title="Drive", editor=SelectEditor(options=drives)), TableColumn(field="class", title="Class", editor=SelectEditor(options=classes)), TableColumn(field="cty", title="City MPG", editor=IntEditor()), TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()), ]
def make_example_datatable(): source = ColumnDataSource(mpg) print(source.column_names) manufacturers = sorted(mpg["manufacturer"].unique()) models = sorted(mpg["model"].unique()) transmissions = sorted(mpg["trans"].unique()) drives = sorted(mpg["drv"].unique()) classes = sorted(mpg["class"].unique()) columns = [ TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")), TableColumn(field="model", title="Model", editor=StringEditor(completions=models)), TableColumn(field="displ", title="Displacement", editor=NumberEditor(step=0.1), formatter=NumberFormatter(format="0.0")), TableColumn(field="year", title="Year", editor=IntEditor()), TableColumn(field="cyl", title="Cylinders", editor=IntEditor()), TableColumn(field="trans", title="Transmission", editor=SelectEditor(options=transmissions)), TableColumn(field="drv", title="Drive", editor=SelectEditor(options=drives)), TableColumn(field="class", title="Class", editor=SelectEditor(options=classes)), TableColumn(field="cty", title="City MPG", editor=IntEditor()), TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()), ] data_table = DataTable(source=source, columns=columns, editable=True, width=1000) plot = Plot(title=None, x_range=DataRange1d(), y_range=DataRange1d(), plot_width=1000, plot_height=300) # Set up x & y axis plot.add_layout(LinearAxis(), 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) # Add Glyphs cty_glyph = Circle(x="index", y="cty", fill_color="#396285", size=8, fill_alpha=0.5, line_alpha=0.5) hwy_glyph = Circle(x="index", y="hwy", fill_color="#CE603D", size=8, fill_alpha=0.5, line_alpha=0.5) cty = plot.add_glyph(source, cty_glyph) hwy = plot.add_glyph(source, hwy_glyph) # Add the tools tooltips = [ ("Manufacturer", "@manufacturer"), ("Model", "@model"), ("Displacement", "@displ"), ("Year", "@year"), ("Cylinders", "@cyl"), ("Transmission", "@trans"), ("Drive", "@drv"), ("Class", "@class"), ] cty_hover_tool = HoverTool(renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")]) hwy_hover_tool = HoverTool(renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")]) select_tool = BoxSelectTool(renderers=[cty, hwy], dimensions='width') plot.add_tools(cty_hover_tool, hwy_hover_tool, select_tool) layout = Column(plot, data_table) doc = Document() doc.add_root(layout) return doc
load_file_js = f.read() load_file_button = Button(label=raman_languages.TEXT__LOAD_DATA_FROM_JSON_FILE, button_type='success', callback=CustomJS(args=dict(file_source=file_source), code=load_file_js)) loaded_file_div = Div(text=raman_languages.TEXT__LOADED_FILE_NONE) # Calibration parameters list calibrate_params_source = ColumnDataSource(user_calibration_params) calibrate_params_source.on_change('data', callback_calibrate_params_change) manual_calibrate_data_table_columns = [ TableColumn(field="pixel_indices", title=raman_languages.TEXT__PIXEL_INDEX, editor=NumberEditor(), formatter=NumberFormatter()), TableColumn(field="wavenumbers", title=raman_languages.TEXT__WAVENUMBER + "/" + raman_languages.WAVELENGTH_UNIT, editor=NumberEditor(), formatter=NumberFormatter()), ] manual_calibrate_data_table = DataTable( source=calibrate_params_source, columns=manual_calibrate_data_table_columns, editable=True, reorderable=True, sortable=True, width=300)
def setup_plot(self): """" code to setup the bokeh plots """ # make bokeh figure tools = [ "tap", "box_zoom", "lasso_select", "box_select", "wheel_zoom", "pan", "reset", ] self.p = figure( x_range=(self.peakipy_data.f2_ppm_0, self.peakipy_data.f2_ppm_1), y_range=(self.peakipy_data.f1_ppm_0, self.peakipy_data.f1_ppm_1), x_axis_label=f"{self.peakipy_data.f2_label} - ppm", y_axis_label=f"{self.peakipy_data.f1_label} - ppm", tools=tools, active_drag="pan", active_scroll="wheel_zoom", active_tap=None, ) if not self.thres: self.thres = threshold_otsu(self.peakipy_data.data[0]) self.contour_start = self.thres # contour level start value self.contour_num = 20 # number of contour levels self.contour_factor = 1.20 # scaling factor between contour levels cl = self.contour_start * self.contour_factor ** np.arange(self.contour_num) if len(cl) > 1 and np.min(np.diff(cl)) <= 0.0: print(f"Setting contour levels to np.abs({cl})") cl = np.abs(cl) self.extent = ( self.peakipy_data.f2_ppm_0, self.peakipy_data.f2_ppm_1, self.peakipy_data.f1_ppm_0, self.peakipy_data.f1_ppm_1, ) self.spec_source = get_contour_data( self.peakipy_data.data[0], cl, extent=self.extent, cmap=viridis ) # negative contours self.spec_source_neg = get_contour_data( self.peakipy_data.data[0] * -1.0, cl, extent=self.extent, cmap=autumn ) self.p.multi_line( xs="xs", ys="ys", line_color="line_color", source=self.spec_source ) self.p.multi_line( xs="xs", ys="ys", line_color="line_color", source=self.spec_source_neg ) # contour_num = Slider(title="contour number", value=20, start=1, end=50,step=1) # contour_start = Slider(title="contour start", value=100000, start=1000, end=10000000,step=1000) self.contour_start = TextInput( value="%.2e" % self.thres, title="Contour level:", width=100 ) # contour_factor = Slider(title="contour factor", value=1.20, start=1., end=2.,step=0.05) self.contour_start.on_change("value", self.update_contour) # for w in [contour_num,contour_start,contour_factor]: # w.on_change("value",update_contour) # plot mask outlines el = self.p.ellipse( x="X_PPM", y="Y_PPM", width="X_DIAMETER_PPM", height="Y_DIAMETER_PPM", source=self.source, fill_color="color", fill_alpha=0.1, line_dash="dotted", line_color="red", ) self.p.add_tools( HoverTool( tooltips=[ ("Index", "$index"), ("Assignment", "@ASS"), ("CLUSTID", "@CLUSTID"), ("RADII", "@X_RADIUS_PPM{0.000}, @Y_RADIUS_PPM{0.000}"), ( f"{self.peakipy_data.f2_label},{self.peakipy_data.f1_label}", "$x{0.000} ppm, $y{0.000} ppm", ), ], mode="mouse", # add renderers renderers=[el], ) ) # p.toolbar.active_scroll = "auto" # draw border around spectrum area spec_border_x = [ self.peakipy_data.f2_ppm_min, self.peakipy_data.f2_ppm_min, self.peakipy_data.f2_ppm_max, self.peakipy_data.f2_ppm_max, self.peakipy_data.f2_ppm_min, ] spec_border_y = [ self.peakipy_data.f1_ppm_min, self.peakipy_data.f1_ppm_max, self.peakipy_data.f1_ppm_max, self.peakipy_data.f1_ppm_min, self.peakipy_data.f1_ppm_min, ] self.p.line( spec_border_x, spec_border_y, line_width=1, line_color="black", line_dash="dotted", line_alpha=0.5, ) self.p.circle(x="X_PPM", y="Y_PPM", source=self.source, color="color") # plot cluster numbers self.p.text( x="X_PPM", y="Y_PPM", text="CLUSTID", text_color="color", source=self.source, text_font_size="8pt", text_font_style="bold", ) self.p.on_event(DoubleTap, self.peak_pick_callback) self.pos_neg_contour_dic = {0: "pos/neg", 1: "pos", 2: "neg"} self.pos_neg_contour_radiobutton = RadioButtonGroup( labels=[ self.pos_neg_contour_dic[i] for i in self.pos_neg_contour_dic.keys() ], active=0, ) self.pos_neg_contour_radiobutton.on_change("active", self.update_contour) # call fit_peaks self.fit_button = Button(label="Fit selected cluster", button_type="primary") # lineshape selection self.lineshapes = { 0: "PV", 1: "V", 2: "G", 3: "L", 4: "PV_PV", # 5: "PV_L", # 6: "PV_G", # 7: "G_L", } self.radio_button_group = RadioButtonGroup( labels=[self.lineshapes[i] for i in self.lineshapes.keys()], active=0 ) self.ls_div = Div( text="""Choose lineshape you wish to fit. This can be Voigt (V), pseudo-Voigt (PV), Gaussian (G), Lorentzian (L). PV_PV fits a PV lineshape with independent "fraction" parameters for the direct and indirect dimensions""" ) self.clust_div = Div( text="""If you want to adjust how the peaks are automatically clustered then try changing the width/diameter/height (integer values) of the structuring element used during the binary dilation step (you can also remove it by selecting 'None'). Increasing the size of the structuring element will cause peaks to be more readily incorporated into clusters. Be sure to save your peak list before doing this as any manual edits will be lost.""" ) self.intro_div = Div( text="""<h2>peakipy - interactive fit adjustment </h2> """ ) self.doc_link = Div( text="<h3><a href='https://j-brady.github.io/peakipy/build/usage/instructions.html', target='_blank'> ℹ️ click here for documentation</a></h3>" ) self.fit_reports = "" self.fit_reports_div = Div(text="", height=400, style={"overflow": "scroll"}) # Plane selection self.select_planes_list = [ f"{i}" for i in range(self.peakipy_data.data.shape[self.peakipy_data.planes]) ] self.select_plane = Select( title="Select plane:", value=self.select_planes_list[0], options=self.select_planes_list, ) self.select_planes_dic = { f"{i}": i for i in range(self.peakipy_data.data.shape[self.peakipy_data.planes]) } self.select_plane.on_change("value", self.update_contour) self.checkbox_group = CheckboxGroup( labels=["fit current plane only"], active=[] ) # not sure this is needed selected_df = self.peakipy_data.df.copy() self.fit_button.on_event(ButtonClick, self.fit_selected) columns = [ TableColumn(field="ASS", title="Assignment"), TableColumn(field="CLUSTID", title="Cluster", editor=IntEditor()), TableColumn( field="X_PPM", title=f"{self.peakipy_data.f2_label}", editor=NumberEditor(step=0.0001), formatter=NumberFormatter(format="0.0000"), ), TableColumn( field="Y_PPM", title=f"{self.peakipy_data.f1_label}", editor=NumberEditor(step=0.0001), formatter=NumberFormatter(format="0.0000"), ), TableColumn( field="X_RADIUS_PPM", title=f"{self.peakipy_data.f2_label} radius (ppm)", editor=NumberEditor(step=0.0001), formatter=NumberFormatter(format="0.0000"), ), TableColumn( field="Y_RADIUS_PPM", title=f"{self.peakipy_data.f1_label} radius (ppm)", editor=NumberEditor(step=0.0001), formatter=NumberFormatter(format="0.0000"), ), TableColumn( field="XW_HZ", title=f"{self.peakipy_data.f2_label} LW (Hz)", editor=NumberEditor(step=0.01), formatter=NumberFormatter(format="0.00"), ), TableColumn( field="YW_HZ", title=f"{self.peakipy_data.f1_label} LW (Hz)", editor=NumberEditor(step=0.01), formatter=NumberFormatter(format="0.00"), ), TableColumn( field="VOL", title="Volume", formatter=NumberFormatter(format="0.0") ), TableColumn( field="include", title="Include", editor=SelectEditor(options=["yes", "no"]), ), TableColumn(field="MEMCNT", title="MEMCNT", editor=IntEditor()), ] self.data_table = DataTable( source=self.source, columns=columns, editable=True, fit_columns=True ) # callback for adding # source.selected.on_change('indices', callback) self.source.selected.on_change("indices", self.select_callback) # Document layout fitting_controls = column( row( column(self.slider_X_RADIUS, self.slider_Y_RADIUS), column( row( widgetbox(self.contour_start, self.pos_neg_contour_radiobutton) ), widgetbox(self.fit_button), ), ), row( column(widgetbox(self.ls_div), widgetbox(self.radio_button_group)), column(widgetbox(self.select_plane), widgetbox(self.checkbox_group)), ), ) # reclustering tab self.struct_el = Select( title="Structuring element:", value="disk", options=["square", "disk", "rectangle", "None", "mask_method"], width=100, ) self.struct_el_size = TextInput( value="3", title="Size(width/radius or width,height for rectangle):", width=100, ) self.recluster = Button(label="Re-cluster", button_type="warning") self.recluster.on_event(ButtonClick, self.recluster_peaks) # edit_fits tabs fitting_layout = fitting_controls log_layout = self.fit_reports_div recluster_layout = row( self.clust_div, column( self.contour_start, self.struct_el, self.struct_el_size, self.recluster ), ) save_layout = column(self.savefilename, self.button, self.exit_button) fitting_tab = Panel(child=fitting_layout, title="Peak fitting") log_tab = Panel(child=log_layout, title="Log") recluster_tab = Panel(child=recluster_layout, title="Re-cluster peaks") save_tab = Panel(child=save_layout, title="Save edited peaklist") self.tabs = Tabs( tabs=[fitting_tab, log_tab, recluster_tab, save_tab], sizing_mode="scale_both", )