def plot_calibrate_time(self, *args, **kwargs): """Experimental viewer for time calibration in a jupyter notebook. Args: accepts the same arguments as `SpatialEncoder.calibrate_time` function """ scan_pos_fs, edge_pos_pix, fit_coeff = self.calibrate_time( *args, **kwargs) source_results = ColumnDataSource( data=dict(x=scan_pos_fs, y=edge_pos_pix)) source_fit = ColumnDataSource(data=dict( x=[scan_pos_fs[0], scan_pos_fs[-1]], y=np.polyval(fit_coeff, [scan_pos_fs[0], scan_pos_fs[-1]]), )) p_time = figure( height=400, width=800, title='Time calibration', x_axis_label='Stage position, fs', y_axis_label='Edge position, pix', ) p_time.scatter('x', 'y', source=source_results) p_time.line('x', 'y', line_color='red', source=source_fit) layout = gridplot([p_time], ncols=1, toolbar_options=dict(logo=None)) handle = show(layout, notebook_handle=True) # Slider def slider_callback(change): left = change['new'][0] right = change['new'][1] fit_coeff = np.polyfit(scan_pos_fs[left:right + 1], edge_pos_pix[left:right + 1], 1) self.pix_per_fs = fit_coeff[0] source_fit.data.update( x=[scan_pos_fs[left], scan_pos_fs[right]], y=np.polyval(fit_coeff, [scan_pos_fs[left], scan_pos_fs[right]]), ) push_notebook(handle=handle) slider = IntRangeSlider( min=0, max=len(scan_pos_fs) - 1, value=[0, len(scan_pos_fs) - 1], step=1, description="Fit range", continuous_update=False, layout=Layout(width='800px'), ) slider.observe(slider_callback, names='value') return slider
def _init_gui(self): close = Button(description=' Close', icon='trash', layout=_wlo) def _close(b): self.close() close.on_click(_close) frame = IntSlider(min=self._df.frame.astype(int).min(), max=self._df.frame.astype(int).max(), value=-1, description='Frame', layout=_wlo) cbut = Button(description=' Columns', icon='barcode') cols = self._df.columns.tolist() cols = SelectMultiple(options=cols, value=cols) def _cols(c): self.columns = c.new self._update_output() cols.observe(_cols, names='value') cfol = Folder(cbut, _ListDict([('cols', cols)])) rbut = Button(description=' Rows', icon='bars') rows = IntRangeSlider(min=self.indexes[0], max=self.indexes[1], value=[0, 50]) def _rows(c): self.indexes = c.new print(self.indexes) self._update_output() rows.observe(_rows, names='value') rfol = Folder(rbut, _ListDict([('rows', rows)])) return _ListDict([('close', close), ('frame', frame), ('cols', cfol), ('rows', rfol)])
def show_amino_acid_on_protein(self, assembly_name, name, sequence_id=0, palette_name='Set1', palette_size=2): """ Display visual controls for showing amino acid sequence on a protein of the scene :param: assembly_name: Name of the assembly containing the protein :param: name: Name of the protein :param: sequence_id: ID of the protein sequence :param: palette_name: Name of the color palette :param: palette_size: Size of the color palette """ sequences = self._be.get_protein_amino_acid_sequences( assembly_name, name) if sequence_id >= len(sequences): raise RuntimeError('Invalid sequence Id') sequence_as_list = sequences[0].split(',') value_range = [int(sequence_as_list[0]), int(sequence_as_list[1])] irs = IntRangeSlider(value=[value_range[0], value_range[1]], min=value_range[0], max=value_range[1]) lbl = Label(value="AA sequence") def update_slider(value): self._be.set_protein_amino_acid_sequence_as_range( assembly_name, name, value['new']) self._be.set_protein_color_scheme( assembly_name, name, self._be.COLOR_SCHEME_AMINO_ACID_SEQUENCE, palette_name, palette_size) lbl.value = sequence_as_list[2][value['new'][0] - value_range[0]:value['new'][1] - value_range[0]] irs.observe(update_slider, 'value') display(irs) display(lbl)