def update_colormap(attrname, old, new_frequency): """ updates the coloring of the plot. :param attrname: unused, but needed for bokeh callback functions :param old: unused, but needed for bokeh callback functions :param new_frequency: new value for the frequency """ mandel_iterations = source_mandel_raw.data['its'][0] frequency = int( np.mean(mandel_iterations[ mandel_iterations != int(slider_max_iterations.value)]) / new_frequency * 10) # todo magic number? print "calculating colors." col = mandel_colormap.iteration_count_to_rgb_color(mandel_iterations, frequency, int(slider_max_iterations.value)) img = mandel_colormap.rgb_color_to_bokeh_rgba(color=col) print "done." print "updating image data." view_data = my_bokeh_utils.get_user_view(plot) source_view.data = view_data source_image.data = dict(image=[img], x0=view_data['x_start'], y0=view_data['y_start'], xw=[view_data['x_end'][0]-view_data['x_start'][0]], yw=[view_data['y_end'][0]-view_data['y_start'][0]], freq=[new_frequency]) print "data was updated."
def update_colormap(attrname, old, new_frequency): """ updates the coloring of the plot. :param attrname: unused, but needed for bokeh callback functions :param old: unused, but needed for bokeh callback functions :param new_frequency: new value for the frequency """ mandel_iterations = source_mandel_raw.data['its'][0] frequency = int( np.mean(mandel_iterations[ mandel_iterations != int(slider_max_iterations.value)]) / new_frequency * 10) # todo magic number? print "calculating colors." col = mandel_colormap.iteration_count_to_rgb_color( mandel_iterations, frequency, int(slider_max_iterations.value)) img = mandel_colormap.rgb_color_to_bokeh_rgba(color=col) print "done." print "updating image data." view_data = my_bokeh_utils.get_user_view(plot) source_view.data = view_data source_image.data = dict( image=[img], x0=view_data['x_start'], y0=view_data['y_start'], xw=[view_data['x_end'][0] - view_data['x_start'][0]], yw=[view_data['y_end'][0] - view_data['y_start'][0]], freq=[new_frequency]) print "data was updated."
def update_mandelbrot_set(): """ updates the raw data of the mandelbrot set corresponding to the current user input. Therefore the currently observed part of the mandelbrot set is computed using the given maximum iteration number. The output data is written to the corresponding bokeh.models.ColumnDataSource """ view_data = my_bokeh_utils.get_user_view(plot) x0 = view_data['x_start'][0] xw = view_data['x_end'][0] - x0 y0 = view_data['y_start'][0] yw = view_data['y_end'][0] - y0 print "calculating mandelbrot set." mandel_iterations = mandel.mandel( x0, y0, xw, yw, # user view mandelbrot_settings.x_res, mandelbrot_settings.y_res, # resolution slider_max_iterations.value, # maximum number of iterations mandelbrot_settings.iteration_bound) print "done." print "updating raw data." source_mandel_raw.data = dict(its=[mandel_iterations], max_iter=[int(slider_max_iterations.value)]) print "data was updated."
def refresh_user_view(): """ periodically called function that updates data with respect to the current user view, if the user view has changed. """ user_view_has_changed = my_bokeh_utils.check_user_view( source_view.data, plot) if user_view_has_changed: source_view.data = my_bokeh_utils.get_user_view(plot) update_quiver_data() update_data(None, None, None)
def refresh_quiver(): """ periodically called function that updates data with respect to the current user view, if the user view has changed. :return: """ user_view_has_changed = my_bokeh_utils.check_user_view(source_view.data, plot_field) if user_view_has_changed: u_str = u_input.value v_str = v_input.value update_quiver_data(u_str, v_str) source_view.data = my_bokeh_utils.get_user_view(plot_field)
def refresh_quiver(): """ periodically called function that updates data with respect to the current user view, if the user view has changed. :return: """ user_view_has_changed = my_bokeh_utils.check_user_view( source_view.data, plot_field) if user_view_has_changed: u_str = u_input.value v_str = v_input.value update_quiver_data(u_str, v_str) source_view.data = my_bokeh_utils.get_user_view(plot_field)
def refresh_user_view(): """ periodically called function that updates data with respect to the current user view, if the user view has changed. :return: """ user_view_has_changed = my_bokeh_utils.check_user_view(source_view.data, plot) if user_view_has_changed: u_str = u_input.value v_str = v_input.value x_mark = source_initialvalue.data['x0'][0] y_mark = source_initialvalue.data['y0'][0] update_quiver_data(u_str, v_str) update_streamline_data(u_str, v_str, x_mark, y_mark) source_view.data = my_bokeh_utils.get_user_view(plot) interactor.update_to_user_view()
def refresh_user_view(): """ periodically called function that updates data with respect to the current user view, if the user view has changed. :return: """ user_view_has_changed = my_bokeh_utils.check_user_view( source_view.data, plot) if user_view_has_changed: u_str = u_input.value v_str = v_input.value x_mark = source_initialvalue.data['x0'][0] y_mark = source_initialvalue.data['y0'][0] update_quiver_data(u_str, v_str) update_streamline_data(u_str, v_str, x_mark, y_mark) source_view.data = my_bokeh_utils.get_user_view(plot) interactor.update_to_user_view()
def refresh_contour(): """ periodically called function that updates data with respect to the current user view, if the user view has changed. """ user_view_has_changed = my_bokeh_utils.check_user_view(source_view.data, plot) if user_view_has_changed: f, _ = my_bokeh_utils.string_to_function_parser(f_input.value, ['x', 'y']) g, _ = my_bokeh_utils.string_to_function_parser(g_input.value, ['x', 'y']) if len(source_mark.data['x']) > 0: # has any point been marked? compute_click_data() contour_f.compute_contour_data(f) contour_g.compute_contour_data(g, [0]) interactor.update_to_user_view() source_view.data = my_bokeh_utils.get_user_view(plot)
def automatic_update(): """ Function that is regularly called by the periodic callback. Updates the plots to the current user view. """ user_view_has_changed = my_bokeh_utils.check_user_view(source_view.data, plot) if user_view_has_changed: source_view.data = my_bokeh_utils.get_user_view(plot) # read control variables N = int(round(degree.value)) # Get the current slider values f = source_f.data['f'][0] t_start = source_periodicity.data['t_start'][0] t_end = source_periodicity.data['t_end'][0] print "updating plot" update_plot(f, N, t_start, t_end)
def automatic_update(): """ Function that is regularly called by the periodic callback. Updates the plots to the current user view. """ user_view_has_changed = my_bokeh_utils.check_user_view( source_view.data, plot) if user_view_has_changed: source_view.data = my_bokeh_utils.get_user_view(plot) # read control variables N = int(round(degree.value)) # Get the current slider values f = source_f.data['f'][0] t_start = source_periodicity.data['t_start'][0] t_end = source_periodicity.data['t_end'][0] print "updating plot" update_plot(f, N, t_start, t_end)
def update_mandelbrot_set(): """ updates the raw data of the mandelbrot set corresponding to the current user input. Therefore the currently observed part of the mandelbrot set is computed using the given maximum iteration number. The output data is written to the corresponding bokeh.models.ColumnDataSource """ view_data = my_bokeh_utils.get_user_view(plot) x0 = view_data['x_start'][0] xw = view_data['x_end'][0] - x0 y0 = view_data['y_start'][0] yw = view_data['y_end'][0] - y0 print "calculating mandelbrot set." mandel_iterations = mandel.mandel(x0, y0, xw, yw, # user view mandelbrot_settings.x_res, mandelbrot_settings.y_res, # resolution slider_max_iterations.value, # maximum number of iterations mandelbrot_settings.iteration_bound) print "done." print "updating raw data." source_mandel_raw.data = dict(its=[mandel_iterations], max_iter=[int(slider_max_iterations.value)]) print "data was updated."
legend_label='fourier series' ) plot.patch('x_patch', 'y_patch', source=source_interval_patch, alpha=.2) plot.line('x_min', 'y_minmax', source=source_interval_bound) plot.line('x_max', 'y_minmax', source=source_interval_bound) sample_controls = widgetbox(sample_function_type) default_controls = column(default_function_input,default_function_period_start,default_function_period_end) # Panels for sample functions or default functions sample_funs = Panel(child=sample_controls, title='sample function') default_funs = Panel(child=default_controls, title='default function') # Add panels to tabs fun_tabs = Tabs(tabs=[sample_funs, default_funs]) fun_tabs.on_change('active', type_input_change) # add callback for panel tabs # lists all the controls in our app controls = column(degree,fun_tabs) # initialize data source_view.data = my_bokeh_utils.get_user_view(plot) function_change() # regularly update user view curdoc().add_periodic_callback(automatic_update, 1000) # make layout curdoc().add_root(row(plot, controls, height=600, width=800)) curdoc().title = split(dirname(__file__))[-1].replace('_',' ').replace('-',' ') # get path of parent directory and only use the name of the Parent Directory for the tab name. Replace underscores '_' and minuses '-' with blanks ' '