def main(options, args): logger = log.get_logger("ginga", options=options) # create a new plot with default tools, using figure fig = figure(x_range=[0,600], y_range=[0,600], plot_width=600, plot_height=600, toolbar_location=None) viewer = ib.CanvasView(logger) viewer.set_figure(fig) def load_file(path): image = AstroImage(logger) image.load_file(path) viewer.set_image(image) def load_file_cb(attr_name, old_val, new_val): #print(attr_name, old_val, new_val) load_file(new_val) # add a entry widget and configure with the call back dstdir = options.indir path_w = TextInput(value=dstdir, title="File:") path_w.on_change('value', load_file_cb) if len(args) > 0: load_file(args[0]) # put the path widget and viewer in a layout and add to the document curdoc().add_root(vplot(fig, path_w))
def make_inputs(self): self.ticker1_select = Select( name='ticker1', title='Portfolio:', value='MSFT', options = ['INTC', 'Tech Basket', 'IBB', 'IGOV'] ) self.ticker2_select = Select( name='ticker2', title='Risk/Performance Metric:', value='Price', options=['Daily Prices', 'Daily Returns', 'Daily Cum Returns', 'Max DD Percentage', 'Percentage Up Days', 'Rolling 95% VaR', 'Rolling Ann. Volatility', 'Rolling Worst Dly. Loss', 'Ann. Sharpe Ratio'] ) self.ticker3_select = TextInput( name='ticker3', title='Window Size:', value='63' ) self.ticker4_select = TextInput( name='ticker4', title='Start Date:', value='2010-01-01' ) self.ticker5_select = TextInput( name='ticker5', title='End Date:', value='2015-08-01' )
def make_inputs(self): self.ticker1_select = TextInput( name='ticker1', title='Drift Function:', value='1.2*(1.1-x)', ) self.ticker1p_select = TextInput( name='ticker1p', title='Drift Derivative:', value='-1.2', ) self.ticker2_select = TextInput( name='ticker2', title='Volatility Function:', value='4.0', ) self.ticker2p_select = TextInput( name='ticker2p', title='Volatility Derivative:', value='0.0', ) self.ticker3_select = TextInput( name='ticker3', title='Number of Paths:', value='500' ) self.ticker3_1_select = TextInput( name='ticker3_1', title='Number of Points:', value='252' ) self.ticker3_2_select = TextInput( name='ticker3_2', title='Time Step:', value='0.01' ) self.ticker4_select = TextInput( name='ticker4', title='Histogram Line:', value='100' ) self.ticker4_1_select = TextInput( name='ticker4_1', title='Initial Value:', value='1.01' ) self.ticker4_2_select = Select( name='ticker4_2', title='MC Scheme:', value='Milstein', options=['Euler','Milstein', 'Pred/Corr'] ) self.button_select = TextInput( name='button', title='Type any word containing "run" to run Simulation ', value = '' )
def plot(): # Set up data N = 200 x = np.linspace(0, 4*np.pi, N) y = np.sin(x) source = ColumnDataSource(data=dict(x=x, y=y)) # Set up plots plot = Figure(plot_height=400, plot_width=400, title="my sine wave", tools="crosshair,pan,reset,resize,save,wheel_zoom", x_range=[0, 4*np.pi], y_range=[-2.5, 2.5]) plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6) # Set up widgets text = TextInput(title="title", value='my sine wave') offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1) amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0) phase = Slider(title="phase", value=0.0, start=0.0, end=2*np.pi) freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1) # Set up callbacks def update_title(attrname, old, new): plot.title = text.value text.on_change('value', update_title) def update_data(attrname, old, new): # Get the current slider values a = amplitude.value b = offset.value w = phase.value k = freq.value # Generate the new curve x = np.linspace(0, 4*np.pi, N) y = a*np.sin(k*x + w) + b source.data = dict(x=x, y=y) for w in [offset, amplitude, phase, freq]: w.on_change('value', update_data) # Set up layouts and add to document inputs = VBoxForm(children=[text, offset, amplitude, phase, freq]) fullformat = HBox(children=[inputs, plot], width=800) return fullformat, []
def main(options, args): logger = log.get_logger("ginga", options=options) TOOLS = "pan,wheel_zoom,box_select,tap" # create a new plot with default tools, using figure fig = figure(x_range=[0,600], y_range=[0,600], plot_width=600, plot_height=600, tools=TOOLS) viewer = ib.CanvasView(logger) viewer.set_figure(fig) ## box_select_tool = fig.select(dict(type=BoxSelectTool)) ## box_select_tool.select_every_mousemove = True #tap_tool = fig.select_one(TapTool).renderers = [cr] # open a session to keep our local document in sync with server session = push_session(curdoc()) #curdoc().add_periodic_callback(update, 50) def load_file(path): image = AstroImage(logger) image.load_file(path) viewer.set_image(image) def load_file_cb(attr_name, old_val, new_val): #print(attr_name, old_val, new_val) load_file(new_val) # add a entry widget and configure with the call back dstdir = options.indir path_w = TextInput(value=dstdir, title="File:") path_w.on_change('value', load_file_cb) curdoc().add_root(vplot(fig, path_w)) if len(args) > 0: load_file(args[0]) # open the document in a browser session.show() # run forever session.loop_until_closed()
def plot(): # FIGURES AND X-AXIS fig1 = Figure(title = 'Energy', plot_width = WIDTH, plot_height = HEIGHT, tools = TOOLS) timeticks = DatetimeTickFormatter(formats=dict(seconds =["%b%d %H:%M:%S"], minutes =["%b%d %H:%M"], hours =["%b%d %H:%M"], days =["%b%d %H:%M"], months=["%b%d %H:%M"], years =["%b%d %H:%M %Y"])) fig1.xaxis.formatter = timeticks # INPUT WIDGETS collection_list = CONN[DB].collection_names(include_system_collections=False) gliders = sorted([platformID for platformID in collection_list if len(platformID)>2]) gliders = Select(title = 'PlatformID', value = gliders[0], options = gliders) prev_glider = Button(label = '<') next_glider = Button(label = '>') glider_controlbox = HBox(children = [gliders, prev_glider, next_glider]) max_amphr = TextInput(title='Max AmpHrs', value='1040') deadby_date = TextInput(title='Deadby Date', value='') data_controlbox = HBox(max_amphr, deadby_date, width = 300) control_box = HBox(glider_controlbox, data_controlbox) # DATA VARS coulombs_raw = ColumnDataSource(dict(x=[],y=[])) coulombs_ext = ColumnDataSource(dict(x=[],y=[])) coulombs_per = ColumnDataSource(dict(x=[],y=[])) # AXIS setup fig1.yaxis.axis_label = 'Coulombs (AmpHr)' fig1.extra_y_ranges = {'usage': Range1d(start=0, end=1200)} # PLOT OBJECTS fig1.line( 'x', 'y', source = coulombs_raw, legend = 'm_coulombs_amphr_total', color = 'blue') fig1.circle('x', 'y', source = coulombs_raw, legend = 'm_coulombs_amphr_total', color = 'blue') fig1.line( 'x', 'y', source = coulombs_ext, legend = 'projected', color = 'red') #fig1.cross('x', 'y', source = coulombs_ext, legend = 'projected', size=10, color = 'red') fig1.renderers.append(Span(name = 'maxamp_span', location = int(max_amphr.value), dimension = 'width', line_color= 'green', line_dash='dashed', line_width=2)) fig1.renderers.append(Span(name = 'maxamp_intersect', location = 1000*time.time(), dimension = 'height', line_color= 'green', line_dash='dashed', line_width=2)) fig1.legend[0].location = 'top_left' fig1.legend[0].legend_padding = 30 # CALLBACK FUNCS def update_coulombs(attrib,old,new): g = gliders.value coulombs_raw.data = load_sensor(g, 'm_coulomb_amphr_total') #coulombs_per.data = moving_usage(coulombs_raw.data) update_projection(None,None,None) def update_projection(attrib,old,new): g = gliders.value try: fig1.select('maxamp_span')[0].location = int(max_amphr.value) coulombs_ext.data, deadby_date.value = calc_deadby_date(g, int(max_amphr.value)) fig1.select('maxamp_intersect')[0].location = coulombs_ext.data['x'][-1] except Exception as e: print('update_projection error',type(e),e) #GLIDER SELECTS def glider_buttons(increment): ops = gliders.options new_index = ops.index(gliders.value) + increment if new_index >= len(ops): new_index = 0 elif new_index < 0: new_index = len(ops)-1 gliders.value = ops[new_index] def next_glider_func(): glider_buttons(1) def prev_glider_func(): glider_buttons(-1) gliders.on_change('value', update_coulombs) next_glider.on_click(next_glider_func) prev_glider.on_click(prev_glider_func) max_amphr.on_change('value', update_projection) update_coulombs(None,None,None) return vplot(control_box, fig1)
def __init__(self, sources, categories, dvhs, rad_bio, roi_viewer, time_series, correlation, regression, mlc_analyzer, custom_title, data_tables): self.sources = sources self.selector_categories = categories.selector self.range_categories = categories.range self.correlation_variables = categories.correlation_variables self.dvhs = dvhs self.rad_bio = rad_bio self.roi_viewer = roi_viewer self.time_series = time_series self.correlation = correlation self.regression = regression self.mlc_analyzer = mlc_analyzer self.uids = {n: [] for n in GROUP_LABELS} self.allow_source_update = True self.current_dvh = [] self.anon_id_map = [] self.colors = itertools.cycle(palette) # !!!!!!!!!!!!!!!!!!!!!!!!!!!! # Selection Filter UI objects # !!!!!!!!!!!!!!!!!!!!!!!!!!!! category_options = list(self.selector_categories) category_options.sort() # Add Current row to source self.add_selector_row_button = Button(label="Add Selection Filter", button_type="primary", width=200) self.add_selector_row_button.on_click(self.add_selector_row) # Row self.selector_row = Select(value='1', options=['1'], width=50, title="Row") self.selector_row.on_change('value', self.selector_row_ticker) # Category 1 self.select_category1 = Select(value="ROI Institutional Category", options=category_options, width=300, title="Category 1") self.select_category1.on_change('value', self.select_category1_ticker) # Category 2 cat_2_sql_table = self.selector_categories[self.select_category1.value]['table'] cat_2_var_name = self.selector_categories[self.select_category1.value]['var_name'] self.category2_values = DVH_SQL().get_unique_values(cat_2_sql_table, cat_2_var_name) self.select_category2 = Select(value=self.category2_values[0], options=self.category2_values, width=300, title="Category 2") self.select_category2.on_change('value', self.select_category2_ticker) # Misc self.delete_selector_row_button = Button(label="Delete", button_type="warning", width=100) self.delete_selector_row_button.on_click(self.delete_selector_row) self.group_selector = CheckboxButtonGroup(labels=["Group 1", "Group 2"], active=[0], width=180) self.group_selector.on_change('active', self.ensure_selector_group_is_assigned) self.selector_not_operator_checkbox = CheckboxGroup(labels=['Not'], active=[]) self.selector_not_operator_checkbox.on_change('active', self.selector_not_operator_ticker) # !!!!!!!!!!!!!!!!!!!!!!!!!!!! # Range Filter UI objects # !!!!!!!!!!!!!!!!!!!!!!!!!!!! category_options = list(self.range_categories) category_options.sort() # Add Current row to source self.add_range_row_button = Button(label="Add Range Filter", button_type="primary", width=200) self.add_range_row_button.on_click(self.add_range_row) # Row self.range_row = Select(value='', options=[''], width=50, title="Row") self.range_row.on_change('value', self.range_row_ticker) # Category self.select_category = Select(value=options.SELECT_CATEGORY_DEFAULT, options=category_options, width=240, title="Category") self.select_category.on_change('value', self.select_category_ticker) # Min and max self.text_min = TextInput(value='', title='Min: ', width=150) self.text_min.on_change('value', self.min_text_ticker) self.text_max = TextInput(value='', title='Max: ', width=150) self.text_max.on_change('value', self.max_text_ticker) # Misc self.delete_range_row_button = Button(label="Delete", button_type="warning", width=100) self.delete_range_row_button.on_click(self.delete_range_row) self.group_range = CheckboxButtonGroup(labels=["Group 1", "Group 2"], active=[0], width=180) self.group_range.on_change('active', self.ensure_range_group_is_assigned) self.range_not_operator_checkbox = CheckboxGroup(labels=['Not'], active=[]) self.range_not_operator_checkbox.on_change('active', self.range_not_operator_ticker) self.query_button = Button(label="Query", button_type="success", width=100) self.query_button.on_click(self.update_data) # define Download button and call download.js on click menu = [("All Data", "all"), ("Lite", "lite"), ("Only DVHs", "dvhs"), ("Anonymized DVHs", "anon_dvhs")] self.download_dropdown = Dropdown(label="Download", button_type="default", menu=menu, width=100) self.download_dropdown.callback = CustomJS(args=dict(source=sources.dvhs, source_rxs=sources.rxs, source_plans=sources.plans, source_beams=sources.beams), code=open(join(dirname(dirname(__file__)), "download.js")).read()) self.layout = column(Div(text="<b>DVH Analytics v%s</b>" % options.VERSION), row(custom_title['1']['query'], Spacer(width=50), custom_title['2']['query'], Spacer(width=50), self.query_button, Spacer(width=50), self.download_dropdown), Div(text="<b>Query by Categorical Data</b>", width=1000), self.add_selector_row_button, row(self.selector_row, Spacer(width=10), self.select_category1, self.select_category2, self.group_selector, self.delete_selector_row_button, Spacer(width=10), self.selector_not_operator_checkbox), data_tables.selection_filter, Div(text="<hr>", width=1050), Div(text="<b>Query by Numerical Data</b>", width=1000), self.add_range_row_button, row(self.range_row, Spacer(width=10), self.select_category, self.text_min, Spacer(width=30), self.text_max, Spacer(width=30), self.group_range, self.delete_range_row_button, Spacer(width=10), self.range_not_operator_checkbox), data_tables.range_filter)
exponent_slider = Slider(title="Weighted Sum Exponent", value=0.1, start=0, end=1, step=0.1, width=200) samples_slider = Slider(title="Number of Aspects", value=15, start=1, end=30, step=1, width=200) ratings_box = TextInput(value="1,2,3,4,5", title="Star Rating:", width=185) def update_dataset(attrname, old, new): dataset = dataset_select.value n_expon = exponent_slider.value n_samples = int(samples_slider.value) n_stars = [int(val) for val in ratings_box.value.split(',')] newdata = get_dataset(dataset, n_expon, n_stars) source_all.data = dict(newdata.to_dict('list')) newdata = get_ends(n_samples) source_cut.data = dict(newdata.to_dict('list')) plot.x_range.factors = newdata['aspects'].tolist() # this was missing
order = int(new) update_data() def on_text_value_change(attr, old, new): try: global expr expr = sy.sympify(new, dict(x=xs)) except (sy.SympifyError, TypeError, ValueError) as exception: dialog.content = str(exception) dialog.visible = True else: update_data() dialog = Dialog(title="Invalid expression") slider = Slider(start=1, end=20, value=order, step=1, title="Order:") slider.on_change('value', on_slider_value_change) text = TextInput(value=str(expr), title="Expression:") text.on_change('value', on_text_value_change) inputs = HBox(children=[slider, text]) layout = VBox(children=[inputs, plot, dialog]) update_data() document.add_root(layout) session.show(layout) if __name__ == "__main__": print("\npress ctrl-C to exit") session.loop_until_closed()
source_point_arc = ColumnDataSource(data=dict(x=[], y=[])) # initialize controls # choose between original and arc length parametrization parametrization_input = CheckboxGroup(labels=['show original parametrization', 'show arc length parametrization'], active=[0, 1]) parametrization_input.on_click(parametrization_change) # slider controlling the current parameter t t_value_input = Slider(title="parameter t", name='parameter t', value=arc_settings.t_value_init, start=arc_settings.t_value_min, end=arc_settings.t_value_max, step=arc_settings.t_value_step) t_value_input.on_change('value', t_value_change) # text input for the x component of the curve x_component_input = TextInput(value=arc_settings.x_component_input_msg, title="curve x") x_component_input.on_change('value', curve_change) # text input for the y component of the curve y_component_input = TextInput(value=arc_settings.y_component_input_msg, title="curve y") y_component_input.on_change('value', curve_change) # dropdown menu for selecting one of the sample curves sample_curve_input = Dropdown(label="choose a sample function pair or enter one below", menu=arc_settings.sample_curve_names) sample_curve_input.on_click(sample_curve_change) # initialize plot toolset = "crosshair,pan,reset,resize,save,wheel_zoom" # Generate a figure container plot = Figure(plot_height=400, plot_width=400, tools=toolset, title="Arc length parametrization",
P2_source = ColumnDataSource(data=dict(x=t, y=0*t )) P0_experiment_source = ColumnDataSource(data=dict(x=t, y=0*t )) P1_experiment_source = ColumnDataSource(data=dict(x=t, y=0*t )) P2_experiment_source = ColumnDataSource(data=dict(x=t, y=0*t )) #plot.multi_line('x', 'y', source=source, line_width=3, line_alpha=0.6) plot.line('x', 'y', source=P0_source, line_width=3, line_alpha=0.6,color='red') plot.line('x', 'y', source=P1_source, line_width=3, line_alpha=0.6,color='green') plot.line('x', 'y', source=P2_source, line_width=3, line_alpha=0.6,color='blue') plot.circle( 'x', 'y', source=P0_experiment_source,color='red', size=6 , legend='SS' ) #,'green','blue'] plot.circle( 'x', 'y', source=P1_experiment_source,color='green', size=6, legend='SD+DS' ) #,'green','blue'] plot.circle( 'x', 'y', source=P2_experiment_source,color='blue', size=6, legend='DD ' ) #,'green','blue'] # Set up widgets path = TextInput(title="file path", value='my sine wave') file_name = TextInput(title="file name", value='1203_24') etta = Slider(title="etta", value=0.08637, start=0.0, end=0.15, step=0.01) #delta = Slider(title="delta [KHz]", value=0.08637, start=0.0, end=0.15, step=0.01) Pi_time = Slider(title="pi_time [us]", value=9.6, start=5, end=15, step=0.05) n_bar = Slider(title="n_bar", value=0.0, start=0.0, end=10, step=0.1) chi = TextInput(title="chi", value='7.0') # Set up callbacks def update_exp_data(attrname, old, new): # set up the data try: #csv_reader = csv.reader(open('00001 - MS Gate 2017Sep13_1203_24.csv'))
def plotting(self): #Tools = [hover, TapTool(), BoxZoomTool(), BoxSelectTool(), PreviewSaveTool(), ResetTool()] TOOLS="crosshair,pan,wheel_zoom,box_zoom,reset,hover,previewsave" tab_plots = [] #output_file("test.html") self.all_elements = [] self.elements_comparison = [] for attr_id, i in zip(self.attribute_ids, range(len(self.attribute_ids))): """ create plots for each datafile and put them in a tab. """ list_of_datasets = getattr(self, attr_id) y_axis_units = [x["y_unit"] for x in list_of_datasets] x_axis_units = [x["x_unit"] for x in list_of_datasets] figure_obj = figure(plot_width = 1000, plot_height = 800, y_axis_type = "log", title = attr_id, tools = TOOLS) #figure_obj.axes.major_label_text_font_size("12pt") #figure_obj.major_label_text_font_size("12pt") setattr(self, attr_id+"_"+"figure_obj",figure_obj) figure_obj.yaxis.axis_label = y_axis_units[0] figure_obj.xaxis.axis_label = x_axis_units[0] if not all(x == y_axis_units[0] for x in y_axis_units): for unit, data in zip(y_axis_units, list_of_datasets): if not unit == y_axis_units[0]: figure_obj.extra_y_ranges = {"foo": Range1d(start = np.amin(data["data"]["y"]), end = np.amax(data["data"]["y"]))} figure_obj.add_layout(LogAxis(y_range_name = "foo", axis_label = unit), "right") break if not all(x == x_axis_units[0] for x in x_axis_units): for unit, data in zip(x_axis_units, list_of_datasets): if not unit == x_axis_units[0]: figure_obj.extra_x_ranges = {"bar": Range1d(start = np.amin(data["data"]["x"]), end = np.amax(data["data"]["x"]))} figure_obj.add_layout(LinearAxis(x_range_name = "bar", axis_label = unit), "above") break figure_obj.xaxis.axis_label = list_of_datasets[0]["x_unit"] colour_list = Spectral11 + RdPu9 + Oranges9 colour_indices = [0, 2, 8, 10, 12, 14, 20, 22, 1, 3, 9, 11, 13, 15] list_of_elements = [] for dataset, color_index in zip(list_of_datasets, colour_indices): self.all_elements.append(dataset["sample element"]) #strip isotope number color = colour_list[color_index] source = ColumnDataSource(data = dataset["data"]) #Datastructure for source of plotting setattr(self, attr_id+"_"+dataset["sample element"]+"_source", source) #Source element generalized for all plotting list_of_elements.append(dataset["sample element"]) figure_obj.line("x", "y", source = getattr(self, attr_id+"_"+dataset["sample element"] +"_source"), line_width = 2, line_color = color, legend = dataset["sample element"], name = dataset["sample element"], ) hover = figure_obj.select_one(HoverTool).tooltips = [("element", "@element"), ("(x,y)", "($x, $y)")] radio_group = RadioGroup(labels = list_of_elements, active=0) """ Need to fetch default variables from input file and replace DEFAULT Block of code produces the layout of buttons and callbacks """ #Calculations on the dataset text_input_rsf = TextInput(value = "default", title = "RSF (at/cm^3): ") do_integral_button = Button(label = "Calibration Integral") smoothing_button = Button(label = "Smoothing on selected curve") text_input_sputter = TextInput(value = "default", title = "Sputter speed: float unit") text_input_crater_depth = TextInput(value = "default", title = "Depth of crater in: float") radio_group.on_change("active", lambda attr, old, new: None) text_input_xval_integral = TextInput(value = "0", title = "x-value for calibration integral ") text_input_yval_integral = TextInput(value = "0", title = "y-value for calibration integral ") #Save files for later use save_flexDPE_button = Button(label = "Save element for FlexPDE") save_all_flexDPE_button = Button(label = "Save all elements for FlexPDE") #Pointers to methods on click / change handlers do_integral_button.on_click(lambda identity = self.attribute_ids[i], radio = radio_group, x_box = text_input_xval_integral, y_box = text_input_yval_integral: self.integrate(identity, radio, x_box, y_box)) smoothing_button.on_click(lambda identity = self.attribute_ids[i], radio = radio_group: self.smoothing(identity, radio) ) save_flexDPE_button.on_click(lambda identity = self.attribute_ids[i], radio = radio_group: self.write_to_flexPDE(identity, radio)) save_all_flexDPE_button.on_click(lambda identity = self.attribute_ids[i], radio = radio_group: self.write_all_to_flexPDE(identity, radio)) text_input_rsf.on_change("value", lambda attr, old, new, radio = radio_group, identity = self.attribute_ids[i], text_input = text_input_rsf, which = "rsf": self.update_data(identity, radio, text_input, new, which)) text_input_sputter.on_change("value", lambda attr, old, new, radio = radio_group, identity = self.attribute_ids[i], text_input = text_input_sputter, which = "sputter": self.update_data(identity, radio, text_input, new, which)) text_input_crater_depth.on_change("value", lambda attr, old, new, radio = radio_group, identity = self.attribute_ids[i], text_input = text_input_crater_depth, which = "crater_depth": self.update_data(identity, radio, text_input, new, which)) #Initialization of actual plotting. tab_plots.append(Panel(child = hplot(figure_obj, vform(radio_group, save_flexDPE_button, save_all_flexDPE_button), vform(text_input_rsf, smoothing_button, text_input_sputter, text_input_crater_depth), vform(text_input_xval_integral, text_input_yval_integral, do_integral_button)), title = attr_id)) """ Check to see if one or more element exists in the samples and creat a comparison plot for each of those elements. """ for element in self.all_elements: checkers = list(self.all_elements) checkers.remove(element) if element in checkers and not element in self.elements_comparison: self.elements_comparison.append(element) """create plots for each element that is to be compared """ for comparison_element in self.elements_comparison: colour_list = Spectral11 + RdPu9 + Oranges9 colour_indices = [0, 2, 8, 10, 12, 14, 20, 22, 1, 3, 9, 11, 13, 15] figure_obj = figure(plot_width = 1000, plot_height = 800, y_axis_type = "log", title = comparison_element, tools = TOOLS) #figure_obj.xaxis.major_label_text_font_size("12pt") #figure_obj.yaxis.major_label_text_font_size("12pt") y_axis_units = [] x_axis_units = [] comparison_datasets = [] for attr_id, color_index in zip(self.attribute_ids, colour_indices): list_of_datasets = getattr(self, attr_id) for dataset in list_of_datasets: if dataset["sample element"] == comparison_element: comparison_datasets.append(dataset) y_axis_units.append(dataset["y_unit"]) x_axis_units.append(dataset["x_unit"]) figure_obj.xaxis.axis_label = comparison_datasets[-1]["x_unit"] figure_obj.yaxis.axis_label = comparison_datasets[-1]["y_unit"] if not all(x == y_axis_units[-1] for x in y_axis_units): for unit, data in zip(y_axis_units, comparison_datasets): if not unit == y_axis_units[-1]: figure_obj.extra_y_ranges = {"foo": Range1d(start = np.amin(data["data"]["y"]), end = np.amax(data["data"]["y"]))} figure_obj.add_layout(LogAxis(y_range_name = "foo", axis_label = unit), "right") break if not all(x == x_axis_units[-1] for x in x_axis_units): for unit, data in zip(x_axis_units, comparison_datasets): if not unit == x_axis_units[-1]: figure_obj.extra_x_ranges = {"bar": Range1d(start = np.amin(data["data"]["x"]), end = np.amax(data["data"]["x"]))} figure_obj.add_layout(LinearAxis(x_range_name = "bar", axis_label = unit), "above") break for attr_id, color_index in zip(self.attribute_ids, colour_indices): list_of_datasets = getattr(self, attr_id) for dataset in list_of_datasets: if dataset["sample element"] == comparison_element: color = colour_list[color_index] """ Logic that ensures that plots get put with correspoinding axes. """ if dataset["x_unit"] != x_axis_units[-1] or dataset["y_unit"] != y_axis_units[-1]: if dataset["x_unit"] != x_axis_units[-1] and dataset["y_unit"] != y_axis_units[-1]: figure_obj.line("x", "y", source = getattr(self, attr_id+"_"+dataset["sample element"]+"_source"), line_width = 2, line_color = color, legend = attr_id, x_range_name = "bar", y_range_name = "foo") elif dataset["x_unit"] != x_axis_units[-1]: figure_obj.line("x", "y", source = getattr(self, attr_id+"_"+dataset["sample element"]+"_source"), line_width = 2, line_color = color, legend = attr_id, x_range_name = "bar") else: figure_obj.line("x", "y", source = getattr(self, attr_id+"_"+dataset["sample element"]+"_source"), line_width = 2, line_color = color, legend = attr_id, y_range_name = "foo") else: figure_obj.line("x", "y", source = getattr(self, attr_id+"_"+dataset["sample element"]+"_source"), line_width = 2, line_color = color, legend = attr_id) tab_plots.append(Panel(child = figure_obj, title = comparison_element)) tabs = Tabs(tabs = tab_plots) session = push_session(curdoc()) session.show() session.loop_until_closed()
return df # Column order for displaying the details of a specific review col_order = ["price", "points", "variety", "province", "description"] all_provinces = [ "All", "South Australia", "Victoria", "Western Australia", "Australia Other", "New South Wales", "Tasmania" ] # Setup the display portions including widgets as well as text and HTML desc = Div(text="All Provinces", width=800) province = Select(title="Province", options=all_provinces, value="All") price_max = Slider(start=0, end=900, step=5, value=200, title="Maximum Price") title = TextInput(title="Title Contains") details = Div(text="Selection Details:", width=800) # Populate the data with the dataframe source = ColumnDataSource(data=load_data()) # Build out the hover tools hover = HoverTool(tooltips=[ ("title", "@title"), ("variety", "@variety"), ]) # Define the tool list as a list of the objects so it is easier to customize # each object TOOLS = [ hover,
input_file = 'input.txt' bert = sys.argv[1] layers = '0' for i in range(int(sys.argv[2]) - 1): layers += ',' + str(i + 1) else: input_file = sys.argv[1] bert = sys.argv[2] layers = '0' for i in range(int(sys.argv[3]) - 1): layers += ',' + str(i + 1) layer_idxs = [int(x) for x in layers.split(',')] text_count = 1 text_input = TextInput() button = Button(label='Обработать', button_type='success') div = Div(text='') def calculate(): with open(input_file, 'w') as f: f.write(text_input.value) args = ['python', '../bert/extract_features.py'] args.append('--input_file=' + input_file) args.append('--output_file=') args.append('--vocab_file=' + bert + 'vocab.txt') args.append('--bert_config_file=' + bert + 'bert_config.json') args.append('--init_checkpoint=' + bert + 'bert_model.ckpt') args.append('--layers=' + layers)
source=source, line_width=3, line_alpha=0.6, color="purple") plot.line('x', 'yB', source=source, line_width=3, line_alpha=0.6, color="blue") plot.circle('x', 'y', source=source2, size=5, color="black") plot.circle('x', 'yG', source=source2, size=5, color="green") plot.circle('x', 'yB', source=source2, size=5, color="blue") plot.circle('x', 'yR', source=source2, size=5, color="red") plot.circle('x', 'yi', source=source2, size=5, color="purple") #plot.line('x', 'yV', source=source, line_width=3, line_alpha=0.6, color="turquoise") #plot.line('x', 'yU', source=source, line_width=3, line_alpha=0.6, color="purple") arrayoftimes = np.array(photometry_time) text = TextInput(title="title", value='my parabola', callback=callback2) lumdist_input = TextInput(title="title", value=str(lumdist)) redshift_input = TextInput(title="title", value=str(redshift)) M_slider = Slider(start=0.1, end=10, value=1, step=.1, title="Ejecta Mass", callback=callback) v_slider = Slider(start=5000, end=20000, value=10000, step=1000, title="Ejecta Velocity", callback=callback)
def callback_subtract_noise_from_signal_button(): global signal_data_averaged_dict global noise_data_averaged_dict waveform_data_source.data = CCD_utils.subtract_dict_data( signal_data_averaged_dict, noise_data_averaged_dict) doc.add_next_tick_callback(callback_update_raman_spec) ### -------------- define callbacks --------------- ### ### -------------- make the document -------------- ### # --- add widgets # Select Serial Port Text Input select_serial_port_text_input = TextInput( title=raman_languages.TEXT__SERIAL_PORT, value=raman_configs.DEFAULT_SERIAL_PORT) select_serial_port_text_input.on_change( 'value', callback_select_serial_port_text_input) # Select Baud Rate select_baud_rate_text_input = TextInput(title=raman_languages.TEXT__BAUD_RATE, value=str( raman_configs.DEFAULT_BAUD_RATE)) select_baud_rate_text_input.on_change('value', callback_select_baud_rate_text_input) # Open Serial Port Button open_serial_port_button = Button(label=raman_languages.TEXT__OPEN_SERIAL_PORT) open_serial_port_button.on_click(callback_open_serial_port)
# Slice direction dropdown def sliceDropdown(): pass sliceDropdownMenu = Select(title="For fMRI Connectivity Only: Choose Direction:", value="X", options=["X", "Y", "Z"], width=int(total_width/6), height=50) # Add ROI button def addroiButton(): pass roiButton = Button(label="Add ROI", width=int(total_width/6), height=30) roiButton.on_click(addroiButton) # ROI name textbox def roiNameTextbox(): pass roiName = TextInput(value="default", title="ROI Name", width=int(total_width/6), height=50) # Choose ROI dropdown def roiDropdown(): pass roiDropdownMenu = Select(title="Choose ROI:", value="X", options=["X", "Y", "Z"], width=int(total_width/6), height=50) #orgenize figures curdoc().add_root(layout([ [fileButton, mapName, ConnectivityButton, AtlasButton, atlasName,MetadataButton], [connectivityMatrix, [sliceDropdownMenu, imageView]], [connectivityDropdown, connectivityMeasure, roiButton, roiName, roiDropdownMenu],
dsTable.datasets_table, dsTable.vars_table, btn_plot_lonXlat, plotLayout, status_bar, name='mainLayout') doc.remove_root(loadLayout) doc.add_root(mainLayout) def log(msg, ex=None): status_bar.text = msg if ex is None: logger.debug(msg) else: logger.exception(msg, ex) doc = curdoc() log("Load an index file to get started.") btnLoad = Button(label="Load") btnLoad.on_click(lambda: load_file(txt_file.value)) txt_file = TextInput(value="index_201x.json", title="Specify index file to load") loadLayout = column(Div(height=50, style={"height": "50px"}), txt_file, btnLoad, status_bar) doc.add_root(loadLayout) # [plot.init_layout()]
style={ "font-family": "Arial", "font-size": "15px" }, width=300) rectangular_pretext = Div(text='Rectangular Reflectors/Sources', style={ "font-family": "Arial", "font-size": "15px" }, width=300) #rotation_pretext = PreText(text='Rotation (Degrees)', width=300) #simulation_params_pretext = PreText(text='Rotation (Degrees)', width=300) # Text Input mesh_width_input = TextInput(value='50', title='Mesh Width', width=100) mesh_height_input = TextInput(value='50', title='Mesh Height', width=100) quality_factor_input = TextInput(value='100', title='Plasmon Q', width=100) plasmon_wavelength_input = TextInput(value='4', title='Plasmon ' + u"\u03BB", width=100) mesh_density_input = TextInput(value='100', title='Mesh Density', width=200) lambda_input = TextInput(value='100', title='Excitation ' + u"\u03BB", width=100) phi_input = TextInput(value='90', title='Excitation ' + u"\u03B8", width=100) # Sliders slider_end_value = min(int(mesh_width_input.value), int(mesh_height_input.value)) circular_radius = Slider(title='Radius',
plot.vbar(x='x', top='y', width=0.5, source=source, color="red") plot2 = figure(plot_height=400, plot_width=1000, title="Coincidence counts", tools="crosshair,pan,reset,save,wheel_zoom", x_range=coinc, y_range=[0, 4000]) plot2.background_fill_color = "black" plot2.border_fill_color = "black" plot2.vbar(x='x', top='y', width=0.5, source=source2, color="yellow") # Set up widgets to control scale of plots # TODO change these to actual range sliders command = TextInput(title="Command Entry:", value='raw counts') scalemin = Slider(title="Singles Scale minimum", value=0.0, start=0.0, end=1000.0, step=100) scalemax = Slider(title="Singles Scale maximum", value=70000.0, start=1000.0, end=500000.0, step=100) scalemin2 = Slider(title="Coinc. Scale minimum", value=0.0, start=0.0, end=5000.0, step=100) scalemax2 = Slider(title="Coinc. Scale maximum", value=4000.0, start=1000.0, end=100000.0, step=100) # other widgets (not all are used yet) phase = Slider(title="phase", value=0.0, start=0.0, end=5.0, step=0.1) points = Slider(title="data points", value=20, start=0, end=500, step=1) statsA = Paragraph(text="100", width=400, height=40) statsB = Paragraph(text="100", width=400, height=40) g2 = Paragraph(text="100", width=400, height=80) g2_2d = Paragraph(text="100", width=400, height=40) # Set up callbacks
import logging logging.basicConfig(level=logging.DEBUG) import numpy as np from bokeh.plotting import Figure from bokeh.models import Plot, ColumnDataSource from bokeh.models.widgets import HBox, Slider, TextInput, VBoxForm from bokeh.io import curdoc source = ColumnDataSource(data=dict(x=[], y=[])) text = TextInput( title="title", name='title', value='my sine wave' ) offset = Slider( title="offset", name='offset', value=0.0, start=-5.0, end=5.0, step=0.1 ) amplitude = Slider( title="amplitude", name='amplitude', value=1.0, start=-5.0, end=5.0 ) phase = Slider( title="phase", name='phase', value=0.0, start=0.0, end=2*np.pi ) freq = Slider(
class Dashboard: def __init__(self, default_dir, port): # path to source directory self.src_dir = os.path.dirname(os.path.abspath(__file__)) # MD directory and files selection self.md_dir = TextInput( title="Path to MD directory containing mdin and mdout files", value="", width=750) self.anim_button = Toggle(label="▶ Load", button_type="warning", width=80, height=50, active=False) self.port = port # container for the buttons that are created while the user types in the textinput self.autocomp_results = column(children=[]) # file used to display temperature, pressure...etc. plots self.mdout_sel = Select( title="MDout file", width=230, value=None, options=[], ) # button to load content self.mdout_button = Button(width=80, height=50, label="Plot", button_type="primary") self.mdout_files = [None] self.md_mdout_files = [] # mdinfo figures progressbar_tooltip = """ <span style="color:#428df5">@completed{0,0}</span> out of <span style="color:#428df5">@total{0,0}</span> steps (<span style="color:#428df5">@remaining{0,0}</span> remaining) """ self.progressbar = figure(title="Current progress", x_range=Range1d(0, 10), tooltips=progressbar_tooltip, height=70, width=350, tools="hover", toolbar_location=None) self.progressbar.xgrid.grid_line_color = None self.progressbar.ygrid.grid_line_color = None self.progressbar.axis.visible = False self.progressbar.outline_line_color = "#444444" self.steps_CDS = ColumnDataSource({ "total": [np.nan], "completed": [np.nan], "remaining": [np.nan], "color": ['#428df5'], }) self.progressbar.hbar( y=0, left=0, right="completed", source=self.steps_CDS, height=0.5, color="color", ) self.progressbar.hover[0].mode = "hline" self.calc_speed = Div(width=150, height=50, text="Calculation speed:", style={ "font-weight": "bold", "color": "#444444", "margin-top": "5px" }) self.eta = Div(width=280, height=50, text="Estimated time remaining:", style={ "font-weight": "bold", "color": "#444444", "margin-top": "5px" }) self.last_update = Div(width=280, height=50, text="Last update:", style={ "font-weight": "bold", "color": "#444444", "margin-top": "5px" }) # number of mdout files displayed on the dashboard at max self.slider = Slider(start=1, end=12, value=2, step=1, callback_policy="mouseup", title="Number of simulations displayed") self.dashboard_CDS = ColumnDataSource({ "y_coords": [0, 1], "mdout": ["heat.out", "prod.out"], "time": [42, 200], "angle": [1.09, 5.193], "color": [sim_palette[0], sim_palette[1]], }) dashboard_tooltip = """ <span style="color:@color">@mdout</span>: @time{0,0.00} ns """ # pie plot self.pie = figure(plot_height=300, width=500, title="Simulations length", toolbar_location=None, tools="hover", tooltips=dashboard_tooltip, x_range=Range1d(-0.5, 1.0)) self.rpie = self.pie.wedge(x=0, y=1, radius=0.4, source=self.dashboard_CDS, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend="mdout") self.pie.axis.axis_label = None self.pie.axis.visible = False self.pie.grid.grid_line_color = None self.pie.legend.label_text_font_size = '9pt' self.pie.legend.border_line_width = 0 self.pie.legend.border_line_alpha = 0 self.pie.legend.spacing = 0 self.pie.legend.margin = 0 # hbar plot self.bar = figure(width=850, plot_height=300, toolbar_location=None, tools="hover", tooltips=dashboard_tooltip) self.rbar = self.bar.hbar(y="y_coords", left=0, right="time", source=self.dashboard_CDS, height=0.8, color="color") self.bar.x_range.set_from_json("start", 0) self.bar.xaxis.axis_label = "Time (ns)" self.bar.yaxis.axis_label = None self.bar.yaxis.visible = False self.bar.hover[0].mode = "hline" ## Mdout figures self.mdinfo_CDS = ColumnDataSource(copy.deepcopy(empty_mddata_dic)) self.moving_avg_trans = CustomJSTransform(v_func=moving_avg_func) ticker = PrintfTickFormatter(format="%4.0e") # Temperature self.temperature_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.temperature_fig.toolbar.autohide = True self.temperature_fig.xaxis.axis_label = "Number of steps" self.temperature_fig.yaxis.axis_label = "Temperature (K)" self.temperature_fig.xaxis.formatter = ticker r = self.temperature_fig.line("Nsteps", "Temperature", color=palette[0], source=self.mdinfo_CDS, _width=1, alpha=0.15) self.temperature_fig.line(transform("Nsteps", self.moving_avg_trans), transform("Temperature", self.moving_avg_trans), color=colorscale(palette[0], 0.85), source=self.mdinfo_CDS, line_width=3) self.temperature_fig.add_tools(make_hover([r])) # Pressure self.pressure_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.pressure_fig.toolbar.autohide = True self.pressure_fig.xaxis.axis_label = "Number of steps" self.pressure_fig.yaxis.axis_label = "Pressure" self.pressure_fig.xaxis.formatter = ticker r = self.pressure_fig.line("Nsteps", "Pressure", color=palette[1], source=self.mdinfo_CDS, line_width=1, alpha=0.15) self.pressure_fig.line(transform("Nsteps", self.moving_avg_trans), transform("Pressure", self.moving_avg_trans), color=colorscale(palette[1], 0.85), source=self.mdinfo_CDS, line_width=3) self.pressure_fig.add_tools(make_hover([r])) # Energy self.energy_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) etot = self.energy_fig.line("Nsteps", "Etot", color=palette[2], source=self.mdinfo_CDS, line_width=1) ektot = self.energy_fig.line("Nsteps", "EKtot", color=palette[3], source=self.mdinfo_CDS, line_width=1) eptot = self.energy_fig.line("Nsteps", "EPtot", color=palette[4], source=self.mdinfo_CDS, line_width=1) legend = Legend(items=[ ("Total", [etot]), ("Kinetic", [ektot]), ("Potential", [eptot]), ], location="top_right") self.energy_fig.add_layout(legend, 'right') self.energy_fig.add_tools(make_hover([etot])) self.energy_fig.legend.location = "top_left" self.energy_fig.legend.click_policy = "hide" self.energy_fig.toolbar.autohide = True self.energy_fig.xaxis.axis_label = "Number of steps" self.energy_fig.yaxis.axis_label = "Energy" self.energy_fig.xaxis.formatter = ticker # Volume self.vol_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.vol_fig.toolbar.autohide = True self.vol_fig.xaxis.axis_label = "Number of steps" self.vol_fig.yaxis.axis_label = "Volume" self.vol_fig.xaxis.formatter = ticker r = self.vol_fig.line("Nsteps", "Volume", color=palette[6], source=self.mdinfo_CDS, line_width=1, alpha=0.15) self.vol_fig.line(transform("Nsteps", self.moving_avg_trans), transform("Volume", self.moving_avg_trans), color=colorscale(palette[6], 0.85), source=self.mdinfo_CDS, line_width=3) self.vol_fig.add_tools(make_hover([r])) # Density self.density_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.density_fig.toolbar.autohide = True self.density_fig.xaxis.axis_label = "Number of steps" self.density_fig.yaxis.axis_label = "Density" self.density_fig.xaxis.formatter = ticker r = self.density_fig.line("Nsteps", "Density", color=palette[7], source=self.mdinfo_CDS, line_width=1, alpha=0.15) self.density_fig.line(transform("Nsteps", self.moving_avg_trans), transform("Density", self.moving_avg_trans), color=colorscale(palette[7], 0.85), source=self.mdinfo_CDS, line_width=3) self.density_fig.add_tools(make_hover([r])) ## RMSD figure self.empty_rmsd_dic = {k: [] for k in ["Time", "RMSD"]} self.rmsd_CDS = ColumnDataSource(self.empty_rmsd_dic) self.rmsd_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.rmsd_fig.toolbar.autohide = True self.rmsd_fig.xaxis.axis_label = "Time (ps)" self.rmsd_fig.yaxis.axis_label = "RMSD (Å)" self.rmsd_fig.xaxis.formatter = ticker r = self.rmsd_fig.line("Time", "RMSD", color=palette[8], source=self.rmsd_CDS, line_width=2) self.rmsd_fig.add_tools( make_hover([r], tooltips=[("Time (ps)", "@Time{0,0}"), ("RMSD (Å)", "@RMSD")])) self.rmsd_button = Button(width=100, label="Calculate RMSD", button_type="primary") self.trajectory = MultiSelect( title="Trajectory file(s)", width=400, value=None, options=[], ) self.rst_traj = Select( title="Restart file", width=400, value=None, options=[], ) self.topology = Select( title="Topology file", width=200, value=None, options=[], ) self.mask = TextInput(title="Mask", value="protein@CA,C,O,N", width=200) # NGLview self.last_rst_update = 0 self.view_button = Button(width=80, label="Visualize", button_type="primary") self.view_canvas = Div(width=size[0], height=size[1] + 60, css_classes=["ngldiv"], text="") self.ngl_help_div = Div(width=0, height=0, text="") self.ngl_help_button = Toggle(width=80, label="Help", active=False) self.ngl_lig = TextInput(title="Ligand name", value="LIG", width=80) self.ngl_representations = CheckboxButtonGroup( labels=["Protein", "Ligand", "Water", "Lipids", "Ions"], active=[0, 1, 2, 3, 4], ) # info about simulation files (min, dt, rst and mdcrd files) self.mdout_info = {} # add callbacks self.add_callbacks() self.md_dir.value = default_dir def ngl_help(self, new_value): """Show help on NGL controls""" if self.ngl_help_button.active: self.ngl_help_div.width = 300 self.ngl_help_div.height = size[1] self.ngl_help_button.label = "Hide" self.ngl_help_div.text = NGL_HELP_TEXT else: self.ngl_help_div.width = 300 self.ngl_help_div.height = size[1] self.ngl_help_button.label = "Help" self.ngl_help_div.text = "" def autocomp_callback(self, attr, old, new): """List all directories for the current typed path, output as buttons to click""" path = os.path.join(new + "*", "") opts = [] if new == "" else glob.glob(path) opts = sorted(opts, key=lambda x: x.split("/")[-2].lower()) buttons = [Button(width=750, label=opt) for opt in opts] for b in buttons: cb = CustomJS(args=dict(md_dir=self.md_dir, button=b), code=""" md_dir.value_input = button.label; md_dir.value = button.label; """) b.js_on_click(cb) self.autocomp_results.children = buttons mdinfo_file = os.path.join(new, "mdinfo") if os.path.exists(mdinfo_file): self.anim_button.button_type = "success" else: self.anim_button.button_type = "warning" def traj_top_callback(self, attr, old, new): log.debug(f"Updating list of trajectory and topology files") try: # search netcdf files traj = [ f for f in os.listdir(self.md_dir.value) if re.search(r'.+\.n(et)?c(df)?$', f) ] traj.sort(key=lambda f: os.path.getmtime( os.path.join(self.md_dir.value, f)), reverse=True) self.trajectory.options = traj # search restart files restart = [ f for f in os.listdir(self.md_dir.value) if re.search(r'.+\.rst7?$', f) ] restart.sort(key=lambda f: os.path.getmtime( os.path.join(self.md_dir.value, f)), reverse=True) self.rst_traj.options = restart if self.rst_traj.options: self.rst_traj.value = self.rst_traj.options[0] # search for .top, .prmtop, .parm7 or .prm top = [ f for f in os.listdir(self.md_dir.value) if re.search(r'.+\.(prm)?top$', f) or re.search(r'.+\.pa?rm7?$', f) ] self.topology.options = top if self.topology.options: self.topology.value = self.topology.options[0] except FileNotFoundError: pass def compute_rmsd(self): """Compute RMSD during a trajectory""" self.rmsd_button.button_type = "default" mask = self.mask.value.replace( "protein", ":ALA,ARG,ASH,ASN,ASP,CYM,CYS,CYX,GLH,GLN,GLU,GLY,HID,HIE,HIP,HYP,HIS,ILE,LEU,LYN,LYS,MET,PHE,PRO,SER,THR,TRP,TYR,VAL" ) topology = os.path.join(self.md_dir.value, self.topology.value) trajectories = [ os.path.join(self.md_dir.value, f) for f in self.trajectory.value ] trajectories.sort(key=lambda f: os.path.getmtime(f), reverse=False) traj = pt.iterload(trajectories, topology) stepsize = get_stepsize(traj) frames = list( traj.iterframe(step=stepsize, autoimage=True, rmsfit=False, mask=mask)) log.debug( f"Computing RMSD for top {topology} and traj {trajectories} with a step of {stepsize}, using mask {mask}" ) ref = frames[0] results = {"Time": [], "RMSD": []} with ProcessPoolExecutor(max_workers=max_workers) as ex: for rmsd, frame in zip( ex.map(partial(compute_rmsd, ref=ref), frames), frames): results["Time"].append(frame.time) results["RMSD"].append(rmsd) del traj self.rmsd_CDS.data = results self.rmsd_button.button_type = "primary" def autoview_structure(self): """Load structure automatically if it has been modified recently""" # check if rst7 file was rewritten recently update_time = os.path.getmtime( os.path.join(self.md_dir.value, self.rst_traj.value)) # and viewing the latest rst7 file if (update_time > self.last_rst_update) and ( self.rst_traj.value == self.rst_traj.options[0]): log.debug( f"Updating {self.rst_traj.value} with more recent version: {update_time}" ) self.last_rst_update = update_time self.view_structure() else: log.debug(f"No recent update of restart {self.rst_traj.value}") def view_structure(self): """Visualize a restart file with NGL""" log.debug( f"Visualizing top {self.topology.value} and restart {self.rst_traj.value}" ) # load rst7 with pytraj (NGL cannot read it directly) traj = pt.load(os.path.join(self.md_dir.value, self.rst_traj.value), os.path.join(self.md_dir.value, self.topology.value)) traj = pt.autoimage(traj) ## pass to parmed to write the pdb data in a StringIO # struct = pmd.load_file(os.path.join(self.md_dir.value, self.topology.value), xyz=traj.xyz) # f = StringIO() # struct.write_pdb(f) # pdb_data = f.getvalue().encode("ascii") # f.close() # write as pdb to temporary file (much faster than parmed + StringIO) with NamedTemporaryFile() as f: pt.write_traj(f.name, traj, format="pdb", overwrite=True) pdb_data = f.read() # create javascript code with open(os.path.join(self.src_dir, "static", "js", "nglviewer.js")) as f: JS_TEMPLATE = f.read() self.js_view_structure.code = JS_TEMPLATE % (pdb_data) # trigger javascript callback by adding an invisible character to the button label self.view_button.label += " " def clear_canvas(self): """Clear the canvas""" log.debug("Clearing canvas") self.mdinfo_CDS.data = copy.deepcopy(empty_mddata_dic) def read_mdout_header(self, mdout): """Read the header of mdout file to search for info on minimization, dt, and output files""" log.debug(f"Reading header of {mdout} mdout file") mdout_path = os.path.join(self.md_dir.value, mdout) found_min, found_dt, found_rst, found_mdcrd = (False, False, False, False) with open(mdout_path, 'r') as f: for i, line in enumerate(f): re1 = re.search(r"imin\s*=\s*([01])", line) if re1: self.mdout_info[mdout]["min"] = bool(int(re1.group(1))) found_min = True re2 = re.search(r"dt\s*=\s*([\.0-9]+)", line) if re2: self.mdout_info[mdout]["dt"] = float(re2.group(1)) found_dt = True re3 = re.search(r"^\| RESTRT: ([^\s]+)\s*$", line) if re3: self.mdout_info[mdout]["rst"] = re3.group(1) found_rst = True re4 = re.search(r"^\| MDCRD: ([^\s]+)\s*$", line) if re4: self.mdout_info[mdout]["mdcrd"] = re4.group(1) found_mdcrd = True if found_min and found_rst and found_mdcrd: if self.mdout_info[mdout][ "min"]: # if min, there's no dt to find log.debug( f"Finished reading header of {mdout}. Closing minimization file." ) break else: if found_dt: log.debug( f"Finished reading header of {mdout}. Closing MD file." ) break elif i > 150: log.debug( f"Could not find all the information within the first 150 lines of {mdout}. Closing file." ) break def is_min(self, mdout): """Returns True if minimization, False if MD, None if the 'imin' keyword was not found""" try: t = self.mdout_info[mdout]["min"] except KeyError: log.debug( f"Parsing {mdout} mdout file to see if it's a minimization") self.read_mdout_header(mdout) t = self.mdout_info[mdout].get("min", None) log.debug(f"{mdout} is a minimization: {t}") return t def stream_mdout(self): """Parse and stream data from mdout files (minimization or MD simulation)""" self.mdout_button.button_type = "default" self.clear_canvas() mdout = self.mdout_sel.value mdout_path = os.path.join(self.md_dir.value, mdout) mdout_data = copy.deepcopy(empty_mddata_dic) # open file with open(mdout_path, 'r') as f: log.debug(f"Parsing data from {mdout} mdout file") lines = [] # stop reading when reaching the following lines for line in f: if ("A V E R A G E S O V E R" in line) or ( "Maximum number of minimization cycles reached" in line): break lines.append(line) # check if min or md: parse_func = parse_min_data if self.is_min(mdout) else parse_md_data # parse in parallel with ProcessPoolExecutor(max_workers=max_workers) as ex: for res in ex.map(parse_func, lines): for k, v in res.items(): mdout_data[k].extend(v) # convert to numpy for key, lst in mdout_data.items(): mdout_data[key] = np.array(lst) # stream to CDS log.debug(f"Done. Streaming the data from {mdout}") self.mdinfo_CDS.stream(mdout_data) mdout_data = copy.deepcopy(empty_mddata_dic) self.mdout_button.button_type = "primary" def latest_mdout_files(self): """List all mdout files present in the MD directory, sorted by modification time""" mdout_files = [ f for f in os.listdir(self.md_dir.value) if re.search(r'.+\.(md)?out$', f) and ("nohup.out" not in f) ] mdout_files.sort( key=lambda f: os.path.getmtime(os.path.join(self.md_dir.value, f)), reverse=True) return mdout_files def get_mdout_files(self): """Update the list of mdout files and automatically select the latest one""" log.debug("Updating the list of mdout files") self.mdout_files = [None] # set mdout file to read self.mdout_files = self.latest_mdout_files() for mdout in self.mdout_files: if not mdout in self.mdout_info: self.mdout_info[mdout] = {} mdout_options = self.mdout_sel.options self.mdout_sel.options = self.mdout_files # if new mdout is created if len(self.mdout_files) > len(mdout_options): self.mdout_sel.value = self.mdout_files[0] def parse_mdinfo(self): """Parse and stream data read from the mdinfo file""" log.debug("Parsing mdinfo file") mdinfo_path = os.path.join(self.md_dir.value, "mdinfo") try: with open(mdinfo_path, 'r') as f: lines = f.readlines() except FileNotFoundError: log.error("No mdinfo file in the current directory") return mdinfo_data = copy.deepcopy(empty_mddata_dic) # min or md latest_mdout_file = self.latest_mdout_files()[0] parse_func = parse_min_data if self.is_min( latest_mdout_file) else parse_md_data for i, line in enumerate(lines): # data res = parse_func(line) for k, v in res.items(): mdinfo_data[k].extend(v) # number of steps re_steps = re.search( r"Total steps :\s*(\d+) \| Completed :\s*(\d+) \| Remaining :\s*(\d+)", line) if re_steps: total = int(re_steps.group(1)) completed = int(re_steps.group(2)) remaining = int(re_steps.group(3)) steps_patch = { "total": [(0, total)], "completed": [(0, completed)], "remaining": [(0, remaining)], } self.steps_CDS.patch(steps_patch) progress = 100 * completed / total self.progressbar.title.text = f"Progress: {progress:6.2f}%" self.progressbar.x_range.set_from_json("end", total) # calculation speed (ns/day) re_speed = re.search(r'Average timings for last', line) if re_speed: re_speed = re.search(r'ns/day =\s*([\.0-9]+)', lines[i + 2]) speed = float(re_speed.group(1)) self.calc_speed.text = f"Calculation speed:<br/>{speed} ns/day" # time remaining re_time = re.search(r'Estimated time remaining:\s*(.+).$', line) if re_time: time_left = re_time.group(1) time_left = pretty_time(time_left) self.eta.text = f"Estimated time remaining:<br/>{time_left}" break # last update self.last_update.text = f"Last update:<br/>{time_passed(os.path.getmtime(mdinfo_path))}" update_time = os.path.getmtime(mdinfo_path) if time.time() - update_time > 5 * 60: # not updated recently self.last_update.style = { "font-weight": "bold", "color": "#d62727", "margin-top": "5px" } else: self.last_update.style = { "font-weight": "bold", "color": "#444444", "margin-top": "5px" } # only update plots if monitoring the latest mdout file if self.mdout_sel.value == latest_mdout_file: log.debug( f"Currently watching the latest mdout '{self.mdout_sel.value}'" ) # fetch previous stream data as dict last_mdinfo_stream = self.mdinfo_CDS.to_df().tail(1).reset_index( drop=True).T.to_dict().get(0) if last_mdinfo_stream: # format the dict for key, value in last_mdinfo_stream.items(): last_mdinfo_stream[key] = [value] # update if mdinfo is different from the previous stream if mdinfo_data != last_mdinfo_stream: log.debug("Streaming new data from mdinfo") for key, value in mdinfo_data.items(): mdinfo_data[key] = np.array(value) self.mdinfo_CDS.stream(mdinfo_data) else: log.debug( f"No previous mdinfo data could be retrieved. Streaming new data" ) for key, value in mdinfo_data.items(): mdinfo_data[key] = np.array(value) self.mdinfo_CDS.stream(mdinfo_data) else: log.debug( f"Currently watching mdout '{self.mdout_sel.value}' != '{latest_mdout_file}'" ) def display_simulations_length(self): """Displays simulation length""" log.debug("Computing total time of simulation(s) displayed") current_time = OrderedDict() # discard min files and limit to XX most recent MD files self.md_mdout_files = [ f for f in self.mdout_sel.options if not self.is_min(f) ][:self.slider.value] for mdout in self.md_mdout_files: mdout_path = os.path.join(self.md_dir.value, mdout) i = 0 for line in readlines_reverse(mdout_path): i += 1 re1 = re.search(r"NSTEP =\s*(\d+)", line) if re1: current_time[mdout] = int( re1.group(1)) * self.mdout_info[mdout].get( "dt", 0.002) * 1e-3 # in ns break if i > 150: break data = pd.DataFrame.from_dict( current_time, orient="index", columns=["time"]).reset_index().rename(columns={"index": "mdout"}) # compute properties for the pie plot data['angle'] = data['time'] / data['time'].sum() * 2 * pi # color palette data['color'] = sim_palette[:len(current_time)] # reverse index order for the barplot data = data.reindex(index=data.index[::-1]).reset_index(drop=True) data = data.reset_index().rename(columns={"index": "y_coords"}) # update self.dashboard_CDS.data = {k: data[k].tolist() for k in data.columns} total_time = data["time"].sum() self.pie.title.text = f"Simulations length: {total_time:.2f} ns" def update_dashboard(self): log.debug("Starting update of the dashboard") self.get_mdout_files() self.parse_mdinfo() self.display_simulations_length() self.autoview_structure() log.debug("Finished updating the dashboard") def callback_slider(self, attr, old, new): log.debug(f"Slider update detected: from {old} to {new}") self.display_simulations_length() def add_callbacks(self): log.debug("Adding callbacks to the widgets") # User input self.md_dir.on_change("value_input", self.autocomp_callback) self.md_dir.on_change("value", self.traj_top_callback) # RMSD self.rmsd_button.on_click(self.compute_rmsd) # NGLView self.js_view_structure = CustomJS(code="", args={ "ligand_mask": self.ngl_lig, "repr": self.ngl_representations }) self.ngl_help_button.on_click(self.ngl_help) # hack to execute both python and JS code on button click self.view_button.js_on_change("label", self.js_view_structure) self.view_button.on_click(self.view_structure) # MDout parsing self.mdout_button.on_click(self.stream_mdout) self.slider.on_change("value_throttled", self.callback_slider)
def __init__(self, default_dir, port): # path to source directory self.src_dir = os.path.dirname(os.path.abspath(__file__)) # MD directory and files selection self.md_dir = TextInput( title="Path to MD directory containing mdin and mdout files", value="", width=750) self.anim_button = Toggle(label="▶ Load", button_type="warning", width=80, height=50, active=False) self.port = port # container for the buttons that are created while the user types in the textinput self.autocomp_results = column(children=[]) # file used to display temperature, pressure...etc. plots self.mdout_sel = Select( title="MDout file", width=230, value=None, options=[], ) # button to load content self.mdout_button = Button(width=80, height=50, label="Plot", button_type="primary") self.mdout_files = [None] self.md_mdout_files = [] # mdinfo figures progressbar_tooltip = """ <span style="color:#428df5">@completed{0,0}</span> out of <span style="color:#428df5">@total{0,0}</span> steps (<span style="color:#428df5">@remaining{0,0}</span> remaining) """ self.progressbar = figure(title="Current progress", x_range=Range1d(0, 10), tooltips=progressbar_tooltip, height=70, width=350, tools="hover", toolbar_location=None) self.progressbar.xgrid.grid_line_color = None self.progressbar.ygrid.grid_line_color = None self.progressbar.axis.visible = False self.progressbar.outline_line_color = "#444444" self.steps_CDS = ColumnDataSource({ "total": [np.nan], "completed": [np.nan], "remaining": [np.nan], "color": ['#428df5'], }) self.progressbar.hbar( y=0, left=0, right="completed", source=self.steps_CDS, height=0.5, color="color", ) self.progressbar.hover[0].mode = "hline" self.calc_speed = Div(width=150, height=50, text="Calculation speed:", style={ "font-weight": "bold", "color": "#444444", "margin-top": "5px" }) self.eta = Div(width=280, height=50, text="Estimated time remaining:", style={ "font-weight": "bold", "color": "#444444", "margin-top": "5px" }) self.last_update = Div(width=280, height=50, text="Last update:", style={ "font-weight": "bold", "color": "#444444", "margin-top": "5px" }) # number of mdout files displayed on the dashboard at max self.slider = Slider(start=1, end=12, value=2, step=1, callback_policy="mouseup", title="Number of simulations displayed") self.dashboard_CDS = ColumnDataSource({ "y_coords": [0, 1], "mdout": ["heat.out", "prod.out"], "time": [42, 200], "angle": [1.09, 5.193], "color": [sim_palette[0], sim_palette[1]], }) dashboard_tooltip = """ <span style="color:@color">@mdout</span>: @time{0,0.00} ns """ # pie plot self.pie = figure(plot_height=300, width=500, title="Simulations length", toolbar_location=None, tools="hover", tooltips=dashboard_tooltip, x_range=Range1d(-0.5, 1.0)) self.rpie = self.pie.wedge(x=0, y=1, radius=0.4, source=self.dashboard_CDS, start_angle=cumsum('angle', include_zero=True), end_angle=cumsum('angle'), line_color="white", fill_color='color', legend="mdout") self.pie.axis.axis_label = None self.pie.axis.visible = False self.pie.grid.grid_line_color = None self.pie.legend.label_text_font_size = '9pt' self.pie.legend.border_line_width = 0 self.pie.legend.border_line_alpha = 0 self.pie.legend.spacing = 0 self.pie.legend.margin = 0 # hbar plot self.bar = figure(width=850, plot_height=300, toolbar_location=None, tools="hover", tooltips=dashboard_tooltip) self.rbar = self.bar.hbar(y="y_coords", left=0, right="time", source=self.dashboard_CDS, height=0.8, color="color") self.bar.x_range.set_from_json("start", 0) self.bar.xaxis.axis_label = "Time (ns)" self.bar.yaxis.axis_label = None self.bar.yaxis.visible = False self.bar.hover[0].mode = "hline" ## Mdout figures self.mdinfo_CDS = ColumnDataSource(copy.deepcopy(empty_mddata_dic)) self.moving_avg_trans = CustomJSTransform(v_func=moving_avg_func) ticker = PrintfTickFormatter(format="%4.0e") # Temperature self.temperature_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.temperature_fig.toolbar.autohide = True self.temperature_fig.xaxis.axis_label = "Number of steps" self.temperature_fig.yaxis.axis_label = "Temperature (K)" self.temperature_fig.xaxis.formatter = ticker r = self.temperature_fig.line("Nsteps", "Temperature", color=palette[0], source=self.mdinfo_CDS, _width=1, alpha=0.15) self.temperature_fig.line(transform("Nsteps", self.moving_avg_trans), transform("Temperature", self.moving_avg_trans), color=colorscale(palette[0], 0.85), source=self.mdinfo_CDS, line_width=3) self.temperature_fig.add_tools(make_hover([r])) # Pressure self.pressure_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.pressure_fig.toolbar.autohide = True self.pressure_fig.xaxis.axis_label = "Number of steps" self.pressure_fig.yaxis.axis_label = "Pressure" self.pressure_fig.xaxis.formatter = ticker r = self.pressure_fig.line("Nsteps", "Pressure", color=palette[1], source=self.mdinfo_CDS, line_width=1, alpha=0.15) self.pressure_fig.line(transform("Nsteps", self.moving_avg_trans), transform("Pressure", self.moving_avg_trans), color=colorscale(palette[1], 0.85), source=self.mdinfo_CDS, line_width=3) self.pressure_fig.add_tools(make_hover([r])) # Energy self.energy_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) etot = self.energy_fig.line("Nsteps", "Etot", color=palette[2], source=self.mdinfo_CDS, line_width=1) ektot = self.energy_fig.line("Nsteps", "EKtot", color=palette[3], source=self.mdinfo_CDS, line_width=1) eptot = self.energy_fig.line("Nsteps", "EPtot", color=palette[4], source=self.mdinfo_CDS, line_width=1) legend = Legend(items=[ ("Total", [etot]), ("Kinetic", [ektot]), ("Potential", [eptot]), ], location="top_right") self.energy_fig.add_layout(legend, 'right') self.energy_fig.add_tools(make_hover([etot])) self.energy_fig.legend.location = "top_left" self.energy_fig.legend.click_policy = "hide" self.energy_fig.toolbar.autohide = True self.energy_fig.xaxis.axis_label = "Number of steps" self.energy_fig.yaxis.axis_label = "Energy" self.energy_fig.xaxis.formatter = ticker # Volume self.vol_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.vol_fig.toolbar.autohide = True self.vol_fig.xaxis.axis_label = "Number of steps" self.vol_fig.yaxis.axis_label = "Volume" self.vol_fig.xaxis.formatter = ticker r = self.vol_fig.line("Nsteps", "Volume", color=palette[6], source=self.mdinfo_CDS, line_width=1, alpha=0.15) self.vol_fig.line(transform("Nsteps", self.moving_avg_trans), transform("Volume", self.moving_avg_trans), color=colorscale(palette[6], 0.85), source=self.mdinfo_CDS, line_width=3) self.vol_fig.add_tools(make_hover([r])) # Density self.density_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.density_fig.toolbar.autohide = True self.density_fig.xaxis.axis_label = "Number of steps" self.density_fig.yaxis.axis_label = "Density" self.density_fig.xaxis.formatter = ticker r = self.density_fig.line("Nsteps", "Density", color=palette[7], source=self.mdinfo_CDS, line_width=1, alpha=0.15) self.density_fig.line(transform("Nsteps", self.moving_avg_trans), transform("Density", self.moving_avg_trans), color=colorscale(palette[7], 0.85), source=self.mdinfo_CDS, line_width=3) self.density_fig.add_tools(make_hover([r])) ## RMSD figure self.empty_rmsd_dic = {k: [] for k in ["Time", "RMSD"]} self.rmsd_CDS = ColumnDataSource(self.empty_rmsd_dic) self.rmsd_fig = figure( plot_height=size[1], plot_width=size[0], active_scroll="wheel_zoom", ) self.rmsd_fig.toolbar.autohide = True self.rmsd_fig.xaxis.axis_label = "Time (ps)" self.rmsd_fig.yaxis.axis_label = "RMSD (Å)" self.rmsd_fig.xaxis.formatter = ticker r = self.rmsd_fig.line("Time", "RMSD", color=palette[8], source=self.rmsd_CDS, line_width=2) self.rmsd_fig.add_tools( make_hover([r], tooltips=[("Time (ps)", "@Time{0,0}"), ("RMSD (Å)", "@RMSD")])) self.rmsd_button = Button(width=100, label="Calculate RMSD", button_type="primary") self.trajectory = MultiSelect( title="Trajectory file(s)", width=400, value=None, options=[], ) self.rst_traj = Select( title="Restart file", width=400, value=None, options=[], ) self.topology = Select( title="Topology file", width=200, value=None, options=[], ) self.mask = TextInput(title="Mask", value="protein@CA,C,O,N", width=200) # NGLview self.last_rst_update = 0 self.view_button = Button(width=80, label="Visualize", button_type="primary") self.view_canvas = Div(width=size[0], height=size[1] + 60, css_classes=["ngldiv"], text="") self.ngl_help_div = Div(width=0, height=0, text="") self.ngl_help_button = Toggle(width=80, label="Help", active=False) self.ngl_lig = TextInput(title="Ligand name", value="LIG", width=80) self.ngl_representations = CheckboxButtonGroup( labels=["Protein", "Ligand", "Water", "Lipids", "Ions"], active=[0, 1, 2, 3, 4], ) # info about simulation files (min, dt, rst and mdcrd files) self.mdout_info = {} # add callbacks self.add_callbacks() self.md_dir.value = default_dir
curdoc().add_root(layout_child) #iterator = iter(file_name_list) button = Button(label=' Play', width=60) button.on_click(animate) button_next = Button(label='Next', width=60) button_next.on_click(partial(next_image, files=file_name_list, action='next')) button_prev = Button(label='Prev', width=60) button_prev.on_click(partial(next_image, files=file_name_list, action='prev')) # https://bokeh.pydata.org/en/latest/docs/reference/models/widgets.inputs.html # TODO(ahundt) switch to AutocompleteInput with list of files file_textbox = TextInput(value=file_name_list[index].split('\\')[-1], width=width) # TODO(ahundt) load another file when it changes # def textbox_update(attrname, old, new): # plot.update(slider.value) # file_textbox.on_change(textbox_update) # Combine the bokeh plot on plot.state with the widgets plot_list = [[plot.state], [gripper_plot.state], [action_plot.state]] widget_list = [[slider, button, button_prev, button_next], [file_textbox]] # "gripper_action" plot, labels based on the gripper opening and closing plot_list.append([gripper_action_plot.state])
class StockApp(VBox): extra_generated_classes = [["StockApp", "StockApp", "VBox"]] jsmodel = "VBox" Y = Instance(ColumnDataSource) # plots hist1 = Instance(Plot) hist2 = Instance(Plot) hist3 = Instance(Plot) # data source source = Instance(ColumnDataSource) risk_source = Instance(ColumnDataSource) # layout boxes mainrow = Instance(HBox) ticker1_box = Instance(HBox) ticker2_box = Instance(HBox) ticker3_box = Instance(HBox) ticker4_box = Instance(HBox) ticker5_box = Instance(HBox) second_row = Instance(HBox) histrow = Instance(HBox) # inputs ticker1 = String(default="1.2*(1.1-x)") ticker1p = String(default="-1.2") ticker2 = String(default="4.0") ticker2p = String(default="0.0") ticker3 = String(default="500") ticker3_1 = String(default="252") ticker3_2 = String(default="0.01") ticker4 = String(default="100") ticker4_1 = String(default="1.01") ticker4_2 = String(default="Milstein") button = String(default="") ticker1_select = Instance(TextInput) ticker1p_select = Instance(TextInput) ticker2_select = Instance(TextInput) ticker2p_select = Instance(TextInput) ticker3_select = Instance(TextInput) ticker3_1_select = Instance(TextInput) ticker3_2_select = Instance(TextInput) ticker4_select = Instance(TextInput) ticker4_1_select = Instance(TextInput) ticker4_2_select = Instance(Select) button_select = Instance(TextInput) input_box = Instance(VBoxForm) def __init__(self, *args, **kwargs): super(StockApp, self).__init__(*args, **kwargs) self._dfs = {} @classmethod def create(cls): """ This function is called once, and is responsible for creating all objects (plots, datasources, etc) """ # create layout widgets obj = cls() obj.mainrow = HBox() obj.ticker1_box = HBox(width=500) obj.ticker2_box = HBox(width=500) obj.ticker3_box = HBox(width=467) obj.ticker4_box = HBox(width=500) obj.ticker5_box = HBox(width=500) obj.second_row = HBox() obj.histrow = HBox() obj.input_box = VBoxForm(width=600) # create input widgets obj.make_inputs() # outputs #obj.make_source() obj.main_mc(252,500,0.01,'Milstein',1.01) obj.make_plots() # layout obj.set_children() return obj def make_inputs(self): self.ticker1_select = TextInput( name='ticker1', title='Drift Function:', value='1.2*(1.1-x)', ) self.ticker1p_select = TextInput( name='ticker1p', title='Drift Derivative:', value='-1.2', ) self.ticker2_select = TextInput( name='ticker2', title='Volatility Function:', value='4.0', ) self.ticker2p_select = TextInput( name='ticker2p', title='Volatility Derivative:', value='0.0', ) self.ticker3_select = TextInput( name='ticker3', title='Number of Paths:', value='500' ) self.ticker3_1_select = TextInput( name='ticker3_1', title='Number of Points:', value='252' ) self.ticker3_2_select = TextInput( name='ticker3_2', title='Time Step:', value='0.01' ) self.ticker4_select = TextInput( name='ticker4', title='Histogram Line:', value='100' ) self.ticker4_1_select = TextInput( name='ticker4_1', title='Initial Value:', value='1.01' ) self.ticker4_2_select = Select( name='ticker4_2', title='MC Scheme:', value='Milstein', options=['Euler','Milstein', 'Pred/Corr'] ) self.button_select = TextInput( name='button', title='Type any word containing "run" to run Simulation ', value = '' ) def make_source(self): self.source = ColumnDataSource(data=self.Y) def main_mc(self,num_pts,num_paths, delta_t, method, Y0): def a(x): return eval(self.ticker1) def ap(x): return eval(self.ticker1p) def b(x): return eval(self.ticker2) def bp(x): return eval(self.ticker2p) rpaths = np.random.normal(0, delta_t, size=(num_pts,num_paths)) Y = np.array([[Y0]*num_paths]) dt_vec = np.array([delta_t]*num_paths) if method == 'Milstein': for i in xrange(0,num_pts): tY = Y[-1,:] dW = rpaths[i,:] Y = np.vstack([Y, tY + a(tY)*dt_vec + b(tY)*dW + 0.5*b(tY)*bp(tY)*(dW*dW-dt_vec)]) elif method == 'Pred/Corr': # Predictor corrector method is taken from equation 2.6 in this paper: # http://www.qfrc.uts.edu.au/research/research_papers/rp222.pdf rpaths2 = np.random.normal(0, delta_t, size=(num_pts,num_paths)) for i in xrange(0,num_pts): tY = Y[-1,:] Ybar = tY + a(tY)*dt_vec + b(tY)*rpaths[i,:] abar_before = a(tY) - 0.5*b(tY)*bp(tY) abar_after = a(Ybar) - 0.5*b(Ybar)*bp(Ybar) Y = np.vstack([Y, tY + 0.5*(abar_before + abar_after)*dt_vec + 0.5*(b(tY)+b(Ybar))*rpaths2[i,:]]) else: # default to Euler Scheme for i in xrange(0,num_pts): tY = Y[-1,:] Y = np.vstack([Y, tY + a(tY)*dt_vec + b(tY)*rpaths[i,:]]) return Y # return simulated paths def path_plot(self): num_paths_plot = min(50,int(self.ticker3)) hist_point = int(self.ticker4) #print 'Hist Point ', hist_point Y = self.Y.as_matrix() pltdat = Y[:,0:num_paths_plot] mY, MY = min(Y[hist_point,:]), max(Y[hist_point,:]) plt.plot(pltdat, alpha=0.1, linewidth=1.8) sns.tsplot(pltdat.T,err_style='ci_band', ci=[68,95,99], alpha=1, \ linewidth = 2.5, color='indianred') #sns.tsplot(pltdat.T,err_style='ci_band', ci=[68,95,99,99.99999], alpha=1, \ # linewidth = 2.5, condition='Mean Path', color='indianred') plt.plot([hist_point, hist_point], [0.99*mY, 1.01*MY], 'k-',label='Time Series Histogram') plt.xlabel('Time Step') plt.ylabel('Price') #plt.legend() p = mpl.to_bokeh() p.title = 'Mean Path (Red), MC Paths (Background) and Density Line (Black)' p.title_text_font_size= str(TITLE_SIZE)+'pt' return p def hist_den_plot(self): Y = self.Y.as_matrix() hist_point = int(self.ticker4) delta_t = float(self.ticker3_2) data = Y[hist_point,:] sns.distplot(data, color='k', hist_kws={"color":"b"}, norm_hist=True) #sns.distplot(data, color='k', hist_kws={"color":"b"}) plt.hist(data) plt.title('Distribution at T = ' + str(np.round(delta_t*hist_point,4)) + ' with Mean: ' +str(np.round(np.mean(data),4)) + ' and Std Dev: ' + str(np.round(np.std(data),4))) plt.xlabel('Price Bins') plt.ylabel('Bin Count') p = mpl.to_bokeh() p.title_text_font_size= str(TITLE_SIZE)+'pt' return p def mc_results(self): # Compute Monte Carlo results Y = self.Y.as_matrix() Y0 = float(self.ticker4_1) hist_point = int(self.ticker4) num_paths = int(self.ticker3) center_point = np.mean(Y[hist_point,:]) stkgrid = np.linspace(0.5*center_point,1.5*center_point,100) meanlst = np.array([]) stdlst = np.array([]) paylst = np.array([]) for stk in stkgrid: meanlst = np.append(meanlst, np.mean(payoff(Y[hist_point,:],stk))) stdlst = np.append(stdlst,np.std(payoff(Y[hist_point,:],stk))/np.sqrt(num_paths)) plt.plot(stkgrid,meanlst+2*stdlst, 'g-') plt.plot(stkgrid,meanlst-2*stdlst,'g-',label='2-Sig Error') plt.plot(stkgrid,meanlst+stdlst,'r-') plt.plot(stkgrid,meanlst-stdlst,'r-',label='1-Sig Error') plt.plot(stkgrid,meanlst,'b',label='Mean') plt.title('MC Option Price (Blue) with 1-Sig (Red) and 2-Sig (Green) Errors') plt.xlabel('Strike') plt.ylabel('Value') p = mpl.to_bokeh() p.title_text_font_size= str(TITLE_SIZE)+'pt' return p def hist_plot(self): histdf = pd.DataFrame(np.random.randn(100, 4), columns=list('ABCD')) #pltdf = self.source.to_df().set_index('date').dropna() #qlow, qhigh = mquantiles(pltdf[ticker],prob=[0.01,0.99]) #tdf = pltdf[ticker] #histdf = tdf[((tdf > qlow) & (tdf < qhigh))] hist, bins = np.histogram(histdf, bins=50) width = 0.7 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) / 2 start = bins.min() end = bins.max() top = hist.max() p = figure( title=' Histogram', plot_width=600, plot_height=400, tools="", title_text_font_size="16pt", x_range=[start, end], y_range=[0, top], x_axis_label = ' Bins', y_axis_label = 'Bin Count' ) p.rect(center, hist / 2.0, width, hist) return p def make_plots(self): self.hist_plots() def hist_plots(self): self.hist1 = self.path_plot() self.hist2 = self.hist_den_plot() self.hist3 = self.mc_results() def set_children(self): self.children = [self.mainrow, self.second_row] self.mainrow.children = [self.input_box, self.hist1] self.second_row.children = [self.hist2, self.hist3] self.input_box.children = [self.ticker1_box, self.ticker2_box, self.ticker3_box,self.ticker4_box,self.ticker5_box] self.ticker1_box.children =[self.ticker1_select, self.ticker1p_select] self.ticker2_box.children =[self.ticker2_select, self.ticker2p_select] self.ticker3_box.children =[self.ticker3_select, self.ticker3_1_select, self.ticker3_2_select] self.ticker4_box.children =[self.ticker4_select, self.ticker4_1_select, self.ticker4_2_select] self.ticker5_box.children =[self.button_select] def input_change(self, obj, attrname, old, new): if obj == self.ticker4_2_select: self.ticker4_2 = new if obj == self.ticker4_1_select: self.ticker4_1 = new if obj == self.ticker4_select: self.ticker4 = new if obj == self.ticker3_2_select: self.ticker3_2 = new if obj == self.ticker3_1_select: self.ticker3_1 = new if obj == self.ticker3_select: self.ticker3 = new if obj == self.ticker2p_select: self.ticker2p = new if obj == self.ticker2_select: self.ticker2 = new if obj == self.ticker1p_select: self.ticker1p = new if obj == self.ticker1_select: self.ticker1 = new if obj == self.button_select: self.button = new if 'run' in self.button: self.make_source() self.make_plots() self.set_children() curdoc().add(self) #self.make_source() #self.make_plots() #self.set_children() #curdoc().add(self) def setup_events(self): super(StockApp, self).setup_events() if self.ticker1_select: self.ticker1_select.on_change('value', self, 'input_change') if self.ticker1p_select: self.ticker1p_select.on_change('value', self, 'input_change') if self.ticker2_select: self.ticker2_select.on_change('value', self, 'input_change') if self.ticker2p_select: self.ticker2p_select.on_change('value', self, 'input_change') if self.ticker3_select: self.ticker3_select.on_change('value', self, 'input_change') if self.ticker3_1_select: self.ticker3_1_select.on_change('value', self, 'input_change') if self.ticker3_2_select: self.ticker3_2_select.on_change('value', self, 'input_change') if self.ticker4_select: self.ticker4_select.on_change('value', self, 'input_change') if self.ticker4_1_select: self.ticker4_1_select.on_change('value', self, 'input_change') if self.ticker4_2_select: self.ticker4_2_select.on_change('value', self, 'input_change') if self.button_select: self.button_select.on_change('value',self, 'input_change') @property def Y(self): tmpdf = pd.DataFrame(self.main_mc(int(self.ticker3_1),int(self.ticker3),float(self.ticker3_2),self.ticker4_2,float(self.ticker4_1))) tmpdf.columns = ['Col_' + str(i) for i in xrange(len(tmpdf.columns))] #print tmpdf return tmpdf
#================== #create plot #================== # Set up data #global: param_choice = data['resolution2'] # #source = ColumnDataSource(data=dict(x=data['scene_lat'] , y=data['scene_lon'], c=param_choice )) plot.circle('scene_lat', 'scene_lon', source=all_data, line_width=3, alpha=0.6) # Set up widgets text = TextInput(title="title", value='Daily Resolution') print("You've made it this far, traveller!") year_slider = Slider(title="Year", value=all_data['year'].min(), start=all_data['year'].min(), end=all_data['year'].max(), step=1) month_slider = Slider(title="Month", value=all_data['year'].min(), start=all_data['year'].min(), end=all_data['year'].max(), step=1) day_slider = DateSlider(title="Day", start=all_data['date'].min(), end=all_data['date'].max(), value=all_data['date'].min(), step=1) #year_slider = Slider(title="Year", value=data['year'].min(), start=data['year'].min(), end=data['year'].max(), step=1) #month_slider = Slider(title="Month", value=data['year'].min(), start=data['year'].min(), end=data['year'].max(), step=1) #day_slider = DateSlider(title="Day", start=data['date'].min(), end=data['date'].max(), value=data['date'].min(), step=1) #date = DateSlider(title="Day", start=data['date'].min(), end=data['date'].max(), value=data['date'].min(), step=1) #param_button_group = RadioButtonGroup(labels=["Resolution", "Potential Water", "Cloud Coverage", "Gelbstoff"], active=0) time_button_group = RadioButtonGroup(labels=["Yearly", "Monthly", "Daily"], active=0) # Set up callbacks
source = ColumnDataSource(data=dict(x=x, y=y)) # Set up plot plot = figure( plot_height=400, plot_width=400, title="my sine wave", tools="crosshair,pan,reset,save,wheel_zoom", x_range=[0, 4 * np.pi], y_range=[-2.5, 2.5], ) plot.line("x", "y", source=source, line_width=3, line_alpha=0.6) # Set up widgets text = TextInput(title="title", value="my sine wave") offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1) amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0, step=0.1) phase = Slider(title="phase", value=0.0, start=0.0, end=2 * np.pi) freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1, step=0.1) # Set up callbacks def update_title(attrname, old, new): plot.title.text = text.value text.on_change("value", update_title) def update_data(attrname, old, new):
def __init__(self): self.options = load_options() self.option_types = ['AUTH_USER_REQ', 'DISABLE_BACKUP_TAB', 'OPTIONAL_TABS', 'LITE_VIEW', 'COLORS', 'SIZE', 'LINE_WIDTH', 'LINE_DASH', 'ALPHA', 'ENDPOINT_COUNT', 'RESAMPLED_DVH_BIN_COUNT'] div = {key: Div(text=key) for key in self.option_types} self.input = {} self.input['AUTH_USER_REQ'] = RadioButtonGroup(labels=["True", "False"], active=1-int(self.options.AUTH_USER_REQ)) self.input['AUTH_USER_REQ'].on_change('active', self.update_auth_user_req) self.input['DISABLE_BACKUP_TAB'] = RadioButtonGroup(labels=["True", "False"], active=1-int(self.options.DISABLE_BACKUP_TAB)) self.input['DISABLE_BACKUP_TAB'].on_change('active', self.update_disable_backup_tab) labels = ['ROI Viewer', 'Planning Data', 'Time-Series', 'Correlation', 'Regression', 'MLC Analyzer'] active = [l for l in range(0, len(labels)) if self.options.OPTIONAL_TABS[labels[l]]] self.input['OPTIONAL_TABS'] = CheckboxGroup(labels=labels, active=active) self.input['OPTIONAL_TABS'].on_change('active', self.update_options_tabs) self.input['LITE_VIEW'] = RadioButtonGroup(labels=["True", "False"], active=1 - int(self.options.LITE_VIEW)) self.input['LITE_VIEW'].on_change('active', self.update_lite_view) color_variables = [c for c in self.options.__dict__ if c.find('COLOR') > -1] color_variables.sort() colors = plot_colors.cnames.keys() colors.sort() self.input['COLORS_var'] = Select(value=color_variables[0], options=color_variables) self.input['COLORS_var'].on_change('value', self.update_input_colors_var) self.input['COLORS_val'] = Select(value=getattr(self.options, color_variables[0]), options=colors) self.input['COLORS_val'].on_change('value', self.update_input_colors_val) size_variables = [s for s in self.options.__dict__ if s.find('SIZE') > -1] size_variables.sort() self.input['SIZE_var'] = Select(value=size_variables[0], options=size_variables) self.input['SIZE_var'].on_change('value', self.update_size_var) self.input['SIZE_val'] = TextInput(value=str(getattr(self.options, size_variables[0])).replace('pt', '')) self.input['SIZE_val'].on_change('value', self.update_size_val) width_variables = [l for l in self.options.__dict__ if l.find('LINE_WIDTH') > -1] width_variables.sort() self.input['LINE_WIDTH_var'] = Select(value=width_variables[0], options=width_variables) self.input['LINE_WIDTH_var'].on_change('value', self.update_line_width_var) self.input['LINE_WIDTH_val'] = TextInput(value=str(getattr(self.options, width_variables[0]))) self.input['LINE_WIDTH_val'].on_change('value', self.update_line_width_val) line_dash_variables = [d for d in self.options.__dict__ if d.find('LINE_DASH') > -1] line_dash_variables.sort() self.input['LINE_DASH_var'] = Select(value=line_dash_variables[0], options=line_dash_variables) self.input['LINE_DASH_var'].on_change('value', self.update_line_dash_var) line_dash_options = ['solid', 'dashed', 'dotted', 'dotdash', 'dashdot'] self.input['LINE_DASH_val'] = Select(value=getattr(self.options, line_dash_variables[0]), options=line_dash_options) self.input['LINE_DASH_val'].on_change('value', self.update_line_dash_val) alpha_variables = [a for a in self.options.__dict__ if a.find('ALPHA') > -1] alpha_variables.sort() self.input['ALPHA_var'] = Select(value=alpha_variables[0], options=alpha_variables) self.input['ALPHA_var'].on_change('value', self.update_alpha_var) self.input['ALPHA_val'] = TextInput(value=str(getattr(self.options, alpha_variables[0]))) self.input['ALPHA_val'].on_change('value', self.update_alpha_val) self.input['ENDPOINT_COUNT'] = TextInput(value=str(self.options.ENDPOINT_COUNT)) self.input['ENDPOINT_COUNT'].on_change('value', self.update_endpoint_count) self.input['RESAMPLED_DVH_BIN_COUNT'] = TextInput(value=str(self.options.RESAMPLED_DVH_BIN_COUNT)) self.input['RESAMPLED_DVH_BIN_COUNT'].on_change('value', self.update_resampled_dvh_bin_count) self.default_options_button = Button(label="Restore Default Options", button_type='warning') self.default_options_button.on_click(self.restore_default_options) self.layout = column(Div(text="<hr>", width=900), Div(text="<b>Options</b>"), row(div['AUTH_USER_REQ'], self.input['AUTH_USER_REQ']), row(div['DISABLE_BACKUP_TAB'], self.input['DISABLE_BACKUP_TAB']), row(div['OPTIONAL_TABS'], self.input['OPTIONAL_TABS']), row(div['LITE_VIEW'], self.input['LITE_VIEW']), row(div['COLORS'], self.input['COLORS_var'], self.input['COLORS_val']), row(div['SIZE'], self.input['SIZE_var'], self.input['SIZE_val']), row(div['LINE_WIDTH'], self.input['LINE_WIDTH_var'], self.input['LINE_WIDTH_val']), row(div['LINE_DASH'], self.input['LINE_DASH_var'], self.input['LINE_DASH_val']), row(div['ALPHA'], self.input['ALPHA_var'], self.input['ALPHA_val']), row(div['ENDPOINT_COUNT'], self.input['ENDPOINT_COUNT']), row(div['RESAMPLED_DVH_BIN_COUNT'], self.input['RESAMPLED_DVH_BIN_COUNT']), row(self.default_options_button, Div(text="Must restart Settings server to take effect after click")))
def plot(): # FIGURES AND X-AXIS fig1 = Figure(title = 'Dive Profile', plot_width = WIDTH, plot_height = HEIGHT, tools = TOOLS) fig2 = Figure(title = 'Dive Controls', plot_width = WIDTH, plot_height = HEIGHT, tools = TOOLS, x_range=fig1.x_range) fig3 = Figure(title = 'Attitude', plot_width = WIDTH, plot_height = HEIGHT, tools = TOOLS, x_range=fig1.x_range) figs = gridplot([[fig1],[fig2],[fig3]]) # Formatting x-axis timeticks = DatetimeTickFormatter(formats=dict(seconds =["%b%d %H:%M:%S"], minutes =["%b%d %H:%M"], hourmin =["%b%d %H:%M"], hours =["%b%d %H:%M"], days =["%b%d %H:%M"], months=["%b%d %H:%M"], years =["%b%d %H:%M %Y"])) fig1.xaxis.formatter = timeticks fig2.xaxis.formatter = timeticks fig3.xaxis.formatter = timeticks # removing gridlines fig1.xgrid.grid_line_color = None fig1.ygrid.grid_line_color = None fig2.xgrid.grid_line_color = None fig2.ygrid.grid_line_color = None fig3.xgrid.grid_line_color = None fig3.ygrid.grid_line_color = None # INPUT WIDGETS collection_list = CONN[DB].collection_names(include_system_collections=False) gliders = sorted([platformID for platformID in collection_list if len(platformID)>2]) gliders = Select(title = 'PlatformID', value = gliders[0], options = gliders) prev_glider = Button(label = '<') next_glider = Button(label = '>') glider_controlbox = HBox(children = [gliders, prev_glider, next_glider], height=80) chunkations = Select(title = 'Chunkation', value = 'segment', options = ['segment', '24hr', '30days', '-ALL-']) chunk_indicator = TextInput(title = 'index', value = '0') prev_chunk = Button(label = '<') next_chunk = Button(label = '>') chunk_ID = PreText(height=80) chunk_controlbox = HBox(chunkations, HBox(chunk_indicator, width=25), prev_chunk, next_chunk, chunk_ID, height = 80) control_box = HBox(glider_controlbox, chunk_controlbox) # DATA VARS deadby_date = '' depth = ColumnDataSource(dict(x=[],y=[])) vert_vel = ColumnDataSource(dict(x=[],y=[])) mbpump = ColumnDataSource(dict(x=[],y=[])) battpos = ColumnDataSource(dict(x=[],y=[])) pitch = ColumnDataSource(dict(x=[],y=[])) mfin = ColumnDataSource(dict(x=[],y=[])) cfin = ColumnDataSource(dict(x=[],y=[])) mroll = ColumnDataSource(dict(x=[],y=[])) mheading = ColumnDataSource(dict(x=[],y=[])) cheading = ColumnDataSource(dict(x=[],y=[])) # AXIS setup colors = COLORS[:] fig1.y_range.flipped = True fig1.yaxis.axis_label = 'm_depth (m)' fig1.extra_y_ranges = {'vert_vel': Range1d(start=-50, end=50), 'dummy': Range1d(start=0, end=100)} fig1.add_layout(place = 'right', obj = LinearAxis(y_range_name = 'vert_vel', axis_label = 'vertical velocity (cm/s)')) fig1.add_layout(place = 'left', obj = LinearAxis(y_range_name = 'dummy', axis_label = ' ')) fig1.yaxis[1].visible = False fig1.yaxis[1].axis_line_alpha = 0 fig1.yaxis[1].major_label_text_alpha = 0 fig1.yaxis[1].major_tick_line_alpha = 0 fig1.yaxis[1].minor_tick_line_alpha = 0 fig2.yaxis.axis_label = 'pitch (deg)' fig2.y_range.start, fig2.y_range.end = -40,40 fig2.extra_y_ranges = {'battpos': Range1d(start=-1, end = 1), 'bpump': Range1d(start=-275, end=275)} fig2.add_layout(place = 'right', obj = LinearAxis(y_range_name = 'battpos', axis_label = 'battpos (in)')) fig2.add_layout(place = 'left', obj = LinearAxis(y_range_name = 'bpump', axis_label = 'bpump (cc)')) fig2.yaxis[1].visible = False # necessary for spacing. later gets set to true fig3.yaxis.axis_label = 'fin/roll (deg)' fig3.y_range.start, fig3.y_range.end = -30, 30 fig3.extra_y_ranges = {'heading': Range1d(start=0, end=360), #TODO dynamic avg centering 'dummy': Range1d(start=0, end=100)} fig3.add_layout(place = 'right', obj = LinearAxis(y_range_name = 'heading', axis_label = 'headings (deg)')) fig3.add_layout(place = 'left', obj = LinearAxis(y_range_name = 'dummy', axis_label = ' ')) fig3.yaxis[1].visible = False fig3.yaxis[1].axis_line_alpha = 0 fig3.yaxis[1].major_label_text_alpha = 0 fig3.yaxis[1].major_tick_line_alpha = 0 fig3.yaxis[1].minor_tick_line_alpha = 0 # PLOT OBJECTS fig1.line( 'x', 'y', source = depth, legend = 'm_depth', color = 'red') fig1.circle('x', 'y', source = depth, legend = 'm_depth', color = 'red') fig1.line( 'x', 'y', source = vert_vel, legend = 'vert_vel', color = 'green', y_range_name = 'vert_vel') fig1.circle('x', 'y', source = vert_vel, legend = 'vert_vel', color = 'green', y_range_name = 'vert_vel') fig1.renderers.append(Span(location = 0, dimension = 'width', y_range_name = 'vert_vel', line_color= 'green', line_dash='dashed', line_width=1)) fig2.line( 'x', 'y', source = pitch, legend = "m_pitch", color = 'indigo') fig2.circle('x', 'y', source = pitch, legend = "m_pitch", color = 'indigo') fig2.line( 'x', 'y', source = battpos, legend = 'm_battpos', color = 'magenta', y_range_name = 'battpos') fig2.circle('x', 'y', source = battpos, legend = 'm_battpos', color = 'magenta', y_range_name = 'battpos') fig2.line( 'x', 'y', source = mbpump, legend = "m_'bpump'", color = 'blue', y_range_name = 'bpump') fig2.circle('x', 'y', source = mbpump, legend = "m_'bpump'", color = 'blue', y_range_name = 'bpump') fig2.renderers.append(Span(location = 0, dimension = 'width', line_color= 'black', line_dash='dashed', line_width=1)) fig3.line( 'x', 'y', source = mfin, legend = 'm_fin', color = 'cyan') fig3.circle('x', 'y', source = mfin, legend = 'm_fin', color = 'cyan') fig3.line( 'x', 'y', source = cfin, legend = 'c_fin', color = 'orange') fig3.circle('x', 'y', source = cfin, legend = 'c_fin', color = 'orange') fig3.line( 'x', 'y', source = mroll, legend = 'm_roll', color = 'magenta') fig3.circle('x', 'y', source = mroll, legend = 'm_roll', color = 'magenta') fig3.line( 'x', 'y', source = mheading, legend = 'm_heading', color = 'blue', y_range_name = 'heading') fig3.circle('x', 'y', source = mheading, legend = 'm_heading', color = 'blue', y_range_name = 'heading') fig3.line( 'x', 'y', source = cheading, legend = 'c_heading', color = 'indigo', y_range_name = 'heading') fig3.circle('x', 'y', source = cheading, legend = 'c_heading', color = 'indigo', y_range_name = 'heading') fig3.renderers.append(Span(location = 0, dimension = 'width', y_range_name = 'default', line_color= 'black', line_dash='dashed', line_width=1)) # CALLBACK FUNCS def update_data(attrib,old,new): g = gliders.value chnk = chunkations.value chindex = abs(int(chunk_indicator.value)) depth.data = dict(x=[],y=[]) vert_vel.data = dict(x=[],y=[]) mbpump.data = dict(x=[],y=[]) battpos.data = dict(x=[],y=[]) pitch.data = dict(x=[],y=[]) mfin.data = dict(x=[],y=[]) cfin.data = dict(x=[],y=[]) mroll.data = dict(x=[],y=[]) mheading.data = dict(x=[],y=[]) cheading.data = dict(x=[],y=[]) depth.data,startend = load_sensor(g, 'm_depth', chnk, chindex) if chnk == 'segment': xbd = startend[2] chunk_ID.text = '{} {} \n{} ({}) \nSTART: {} \nEND: {}'.format(g, xbd['mission'], xbd['onboard_filename'], xbd['the8x3_filename'], e2ts(xbd['start']), e2ts(xbd['end'])) if len(set(depth.data['x']))<=1 and attrib == 'chunk': if old > new: next_chunk.clicks += 1 else: prev_chunk.clicks += 1 return elif len(set(depth.data['x']))<=1 and chunk_indicator.value == 0: chunk_indicator.value = 1 elif chnk in ['24hr', '30days']: chunk_ID.text = '{} \nSTART: {} \nEND: {}'.format(g, e2ts(startend[0]), e2ts(startend[1])) elif chnk == '-ALL-': chunk_ID.text = '{} \nSTART: {} \nEND: {}'.format(g,e2ts(depth.data['x'][0] /1000), e2ts(depth.data['x'][-1]/1000)) vert_vel.data = calc_vert_vel(depth.data) mbpump.data,_ = load_sensor(g, 'm_de_oil_vol', chnk, chindex) if len(mbpump.data['x']) > 1: #for yax in fig2.select('mbpump'): # yax.legend = 'm_de_oil_vol' pass else: mbpump.data,_ = load_sensor(g, 'm_ballast_pumped', chnk, chindex) #for yax in fig2.select('mbpump'): # yax.legend = 'm_ballast_pumped' battpos.data,_ = load_sensor(g, 'm_battpos', chnk, chindex) pitch.data,_ = load_sensor(g, 'm_pitch', chnk, chindex) pitch.data['y'] = [math.degrees(y) for y in pitch.data['y']] mfin.data,_ = load_sensor(g, 'm_fin', chnk, chindex) cfin.data,_ = load_sensor(g, 'c_fin', chnk, chindex) mroll.data,_ = load_sensor(g, 'm_roll', chnk, chindex) mheading.data,_ = load_sensor(g, 'm_heading', chnk, chindex) cheading.data,_ = load_sensor(g, 'c_heading', chnk, chindex) mfin.data['y'] = [math.degrees(y) for y in mfin.data['y']] cfin.data['y'] = [math.degrees(y) for y in cfin.data['y']] mheading.data['y'] = [math.degrees(y) for y in mheading.data['y']] cheading.data['y'] = [math.degrees(y) for y in cheading.data['y']] mroll.data['y'] = [math.degrees(y) for y in mroll.data['y']] fig1.yaxis[1].visible = True fig2.yaxis[1].visible = True fig3.yaxis[1].visible = True #GLIDER SELECTS def glider_buttons(increment): ops = gliders.options new_index = ops.index(gliders.value) + increment if new_index >= len(ops): new_index = 0 elif new_index < 0: new_index = len(ops)-1 gliders.value = ops[new_index] chunkation_update(None, None, None) #reset chunk indicator and clicks def next_glider_func(): glider_buttons(1) def prev_glider_func(): glider_buttons(-1) def update_glider(attrib,old,new): chunk_indicator.value = '0' #update_data(None,None,None) gliders.on_change('value', update_glider) next_glider.on_click(next_glider_func) prev_glider.on_click(prev_glider_func) #CHUNK SELECTS def chunkation_update(attrib,old,new): chunk_indicator.value = '0' prev_chunk.clicks = 0 next_chunk.clicks = 0 update_data(None,None,None) if new == '-ALL-': chunk_indicator.value = '-' def chunk_func(): chunkdiff = prev_chunk.clicks - next_chunk.clicks if chunkdiff < 0: prev_chunk.clicks = 0 next_chunk.clicks = 0 chunkdiff = 0 print (chunkdiff) chunk_indicator.value = str(chunkdiff) def chunk_indicator_update(attrib,old,new): try: if abs(int(old)-int(new))>1: #manual update, triggers new non-manual indicator update, ie else clause below prev_chunk.clicks = int(new) next_chunk.clicks = 0 else: update_data('chunk',int(old),int(new)) print("UPDATE", old, new) except Exception as e: print(type(e),e, old, new) chunkations.on_change('value', chunkation_update) chunk_indicator.on_change('value', chunk_indicator_update) next_chunk.on_click(chunk_func) prev_chunk.on_click(chunk_func) update_data(None,None,None) return vplot(control_box, figs)
data.stream( dict(time=new_price["delayedPriceTime"], display_time=new_price["processedTime"], price=new_price["delayedPrice"]), 10000) return hover = HoverTool(tooltips=[("Time", "@display_time"), ("IEX Real-Time Price", "@price")]) price_plot = figure(plot_width=800, plot_height=400, x_axis_type='datetime', tools=[hover], title="Real-Time Price Plot") price_plot.line(source=data, x='time', y='price') price_plot.xaxis.axis_label = "Time" price_plot.yaxis.axis_label = "IEX Real-Time Price" price_plot.title.text = "IEX Real Time Price: " + TICKER ticker_textbox = TextInput(placeholder="Ticker") update = Button(label="Update") update.on_click(update_ticker) inputs = widgetbox([ticker_textbox, update], width=200) curdoc().add_root(row(inputs, price_plot, width=1600)) curdoc().title = "Real-Time Price Plot from IEX" curdoc().add_periodic_callback(update_price, 1000)
class Query: def __init__(self, sources, categories, dvhs, rad_bio, roi_viewer, time_series, correlation, regression, mlc_analyzer, custom_title, data_tables): self.sources = sources self.selector_categories = categories.selector self.range_categories = categories.range self.correlation_variables = categories.correlation_variables self.dvhs = dvhs self.rad_bio = rad_bio self.roi_viewer = roi_viewer self.time_series = time_series self.correlation = correlation self.regression = regression self.mlc_analyzer = mlc_analyzer self.uids = {n: [] for n in GROUP_LABELS} self.allow_source_update = True self.current_dvh = [] self.anon_id_map = [] self.colors = itertools.cycle(palette) # !!!!!!!!!!!!!!!!!!!!!!!!!!!! # Selection Filter UI objects # !!!!!!!!!!!!!!!!!!!!!!!!!!!! category_options = list(self.selector_categories) category_options.sort() # Add Current row to source self.add_selector_row_button = Button(label="Add Selection Filter", button_type="primary", width=200) self.add_selector_row_button.on_click(self.add_selector_row) # Row self.selector_row = Select(value='1', options=['1'], width=50, title="Row") self.selector_row.on_change('value', self.selector_row_ticker) # Category 1 self.select_category1 = Select(value="ROI Institutional Category", options=category_options, width=300, title="Category 1") self.select_category1.on_change('value', self.select_category1_ticker) # Category 2 cat_2_sql_table = self.selector_categories[self.select_category1.value]['table'] cat_2_var_name = self.selector_categories[self.select_category1.value]['var_name'] self.category2_values = DVH_SQL().get_unique_values(cat_2_sql_table, cat_2_var_name) self.select_category2 = Select(value=self.category2_values[0], options=self.category2_values, width=300, title="Category 2") self.select_category2.on_change('value', self.select_category2_ticker) # Misc self.delete_selector_row_button = Button(label="Delete", button_type="warning", width=100) self.delete_selector_row_button.on_click(self.delete_selector_row) self.group_selector = CheckboxButtonGroup(labels=["Group 1", "Group 2"], active=[0], width=180) self.group_selector.on_change('active', self.ensure_selector_group_is_assigned) self.selector_not_operator_checkbox = CheckboxGroup(labels=['Not'], active=[]) self.selector_not_operator_checkbox.on_change('active', self.selector_not_operator_ticker) # !!!!!!!!!!!!!!!!!!!!!!!!!!!! # Range Filter UI objects # !!!!!!!!!!!!!!!!!!!!!!!!!!!! category_options = list(self.range_categories) category_options.sort() # Add Current row to source self.add_range_row_button = Button(label="Add Range Filter", button_type="primary", width=200) self.add_range_row_button.on_click(self.add_range_row) # Row self.range_row = Select(value='', options=[''], width=50, title="Row") self.range_row.on_change('value', self.range_row_ticker) # Category self.select_category = Select(value=options.SELECT_CATEGORY_DEFAULT, options=category_options, width=240, title="Category") self.select_category.on_change('value', self.select_category_ticker) # Min and max self.text_min = TextInput(value='', title='Min: ', width=150) self.text_min.on_change('value', self.min_text_ticker) self.text_max = TextInput(value='', title='Max: ', width=150) self.text_max.on_change('value', self.max_text_ticker) # Misc self.delete_range_row_button = Button(label="Delete", button_type="warning", width=100) self.delete_range_row_button.on_click(self.delete_range_row) self.group_range = CheckboxButtonGroup(labels=["Group 1", "Group 2"], active=[0], width=180) self.group_range.on_change('active', self.ensure_range_group_is_assigned) self.range_not_operator_checkbox = CheckboxGroup(labels=['Not'], active=[]) self.range_not_operator_checkbox.on_change('active', self.range_not_operator_ticker) self.query_button = Button(label="Query", button_type="success", width=100) self.query_button.on_click(self.update_data) # define Download button and call download.js on click menu = [("All Data", "all"), ("Lite", "lite"), ("Only DVHs", "dvhs"), ("Anonymized DVHs", "anon_dvhs")] self.download_dropdown = Dropdown(label="Download", button_type="default", menu=menu, width=100) self.download_dropdown.callback = CustomJS(args=dict(source=sources.dvhs, source_rxs=sources.rxs, source_plans=sources.plans, source_beams=sources.beams), code=open(join(dirname(dirname(__file__)), "download.js")).read()) self.layout = column(Div(text="<b>DVH Analytics v%s</b>" % options.VERSION), row(custom_title['1']['query'], Spacer(width=50), custom_title['2']['query'], Spacer(width=50), self.query_button, Spacer(width=50), self.download_dropdown), Div(text="<b>Query by Categorical Data</b>", width=1000), self.add_selector_row_button, row(self.selector_row, Spacer(width=10), self.select_category1, self.select_category2, self.group_selector, self.delete_selector_row_button, Spacer(width=10), self.selector_not_operator_checkbox), data_tables.selection_filter, Div(text="<hr>", width=1050), Div(text="<b>Query by Numerical Data</b>", width=1000), self.add_range_row_button, row(self.range_row, Spacer(width=10), self.select_category, self.text_min, Spacer(width=30), self.text_max, Spacer(width=30), self.group_range, self.delete_range_row_button, Spacer(width=10), self.range_not_operator_checkbox), data_tables.range_filter) def get_query(self, group=None): if group: if group == 1: active_groups = [1] elif group == 2: active_groups = [2] else: active_groups = [1, 2] # Used to accumulate lists of query strings for each table # Will assume each item in list is complete query for that SQL column queries = {'Plans': [], 'Rxs': [], 'Beams': [], 'DVHs': []} # Used to group queries by variable, will combine all queries of same variable with an OR operator # e.g., queries_by_sql_column['Plans'][key] = list of strings, where key is sql column queries_by_sql_column = {'Plans': {}, 'Rxs': {}, 'Beams': {}, 'DVHs': {}} for active_group in active_groups: # Accumulate categorical query strings data = self.sources.selectors.data for r in data['row']: r = int(r) if data['group'][r - 1] in {active_group, 3}: var_name = self.selector_categories[data['category1'][r - 1]]['var_name'] table = self.selector_categories[data['category1'][r - 1]]['table'] value = data['category2'][r - 1] if data['not_status'][r - 1]: operator = "!=" else: operator = "=" query_str = "%s %s '%s'" % (var_name, operator, value) # Append query_str in query_by_sql_column if var_name not in queries_by_sql_column[table].keys(): queries_by_sql_column[table][var_name] = [] queries_by_sql_column[table][var_name].append(query_str) # Accumulate numerical query strings data = self.sources.ranges.data for r in data['row']: r = int(r) if data['group'][r - 1] in {active_group, 3}: var_name = self.range_categories[data['category'][r - 1]]['var_name'] table = self.range_categories[data['category'][r - 1]]['table'] value_low, value_high = data['min'][r - 1], data['max'][r - 1] if data['category'][r - 1] != 'Simulation Date': value_low, value_high = float(value_low), float(value_high) # Modify value_low and value_high so SQL interprets values as dates, if applicable if var_name in {'sim_study_date', 'birth_date'}: value_low = "'%s'" % value_low value_high = "'%s'" % value_high if data['not_status'][r - 1]: query_str = var_name + " NOT BETWEEN " + str(value_low) + " AND " + str(value_high) else: query_str = var_name + " BETWEEN " + str(value_low) + " AND " + str(value_high) # Append query_str in query_by_sql_column if var_name not in queries_by_sql_column[table]: queries_by_sql_column[table][var_name] = [] queries_by_sql_column[table][var_name].append(query_str) for table in queries: temp_str = [] for v in queries_by_sql_column[table].keys(): # collect all constraints for a given sql column into one list q_by_sql_col = [q for q in queries_by_sql_column[table][v]] # combine all constraints for a given sql column with 'or' operators temp_str.append("(%s)" % ' OR '.join(q_by_sql_col)) queries[table] = ' AND '.join(temp_str) print(str(datetime.now()), '%s = %s' % (table, queries[table]), sep=' ') # Get a list of UIDs that fit the plan, rx, and beam query criteria. DVH query criteria will not alter the # list of UIDs, therefore dvh_query is not needed to get the UID list print(str(datetime.now()), 'getting uids', sep=' ') uids = get_study_instance_uids(plans=queries['Plans'], rxs=queries['Rxs'], beams=queries['Beams'])['union'] # uids: a unique list of all uids that satisfy the criteria # queries['DVHs']: the dvh query string for SQL return uids, queries['DVHs'] # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # Functions for Querying by categorical data # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! def update_select_category2_values(self): new = self.select_category1.value table_new = self.selector_categories[new]['table'] var_name_new = self.selector_categories[new]['var_name'] new_options = DVH_SQL().get_unique_values(table_new, var_name_new) self.select_category2.options = new_options self.select_category2.value = new_options[0] def ensure_selector_group_is_assigned(self, attr, old, new): if not self.group_selector.active: self.group_selector.active = [-old[0] + 1] self.update_selector_source() def update_selector_source(self): if self.selector_row.value: r = int(self.selector_row.value) - 1 group = sum([i + 1 for i in self.group_selector.active]) group_labels = ['1', '2', '1 & 2'] group_label = group_labels[group - 1] not_status = ['', 'Not'][len(self.selector_not_operator_checkbox.active)] patch = {'category1': [(r, self.select_category1.value)], 'category2': [(r, self.select_category2.value)], 'group': [(r, group)], 'group_label': [(r, group_label)], 'not_status': [(r, not_status)]} self.sources.selectors.patch(patch) def add_selector_row(self): if self.sources.selectors.data['row']: temp = self.sources.selectors.data for key in list(temp): temp[key].append('') temp['row'][-1] = len(temp['row']) self.sources.selectors.data = temp new_options = [str(x + 1) for x in range(len(temp['row']))] self.selector_row.options = new_options self.selector_row.value = new_options[-1] self.select_category1.value = options.SELECT_CATEGORY1_DEFAULT self.select_category2.value = self.select_category2.options[0] self.selector_not_operator_checkbox.active = [] else: self.selector_row.options = ['1'] self.selector_row.value = '1' self.sources.selectors.data = dict(row=[1], category1=[''], category2=[''], group=[], group_label=[''], not_status=['']) self.update_selector_source() clear_source_selection(self.sources, 'selectors') def select_category1_ticker(self, attr, old, new): self.update_select_category2_values() self.update_selector_source() def select_category2_ticker(self, attr, old, new): self.update_selector_source() def selector_not_operator_ticker(self, attr, old, new): self.update_selector_source() def selector_row_ticker(self, attr, old, new): if self.sources.selectors.data['category1'] and self.sources.selectors.data['category1'][-1]: r = int(self.selector_row.value) - 1 category1 = self.sources.selectors.data['category1'][r] category2 = self.sources.selectors.data['category2'][r] group = self.sources.selectors.data['group'][r] not_status = self.sources.selectors.data['not_status'][r] self.select_category1.value = category1 self.select_category2.value = category2 self.group_selector.active = [[0], [1], [0, 1]][group - 1] if not_status: self.selector_not_operator_checkbox.active = [0] else: self.selector_not_operator_checkbox.active = [] def update_selector_row_on_selection(self, attr, old, new): if new: self.selector_row.value = self.selector_row.options[min(new)] def delete_selector_row(self): if self.selector_row.value: new_selectors_source = self.sources.selectors.data index_to_delete = int(self.selector_row.value) - 1 new_source_length = len(self.sources.selectors.data['category1']) - 1 if new_source_length == 0: clear_source_data(self.sources, 'selector') self.selector_row.options = [''] self.selector_row.value = '' self.group_selector.active = [0] self.selector_not_operator_checkbox.active = [] self.select_category1.value = options.SELECT_CATEGORY1_DEFAULT self.select_category2.value = self.select_category2.options[0] else: for key in list(new_selectors_source): new_selectors_source[key].pop(index_to_delete) for i in range(index_to_delete, new_source_length): new_selectors_source['row'][i] -= 1 self.selector_row.options = [str(x + 1) for x in range(new_source_length)] if self.selector_row.value not in self.selector_row.options: self.selector_row.value = self.selector_row.options[-1] self.sources.selectors.data = new_selectors_source clear_source_selection(self.sources, 'selectors') # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # Functions for Querying by numerical data # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! def add_range_row(self): if self.sources.ranges.data['row']: temp = self.sources.ranges.data for key in list(temp): temp[key].append('') temp['row'][-1] = len(temp['row']) self.sources.ranges.data = temp new_options = [str(x + 1) for x in range(len(temp['row']))] self.range_row.options = new_options self.range_row.value = new_options[-1] self.select_category.value = options.SELECT_CATEGORY_DEFAULT self.group_range.active = [0] self.range_not_operator_checkbox.active = [] else: self.range_row.options = ['1'] self.range_row.value = '1' self.sources.ranges.data = dict(row=['1'], category=[''], min=[''], max=[''], min_display=[''], max_display=[''], group=[''], group_label=[''], not_status=['']) self.update_range_titles(reset_values=True) self.update_range_source() clear_source_selection(self.sources, 'ranges') def update_range_source(self): if self.range_row.value: table = self.range_categories[self.select_category.value]['table'] var_name = self.range_categories[self.select_category.value]['var_name'] r = int(self.range_row.value) - 1 group = sum([i + 1 for i in self.group_range.active]) # a result of 3 means group 1 & 2 group_labels = ['1', '2', '1 & 2'] group_label = group_labels[group - 1] not_status = ['', 'Not'][len(self.range_not_operator_checkbox.active)] if self.select_category.value == 'Simulation Date': min_value = str(parse(self.text_min.value).date()) min_display = min_value max_value = str(parse(self.text_max.value).date()) max_display = max_value else: try: min_value = float(self.text_min.value) except ValueError: try: min_value = float(DVH_SQL().get_min_value(table, var_name)) except TypeError: min_value = '' try: max_value = float(self.text_max.value) except ValueError: try: max_value = float(DVH_SQL().get_max_value(table, var_name)) except TypeError: max_value = '' if min_value or min_value == 0.: min_display = "%s %s" % (str(min_value), self.range_categories[self.select_category.value]['units']) else: min_display = 'None' if max_value or max_value == 0.: max_display = "%s %s" % (str(max_value), self.range_categories[self.select_category.value]['units']) else: max_display = 'None' patch = {'category': [(r, self.select_category.value)], 'min': [(r, min_value)], 'max': [(r, max_value)], 'min_display': [(r, min_display)], 'max_display': [(r, max_display)], 'group': [(r, group)], 'group_label': [(r, group_label)], 'not_status': [(r, not_status)]} self.sources.ranges.patch(patch) self.group_range.active = [[0], [1], [0, 1]][group - 1] self.text_min.value = str(min_value) self.text_max.value = str(max_value) def update_range_titles(self, reset_values=False): table = self.range_categories[self.select_category.value]['table'] var_name = self.range_categories[self.select_category.value]['var_name'] min_value = DVH_SQL().get_min_value(table, var_name) self.text_min.title = 'Min: ' + str(min_value) + ' ' + self.range_categories[self.select_category.value]['units'] max_value = DVH_SQL().get_max_value(table, var_name) self.text_max.title = 'Max: ' + str(max_value) + ' ' + self.range_categories[self.select_category.value]['units'] if reset_values: self.text_min.value = str(min_value) self.text_max.value = str(max_value) def range_row_ticker(self, attr, old, new): if self.sources.ranges.data['category'] and self.sources.ranges.data['category'][-1]: r = int(new) - 1 category = self.sources.ranges.data['category'][r] min_new = self.sources.ranges.data['min'][r] max_new = self.sources.ranges.data['max'][r] group = self.sources.ranges.data['group'][r] not_status = self.sources.ranges.data['not_status'][r] self.allow_source_update = False self.select_category.value = category self.text_min.value = str(min_new) self.text_max.value = str(max_new) self.update_range_titles() self.group_range.active = [[0], [1], [0, 1]][group - 1] self.allow_source_update = True if not_status: self.range_not_operator_checkbox.active = [0] else: self.range_not_operator_checkbox.active = [] def select_category_ticker(self, attr, old, new): if self.allow_source_update: self.update_range_titles(reset_values=True) self.update_range_source() def min_text_ticker(self, attr, old, new): if self.allow_source_update: self.update_range_source() def max_text_ticker(self, attr, old, new): if self.allow_source_update: self.update_range_source() def range_not_operator_ticker(self, attr, old, new): if self.allow_source_update: self.update_range_source() def delete_range_row(self): if self.range_row.value: new_range_source = self.sources.ranges.data index_to_delete = int(self.range_row.value) - 1 new_source_length = len(self.sources.ranges.data['category']) - 1 if new_source_length == 0: clear_source_data(self.sources, 'ranges') self.range_row.options = [''] self.range_row.value = '' self.group_range.active = [0] self.range_not_operator_checkbox.active = [] self.select_category.value = options.SELECT_CATEGORY_DEFAULT self.text_min.value = '' self.text_max.value = '' else: for key in list(new_range_source): new_range_source[key].pop(index_to_delete) for i in range(index_to_delete, new_source_length): new_range_source['row'][i] -= 1 self.range_row.options = [str(x + 1) for x in range(new_source_length)] if self.range_row.value not in self.range_row.options: self.range_row.value = self.range_row.options[-1] self.sources.ranges.data = new_range_source clear_source_selection(self.sources, 'ranges') def ensure_range_group_is_assigned(self, attr, old, new): if not self.group_range.active: self.group_range.active = [-old[0] + 1] self.update_range_source() def update_range_row_on_selection(self, attr, old, new): if new: self.range_row.value = self.range_row.options[min(new)] # main update function def update_data(self): global BAD_UID BAD_UID = {n: [] for n in GROUP_LABELS} old_update_button_label = self.query_button.label old_update_button_type = self.query_button.button_type self.query_button.label = 'Updating...' self.query_button.button_type = 'warning' print(str(datetime.now()), 'Constructing query for complete dataset', sep=' ') uids, dvh_query_str = self.get_query() print(str(datetime.now()), 'getting dvh data', sep=' ') self.current_dvh = DVH(uid=uids, dvh_condition=dvh_query_str) if self.current_dvh.count: print(str(datetime.now()), 'initializing source data ', self.current_dvh.query, sep=' ') self.time_series.update_current_dvh_group(self.update_dvh_data(self.current_dvh)) if not options.LITE_VIEW: print(str(datetime.now()), 'updating correlation data') self.correlation.update_data(self.correlation_variables) print(str(datetime.now()), 'correlation data updated') self.dvhs.update_source_endpoint_calcs() if not options.LITE_VIEW: self.dvhs.calculate_review_dvh() self.rad_bio.initialize() self.time_series.y_axis.value = '' self.roi_viewer.update_mrn() try: self.mlc_analyzer.update_mrn() except: pass else: print(str(datetime.now()), 'empty dataset returned', sep=' ') self.query_button.label = 'No Data' self.query_button.button_type = 'danger' time.sleep(2.5) self.query_button.label = old_update_button_label self.query_button.button_type = old_update_button_type # updates beam ColumnSourceData for a given list of uids def update_beam_data(self, uids): cond_str = "study_instance_uid in ('" + "', '".join(uids) + "')" beam_data = QuerySQL('Beams', cond_str) groups = self.get_group_list(beam_data.study_instance_uid) anon_id = [self.anon_id_map[beam_data.mrn[i]] for i in range(len(beam_data.mrn))] attributes = ['mrn', 'beam_dose', 'beam_energy_min', 'beam_energy_max', 'beam_mu', 'beam_mu_per_deg', 'beam_mu_per_cp', 'beam_name', 'beam_number', 'beam_type', 'scan_mode', 'scan_spot_count', 'control_point_count', 'fx_count', 'fx_grp_beam_count', 'fx_grp_number', 'gantry_start', 'gantry_end', 'gantry_rot_dir', 'gantry_range', 'gantry_min', 'gantry_max', 'collimator_start', 'collimator_end', 'collimator_rot_dir', 'collimator_range', 'collimator_min', 'collimator_max', 'couch_start', 'couch_end', 'couch_rot_dir', 'couch_range', 'couch_min', 'couch_max', 'radiation_type', 'ssd', 'treatment_machine'] for i in ['min', 'mean', 'median', 'max']: for j in ['area', 'complexity', 'cp_mu', 'x_perim', 'y_perim']: attributes.append('%s_%s' % (j, i)) data = {attr: getattr(beam_data, attr) for attr in attributes} data['anon_id'] = anon_id data['group'] = groups data['uid'] = beam_data.study_instance_uid self.sources.beams.data = data # updates plan ColumnSourceData for a given list of uids def update_plan_data(self, uids): cond_str = "study_instance_uid in ('" + "', '".join(uids) + "')" plan_data = QuerySQL('Plans', cond_str) # Determine Groups groups = self.get_group_list(plan_data.study_instance_uid) anon_id = [self.anon_id_map[plan_data.mrn[i]] for i in range(len(plan_data.mrn))] attributes = ['mrn', 'age', 'birth_date', 'dose_grid_res', 'fxs', 'patient_orientation', 'patient_sex', 'physician', 'rx_dose', 'sim_study_date', 'total_mu', 'tx_modality', 'tx_site', 'heterogeneity_correction', 'complexity'] data = {attr: getattr(plan_data, attr) for attr in attributes} data['anon_id'] = anon_id data['group'] = groups data['uid'] = plan_data.study_instance_uid self.sources.plans.data = data # updates rx ColumnSourceData for a given list of uids def update_rx_data(self, uids): cond_str = "study_instance_uid in ('" + "', '".join(uids) + "')" rx_data = QuerySQL('Rxs', cond_str) groups = self.get_group_list(rx_data.study_instance_uid) anon_id = [self.anon_id_map[rx_data.mrn[i]] for i in range(len(rx_data.mrn))] attributes = ['mrn', 'plan_name', 'fx_dose', 'rx_percent', 'fxs', 'rx_dose', 'fx_grp_count', 'fx_grp_name', 'fx_grp_number', 'normalization_method', 'normalization_object'] data = {attr: getattr(rx_data, attr) for attr in attributes} data['anon_id'] = anon_id data['group'] = groups data['uid'] = rx_data.study_instance_uid self.sources.rxs.data = data def get_group_list(self, uids): groups = [] for r in range(len(uids)): if uids[r] in self.uids['1']: if uids[r] in self.uids['2']: groups.append('Group 1 & 2') else: groups.append('Group 1') else: groups.append('Group 2') return groups def update_dvh_data(self, dvh): dvh_group_1, dvh_group_2 = [], [] group_1_constraint_count, group_2_constraint_count = group_constraint_count(self.sources) if group_1_constraint_count and group_2_constraint_count: extra_rows = 12 elif group_1_constraint_count or group_2_constraint_count: extra_rows = 6 else: extra_rows = 0 print(str(datetime.now()), 'updating dvh data', sep=' ') line_colors = [color for j, color in itertools.izip(range(dvh.count + extra_rows), self.colors)] x_axis = np.round(np.add(np.linspace(0, dvh.bin_count, dvh.bin_count) / 100., 0.005), 3) print(str(datetime.now()), 'beginning stat calcs', sep=' ') if self.dvhs.radio_group_dose.active == 1: stat_dose_scale = 'relative' x_axis_stat = dvh.get_resampled_x_axis() else: stat_dose_scale = 'absolute' x_axis_stat = x_axis if self.dvhs.radio_group_volume.active == 0: stat_volume_scale = 'absolute' else: stat_volume_scale = 'relative' print(str(datetime.now()), 'calculating patches', sep=' ') if group_1_constraint_count == 0: self.uids['1'] = [] clear_source_data(self.sources, 'patch_1') clear_source_data(self.sources, 'stats_1') else: print(str(datetime.now()), 'Constructing Group 1 query', sep=' ') self.uids['1'], dvh_query_str = self.get_query(group=1) dvh_group_1 = DVH(uid=self.uids['1'], dvh_condition=dvh_query_str) self.uids['1'] = dvh_group_1.study_instance_uid stat_dvhs_1 = dvh_group_1.get_standard_stat_dvh(dose_scale=stat_dose_scale, volume_scale=stat_volume_scale) if self.dvhs.radio_group_dose.active == 1: x_axis_1 = dvh_group_1.get_resampled_x_axis() else: x_axis_1 = np.add(np.linspace(0, dvh_group_1.bin_count, dvh_group_1.bin_count) / 100., 0.005) self.sources.patch_1.data = {'x_patch': np.append(x_axis_1, x_axis_1[::-1]).tolist(), 'y_patch': np.append(stat_dvhs_1['q3'], stat_dvhs_1['q1'][::-1]).tolist()} self.sources.stats_1.data = {'x': x_axis_1.tolist(), 'min': stat_dvhs_1['min'].tolist(), 'q1': stat_dvhs_1['q1'].tolist(), 'mean': stat_dvhs_1['mean'].tolist(), 'median': stat_dvhs_1['median'].tolist(), 'q3': stat_dvhs_1['q3'].tolist(), 'max': stat_dvhs_1['max'].tolist()} if group_2_constraint_count == 0: self.uids['2'] = [] clear_source_data(self.sources, 'patch_2') clear_source_data(self.sources, 'stats_2') else: print(str(datetime.now()), 'Constructing Group 2 query', sep=' ') self.uids['2'], dvh_query_str = self.get_query(group=2) dvh_group_2 = DVH(uid=self.uids['2'], dvh_condition=dvh_query_str) self.uids['2'] = dvh_group_2.study_instance_uid stat_dvhs_2 = dvh_group_2.get_standard_stat_dvh(dose_scale=stat_dose_scale, volume_scale=stat_volume_scale) if self.dvhs.radio_group_dose.active == 1: x_axis_2 = dvh_group_2.get_resampled_x_axis() else: x_axis_2 = np.add(np.linspace(0, dvh_group_2.bin_count, dvh_group_2.bin_count) / 100., 0.005) self.sources.patch_2.data = {'x_patch': np.append(x_axis_2, x_axis_2[::-1]).tolist(), 'y_patch': np.append(stat_dvhs_2['q3'], stat_dvhs_2['q1'][::-1]).tolist()} self.sources.stats_2.data = {'x': x_axis_2.tolist(), 'min': stat_dvhs_2['min'].tolist(), 'q1': stat_dvhs_2['q1'].tolist(), 'mean': stat_dvhs_2['mean'].tolist(), 'median': stat_dvhs_2['median'].tolist(), 'q3': stat_dvhs_2['q3'].tolist(), 'max': stat_dvhs_2['max'].tolist()} print(str(datetime.now()), 'patches calculated', sep=' ') if self.dvhs.radio_group_dose.active == 0: x_scale = ['Gy'] * (dvh.count + extra_rows + 1) self.dvhs.plot.xaxis.axis_label = "Dose (Gy)" else: x_scale = ['%RxDose'] * (dvh.count + extra_rows + 1) self.dvhs.plot.xaxis.axis_label = "Relative Dose (to Rx)" if self.dvhs.radio_group_volume.active == 0: y_scale = ['cm^3'] * (dvh.count + extra_rows + 1) self.dvhs.plot.yaxis.axis_label = "Absolute Volume (cc)" else: y_scale = ['%Vol'] * (dvh.count + extra_rows + 1) self.dvhs.plot.yaxis.axis_label = "Relative Volume" # new_endpoint_columns = [''] * (dvh.count + extra_rows + 1) x_data, y_data = [], [] for n in range(dvh.count): if self.dvhs.radio_group_dose.active == 0: x_data.append(x_axis.tolist()) else: x_data.append(np.divide(x_axis, dvh.rx_dose[n]).tolist()) if self.dvhs.radio_group_volume.active == 0: y_data.append(np.multiply(dvh.dvh[:, n], dvh.volume[n]).tolist()) else: y_data.append(dvh.dvh[:, n].tolist()) y_names = ['Max', 'Q3', 'Median', 'Mean', 'Q1', 'Min'] # Determine Population group (blue (1) or red (2)) dvh_groups = [] for r in range(len(dvh.study_instance_uid)): current_uid = dvh.study_instance_uid[r] current_roi = dvh.roi_name[r] if dvh_group_1: for r1 in range(len(dvh_group_1.study_instance_uid)): if dvh_group_1.study_instance_uid[r1] == current_uid and dvh_group_1.roi_name[r1] == current_roi: dvh_groups.append('Group 1') if dvh_group_2: for r2 in range(len(dvh_group_2.study_instance_uid)): if dvh_group_2.study_instance_uid[r2] == current_uid and dvh_group_2.roi_name[r2] == current_roi: if len(dvh_groups) == r + 1: dvh_groups[r] = 'Group 1 & 2' else: dvh_groups.append('Group 2') if len(dvh_groups) < r + 1: dvh_groups.append('error') dvh_groups.insert(0, 'Review') for n in range(6): if group_1_constraint_count > 0: dvh.mrn.append(y_names[n]) dvh.roi_name.append('N/A') x_data.append(x_axis_stat.tolist()) current = stat_dvhs_1[y_names[n].lower()].tolist() y_data.append(current) dvh_groups.append('Group 1') if group_2_constraint_count > 0: dvh.mrn.append(y_names[n]) dvh.roi_name.append('N/A') x_data.append(x_axis_stat.tolist()) current = stat_dvhs_2[y_names[n].lower()].tolist() y_data.append(current) dvh_groups.append('Group 2') # Adjust dvh object to include stats data attributes = ['rx_dose', 'volume', 'surface_area', 'min_dose', 'mean_dose', 'max_dose', 'dist_to_ptv_min', 'dist_to_ptv_median', 'dist_to_ptv_mean', 'dist_to_ptv_max', 'dist_to_ptv_centroids', 'ptv_overlap', 'cross_section_max', 'cross_section_median', 'spread_x', 'spread_y', 'spread_z', 'toxicity_grade'] if extra_rows > 0: dvh.study_instance_uid.extend(['N/A'] * extra_rows) dvh.institutional_roi.extend(['N/A'] * extra_rows) dvh.physician_roi.extend(['N/A'] * extra_rows) dvh.roi_type.extend(['Stat'] * extra_rows) if group_1_constraint_count > 0: for attr in attributes: getattr(dvh, attr).extend(calc_stats(getattr(dvh_group_1, attr))) if group_2_constraint_count > 0: for attr in attributes: getattr(dvh, attr).extend(calc_stats(getattr(dvh_group_2, attr))) # Adjust dvh object for review dvh dvh.dvh = np.insert(dvh.dvh, 0, 0, 1) dvh.count += 1 dvh.mrn.insert(0, self.dvhs.select_reviewed_mrn.value) dvh.study_instance_uid.insert(0, '') dvh.institutional_roi.insert(0, '') dvh.physician_roi.insert(0, '') dvh.roi_name.insert(0, self.dvhs.select_reviewed_dvh.value) dvh.roi_type.insert(0, 'Review') dvh.rx_dose.insert(0, 0) dvh.volume.insert(0, 0) dvh.surface_area.insert(0, '') dvh.min_dose.insert(0, '') dvh.mean_dose.insert(0, '') dvh.max_dose.insert(0, '') dvh.dist_to_ptv_min.insert(0, 'N/A') dvh.dist_to_ptv_mean.insert(0, 'N/A') dvh.dist_to_ptv_median.insert(0, 'N/A') dvh.dist_to_ptv_max.insert(0, 'N/A') dvh.dist_to_ptv_centroids.insert(0, 'N/A') dvh.ptv_overlap.insert(0, 'N/A') dvh.cross_section_max.insert(0, 'N/A') dvh.cross_section_median.insert(0, 'N/A') dvh.spread_x.insert(0, 'N/A') dvh.spread_y.insert(0, 'N/A') dvh.spread_z.insert(0, 'N/A') dvh.toxicity_grade.insert(0, -1) line_colors.insert(0, options.REVIEW_DVH_COLOR) x_data.insert(0, [0]) y_data.insert(0, [0]) # anonymize ids self.anon_id_map = {mrn: i for i, mrn in enumerate(list(set(dvh.mrn)))} anon_id = [self.anon_id_map[dvh.mrn[i]] for i in range(len(dvh.mrn))] print(str(datetime.now()), "writing sources.dvhs.data", sep=' ') self.sources.dvhs.data = {'mrn': dvh.mrn, 'anon_id': anon_id, 'group': dvh_groups, 'uid': dvh.study_instance_uid, 'roi_institutional': dvh.institutional_roi, 'roi_physician': dvh.physician_roi, 'roi_name': dvh.roi_name, 'roi_type': dvh.roi_type, 'rx_dose': dvh.rx_dose, 'volume': dvh.volume, 'surface_area': dvh.surface_area, 'min_dose': dvh.min_dose, 'mean_dose': dvh.mean_dose, 'max_dose': dvh.max_dose, 'dist_to_ptv_min': dvh.dist_to_ptv_min, 'dist_to_ptv_mean': dvh.dist_to_ptv_mean, 'dist_to_ptv_median': dvh.dist_to_ptv_median, 'dist_to_ptv_max': dvh.dist_to_ptv_max, 'dist_to_ptv_centroids': dvh.dist_to_ptv_centroids, 'ptv_overlap': dvh.ptv_overlap, 'cross_section_max': dvh.cross_section_max, 'cross_section_median': dvh.cross_section_median, 'spread_x': dvh.spread_x, 'spread_y': dvh.spread_y, 'spread_z': dvh.spread_z, 'x': x_data, 'y': y_data, 'color': line_colors, 'x_scale': x_scale, 'y_scale': y_scale, 'toxicity_grade': dvh.toxicity_grade} print(str(datetime.now()), 'begin updating beam, plan, rx data sources', sep=' ') self.update_beam_data(dvh.study_instance_uid) self.update_plan_data(dvh.study_instance_uid) self.update_rx_data(dvh.study_instance_uid) print(str(datetime.now()), 'all sources set', sep=' ') return {'1': dvh_group_1, '2': dvh_group_2}
def volcano(data, folder='', tohighlight=None, tooltips=[('gene', '@gene_id')], title="volcano plot", xlabel='log-fold change', ylabel='-log(Q)', maxvalue=100, searchbox=False, logfoldtohighlight=0.15, pvaltohighlight=0.1, showlabels=False): """ Make an interactive volcano plot from Differential Expression analysis tools outputs Args: ----- data: a df with rows genes and cols [log2FoldChange, pvalue, gene_id] folder: str of location where to save the plot, won't save if empty tohighlight: list[str] of genes to highlight in the plot tooltips: list[tuples(str,str)] if user wants tot specify another bokeh tooltip title: str plot title xlabel: str if user wants to specify the title of the x axis ylabel: str if user wants tot specify the title of the y axis maxvalue: float the max -log2(pvalue authorized usefull when managing inf vals) searchbox: bool whether or not to add a searchBox to interactively highlight genes logfoldtohighlight: float min logfoldchange when to diplay points pvaltohighlight: float min pvalue when to diplay points showlabels: bool whether or not to show a text above each datapoint with its label information Returns: -------- The bokeh object """ # pdb.set_trace() to_plot_not, to_plot_yes = selector( data, tohighlight if tohighlight is not None else [], logfoldtohighlight, pvaltohighlight) hover = bokeh.models.HoverTool(tooltips=tooltips, names=['circles']) # Create figure p = bokeh.plotting.figure(title=title, plot_width=650, plot_height=450) p.xgrid.grid_line_color = 'white' p.ygrid.grid_line_color = 'white' p.xaxis.axis_label = xlabel p.yaxis.axis_label = ylabel # Add the hover tool p.add_tools(hover) p, source1 = add_points(p, to_plot_not, 'log2FoldChange', 'pvalue', color='#1a9641', maxvalue=maxvalue) p, source2 = add_points(p, to_plot_yes, 'log2FoldChange', 'pvalue', color='#fc8d59', alpha=0.6, outline=True, maxvalue=maxvalue) if showlabels: labels = LabelSet(x='log2FoldChange', y='transformed_q', text_font_size='7pt', text="gene_id", level="glyph", x_offset=5, y_offset=5, source=source2, render_mode='canvas') p.add_layout(labels) if searchbox: text = TextInput(title="text", value="gene") text.js_on_change( 'value', CustomJS(args=dict(source=source1), code=""" var data = source.data var value = cb_obj.value var gene_id = data.gene_id var a = -1 for (let i=0; i < gene_id.length; i++) { if ( gene_id[i]===value ) { a=i; console.log(i); data.size[i]=7; data.alpha[i]=1; data.color[i]='#fc8d59' } } source.data = data console.log(source) console.log(cb_obj) source.change.emit() console.log(source) """)) p = column(text, p) p.output_backend = "svg" if folder: save(p, folder + title.replace(' ', "_") + "_volcano.html") export_svg(p, filename=folder + title.replace(' ', "_") + "_volcano.svg") try: show(p) except: show(p) return p
PLOT_WIDTH=500 sourceQuad = ColumnDataSource(dict(left=[min(source_small.data['x'])],top=[Max_Y],right=[max(source_small.data['x'])],bottom=[Min_Y])) toolset = "box_zoom,resize,pan,reset,save,xwheel_zoom" plot_zoomed = Figure(plot_width=1000, plot_height=500, x_axis_type="datetime",tools=toolset, lod_factor=100,lod_interval=1000) plot_zoomed.line('x', 'y',source=source_zoomed, color='navy', alpha=0.5) plot = Figure(plot_width=PLOT_WIDTH, plot_height=250, x_axis_type="datetime",toolbar_location=None,lod_factor=100,lod_interval=1000) plot.line('x', 'y',source=source_small, color='navy', alpha=0.5) plot.y_range.start=Min_Y plot.y_range.end=Max_Y glyph = Quad(left="left", right="right", top="top", bottom="bottom", fill_color="#b3de69", fill_alpha=0.1) plot.add_glyph(sourceQuad, glyph) RangeStartX=0 RangeEndX=1 text_start_x = TextInput(title="X range start", name='x_range_start', value="0") text_end_x = TextInput(title="X range end", name='x_range_end', value="1") text_start_x.on_change('value', update_data) text_end_x.on_change('value', update_data) toolset = "box_zoom,resize,pan,reset,save,x_wheel_zoom" plot_zoomed.x_range.callback = CustomJS(args=dict(xrange=plot_zoomed.x_range,start_x=text_start_x,end_x=text_end_x),code=""" var start = xrange.get("start"); var end = xrange.get("end"); start_x.set("value",start.toString()); end_x.set("value",end.toString()); start_x.trigger('change'); end_x.trigger('change'); """)
# Authorize access to discogs database d = discogs_client.Client(user_agent, user_token=user_token) df = pd.read_csv(join(dirname(__file__), 'decks_genre_filtered.csv')) # df.release_date.apply(lambda x: datetime.strptime(x, "%Y-%m-%d")) source = ColumnDataSource(data=dict()) # Input Buttons genre_filter = [ 'All', 'Acid', 'Ambient', 'Breaks', 'Chicago', 'Deep House', 'Detroit', 'Dub Techno', 'House', 'Minimal', 'Techhouse', 'Techno' ] genre = Select(title="genre", value="All", options=genre_filter) slider_min = Slider(title="Minimum Price", start=0, end=25, value=0, step=1) slider_max = Slider(title="Maximum Price", start=0, end=150, value=20, step=1) search_text = TextInput(title="Search") columns = [ TableColumn(field="release_date", title="Release Date"), TableColumn(field="release", title="Release Name"), TableColumn(field="artist", title="Artist"), TableColumn(field="label", title="Label"), TableColumn(field="genre", title="Genre"), TableColumn(field="catalog_num", title="Catalog Number"), TableColumn(field="price", title="Price (in USD)", formatter=NumberFormatter(format="$0.00")), TableColumn(field="in_stock", title="Percent Available", formatter=NumberFormatter(format="‘0.00%")) ]
tools = [PanTool(), BoxZoomTool(), WheelZoomTool(), ResetTool(), hover, PreviewSaveTool()] p = Figure(title="NicheLife Map", plot_width=800, plot_height=700, tools=tools) # tools="pan,wheel_zoom,reset,box_zoom,save") # toolbar_location="top", #box_select, p.grid.grid_line_alpha = 0 p.patches("ct_x", "ct_y", source=source, fill_color="QI_colmap", fill_alpha=0.7, line_color="white", line_width=0.5) # image1 = ImageURL(url=source.data["image"], x=-74.04, y=40.85) # p.add_glyph(source, image1) p.image_url(url=imageurl, x="-74.04", y="40.85") # Set up widgets text = TextInput(title="Map Name", value="NicheLife Map") feature1 = Slider(title="Subway Accessibility", value=0.5, start=0, end=1, step=0.1) feature2 = Slider(title="Safety", value=0.5, start=0, end=1, step=0.1) feature3 = Slider(title="Public Satisfaction", value=0.5, start=0, end=1, step=0.1) feature4 = Slider(title="Restaurants", value=0.5, start=0, end=1, step=0.1) feature5 = Slider(title="Grocery Stores", value=0.5, start=0, end=1, step=0.1) feature6 = Slider(title="Nightlife", value=0.5, start=0, end=1, step=0.1) price = Select(title="Show Affordability", options=["Yes", "No"]) # Set up callbacks def update_title(attrname, old, new): p.title = text.value text.on_change("value", update_title)
metric.value, size=10, color=color_set[i % len(color_set)], source=main_source[i]) i += 1 return p def update(attr, old, new): layout.children[1] = create_figure() #Creates the widgets and updates values when they are changed cat = Select(title="Category:", value="ReagentLot", options=cat_list) cat.on_change('value', update) metric = Select(title="Metric:", value="Q30", options=metric_list) metric.on_change('value', update) text = TextInput(title='N', value='300') text.on_change('value', update) cat_wig = widgetbox(cat) metric_wig = widgetbox(metric) text_wig = widgetbox(text) layout = column(row(metric_wig, cat_wig, text_wig), create_figure()) curdoc().add_root(layout)
# p_logo = figure(toolbar_location=None, tools = "lasso_select", x_range=(0,1), y_range=(0,1), plot_width=520, plot_height=200) # img = mpimg.imread("cylance_logo.png") # p_logo.image_url(url=["cylance_logo.png"], x=0, y=0) # p_logo.background_fill_color = "black" # p_logo.border_fill_color = "black" # p_logo.grid.grid_line_color = "black" # p_logo.outline_line_color = "black" # radio button group for uploading file radio_group = RadioButtonGroup(labels=["NO-SPLIT", "SPLIT", "START"], button_type="success") radio_group.width = 500 radio_group.on_click(_fit_util) # text for console output text_input = TextInput(value="", title="CONSOLE") text_input.width = 500 cluster_stats = Div( render_as_text=False, text=generate_display_string("", name="Cluster Statistics", height=100) ) cluster_stats.width = 500 cluster_stats.height = 100 cluster_commonality = Div( render_as_text=False, text=generate_display_string("") ) cluster_commonality.width = 500 cluster_commonality.height = 300
def initialize(curr_doc: CurrentDoc, max_indep_elements=20, catch_radius=0.15): """ Creates and configures all bokeh objects and starts the web app. :param max_indep_elements: maximum number of node independent elements accepted in the input plot (int) :param catch_radius: radius in which to select an element in input plot (double) :return: none """ curr_doc.catch_radius = catch_radius ''' ############################### # TEXT BOXES ############################### ''' # Div object showing x and y position of the cursor in the input plot div_xy = Div(width=75, height=25) # Div object showing hints for the graphical input into the input plot through the element buttons div_input_width = curr_doc.plot_input.plot_width - div_xy.width - 10 curr_doc.div_input = Div(width=div_input_width, height=div_xy.height) # Div object showing general text messages to the user curr_doc.div_msg = Div(css_classes=["MSG_BOX"], text=" ", width=curr_doc.plot_input.plot_width, height=100) # doc.div_msg = Div(css_classes=["MSG_BOX"], text=" ", width=doc.plot_input.plot_width, height=100) ''' ############################### # INPUT PLOT ############################### ''' # style and configuration of the input plot # this plot is used to allow the user to connect mechanical elements tooltips = [("name", "@name_user"), ("(x, y)", "(@x{0.0}, @y{0.0})")] curr_doc.plot_input = figure( # plot_width=600, plot_height=300, tools="pan,wheel_zoom,reset,lasso_select,hover,save", toolbar_location="above", # x_axis_label='x', y_axis_label='y', x_minor_ticks=10, y_minor_ticks=10, x_range=Range1d(start=0, end=5), y_range=Range1d(start=0, end=5), match_aspect=True, aspect_scale=1.0, tooltips=tooltips, ) curr_doc.plot_input.toolbar.logo = None configure_input_plot(curr_doc, curr_doc.plot_input, div_xy, max_indep_elements) ''' ############################### # OUTPUT PLOTS ############################### ''' # initialize plots for the output after calculations plot_output_width = 800 plot_output_height = 250 curr_doc.plot_normal_f = figure(plot_width=plot_output_width, plot_height=plot_output_height, active_scroll="wheel_zoom") curr_doc.plot_normal_f.toolbar.logo = None curr_doc.plot_normal_f.title.text = 'Normal force' curr_doc.plot_normal_disp = figure(plot_width=plot_output_width, plot_height=plot_output_height, active_scroll="wheel_zoom") curr_doc.plot_normal_disp.toolbar.logo = None curr_doc.plot_normal_disp.title.text = 'Normal displacement' curr_doc.plot_shear_f = figure(plot_width=plot_output_width, plot_height=plot_output_height, active_scroll="wheel_zoom") curr_doc.plot_shear_f.toolbar.logo = None curr_doc.plot_shear_f.title.text = 'Shear force' curr_doc.plot_moment = figure(plot_width=plot_output_width, plot_height=plot_output_height, active_scroll="wheel_zoom") curr_doc.plot_moment.toolbar.logo = None curr_doc.plot_moment.title.text = 'Bending moment' curr_doc.plot_shear_disp = figure(plot_width=plot_output_width, plot_height=plot_output_height, active_scroll="wheel_zoom") curr_doc.plot_shear_disp.toolbar.logo = None curr_doc.plot_shear_disp.title.text = 'Shear displacement' curr_doc.plot_shear_angle = figure(plot_width=plot_output_width, plot_height=plot_output_height, active_scroll="wheel_zoom") curr_doc.plot_shear_angle.toolbar.logo = None curr_doc.plot_shear_angle.title.text = 'Rotation angle' curr_doc.plot_list = [ curr_doc.plot_normal_f, curr_doc.plot_normal_disp, curr_doc.plot_shear_f, curr_doc.plot_moment, curr_doc.plot_shear_angle, curr_doc.plot_shear_disp ] # add plot renderer ds = ColumnDataSource(data=dict(x=[], y=[])) curr_doc.plot_normal_f.circle('x', 'y', source=ds) curr_doc.plot_normal_disp.circle('x', 'y', source=ds) curr_doc.plot_shear_f.circle('x', 'y', source=ds) curr_doc.plot_moment.circle('x', 'y', source=ds) curr_doc.plot_shear_disp.circle('x', 'y', source=ds) curr_doc.plot_normal_f.circle('x', 'y', source=ds) curr_doc.plot_shear_angle.circle('x', 'y', source=ds) ''' ############################### # TEST CASES ############################### ''' menu_tc = [("Single beam load", "single_beam_load"), ("Two beam lineload", "two_beam_lineload"), ("Angled structure", "fin_struc_soft_lab")] dropdown_tc = Dropdown(label="Show test case", menu=menu_tc, width=150) dropdown_tc.on_change('value', partial(vis_cbs.cb_plot_testcase, curr_doc=curr_doc)) # partial(vis_cbs.cb_get_textinput, key=key_elinfo_n) ''' ############################### # CALCULATE AND DELETE BUTTONS ############################### ''' # add and configure a button to start calculations button_calc = Button(label="Calculate", width=240) button_calc.on_click( partial(vis_cbs.cb_button_calculation, curr_doc, button_calc)) # add and configure a button to delete selected elements of the input graph b_del_w = int((button_calc.width - 10) / 2) button_del_selected = Button(label="Delete selected", width=b_del_w) button_del_selected.on_click( partial(vis_cbs.cb_button_delete, curr_doc=curr_doc, all_selected=False)) # add and configure a button to delete selected elements of the input graph button_del_all = Button(label="Delete all", width=b_del_w) button_del_all.on_click( partial(vis_cbs.cb_button_delete, curr_doc=curr_doc, all_selected=True)) ''' ############################################ # BOX OF ELEMENTS TO SELECT FOR INPUT PLOT ############################################ ''' # titles for groups of mechanical elements text_supports = Div(text="Supports:", width=100, height=20) text_springs = Div(text="Springs:", width=100, height=20) text_node = Div(text="Node:", width=100, height=20) text_joints = Div(text="Joints:", width=100, height=20) text_elements = Div(text="Line elements:", width=100, height=20) text_loads = Div(text="Loads:", width=100, height=20) b_height = 50 b_line_width = 72 # configure buttons for mechanical supports button_support_clamped = Button( label="", css_classes=[eLnum.ElSupEnum.SUPPORT_CLAMPED.name], width=b_height, height=b_height) curr_doc.buttons[ eLnum.ElSupEnum.SUPPORT_CLAMPED.value] = button_support_clamped button_support_clamped.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SUPPORT_CLAMPED)) button_support_normal = Button( label="", css_classes=[eLnum.ElSupEnum.SUPPORT_NORMAL_FORCE.name], width=b_height, height=b_height) curr_doc.buttons[ eLnum.ElSupEnum.SUPPORT_NORMAL_FORCE.value] = button_support_normal button_support_normal.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SUPPORT_NORMAL_FORCE)) button_support_transverse = Button( label="", css_classes=[eLnum.ElSupEnum.SUPPORT_TRANSVERSE_FORCE.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.SUPPORT_TRANSVERSE_FORCE. value] = button_support_transverse button_support_transverse.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SUPPORT_TRANSVERSE_FORCE)) button_support_fixed_conti = Button( label="", css_classes=[eLnum.ElSupEnum.SUPPORT_FIXED_CONTINUOUS.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.SUPPORT_FIXED_CONTINUOUS. value] = button_support_fixed_conti button_support_fixed_conti.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SUPPORT_FIXED_CONTINUOUS)) button_support_fixed_joint = Button( label="", css_classes=[eLnum.ElSupEnum.SUPPORT_FIXED_JOINT.name], width=b_height, height=b_height) curr_doc.buttons[ eLnum.ElSupEnum.SUPPORT_FIXED_JOINT.value] = button_support_fixed_joint button_support_fixed_joint.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SUPPORT_FIXED_JOINT)) button_support_roller_conti = Button( label="", css_classes=[eLnum.ElSupEnum.SUPPORT_ROLLER_CONTINUOUS.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.SUPPORT_ROLLER_CONTINUOUS. value] = button_support_roller_conti button_support_roller_conti.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SUPPORT_ROLLER_CONTINUOUS)) button_support_roller_joint = Button( label="", css_classes=[eLnum.ElSupEnum.SUPPORT_ROLLER_JOINT.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.SUPPORT_ROLLER_JOINT. value] = button_support_roller_joint button_support_roller_joint.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SUPPORT_ROLLER_JOINT)) button_spring_support = Button( label="", css_classes=[eLnum.ElSupEnum.SPRING_SUPPORT.name], width=b_height, height=b_height) curr_doc.buttons[ eLnum.ElSupEnum.SPRING_SUPPORT.value] = button_spring_support button_spring_support.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SPRING_SUPPORT)) button_spring_moment_support = Button( label="", css_classes=[eLnum.ElSupEnum.SPRING_MOMENT_SUPPORT.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.SPRING_MOMENT_SUPPORT. value] = button_spring_moment_support button_spring_moment_support.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SPRING_MOMENT_SUPPORT)) # configure curr_doc.buttons for connectors button_node = Button(label="", css_classes=[eLnum.ElSupEnum.NODE.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.NODE.value] = button_node button_node.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.NODE)) button_joint = Button(label="", css_classes=[eLnum.ElSupEnum.JOINT.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.JOINT.value] = button_joint button_joint.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.JOINT)) button_joint_normal = Button( label="", css_classes=[eLnum.ElSupEnum.JOINT_NORMAL_FORCE.name], width=b_height, height=b_height) curr_doc.buttons[ eLnum.ElSupEnum.JOINT_NORMAL_FORCE.value] = button_joint_normal button_joint_normal.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.JOINT_NORMAL_FORCE)) button_joint_transverse = Button( label="", css_classes=[eLnum.ElSupEnum.JOINT_TRANSVERSE_FORCE.name], width=b_height, height=b_height) curr_doc.buttons[ eLnum.ElSupEnum.JOINT_TRANSVERSE_FORCE.value] = button_joint_transverse button_joint_transverse.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.JOINT_TRANSVERSE_FORCE)) button_spring = Button(label="", css_classes=[eLnum.ElSupEnum.SPRING.name], width=b_line_width, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.SPRING.value] = button_spring button_spring.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.SPRING)) # configure buttons for mechanical 1D or 2D elements # button_rod = Button(label="", css_classes=[eLnum.ElSupEnum.ROD.name], width=b_line_width, height=b_height) # curr_doc.buttons[eLnum.ElSupEnum.ROD.value] = button_rod # button_rod.on_click(partial(vis_cbs.cb_button_element_click, button_enum=eLnum.ElSupEnum.ROD)) button_beam = Button(label="", css_classes=[eLnum.ElSupEnum.BEAM.name], width=b_line_width, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.BEAM.value] = button_beam button_beam.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.BEAM)) # configure buttons for mechanical loads button_load_point = Button(label="", css_classes=[eLnum.ElSupEnum.LOAD_POINT.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.LOAD_POINT.value] = button_load_point button_load_point.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.LOAD_POINT)) button_load_moment = Button(label="", css_classes=[eLnum.ElSupEnum.LOAD_MOMENT.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.LOAD_MOMENT.value] = button_load_moment button_load_moment.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.LOAD_MOMENT)) button_load_random = Button(label="", css_classes=[eLnum.ElSupEnum.LOAD_LINE.name], width=b_line_width, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.LOAD_LINE.value] = button_load_random button_load_random.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.LOAD_LINE)) button_load_temp = Button(label="", css_classes=[eLnum.ElSupEnum.LOAD_TEMP.name], width=b_height, height=b_height) curr_doc.buttons[eLnum.ElSupEnum.LOAD_TEMP.value] = button_load_temp button_load_temp.on_click( partial(vis_cbs.cb_button_element_click, curr_doc=curr_doc, button_enum=eLnum.ElSupEnum.LOAD_TEMP)) ''' ############################### # ELEMENT INFO BOX ############################### ''' elinfo_object_height = 26 elinfo_label_width1 = 60 elinfo_label_width2 = 40 elinfo_input_width = 60 # labels for values of an element of the input plot text_elinfo_name = Div(text="name:", width=elinfo_label_width1, height=elinfo_object_height) text_elinfo_x = Div(text="x:", width=elinfo_label_width1, height=elinfo_object_height) curr_doc.div_element_info["x"] = text_elinfo_x text_elinfo_y = Div(text="y:", width=elinfo_label_width1, height=elinfo_object_height) curr_doc.div_element_info["y"] = text_elinfo_y text_elinfo_angle1 = Div(text="angle:", width=elinfo_label_width1, height=elinfo_object_height) text_elinfo_angle2 = Div(text="°", width=elinfo_label_width2 - 20, height=elinfo_object_height) spacer_y_a = Div(text="", width=text_elinfo_angle2.width, height=elinfo_object_height) text_elinfo_k1 = Div(text="spring:", width=elinfo_label_width1, height=elinfo_object_height) text_elinfo_k2 = Div(text="* k", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_length1 = Div(text="length:", width=elinfo_label_width1, height=elinfo_object_height) text_elinfo_length2 = Div(text="* l", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_force1 = Div(text="force:", width=elinfo_label_width1, height=elinfo_object_height) text_elinfo_force2 = Div(text="* F", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_moment1 = Div(text="moment:", width=elinfo_label_width1, height=elinfo_object_height) text_elinfo_moment2 = Div(text="* M", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_beam = Div(text="BEAM", width=elinfo_object_height, height=elinfo_label_width1, css_classes=["ELINFO_VERTICAL_TEXT"]) text_elinfo_h = Div(text="* h", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_ei = Div(text="* EI", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_ea = Div(text="* EA", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_lineload = Div(text="LINE LOAD", width=elinfo_object_height, height=elinfo_label_width1, css_classes=["ELINFO_VERTICAL_TEXT"]) text_elinfo_xn = Div(text="* n", width=elinfo_label_width2 - 10, height=elinfo_object_height) curr_doc.div_element_info["xn"] = text_elinfo_xn text_elinfo_yq = Div(text="* q", width=elinfo_label_width2 - 10, height=elinfo_object_height) curr_doc.div_element_info["yq"] = text_elinfo_yq text_elinfo_temp = Div(text="TEMP.", width=elinfo_object_height, height=elinfo_label_width1, css_classes=["ELINFO_VERTICAL_TEXT"]) text_elinfo_dt = Div(text="* dT", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_tt = Div(text="* T", width=elinfo_label_width2, height=elinfo_object_height) text_elinfo_at = Div(text="* αT", width=elinfo_label_width2, height=elinfo_object_height) # text inputs showing the current value of an input plot element and taking input for a value change # name input_elinfo_name = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_n = "name" curr_doc.input_element_info[key_elinfo_n] = input_elinfo_name input_elinfo_name.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_n)) # xy input_elinfo_x = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_x = "x" curr_doc.input_element_info[key_elinfo_x] = input_elinfo_x input_elinfo_x.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_x)) input_elinfo_y = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_y = "y" curr_doc.input_element_info[key_elinfo_y] = input_elinfo_y input_elinfo_y.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_y)) # angle input_elinfo_angle = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_angle = "angle" curr_doc.input_element_info[key_elinfo_angle] = input_elinfo_angle input_elinfo_angle.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_angle)) # spring constant input_elinfo_k = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_k = "k" curr_doc.input_element_info[key_elinfo_k] = input_elinfo_k input_elinfo_k.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_k)) # length input_elinfo_length = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_length = "length" curr_doc.input_element_info[key_elinfo_length] = input_elinfo_length input_elinfo_k.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_length)) # point load input_elinfo_force = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_f = "force" curr_doc.input_element_info[key_elinfo_f] = input_elinfo_force input_elinfo_force.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_f)) # moment input_elinfo_moment = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_m = "moment" curr_doc.input_element_info[key_elinfo_m] = input_elinfo_moment input_elinfo_moment.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_m)) # beam input_elinfo_h = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_h = "h" curr_doc.input_element_info[key_elinfo_h] = input_elinfo_h input_elinfo_h.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_h)) check_elinfo_beam = CheckboxGroup(labels=["EA -> inf.", "EI -> inf."], active=[], disabled=True, width=elinfo_input_width + elinfo_label_width1) curr_doc.group_element_info["beam"] = check_elinfo_beam check_elinfo_beam.on_change( 'active', partial(vis_cbs.cb_elinfo_beam, curr_doc=curr_doc)) input_elinfo_ea = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_ea = "ea" curr_doc.input_element_info[key_elinfo_ea] = input_elinfo_ea input_elinfo_ea.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_ea)) input_elinfo_ei = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_ei = "ei" curr_doc.input_element_info[key_elinfo_ei] = input_elinfo_ei input_elinfo_ei.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_ei)) # line load radio_elinfo_ll = RadioGroup( labels=["local", "global"], active=0, disabled=True, # "angle" width=elinfo_input_width + elinfo_label_width1) curr_doc.group_element_info["ll"] = radio_elinfo_ll radio_elinfo_ll.on_change( 'active', partial(vis_cbs.cb_elinfo_lineload, curr_doc=curr_doc)) input_elinfo_xns = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height + 20, disabled=True, title="start") key_elinfo_xns = "xn_start" curr_doc.input_element_info[key_elinfo_xns] = input_elinfo_xns input_elinfo_xns.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_xns)) input_elinfo_xne = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height + 20, disabled=True, title="end") key_elinfo_xne = "xn_end" curr_doc.input_element_info[key_elinfo_xne] = input_elinfo_xne input_elinfo_xne.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_xne)) input_elinfo_yqs = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_yqs = "yq_start" curr_doc.input_element_info[key_elinfo_yqs] = input_elinfo_yqs input_elinfo_yqs.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_yqs)) input_elinfo_yqe = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_yqe = "yq_end" curr_doc.input_element_info[key_elinfo_yqe] = input_elinfo_yqe input_elinfo_yqe.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_yqe)) # temperature load input_elinfo_dt = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_dt = "dT" curr_doc.input_element_info[key_elinfo_dt] = input_elinfo_dt input_elinfo_dt.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_dt)) input_elinfo_tt = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_tt = "T" curr_doc.input_element_info[key_elinfo_tt] = input_elinfo_tt input_elinfo_tt.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_tt)) input_elinfo_at = TextInput(value="-", width=elinfo_input_width, height=elinfo_object_height, disabled=True) key_elinfo_at = "aT" curr_doc.input_element_info[key_elinfo_at] = input_elinfo_at input_elinfo_at.on_change( 'value', partial(vis_cbs.cb_get_textinput, curr_doc=curr_doc, key=key_elinfo_at)) # button for deleting an input plot element button_elinfo_del = Button(label="Delete element", width=elinfo_label_width1 + elinfo_input_width + elinfo_label_width2, height=elinfo_object_height + 10, disabled=False) button_elinfo_del.on_click( partial(vis_cbs.cb_button_delete, curr_doc=curr_doc, single=True)) ''' ############################### # CHECKBOXES FOR OUTPUT PLOTS ############################### ''' check_labels = ["Min/ max values", "Start/ end values", "Zero points"] check_init_active = [1] check_plot_nf = CheckboxGroup(labels=check_labels, active=check_init_active) # inline=False text_plot_nf = Div(text="", width=100, height=10) check_plot_nf.on_change( 'active', partial(vis_cbs.cb_toggle_characteristic_values, curr_doc=curr_doc, output_plot=curr_doc.plot_normal_f, div=text_plot_nf)) check_plot_nd = CheckboxGroup(labels=check_labels, active=check_init_active) text_plot_nd = Div(text="", width=100, height=10) check_plot_nd.on_change( 'active', partial(vis_cbs.cb_toggle_characteristic_values, curr_doc=curr_doc, output_plot=curr_doc.plot_normal_disp, div=text_plot_nd)) check_plot_sf = CheckboxGroup(labels=check_labels, active=check_init_active) text_plot_sf = Div(text="", width=100, height=10) check_plot_sf.on_change( 'active', partial(vis_cbs.cb_toggle_characteristic_values, curr_doc=curr_doc, output_plot=curr_doc.plot_shear_f, div=text_plot_sf)) check_plot_mo = CheckboxGroup(labels=check_labels, active=check_init_active) text_plot_mo = Div(text="", width=100, height=10) check_plot_mo.on_change( 'active', partial(vis_cbs.cb_toggle_characteristic_values, curr_doc=curr_doc, output_plot=curr_doc.plot_moment, div=text_plot_mo)) check_plot_sa = CheckboxGroup(labels=check_labels, active=check_init_active) text_plot_sa = Div(text="", width=100, height=10) check_plot_sa.on_change( 'active', partial(vis_cbs.cb_toggle_characteristic_values, curr_doc=curr_doc, output_plot=curr_doc.plot_shear_angle, div=text_plot_sa)) check_plot_sd = CheckboxGroup(labels=check_labels, active=check_init_active) text_plot_sd = Div(text="", width=100, height=10) check_plot_sd.on_change( 'active', partial(vis_cbs.cb_toggle_characteristic_values, curr_doc=curr_doc, output_plot=curr_doc.plot_shear_disp, div=text_plot_sd)) ''' ############################### # IMAGES: SIGN CONVENTION ############################### ''' sign_convention_N = Div( text= "<img src='/System_of_Beams/static/images/sign_convention_N_u.png' width=100 height=60>", width=100, height=60) sign_convention_u = Div( text= "<img src='/System_of_Beams/static/images/sign_convention_N_u.png' width=100 height=60>", width=100, height=60) sign_convention_SF = Div( text= "<img src='/System_of_Beams/static/images/sign_convention_SF_w.png' width=100 height=60>", width=100, height=60) sign_convention_M = Div( text= "<img src='/System_of_Beams/static/images/sign_convention_M.png' width=100 height=60>", width=100, height=60) sign_convention_phi = Div( text= "<img src='/System_of_Beams/static/images/sign_convention_phi.png' width=100 height=60>", width=100, height=60) sign_convention_w = Div( text= "<img src='/System_of_Beams/static/images/sign_convention_SF_w.png' width=100 height=60>", width=100, height=60) ''' ############################### # HTML LATEX DESCRIPTION ############################### ''' # latex packages not working with updated bokeh! # description_filename = join(dirname(__file__), "description.html") # description = LatexDiv(text=open(description_filename).read(), render_as_text=False, width=910) ''' #################################### # CREATE LAYOUT AND START DOCUMENT #################################### ''' spacer = Div(text="", width=20, height=20) minispacer = Div(text="", width=0, height=0) # element buttons layout_supports_1 = row(button_support_clamped, button_support_normal, button_support_transverse) layout_supports_2 = row(button_support_fixed_joint, button_support_fixed_conti, button_support_roller_joint, button_support_roller_conti) layout_springs = row(button_spring_support, button_spring_moment_support) layout_node = row(button_node) layout_joints = row(button_joint, button_joint_normal, button_joint_transverse, button_spring) layout_elements = row(button_beam) # button_rod, layout_loads = row(button_load_point, button_load_moment, button_load_random, button_load_temp) layout_input_elements = column( spacer, text_supports, layout_supports_1, layout_supports_2, row(column(text_springs, layout_springs), spacer, minispacer, column(text_node, layout_node)), text_joints, layout_joints, text_elements, layout_elements, text_loads, layout_loads) # element info box elinfo_name = row(text_elinfo_name, input_elinfo_name) curr_doc.children_element_info[key_elinfo_n] = elinfo_name elinfo_xy = row(text_elinfo_x, input_elinfo_x, spacer_y_a, text_elinfo_y, input_elinfo_y) curr_doc.children_element_info[key_elinfo_x] = elinfo_xy elinfo_angle_length = row(text_elinfo_angle1, input_elinfo_angle, text_elinfo_angle2, text_elinfo_length1, input_elinfo_length, text_elinfo_length2) curr_doc.children_element_info[key_elinfo_angle] = elinfo_angle_length elinfo_k = row(text_elinfo_k1, input_elinfo_k, text_elinfo_k2) curr_doc.children_element_info[key_elinfo_k] = elinfo_k elinfo_force = row(text_elinfo_force1, input_elinfo_force, text_elinfo_force2) curr_doc.children_element_info[key_elinfo_f] = elinfo_force elinfo_moment = row(text_elinfo_moment1, input_elinfo_moment, text_elinfo_moment2) curr_doc.children_element_info[key_elinfo_m] = elinfo_moment elinfo_beam = row( minispacer, column(minispacer, text_elinfo_beam), column(check_elinfo_beam, row(input_elinfo_h, text_elinfo_h)), column(row(input_elinfo_ea, text_elinfo_ea), row(input_elinfo_ei, text_elinfo_ei))) curr_doc.children_element_info[key_elinfo_h] = elinfo_beam elinfo_lineload = row( minispacer, column(spacer, text_elinfo_lineload), column(spacer, radio_elinfo_ll), column(row(input_elinfo_xns, input_elinfo_xne), row(input_elinfo_yqs, input_elinfo_yqe)), column(spacer, text_elinfo_xn, text_elinfo_yq)) curr_doc.children_element_info[key_elinfo_ei] = elinfo_lineload elinfo_dt = row( minispacer, column(minispacer, text_elinfo_temp), column( row(input_elinfo_dt, text_elinfo_dt, minispacer, input_elinfo_at, text_elinfo_at), row(input_elinfo_tt, text_elinfo_tt))) curr_doc.children_element_info[key_elinfo_dt] = elinfo_dt curr_doc.layout_element_info = row( minispacer, column(minispacer, elinfo_name, elinfo_xy, elinfo_angle_length, spacer, elinfo_k, elinfo_force, elinfo_moment, spacer, elinfo_beam, spacer, elinfo_lineload, spacer, elinfo_dt, spacer, button_elinfo_del, minispacer), minispacer, css_classes=["ELEMENT_INFO_BOX"], margin=(20, 0, 0, 20), visible=True) # input plot with element buttons, delete and calculation buttons and divs user_input = row(curr_doc.plot_input, spacer, layout_input_elements) user_input_info = row(curr_doc.div_input, div_xy, spacer, button_del_selected, button_del_all) user_msg = row(curr_doc.div_msg, spacer, button_calc) # output plots and check boxes for characteristic values user_output = column( row(curr_doc.plot_normal_f, spacer, column(spacer, check_plot_nf, sign_convention_N)), row(curr_doc.plot_normal_disp, spacer, column(spacer, check_plot_nd, sign_convention_u)), row(curr_doc.plot_shear_f, spacer, column(spacer, check_plot_sf, sign_convention_SF)), row(curr_doc.plot_moment, spacer, column(spacer, check_plot_mo, sign_convention_M)), row(curr_doc.plot_shear_angle, spacer, column(spacer, check_plot_sa, sign_convention_phi)), row(curr_doc.plot_shear_disp, spacer, column(spacer, check_plot_sd, sign_convention_w))) # assemble complete layout doc_layout = column( spacer, row(spacer, spacer, dropdown_tc), row(column(user_input, user_input_info, user_msg), minispacer, curr_doc.layout_element_info), spacer, user_output) # add layout curr_doc.curr_doc.add_root(doc_layout) # set title of browser tab curr_doc.curr_doc.title = split(dirname(__file__))[-1].replace( '_', ' ').replace('-', ' ') doc_title = split(dirname(__file__))[-1].replace('_', ' ').replace('-', ' ')
# initialize data source source_fourier = ColumnDataSource(data=dict(t=[], x_fourier=[])) source_orig = ColumnDataSource(data=dict(t=[], x_orig=[])) source_interval_patch = ColumnDataSource(data=dict(x_patch=[], y_patch=[])) source_interval_bound = ColumnDataSource(data=dict(x_min=[], x_max=[], y_minmax=[])) source_coeff = ColumnDataSource(data=dict(a=[], b=[])) source_f = ColumnDataSource(data=dict(f=[None])) source_periodicity = ColumnDataSource(data=dict(t_start=[None], t_end=[None])) source_view = ColumnDataSource(data=dict(x_start=[None], x_end=[None], y_start=[None], y_end=[None])) # initialize controls # buttons for choosing a sample function sample_function_type = RadioButtonGroup(labels=fs.function_names, active=fs.function_init) # here one can choose arbitrary input function default_function_input = TextInput(value=fs.function_input_init) default_function_period_start = TextInput(title='period start', value=fs.timeinterval_start_init) default_function_period_end = TextInput(title='period end', value=fs.timeinterval_end_init) # slider controlling degree of the fourier series degree = Slider(title="degree", name='degree', value=fs.degree_init, start=fs.degree_min, end=fs.degree_max, step=fs.degree_step) # initialize callback behaviour degree.on_change('value', degree_change) default_function_input.on_change('value', type_input_change) # todo write default functions for any callback, like above default_function_period_start.on_change('value', type_input_change) default_function_period_end.on_change('value', type_input_change) sample_function_type.on_change('active', type_input_change)
Stream.twitterStream.disconnect() global straming straming = False rdf['flash'] = 0 # def update_count(): # start_button_click p.x_range.on_change('end', update_lod) start_button = Button(label="Start", button_type="primary", width=80) start_button.on_click(start_button_click) stop_button = Button(label="Stop", button_type="danger", width=80) stop_button.on_click(stop_button_click) text_input = TextInput(placeholder="Enter query here", width=400) spacer_row = Spacer(width=450) spacer_pad_col = Spacer(height=20) spacer_pad_row = Spacer(width=100) spacer_col = Spacer(height=20) layout = column(row( spacer_row, text_input, start_button, stop_button, spacer_row), spacer_col, p) main_layout = row(spacer_pad_row, column( spacer_pad_col, layout, spacer_pad_col), spacer_pad_row) def update_counts(): if straming:
def plotting(): forcs = ptsgdf.drop('geometry', axis=1).copy() ptscs = ColumnDataSource(forcs) # uscs = usmap.drop('geometry', axis=1).copy() # usmcs = ColumnDataSource(uscs) plotp = figure(title="Airport Rankings", plot_width=1200, plot_height=1000) text_input1 = TextInput(value="", title="Enter Departing City") text_input2 = TextInput(value="", title="Enter Destination City") text_input3 = TextInput( value="", title="Number of Flights from Departing City to Destination") def update1(attr, old, new): global liness if liness is not None: liness.visible = False xlist = list() ylist = list() loccom = text_input1.value if loccom: for i in range(nc): ind = list(dadfra.index).index(loccom) if dadfra.loc[loccom, :][i] > 0: xlist.append([ptsgdf.loc[i, "x"], ptsgdf.loc[ind, "x"]]) ylist.append([ptsgdf.loc[i, "y"], ptsgdf.loc[ind, "y"]]) # hover2 = HoverTool(names = ["airl"]) # hover2.tooltips = [("Number of Flights")] # plotp.add_tools(hover1) liness = plotp.multi_line(xlist, ylist, line_width=1, line_color="green") liness.visible = True if loccom: if text_input2.value: text_input3.value = str( int(dadfra.loc[text_input1.value, text_input2.value])) #inst = inst +1 text_input1.on_change("value", update1) def update2(attr, old, new): if text_input1.value: if text_input2.value: text_input3.value = str( int(dadfra.loc[text_input1.value, text_input2.value])) text_input2.on_change("value", update2) hover1 = HoverTool(names=["airp"]) plotp.patches(xarr, yarr, color="cyan", alpha=1.0, line_color="black", line_width=2) plotp.circle('x', 'y', source=ptscs, name="airp", color='red', size=5) hover1.tooltips = [("Airport Name", "@City"), ("Airport Rank", "@Rank")] plotp.add_tools(hover1) curdoc().add_root(row(plotp, column(text_input1, text_input2, text_input3)))
# CONTROLS dataset = Select(title="Dataset", options=data_manager.dataset_ids, value=selected_dataset) measure = Select(title="Measure", options=[ ('cosine_similarity', 'Cosine Similarity'), ('cosine', 'Cosine Distance'), ('euclidean', 'Euclidean'), ('dot_product', 'Dot product'), ('correlation', 'Correlation'), ], value='cosine_similarity') axes_preset = '; '.join(['usa', 'europe', 'china', 'japan', 'brazil']) axes = TextInput(title='Axes Formulae (separated by ";")', placeholder=axes_preset) items_preset = '; '.join(['food', 'movie']) items = TextInput(title='Items Formulae (separated by ";")', placeholder=items_preset) visualization_title = Div(text="<strong>Visualization</strong>") opacity = Slider(title="Opacity", value=0.2, start=0, end=1, step=0.1) # BIND CONTROL EVENTS dataset.on_change('value', update) axes.on_change('value', update) items.on_change('value', update) measure.on_change('value', update) opacity.on_change('value', update)
self.fasta = fasta self.title = title self.notes = notes self.highsupport = highsupport self.full = full self.partial = partial self.annotations = annotations GTF = TextInput(title="Enter the name of annotation file", value="gencode.vM8.annotation.gtf") Format = TextInput(title="Enter the format of annotation file, standard is gtf", value="standard") Matches = TextInput( title="Enter the name of pickle files from MatchAnnot, e.g. of multiple files: match1.pickle,match2.pickle", value="matches.pickle", ) Gene = TextInput(title="Select gene to visualize") Alpha = Slider(title="Alpha value of exons", value=1.0, start=0, end=1.0, step=0.1) Full = Slider(title="Full support threshold", value=0, start=0, end=30, step=1.0) Partial = Slider(title="Partial support threshold", value=0, start=0, end=50, step=1.0) Group = Select(title="Group isoform or not", value="on", options=["on", "off"]) Cluster = Slider(title="The number of groups", value=3, start=1, end=5, step=1.0) Width = Slider(title="The width of transcripts", value=20, start=5, end=30, step=1) Save = TextInput(title="Enter the folder name to data in Fasta", value=None) blockSource = ColumnDataSource( data=dict(top=[], bottom=[], left=[], right=[], exon=[], start=[], end=[], chromosome=[], xs=[], ys=[]) ) source = ColumnDataSource(data=dict(x=[], y=[], color=[], line_alpha=[], width=[], QScore=[], start=[], end=[])) geneSource = ColumnDataSource(data=dict(Gene=[], Cluster=[])) df = pd.DataFrame()
'lws':[2] } )) circobs = p.circle(x='xs', y='ys', color='colors', source=ColumnDataSource(data= { 'xs':[[]], 'ys':[[]], 'colors':['white'], } )) # add a button widget and configure with the call back button = Button(label="Fetch Data") namefield = TextInput(value="", title="Name(s):") bandfield = TextInput(value="", title="Band(s):") # add a text renderer to out plot (no data yet) with open('/root/astrocats/astrocats/supernovae/output/names.min.json') as f: names = json.loads(f.read()) names = list(names.keys()) unames = [x.upper() for x in names] bands = plotting.bandcodes ubands = [x.upper() for x in bands] nds = [] def callback():
value="10") top_n_clusters_dropdown = Dropdown(label="Show Top 100 Clusters", button_type="warning", menu=n_clusters_menu, value="100") tfidf_slider = Slider(start=0, end=1, value=0, step=.05, title="Informativeness") cval_slider = Slider(start=0, end=1, value=0, step=.05, title="Completeness") freq_slider = Slider(start=0, end=1, value=0, step=.05, title="Linguistical") filter_topics_tab = Panel(child=filter_topics_table, title="Filter Topics") filter_custom_tab = Panel(child=filter_custom_table, title="Custom Trends") filter_tabs = Tabs(tabs=[filter_topics_tab, filter_custom_tab]) search_input_box = TextInput(title="Search:", value="", width=300) search_button = Button(label="Go", button_type="success", width=50, css_classes=['search_button']) clear_button = Button(label="Clear", button_type="success", width=50, css_classes=['clear_button']) buttons_layout = column(Div(height=0), Row(search_button, clear_button)) analyse_button = Button(label="re-analyze", button_type="success") filter_label = Div(text="", style={ 'color': 'red', 'padding-bottom': '0px', 'font-size': '15px'
# Plot constraint function contour g(x,y)=0 contour_g = my_bokeh_utils.Contour(plot, line_color='red', line_width=2, legend='g(x,y) = 0') # Plot corresponding tangent vector quiver_isolevel = my_bokeh_utils.Quiver(plot, fix_at_middle=False, line_width=2, color='black') # Plot corresponding tangent vector quiver_constraint = my_bokeh_utils.Quiver(plot, fix_at_middle=False, line_width=2, color='red') # Plot mark at position on constraint function plot.cross(x='x', y='y', color='red', size=10, line_width=2, source=source_mark) # object that detects, if a position in the plot is clicked on interactor = my_bokeh_utils.Interactor(plot) # adds callback function to interactor, if position in plot is clicked, call on_selection_change interactor.on_click(on_selection_change) # text input window for objective function f(x,y) to be optimized f_input = TextInput(value=lagrange_settings.f_init, title="f(x,y):") f_input.on_change('value', f_changed) # dropdown menu for selecting one of the sample functions sample_fun_input_f = Dropdown(label="choose a sample function f(x,y) or enter one below", menu=lagrange_settings.sample_f_names) sample_fun_input_f.on_click(sample_fun_input_f_changed) # text input window for side condition g(x,y)=0 g_input = TextInput(value=lagrange_settings.g_init, title="g(x,y):") g_input.on_change('value', g_changed) # dropdown menu for selecting one of the sample functions sample_fun_input_g = Dropdown(label="choose a sample function g(x,y) or enter one below", menu=lagrange_settings.sample_g_names) sample_fun_input_g.on_click(sample_fun_input_g_changed)
def on_text_value_change(attr, old, new): try: global expr expr = sy.sympify(new, dict(x=xs)) except (sy.SympifyError, TypeError, ValueError) as exception: dialog.content = str(exception) dialog.visible = True else: update_data() dialog = Dialog(title="Invalid expression") slider = Slider(start=1, end=20, value=order, step=1, title="Order", callback_policy="mouseup") slider.on_change("value", on_slider_value_change) text = TextInput(value=str(expr), title="Expression:") text.on_change("value", on_text_value_change) inputs = WidgetBox(children=[slider, text], width=400) layout = Column(children=[inputs, plot, dialog]) update_data() document.add_root(layout) session.show(layout) if __name__ == "__main__": print("\npress ctrl-C to exit") session.loop_until_closed()
def compare(): # if proj among arguments, show this tree first. try: proj_a = int(request.args.get('proj_a', None)) proj_b = int(request.args.get('proj_b', None)) except (TypeError, ValueError): proj_a = proj_b = None include = request.args.get('include', None) # list of projects (and proj_names) used to create dropdown project selector upload_list = UserFile.query.filter_by(user_id=current_user.id).\ filter_by(run_complete=True).order_by(UserFile.file_id).all() if len(upload_list) > 1: # Use specified project from args or highest file_id as CURRENT PROJECT current_proj = upload_list[-1] # override if valid proj specified if proj_a and proj_b: current_temp_a = [u for u in upload_list if u.file_id == proj_a] current_temp_b = [u for u in upload_list if u.file_id == proj_b] # if not among user's finished projects, use highest file_id if len(current_temp_a) == 1 and len(current_temp_b) == 1: current_proj_a = current_temp_a[0] current_proj_b = current_temp_b[0] else: current_proj_a = upload_list[-2] current_proj_b = upload_list[-1] else: current_proj_a = upload_list[-2] current_proj_b = upload_list[-1] detail_path1 = naming_rules.get_detailed_path(current_proj_a) detail_path2 = naming_rules.get_detailed_path(current_proj_b) js_name1 = naming_rules.get_js_name(current_proj_a) js_name2 = naming_rules.get_js_name(current_proj_b) xlabel = u"Effect size ({})".format(current_proj_a.get_fancy_filename()) ylabel = u"Effect size ({})".format(current_proj_b.get_fancy_filename()) # load pathways with 1+ mutation in 1+ patients, # ignoring ones with 'cancer' etc in name all_paths1 = load_pathway_list_from_file(detail_path1) all_paths2 = load_pathway_list_from_file(detail_path2) # IDs with p<0.05 and +ve effect sig_p = OrderedDict( [(i.path_id, i.nice_name) for i in all_paths1 if i.gene_set]) sig_pids1 = [i for i in sig_p] sig_p2 = OrderedDict( [(i.path_id, i.nice_name) for i in all_paths2 if i.gene_set]) sig_pids2 = [i for i in sig_p2] sig_p.update(sig_p2) # ORDERED by proj1 effect size # BUILD DATAFRAME WITH ALL sig PATHWAYS, proj1 object order. pway_names = sig_p.values() # order important columns = ['path_id', 'pname', 'ind1', 'ind2', 'e1', 'e2', 'e1_only', 'e2_only', 'q1', 'q2'] df = pd.DataFrame(index=sig_p.keys(), data={'pname': pway_names}, columns=columns) for path_group, evar, qvar, ind, sigs in \ [(all_paths1, 'e1', 'q1', 'ind1', sig_pids1), (all_paths2, 'e2', 'q2', 'ind2', sig_pids2)]: for path in path_group: path_id = path.path_id if path_id not in sig_p: continue df.loc[path_id, evar] = get_effect(path) df.loc[path_id, qvar] = get_q(path) temp_ind = sigs.index(path_id) if path_id in sigs else -1 df.loc[path_id, ind] = temp_ind df.ind1.fillna(-1, inplace=True) df.ind2.fillna(-1, inplace=True) df.e1_only = df.where(df.e2.isnull())['e1'] df.e2_only = df.where(df.e1.isnull())['e2'] inds1 = list(df.ind1) inds2 = list(df.ind2) source = ColumnDataSource(data=df) source_full = ColumnDataSource(data=df) source.name, source_full.name = 'data_visible', 'data_full' # SET UP FIGURE minx = df.e1.min() minx *= 1 - minx / abs(minx) * 0.2 miny = df.e2.min() miny *= 1 - miny/abs(miny) * 0.2 maxx = df.e1.max() * 1.2 maxy = df.e2.max() * 1.2 TOOLS = "lasso_select,box_select,hover,crosshair,pan,wheel_zoom,"\ "box_zoom,reset,tap,help" # poly_select,lasso_select, previewsave # SUPLOTS p = figure(plot_width=DIM_COMP_W, plot_height=DIM_COMP_H, tools=TOOLS, title=None, logo=None, toolbar_location="above", x_range=Range1d(minx, maxx), y_range=Range1d(miny, maxy), x_axis_type="log", y_axis_type="log" ) pb = figure(plot_width=DIM_COMP_SM, plot_height=DIM_COMP_H, tools=TOOLS, y_range=p.y_range, x_axis_type="log", y_axis_type="log") pa = figure(plot_width=DIM_COMP_W, plot_height=DIM_COMP_SM, tools=TOOLS, x_range=p.x_range, x_axis_type="log", y_axis_type="log") pp = figure(plot_width=DIM_COMP_SM, plot_height=DIM_COMP_SM, tools=TOOLS, outline_line_color=None) # SPANS p.add_layout(plot_fns.get_span(1, 'height')) p.add_layout(plot_fns.get_span(1, 'width')) pa.add_layout(plot_fns.get_span(1, 'height')) pb.add_layout(plot_fns.get_span(1, 'width')) # STYLE for ax in [p, pa, pb]: ax.grid.visible = False ax.outline_line_width = 2 ax.background_fill_color = 'whitesmoke' for ax in [pa, pb]: ax.xaxis.visible = False ax.yaxis.visible = False pa.title.text = xlabel pb.title.text = ylabel pa.title_location, pa.title.align = 'below', 'center' pb.title_location, pb.title.align = 'left', 'center' # WIDGETS q_input = TextInput(value='', title="P* cutoff", placeholder='e.g. 0.05') gene_input = TextInput(value='', title="Gene list", placeholder='e.g. TP53,BRAF') radio_include = RadioGroup(labels=["Include", "Exclude"], active=0) widgets = widgetbox(q_input, gene_input, radio_include, width=200, css_classes=['widgets_sg']) grid = gridplot([[pb, p, widgets], [Spacer(width=DIM_COMP_SM), pa, Spacer()]], sizing_mode='fixed') cb_inclusion = CustomJS(args=dict(genes=gene_input), code=""" var gene_str = genes.value if (!gene_str) return; var include = cb_obj.active == 0 ? true : false selectPathwaysByGenes(gene_str, include); """) cb_genes = CustomJS(args=dict(radio=radio_include), code=""" var gene_str = cb_obj.value if (!gene_str) return; var include = radio.active == 0 ? true : false selectPathwaysByGenes(gene_str, include); """) radio_include.js_on_change('active', cb_inclusion) gene_input.js_on_change('value', cb_genes) # SCATTER p.circle("e1", "e2", source=source, **SCATTER_KW) pa.circle('e1_only', 1, source=source, **SCATTER_KW) pb.circle(1, 'e2_only', source=source, **SCATTER_KW) # HOVER for hover in grid.select(dict(type=HoverTool)): hover.tooltips = OrderedDict([ ("name", "@pname"), ("effects", "(@e1, @e2)"), ("P*", ("(@q1, @q2)")) ]) # ADD Q FILTERING CALLBACK callback = CustomJS(args=dict(source=source, full=source_full), code=""" // get old selection indices, if any var prv_selected = source.selected['1d'].indices; var prv_select_full = [] for(var i=0; i<prv_selected.length; i++){ prv_select_full.push(scatter_array[prv_selected[i]]) } var new_selected = [] var q_val = cb_obj.value; if(q_val == '') q_val = 1 var fullset = full.data; var n_total = fullset['e1'].length; // Convert float64arrays to array var col_names = %s ; col_names.forEach(function(col_name){ source.data[col_name] = [].slice.call(source.data[col_name]) source.data[col_name].length = 0 }) scatter_array.length = 0; var j = -1; // new glyph indices for (i = 0; i < n_total; i++) { this_q1 = fullset['q1'][i]; this_q2 = fullset['q2'][i]; if(this_q1 <= q_val || this_q2 <= q_val){ j++; // preserve previous selection if still visible col_names.forEach(function(col){ source.data[col].push(fullset[col][i]); }) scatter_array.push(i) if($.inArray(i, prv_select_full) > -1){ new_selected.push(j); } } } source.selected['1d'].indices = new_selected; source.trigger('change'); updateIfSelectionChange_afterWait(); """ % columns) q_input.js_on_change('value', callback) script, div = plot_fns.get_bokeh_components(grid) proj_dir_a = naming_rules.get_project_folder(current_proj_a) proj_dir_b = naming_rules.get_project_folder(current_proj_b) if os.path.exists(os.path.join(proj_dir_a, 'matrix_svg_cnv')) and \ os.path.exists(os.path.join(proj_dir_b, 'matrix_svg_cnv')): has_cnv = True else: has_cnv = False else: # not enough projects yet! flash("Two completed projects are required for a comparison.", "warning") return redirect(url_for('.index')) return render_template('pway/compare.html', current_projs=[current_proj_a, current_proj_b], inds_use=[inds1, inds2], has_cnv=has_cnv, js_name_a=js_name1, js_name_b=js_name2, projects=upload_list, bokeh_script=script, bokeh_div=div, include_genes=include, resources=plot_fns.resources)
x = np.arange(0, max_days_to_compute, 1) # times y = get_util_vs_time_data(days=x) source = ColumnDataSource(data=dict(x=x, y=y)) # Set up plot plot = figure(plot_height=plot_height, plot_width=plot_width, title=plot_title, tools="crosshair,pan,reset,save,wheel_zoom", x_range=[0, max_days_to_display], x_axis_label="Days Since Attack", y_axis_label="Relative Profit of Attacking (Millions of USD)") plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6) # Set up widgets text = TextInput(title="Title", value='mighty bitcoin') mining_power = Slider(title="Mining Power", start=min_mining_power, end=max_mining_power, value=default_mining_power, step=mining_power_step) discount_rate = Slider(title="Discount Rate", start=min_discount, end=max_discount, value=default_discount, step=discount_step) btc_stolen = Slider(title="Amount of BTC Stolen", start=min_btc_stolen, end=max_btc_stolen, value=default_btc_stolen, step=btc_stolen_step) btc_owned_0 = Slider(title="BTC Owned At Time 0", start=min_btc_owned_0, end=max_btc_owned_0, value=default_btc_owned_0, step=btc_owned_0_step) exchange_rate = Slider(title="BTC-USD Exchange Rate", start=min_rate, end=max_rate, value=default_rate, step=rate_step) btc_f_stolen = Slider(title="Fraction Amount of BTC Stolen", start=min_btc_f_stolen, end=max_btc_f_stolen, value=default_btc_f_stolen, step=btc_f_stolen_step) btc_f_owned_0 = Slider(title="Fraction BTC Owned At Time 0", start=min_btc_f_owned_0, end=max_btc_f_owned_0, value=default_btc_f_owned_0, step=btc_f_owned_0_step) hline = Span(location=0, dimension='width', line_color='green', line_width=1.5) plot.renderers.extend([hline]) # Set up callbacks def update_title(attrname, old, new):
def explore_tab(df): def get_dataset(src, name, words, start, end): df = src[src.user == name].copy() mask = (df['timestamp'] > start) & (df['timestamp'] <= end) df = df[mask] words = [str(i) for i in words.split()] safe_words = [] for word in words: word = re.escape(word) word = "(?=.*{})".format(word) safe_words.append(word) df = df[df['texts'].str.contains(''.join(safe_words))] source = ColumnDataSource(data=dict()) cols = ['texts', 'displaySource', 'source'] df[cols] = df[cols].replace({',': '', ',,': '', ';': ''}, regex=True) source.data = { # 'index': df.index, 'impressionTime': df.impressionTime, 'impressionOrder': df.impressionOrder, 'source': df.source, 'fblinktype': df.fblinktype, 'texts': df.texts, 'textsize': df.textsize, 'publicationTime': df.publicationTime, 'permaLink': df.permaLink, 'nature': df.nature, 'ANGRY': df.ANGRY, 'HAHA': df.HAHA, 'LIKE': df.LIKE, 'LOVE': df.LOVE, 'SAD': df.SAD, 'WOW': df.WOW, 'displaySource': df.displaySource, 'id': df.id, 'timestamp': df.timestamp, # 'images': df.images, # 'opengraph': df.opengraph, 'postId': df.postId, # 'semanticCount': df.semanticCount, # 'semanticId': df.semanticId, 'sourceLink': df.sourceLink, 'timeline': df.timeline, 'user': df.user, # 'videoautoplay': df.videoautoplay } return source def make_table(source): # Columns of tablem table_columns = [ TableColumn(field='impressionTime', title='Time'), TableColumn(field='impressionOrder', title='Order'), TableColumn(field='source', title='Source'), TableColumn(field='fblinktype', title='Type'), TableColumn(field='texts', title='Text'), TableColumn(field='textsize', title='Text Size'), TableColumn(field='publicationTime', title='Publication Time'), TableColumn(field='permaLink', title='Link'), TableColumn(field='nature', title='Nature'), TableColumn(field='ANGRY', title='Angry'), TableColumn(field='HAHA', title='Haha'), TableColumn(field='LIKE', title='Like'), TableColumn(field='LOVE', title='Love'), TableColumn(field='SAD', title='Sad'), TableColumn(field='WOW', title='Wow') ] user_table = DataTable(source=source, columns=table_columns, width=1400) return user_table def update(attrname, old, new): name = name_select.value text_filter = text_input.value start = date_slider.value[0] end = date_slider.value[1] src = get_dataset(df, name, text_filter, start, end) source.data.update(src.data) name = df.user.iloc[0] words = '' names = df.user.unique() start = df.timestamp.min() end = df.timestamp.max() name_select = Select(value=name, title='User', options=sorted(names)) text_input = TextInput(value="", title="Filter text:") date_slider = DateRangeSlider(title="Date Range: ", start=df.timestamp.min(), end=date.today(), value=(df.timestamp.min(), date.today()), step=1, callback_policy='mouseup') button = Button(label="Download", button_type="success") source = get_dataset(df, name, words, start, end) table = make_table(source) name_select.on_change('value', update) text_input.on_change('value', update) date_slider.on_change('value', update) button.js_on_click( CustomJS(args=dict(source=source), code=open(join(dirname(__file__), "download.js")).read())) controls = column(name_select, date_slider, text_input, button) tab = Panel(child=row(table, controls), title='Explore') return tab
def plotting(self): if self.debug: self.debug_file = open("debug_output.txt", "w") self.debug_file.write("Initialized plotting subroutine \n") TOOLS="pan,wheel_zoom,box_zoom,reset,hover,previewsave" tab_plots = [] self.all_elements = [] self.elements_comparison = [] for filename in self.filenames: if "ITO" in filename: tab_plots.append(self.mass_plotting(filename)) continue data_dict = self.data_generation(filename) self.data_test(data_dict) name_check = data_dict["gen_info"]["DATA FILES"] attr_id = name_check[1][4][:-3] + "_" + name_check[2][2] self.attribute_ids.append(attr_id) attr_extra_y_ranges = False attr_extra_x_ranges = False local_source_line = [] """ create plots for each datafile and put them in a tab. """ y_axis_units = [x["y_unit"] for x in data_dict["data"]] x_axis_units = [x["x_unit"] for x in data_dict["data"]] figure_obj = figure(plot_width = 1000, plot_height = 800, y_axis_type = "log", title = attr_id, tools = TOOLS) #figure_obj.axes.major_label_text_font_size("12pt") #figure_obj.major_label_text_font_size("12pt") hover = figure_obj.select(dict(type = HoverTool)) hover.tooltips = [ ("Element:", "@element"), ("(x, y):", "($x, $y)")] self.figure_data.append((figure_obj, data_dict)) figure_obj.yaxis.axis_label = y_axis_units[0] figure_obj.xaxis.axis_label = x_axis_units[0] if not all(x == y_axis_units[0] for x in y_axis_units): for unit, dataset in zip(y_axis_units, data_dict["data"]): if not unit == y_axis_units[0]: extra_y_ranges_exists = attr_extra_y_ranges extra_y_ranges_exists = True if self.debug: self.debug_file.write("Added extra y-axis for file_id: %s, element: %s | New length %g \n" %(attr_id, dataset["sample_element"], len(figure_obj.yaxis))) figure_obj.extra_y_ranges = {"foo": Range1d(start = np.amin(dataset["y"]), end = np.amax(dataset["y"]))} figure_obj.add_layout(LogAxis(y_range_name = "foo", axis_label = unit), "right") break if not all(x == x_axis_units[0] for x in x_axis_units): for unit, dataset in zip(x_axis_units, data_dict["data"]): if not unit == x_axis_units[0]: extra_x_ranges_exists = attr_extra_x_ranges extra_x_ranges_exists = True if self.debug: self.debug_file.write("Added extra x-axis for file_id: %s, element: %s. | New length %g \n" %(attr_id, dataset["sample_element"], len(figure_obj.yaxis))) figure_obj.extra_x_ranges = {"bar": Range1d(start = np.amin(dataset["x"]), end = np.amax(dataset["x"]))} figure_obj.add_layout(LinearAxis(x_range_name = "bar", axis_label = unit), "above") break figure_obj.xaxis.axis_label = x_axis_units[0] colour_list = Spectral11 + RdPu9 + Oranges9 colour_indices = [0, 2, 8, 10, 12, 14, 20, 22, 1, 3, 9, 11, 13, 15] list_of_elements = [] source_list = [] line_list = [] for dataset, color_index in zip(data_dict["data"], colour_indices): self.all_elements.append(dataset["sample_element"]) #strip isotope number color = colour_list[color_index] source = ColumnDataSource(data = dataset) #Datastructure for source of plotting self.source_test(source) list_of_elements.append(dataset["sample_element"]) line_glyph = figure_obj.line("x", "y", source = source, line_width = 2, line_color = color, legend = dataset["sample_element"]) if self.debug: self.debug_file.write("Create line object on figure %s at %s \n" %(id(figure_obj), id(line_glyph))) line_list.append(line_glyph) source_list.append(source) local_source_line.append([[source, line] for source, line in zip(source_list, line_list)]) self.source_line.append(local_source_line) #Calculations on the dataset text_input_rsf = TextInput(value = "default", title = "RSF or SF (at/cm^3): ") do_integral_button = Button(label = "Calibration integral") smoothing_button = Button(label = "smth selct elem") matplot_button = Button(label = "Create matplotlib fig") text_input_sputter = TextInput(value = "default", title = "Sputter speed: number unit") text_input_crater_depth = TextInput(value = "default", title = "Depth of crater in: number unit") radio_group = RadioGroup(labels = list_of_elements, active=0) text_input_xval_integral = TextInput(value = "0", title = "x-delimiter ") text_input_dose = TextInput(value = "0", title = "Dose[cm^-2] ") #Save files for later use save_flexDPE_button = Button(label = "Save element for FlexPDE") save_all_flexDPE_button = Button(label = "Save all elements for FlexPDE") save_textfile_button = Button(label = "Sava Data in textfile") #Pointers to methods on click / change handlers radio_group.on_change("active", lambda attr, old, new: None) matplot_button.on_click(lambda source_list = source_list: self.matplotlib_export(source_list)) do_integral_button.on_click(lambda source_list = source_list, line_list = line_list, source_line = self.source_line, figure_data = self.figure_data, data_dict = data_dict, radio = radio_group, x_box = text_input_xval_integral, dose = text_input_dose, extra_y_ranges = attr_extra_y_ranges: self.integrate(data_dict, source_list, line_list, source_line, figure_data, radio, x_box, dose, extra_y_ranges)) smoothing_button.on_click(lambda source_list = source_list, radio = radio_group, data_dict = data_dict, x_box = text_input_xval_integral: self.smoothing(source_list, data_dict, radio, x_box) ) save_flexDPE_button.on_click(lambda source_list = source_list, attrname = attr_id, radio = radio_group: self.write_to_flexPDE(source_list, attrname, radio)) save_all_flexDPE_button.on_click(lambda source_list = source_list, attrname = attr_id: self.write_all_to_flexPDE(source_list, attrname)) save_textfile_button.on_click(lambda data_dict = data_dict, source_list = source_list, attrname = attr_id, radio = radio_group: self.write_new_datafile(data_dict, source_list, attrname,radio)) text_input_rsf.on_change("value", lambda attr, old, new, radio = radio_group, data_dict = data_dict, figure = figure_obj, source_list = source_list, text_input = text_input_rsf, line_list = line_list, which = "rsf": self.update_data(line_list, data_dict, source_list, figure, radio, text_input, new, which)) text_input_sputter.on_change("value", lambda attr, old, new, radio = radio_group, data_dict = data_dict, figure = figure_obj, source_list = source_list, text_input = text_input_sputter, which = "sputter": self.update_data(data_dict, source_list, figure, radio, text_input, new, which)) text_input_crater_depth.on_change("value", lambda attr, old, new, radio = radio_group, data_dict = data_dict, source_list = source_list, figure = figure_obj, text_input = text_input_crater_depth, which = "crater_depth": self.update_data(data_dict, source_list, figure, radio, text_input, new, which)) #Initialization of actual plotting. tab_plots.append(Panel(child = hplot(figure_obj, vform( vform(radio_group, save_flexDPE_button, save_all_flexDPE_button, save_textfile_button, matplot_button), vform(text_input_rsf, smoothing_button, text_input_sputter, text_input_crater_depth) ), vform(text_input_xval_integral, text_input_dose, do_integral_button)), title = attr_id)) """ Check to see if one or more element exists in the samples and creat a comparison plot for each of those elements. """ for element in self.all_elements: checkers = list(self.all_elements) checkers.remove(element) if element in checkers and not element in self.elements_comparison: self.elements_comparison.append(element) """create plots for each element that is to be compared """ for comparison_element in self.elements_comparison: figure_obj = figure(plot_width = 1000, plot_height = 800, y_axis_type = "log", title = comparison_element, tools = TOOLS) #figure_obj.xaxis.major_label_text_font_size("12pt") #figure_obj.yaxis.major_label_text_font_size("12pt") y_axis_units = [] x_axis_units = [] comparison_datasets = [] for data_dict_iter in self.column(self.figure_data, 1): for dataset in data_dict_iter["data"]: if dataset["sample_element"] == comparison_element: comparison_datasets.append(dataset) y_axis_units.append(dataset["y_unit"]) x_axis_units.append(dataset["x_unit"]) figure_obj.xaxis.axis_label = comparison_datasets[-1]["x_unit"] figure_obj.yaxis.axis_label = comparison_datasets[-1]["y_unit"] if not all(x == y_axis_units[-1] for x in y_axis_units): for unit, data in zip(y_axis_units, comparison_datasets): if not unit == y_axis_units[-1]: figure_obj.extra_y_ranges = {"foo": Range1d(start = np.amin(data["y"]), end = np.amax(data["y"]))} figure_obj.add_layout(LogAxis(y_range_name = "foo", axis_label = unit), "right") break if not all(x == x_axis_units[-1] for x in x_axis_units): for unit, data in zip(x_axis_units, comparison_datasets): if not unit == x_axis_units[-1]: figure_obj.extra_x_ranges = {"bar": Range1d(start = np.amin(data["x"]), end = np.amax(data["x"]))} figure_obj.add_layout(LinearAxis(x_range_name = "bar", axis_label = unit), "above") break active_sources = [] for data_dict, source_line_nested, attr_id, color_index in zip(self.column(self.figure_data, 1), self.source_line, self.attribute_ids, colour_indices): for dataset, source_lis_coup, in zip(data_dict["data"], source_line_nested[0]): source_local = source_lis_coup[0] active_sources.append(source_local) self.source_test(source_local) self.source_dataset_test(source_local, dataset) if dataset["sample_element"] == comparison_element: color = colour_list[color_index] """ Logic that ensures that plots get put with correspoinding axes. """ if dataset["x_unit"] != x_axis_units[-1] or dataset["y_unit"] != y_axis_units[-1]: if dataset["x_unit"] != x_axis_units[-1] and dataset["y_unit"] != y_axis_units[-1]: name_check = data_dict["gen_info"]["DATA FILES"] attr_id = name_check[1][4][:-3] + "_" + name_check[2][2] figure_obj.line("x", "y", source = source_local, line_width = 2, line_color = color, legend = attr_id, x_range_name = "bar", y_range_name = "foo") elif dataset["x_unit"] != x_axis_units[-1]: figure_obj.line("x", "y", source = source_local, line_width = 2, line_color = color, legend = attr_id, x_range_name = "bar") else: figure_obj.line("x", "y", source = source_local, line_width = 2, line_color = color, legend = attr_id, y_range_name = "foo") else: figure_obj.line("x", "y", source = source_local, line_width = 2, line_color = color, legend = attr_id) matplot_button = Button(label = "Create matplotlib fig") save_all_flexDPE_button = Button(label = "Save all elements for FlexPDE") matplot_button.on_click(lambda source_list = active_sources: self.matplotlib_export(source_list)) save_all_flexDPE_button.on_click(lambda source_list = active_sources, attrname = comparison_element: self.write_all_to_flexPDE(source_list, attrname)) tab_plots.append(Panel(child = hplot(figure_obj, vform(save_all_flexDPE_button, matplot_button)), title = comparison_element)) tabs = Tabs(tabs = tab_plots) #curdoc().add_root(tabs) session = push_session(curdoc()) session.show() session.loop_until_closed()
acq_period_select = Select(title="Acquisition Period (s):", value="100", options=[".5","1","10","100","300","1000"]) num_avgs_select = Select(title="Number of Points to Average:", value="100", options=["100","1000","10000","100000","1000000"]) channel_name_select1 = Select(title='Channel Select:', value="Channel 1", options =["Channel 1", "Channel 2", "Channel 3", "Channel 4"]) channel_name_select2 = Select(title='Channel Names:', value="Channel 1", options =["Channel 1", "Channel 2", "Channel 3", "Channel 4"]) number_points_select = Select(title="Number of Points", value="100", options =["100", "200", "500", "1000", "5000", "10000", "100000", "1000000"]) load_plot_type_select = Select(title="Plot Type:", value="Multi-plot", options =["Multi-plot", "Pulse Capture Plot"]) # Text inputs channel_name_input = TextInput(title="Name:") trigger_level_input = TextInput(value="1", title="Trigger Level (V)") time_range_input = TextInput(value="1000", title="Time Range (us)") load_file_input = TextInput(value=home_dir, title="Load file:") save_filepath_input = TextInput(value=home_dir, title="Save to directory:") force_save_filename_input = TextInput(value=str(dt.now(PT).year)+"_"+str(dt.now(PT).month)+"_"+str(dt.now(PT).day)+".h5", title="Save as filename:") save_filepath_PC_input = TextInput(value=home_dir, title="Save to directory:") save_filename_PC_input = TextInput(value="PC_"+str(dt.now(PT).year)+"_"+str(dt.now(PT).month)+"_"+str(dt.now(PT).day)+".h5", title="Save as filename:") #setup event handlers all_off_button.on_click(lambda x: allOff_ButtonClick()) all_on_button.on_click(lambda x: allOn_ButtonClick()) reset_button.on_click(lambda x: reset_ButtonClick())
height_map={ "Current Location":y_local_height, "Current Industry":y_indus_height, "Current Company":y_company_height } new_axis_map={ "Current Location":'location', "Current Industry":'industry', "Current Company":'company' } source = ColumnDataSource(data=dict(x=[],y=[],height=[])) cities=TextInput(title='location name') companies=TextInput(title='company name') industries=TextInput(title='industry name') x_axis=Select(title='X axis',options=sorted(axis_map.keys()),value='Current Industry') plot = figure(plot_height=600, plot_width=800, title="", toolbar_location=None, tools=[hover],x_range=industry[:10],y_range=[0,2000]) plot.rect(x='x',y='y',width=.8,height='height',source=source) plot.xaxis.major_label_orientation = np.pi/3 controls=[x_axis,cities,companies,industries] inputs=HBox(VBoxForm(*controls)) def select_types(): city_val=cities.value.strip() company_val=companies.value.strip()
from bokeh.io import curdoc from bokeh.layouts import column from bokeh.models.widgets import TextInput, Button, Paragraph # create some widgets button = Button(label="Say HI") input = TextInput(value="Bokeh") output = Paragraph() # add a callback to a widget def update(): output.text = "Hello, " + input.value button.on_click(update) # create a layout for everything layout = column(button, input, output) # add the layout to curdoc curdoc().add_root(layout)
# create a grid of samples xx, hx = np.linspace(source_view.data['x_start'][0], source_view.data['x_end'][0], curveintegral_settings.n_sample, retstep=True) yy, hy = np.linspace(source_view.data['y_start'][0], source_view.data['y_end'][0], curveintegral_settings.n_sample, retstep=True) x_val, y_val = np.meshgrid(xx, yy) # evaluate function at sample points u_val = u_fun(x_val, y_val) v_val = v_fun(x_val, y_val) return x_val, y_val, u_val, v_val, hx # initialize controls # text input for input of the vector function [fx(x,y),fy(x,y)] u_input = TextInput(value=curveintegral_settings.sample_functions[curveintegral_settings.init_fun_key][0], title="fx(x,y):") v_input = TextInput(value=curveintegral_settings.sample_functions[curveintegral_settings.init_fun_key][1], title="fy(x,y):") u_input.on_change('value', function_change) v_input.on_change('value', function_change) # text input for input of the parametrized curve [cx(t),cy(t)] cx_input = TextInput(value=curveintegral_settings.sample_curves[curveintegral_settings.init_curve_key][0], title="cx(t):") cy_input = TextInput(value=curveintegral_settings.sample_curves[curveintegral_settings.init_curve_key][1], title="cy(t):") # slider controlling the parameter t parameter_input = Slider(title="t", value=curveintegral_settings.parameter_input_init, start=curveintegral_settings.parameter_min,
x = np.linspace(0, 4 * np.pi, N) y = np.sin(x) source = ColumnDataSource(data=dict(x=x, y=y)) # Set up plot plot = figure(plot_height=800, plot_width=800, title="my sine wave", tools="crosshair,pan,reset,save,wheel_zoom", x_range=[0, 4 * np.pi], y_range=[-2.5, 2.5]) plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6) # Set up widgets text = TextInput(title="title", value='my sine wave') offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1) amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0, step=0.1) phase = Slider(title="phase", value=0.0, start=0.0, end=2 * np.pi) freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1, step=0.1) # Set up callbacks def update_title(attrname, old, new): plot.title.text = text.value text.on_change('value', update_title) def update_data(attrname, old, new):
N = 200 x = np.linspace(0, 4*np.pi, N) y = np.sin(x) source = ColumnDataSource(data=dict(x=x, y=y)) # Set up plot plot = Figure(plot_height=400, plot_width=400, title="my sine wave", tools="crosshair,pan,reset,resize,save,wheel_zoom", x_range=[0, 4*np.pi], y_range=[-2.5, 2.5]) plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6) # Set up widgets text = TextInput(title="title", value='my sine wave') offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1) amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0) phase = Slider(title="phase", value=0.0, start=0.0, end=2*np.pi) freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1) # Set up callbacks def update_title(attrname, old, new): plot.title.text = text.value text.on_change('value', update_title) def update_data(attrname, old, new): # Get the current slider values
width=200, options=bond_type_selections) scale_select = Select(value=scale_selections[0], title=u'基金资产净值', width=200, options=scale_selections) time_select = Select(value=u'1年', title=u'业绩时间窗口', width=200, options=time_selections) time_select.on_change('value', lambda attr, old, new: update_data()) fund_button = Button(label=u"筛选基金", button_type="success", width=200) fund_button.on_click(select_fund) update_button = Button(label=u'更新数据', button_type='success', width=200) update_button.on_click(update_new_data) fund_text = TextInput(value='000088.OF', title=u'基金Wind代码', width=200) fund_text.on_change('value', lambda attr, old, new: update_data()) columns = [ TableColumn(field='sec_name', title=u'基金简称'), TableColumn(field='wind_code', title=u'万得代码'), TableColumn(field='fundmanager', title=u'基金经理'), TableColumn(field='netasset', title=u'基金资产净值', formatter=NumberFormatter(format='$0,0.00')), TableColumn(field='current return', title=u'当前业绩', formatter=NumberFormatter(format='0.00%')), TableColumn(field='volatility', title=u'波动率', formatter=NumberFormatter(format='0.00%')),
from bokeh.models.widgets import Button, TextInput label_saccade_button = Button(label='saccade') label_saccade_button.on_click(label_saccade_cb) label_pursuit_button = Button(label='pursuit') label_pursuit_button.on_click(label_pursuit_cb) label_fixation_button = Button(label='fixation') label_fixation_button.on_click(label_fixation_cb) remove_button = Button(label='remove') remove_button.on_click(remove_cb) trial_text = TextInput(value=str(trialNum)) trial_text.on_change('value', trial_text_cb) nextTrial_button = Button(label='+trial') nextTrial_button .on_click(next_trial_cb) prevTrial_button= Button(label='-trial') prevTrial_button.on_click(prev_trial_cb) from bokeh.layouts import row buttonBox = row(label_saccade_button, label_pursuit_button, label_fixation_button, remove_button) trialSelectBox = row(prevTrial_button, trial_text, nextTrial_button) #, sizing_mode='scale_width' ########################################################################### # Get the HTML description header
update_volume_table() update_eyby() update_industry_corr() # update_min_liquidity() # update_wei_index_table() # update_wei_index() update_record_high_table() asset_select = Select(value=u"万得全A指数", title="资产", width=300, options=asset_selections) asset_select.on_change('value', lambda attr, old, new: update_data()) time_text = TextInput(value="2005-01-01", title="开始时间(例如:20050101或2005-01-01)", width=300) time_text.on_change('value', lambda attr, old, new: update_all()) today = (datetime.datetime.today() - datetime.timedelta(1)) time_end_text = TextInput(value=today.strftime("%Y-%m-%d"), title="终止时间", width=300) time_end_text.on_change('value', lambda attr, old, new: update_all()) asset_text_1 = TextInput(value="881001.WI", title=u"资产一(万得代码)", width=300) asset_text_2 = TextInput(value="HSI.HI", title=u"资产二(万得代码)", width=300) department_select = Select(value=u"万得全A", title=u"选择板块", width=300, options=index_selections) department_select.on_change('value', lambda attr, old, new: update_cost()) industry_select = Select(value=u"石油石化",