def __call__(self, *args, **kwargs):
        assert all([linename in kwargs.keys() for linename in self.linenames]), "Line names must be in dict of keyword " \
                                                                                "arguments."

        for linename in self.linenames:
            # Fetch from kwargs
            inp = kwargs[linename]
            # Parse
            if isinstance(inp, (tuple, list)):
                assert len(inp) == 2
                xval, yval = inp
            else:
                yval = inp
                if self.xaxis == 'iterations':
                    xval = kwargs['iternum']
                elif self.xaxis == 'epochs':
                    xval = kwargs['epoch']
                elif self.xaxis in kwargs.keys():
                    # Easter egg
                    xval = kwargs[self.xaxis]
                else:
                    raise NotImplementedError(
                        "Unknown token for x-axis: {}. Correct tokens are: "
                        "'iterations' and 'epochs'".format(self.xaxis))

            self.datasources[linename].data["y"].append(yval)
            self.datasources[linename].data["x"].append(xval)

            # Send to server
            bplt.cursession().store_objects(self.datasources[linename])
Exemple #2
0
    def __call__(self, *args, **kwargs):
        # Note: there used to be an assert statement here about linenames not being in kwargs.keys(). These days, a
        # linename is simply ignored (for the iteration) if it's not passed as a keyword arg.

        for linename in self.linenames:
            # Fetch from kwargs if it's in there (skip otherwise)
            # Skip
            if linename not in kwargs.keys():
                continue
            # Fetch
            inp = kwargs[linename]
            # Parse
            if isinstance(inp, (tuple, list)):
                assert len(inp) == 2
                xval, yval = inp
            else:
                yval = inp
                if self.xaxis == 'iterations':
                    xval = kwargs['iternum']
                elif self.xaxis == 'epochs':
                    xval = kwargs['epoch']
                elif self.xaxis in kwargs.keys():
                    # Easter egg
                    xval = kwargs[self.xaxis]
                else:
                    raise NotImplementedError("Unknown token for x-axis: {}. Correct tokens are: "
                                              "'iterations' and 'epochs'".format(self.xaxis))

            self.datasources[linename].data["y"].append(yval)
            self.datasources[linename].data["x"].append(xval)

            # Send to server
            bplt.cursession().store_objects(self.datasources[linename])
Exemple #3
0
 def update(self, r, theta):
     renderer = self.plot.select(dict(name='scatter'))[0]
     x = r * cos(theta)
     y = r * sin(theta)
     renderer.data_source.data['x'] = x
     renderer.data_source.data['y'] = y
     cursession().store_objects(renderer.data_source)
 def set_data_images(self, data_img, img_list):
     if len(data_img) != len(img_list):
         print 'ERROR: Number of images incorrect. It should be: ' + str(len(data_img)) + ' and got: ' \
               + str(len(img_list))
         exit()
     else:
         for i in xrange(len(data_img)):
             data_img[i].data['image'] = [self.convert_image(img_list[i])]
             cursession().store_objects(data_img[i])
 def set_data_images(self, data_img, img_list):
     if len(data_img) != len(img_list):
         print 'ERROR: Number of images incorrect. It should be: ' + str(len(data_img)) + ' and got: ' \
               + str(len(img_list))
         exit()
     else:
         for i in xrange(len(data_img)):
             data_img[i].data['image'] = [self.convert_image(img_list[i])]
             cursession().store_objects(data_img[i])
 def run(self):
     while not rospy.is_shutdown():
         print "<<<<<< Updating plot >>>>>"
         self.ds.data["x"] = self.x_data
         self.ds.data["y"] = self.y_data
         self.ds._dirty = True
         cursession().store_objects(self.ds)
     
         time.sleep(0.01)
Exemple #7
0
 def update(self, acq):
     c1, c2 = acq.plot_code_window
     dopp_min, dopp_max = acq.dopp_bins[0], acq.dopp_bins[-1]
     img = self.make_image(acq.plot_corr)
     self.renderer.data_source.data['image'] = img
     self.renderer.data_source.data['x'] = [c1]
     self.renderer.data_source.data['y'] = [c2]
     self.renderer.data_source.data['dw'] = [c2 - c1]
     self.renderer.data_source.data['dh'] = [dopp_max - dopp_min]
     cursession().store_objects(self.renderer.data_source)
Exemple #8
0
    def update(self, acq):
        renderer = self.plot.select(dict(name='line'))[0]
        angles = unwrap(angle(acq.phases))
        t = arange(len(angles)) * acq.block_length

        print(t[0], t[-1], angles[0], angles[-1])
        renderer.data_source.data['x'] = t
        renderer.data_source.data['y'] = angles
        renderer.data_source._dirty = True
        cursession().store_objects(renderer.data_source)
 def append_data_plot(self, values):
     if self.n_lines_plot != len(values):
         print 'ERROR: Number of values incorrect. It should be: ' + str(self.n_lines_plot) + ' and got: ' \
               + str(len(values))
         exit()
     else:
         for i in xrange(len(self.data_plot)):
             self.data_plot[i].data["x"].append(len(self.data_plot[i].data["x"]))
             self.data_plot[i].data["y"].append(values[i])
             cursession().store_objects(self.data_plot[i])
 def append_data_plot(self, values):
     if self.n_lines_plot != len(values):
         print 'ERROR: Number of values incorrect. It should be: ' + str(self.n_lines_plot) + ' and got: ' \
               + str(len(values))
         exit()
     else:
         for i in xrange(len(self.data_plot)):
             self.data_plot[i].data["x"].append(
                 len(self.data_plot[i].data["x"]))
             self.data_plot[i].data["y"].append(values[i])
             cursession().store_objects(self.data_plot[i])
Exemple #11
0
def update_plot(algo):
    ''' Extend this to update a live streaming plot (require bokeh server)
    '''
    # Dive into the 'history_container' how lookbacks are calculated
    hist_df = algo.history(5, '1d', 'price')
    hist_df = hist_df.fill_na(0)
    for sid_id in algo.asset_finder.sids:
        renderer = algo.figure.select(dict(name=str(sid_id)))[0]
        ds = renderer.data_source
        ds.data["y"] = hist_df[sid_id].values
        cursession().store_objects(ds)
def background_thread(ds):
    """Plot animation, update data if play is True, otherwise stop"""
    try:
        while True:
            for i in np.hstack((np.linspace(1, -1, 100), np.linspace(-1, 1, 100))):
                if should_play():
                    ds.data["y"] = y * i
                    cursession().store_objects(ds)
                time.sleep(0.05)
    except:
        logger.exception("An error occurred")
        raise
Exemple #13
0
 def run(self):
     while True:
         priority, obj = self.queue.get()
         if priority == PushThread.PUT:
             cursession().store_objects(obj)
         elif priority == PushThread.PUSH:
             push()
             # delete queued objects when training has finished
             if obj == "after_training":
                 with self.queue.mutex:
                     del self.queue.queue[:]
                 break
         self.queue.task_done()
Exemple #14
0
 def run(self):
     while True:
         priority, obj = self.queue.get()
         if priority == PushThread.PUT:
             cursession().store_objects(obj)
         elif priority == PushThread.PUSH:
             push()
             # delete queued objects when training has finished
             if obj == "after_training":
                 with self.queue.mutex:
                     del self.queue.queue[:]
                 break
         self.queue.task_done()
Exemple #15
0
 def on_epoch_end(self, epoch, logs={}):
     I = self.get_image()
     if not hasattr(self, 'fig'):
         self.fig = figure(title=self.fig_title,
                           x_range=[0, 1], y_range=[0, 1])
         self.fig.image(image=[I], x=[0], y=[0], dw=[1], dh=[1],
                        name='weight')
         renderer = self.fig.select({'name': 'weight'})
         self.plots.append(renderer[0].data_source)
         show(self.fig)
     else:
         self.plots[0].data['image'] = [I]
     cursession().store_objects(self.plots[0])
     push()
Exemple #16
0
    def __init__(self,
                 mode='arduino',
                 serialObject=None):  #nof indicates number of json fields
        self.mode = mode
        self.modeset = True
        if mode is 'arduino':
            import serial
            if serialObject is None:
                n = 0
                while True:
                    try:
                        self.ser = serial.Serial(SERIAL_PORT_DEV + str(n),
                                                 BAUDRATE)
                        break
                    except serial.serialutil.SerialException:
                        print 'Could not open any serial port on {0}{1}. Trying with {0}{2}'.format(
                            SERIAL_PORT_DEV, n, n + 1)
                        n += 1
            else:
                self.ser = serialObject
                self.ser.open()
        elif mode is 'rpi':
            self.bmp, self.dht = BMP180Wrapper(), DHT22Wrapper()

        self.data = {}
        self.data["temp"], self.data["hum"], self.data["pres"], self.data[
            "timenow"] = [], [], [], []
        self.lastdata = ''
        self.lastjson = None

        #charts
        self.tempchart, self.preschart, self.humchart = MeteoStation.MeteoChart(
            'temp', 'Temperature',
            'Temperature in *C'), MeteoStation.MeteoChart(
                'pres', 'Pressure',
                'Pressure in hPa'), MeteoStation.MeteoChart(
                    'hum', 'Humidity', 'Humidity in %RH')
        self.charts = [self.tempchart, self.preschart, self.humchart]
        self.figs = [chart.fig for chart in self.charts]
        self.show_all()
        cursession().publish()

        #pymongo integration
        try:
            self.db = client['meteo_db']
            self.collection = self.db.colletion['meteo_data_collection']
        except:  #retry with object-style formalism
            self.db = client.meteo_db
            self.collection = self.db.collection.meteo_data_collection
Exemple #17
0
    def update_plots(self, epoch, monitors):
        """
        Given the calculated monitors (collapsed name and value tuple), add its datapoint to the appropriate figure
        and update the figure in bokeh-server.

        Parameters
        ----------
        epoch : int
            The epoch (x-axis value in the figure).
        monitors : dict
            The dictionary of monitors calculated at this epoch. The dictionary is of the form
            {collapsed_monitor_name: value}. The name is the same that was used in the creation of the
            figures in the plot, so it is used as the key to finding the appropriate figure to add the
            data.
        """
        if BOKEH_AVAILABLE:
            for key, value in monitors.items():
                if key in self.figure_indices:
                    if key not in self.plots:
                        # grab the correct figure by its index for the key (same with the color)
                        fig = self.figures[self.figure_indices[key]]
                        color_idx = self.figure_color_indices[
                            self.figure_indices[key]]
                        # split the channel from the monitor name
                        name = key.split(COLLAPSE_SEPARATOR, 1)
                        if len(name) > 1:
                            name = name[1]
                        else:
                            name = name[0]
                        # create a new line
                        fig.line([epoch], [value],
                                 legend=name,
                                 x_axis_label='iterations',
                                 y_axis_label='value',
                                 name=name,
                                 line_color=self.colors[color_idx %
                                                        len(self.colors)])
                        color_idx += 1
                        # set the color index back in the figure list
                        self.figure_color_indices[
                            self.figure_indices[key]] = color_idx
                        # grab the render object and put it in the plots dictionary
                        renderer = fig.select(dict(name=name))
                        self.plots[key] = renderer[0].data_source
                    else:
                        self.plots[key].data['x'].append(epoch)
                        self.plots[key].data['y'].append(value)
                        cursession().store_objects(self.plots[key])
            push()
    def __init__(self, title, legends, n_images_train=0, n_images_test=0, n_cols_images=3, axisx="Epochs",
                 axisy="Values", line_width=4, alpha=0.8, line_dash=[4, 4], plot_width=800, plot_height=400):

        # Save some parameters
        self.n_lines_plot = len(legends)
        self.n_images_train = n_images_train
        self.n_images_test = n_images_test

        # prepare output to server
        output_server(title)
        cursession().publish()

        # Create the figure plot
        if self.n_lines_plot > 0:
            p_plot, self.data_plot = self.create_figure_plot(title, legends, axisx=axisx, axisy=axisy,
                                                             line_width=line_width, alpha=alpha, line_dash=line_dash,
                                                             plot_width=plot_width, plot_height=plot_height)

        if n_images_train > 0:
            # Create black images as initialization
            img = np.zeros((64, 256, 3))
            img_batch = []
            for i in xrange(n_images_train):
                img_batch.append(img)

            # Create the training image grid
            p_images_train, self.data_img_train = self.create_grid_images(img_batch, name='img_train', n_cols=n_cols_images)

        if n_images_test > 0:
            # Create black images as initialization
            img = np.zeros((64, 256, 3))
            img_batch = []
            for i in xrange(n_images_test):
                img_batch.append(img)

            # Create the testing image grid
            p_images_test, self.data_img_test = self.create_grid_images(img_batch, name='img_test', n_cols=n_cols_images)

        # Create a vertical grid with the plot and the train and test images
        if self.n_lines_plot > 0 and n_images_train > 0 and n_images_test > 0:
            p = vplot(p_plot, p_images_train, p_images_test)
        elif self.n_lines_plot > 0 and n_images_train > 0 and n_images_test <= 0:
            p = vplot(p_plot, p_images_train)
        else:
            print 'ERROR: Not implemented combination. Please, do it!'

        # Show the plot
        show(p)
Exemple #19
0
def main(document, server_url):
    plots = {}

    output_server(document, url=server_url)

    # Create figures for each group of channels
    p = []
    p_indices = {}
    for i, channel_set in enumerate(channels):
        channel_set_opts = {}
        if isinstance(channel_set, dict):
            channel_set_opts = channel_set
            channel_set = channel_set_opts.pop("channels")
        channel_set_opts.setdefault("title", "{} #{}".format(document, i + 1))
        p.append(figure(**channel_set_opts))
        for channel in channel_set:
            p_indices[channel] = i

    files = [f for f in listdir(document) if isfile(join(document, f)) and "_log_" in f]

    for file_name in sorted(files, key=lambda s: int(re.findall(r"\d+", s)[1])):
        with open(join(document, file_name), "rb") as f:
            log = pickle.load(f)

        iteration = log.status["iterations_done"]
        i = 0
        for key, value in log.current_row.items():
            if key in p_indices:
                if key not in plots:
                    fig = p[p_indices[key]]
                    fig.line(
                        [iteration],
                        [value],
                        legend=key,
                        x_axis_label="iterations",
                        y_axis_label="value",
                        name=key,
                        line_color=colors[i % len(colors)],
                    )
                    i += 1
                    renderer = fig.select(dict(name=key))
                    plots[key] = renderer[0].data_source
                else:
                    plots[key].data["x"].append(iteration)
                    plots[key].data["y"].append(value)

                    cursession().store_objects(plots[key])
        push()
Exemple #20
0
def animated():

    from numpy import pi, cos, sin, linspace, zeros_like

    N = 50 + 1
    r_base = 8
    theta = linspace(0, 2 * pi, N)
    r_x = linspace(0, 6 * pi, N - 1)
    rmin = r_base - cos(r_x) - 1
    rmax = r_base + sin(r_x) + 1

    colors = ["FFFFCC", "#C7E9B4", "#7FCDBB", "#41B6C4", "#2C7FB8",
              "#253494", "#2C7FB8", "#41B6C4", "#7FCDBB", "#C7E9B4"] * 5

    cx = cy = zeros_like(rmin)

    output_server("animated_reveal")

    figure(title="Animations")

    hold()

    annular_wedge(
        cx, cy, rmin, rmax, theta[:-1], theta[1:],
        x_range=[-11, 11],
        y_range=[-11, 11],
        inner_radius_units="data",
        outer_radius_units="data",
        fill_color=colors,
        line_color="black",
        tools="pan,wheel_zoom,box_zoom,reset,previewsave"
    )

    return curplot(), cursession()
Exemple #21
0
def update_plots(root, figures, types):
    # for type, ids in types.iteritems():
    for type, fig in figures.iteritems():
        for id in types[type]:
            renderer = fig.select(dict(name=id))
            ds = renderer[0].data_source
            y = get_data(root, id)
            # if len(y) > fig.x_range.end-5:
            #     print "heeeeey"
            #     fig.x_range = Range1d(start=0, end=len(y)+20)
            ds.data["y"] = y
            ds.data["x"] = np.arange(len(y))
            ds._dirty = True
            cursession().store_objects(ds)

    cursession().publish()
Exemple #22
0
def distribution():

    mu, sigma = 0, 0.5

    measured = np.random.normal(mu, sigma, 1000)
    hist, edges = np.histogram(measured, density=True, bins=20)

    x = np.linspace(-2, 2, 1000)
    pdf = 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(x - mu) ** 2 / (2 * sigma ** 2))
    cdf = (1 + scipy.special.erf((x - mu) / np.sqrt(2 * sigma ** 2))) / 2

    output_server("distribution_reveal")

    hold()

    figure(title="Interactive plots",
           tools="pan, wheel_zoom, box_zoom, reset, previewsave",
           background_fill="#E5E5E5")
    quad(top=hist, bottom=np.zeros(len(hist)), left=edges[:-1], right=edges[1:],
         fill_color="#333333", line_color="#E5E5E5", line_width=3)

    # Use `line` renderers to display the PDF and CDF
    line(x, pdf, line_color="#348abd", line_width=8, alpha=0.7, legend="PDF")
    line(x, cdf, line_color="#7a68a6", line_width=8, alpha=0.7, legend="CDF")

    xgrid().grid_line_color = "white"
    xgrid().grid_line_width = 3
    ygrid().grid_line_color = "white"
    ygrid().grid_line_width = 3

    legend().orientation = "top_left"

    return curplot(), cursession()
Exemple #23
0
def draw_plot(all_freqs, all_segm_dict, uniq_id="no-id"):
    #zbior nazw wszystkich komorek podczas symulacji
    cells_types = set()

    for i in range(len(all_freqs)):
        for e in all_freqs[i].keys():
            cells_types.add(e)

    #dla kazdego typu komorek przypisywany jest inny kolor
    col_dict = {}
    from bokeh.palettes import brewer
    colors_palette = brewer["Spectral"][11]
    color = lambda: random.randint(0, 255)
    for i, element in enumerate(cells_types):
        if i < 11:
            col_dict[element] = colors_palette[i]
        else:
            #losowy kolor
            col_dict[element] = ('#%02X%02X%02X' % (color(), color(), color()))

    #dodanie klucza od wartosci ktorych nie ma po pierwszej iteracji
    for element in cells_types:
        for i in range(len(all_freqs)):
            if element not in all_freqs[i]:
                all_freqs[i][element] = [0, 0, 0, 0]

    output_server("stops3" + uniq_id)

    bar, geny = plot_segments(all_freqs[0], col_dict)
    plot = plot_environment(all_segm_dict[0])

    push()

    return bar, plot, cursession(), geny
Exemple #24
0
def distribution():

    mu, sigma = 0, 0.5

    measured = np.random.normal(mu, sigma, 1000)
    hist, edges = np.histogram(measured, density=True, bins=20)

    x = np.linspace(-2, 2, 1000)
    pdf = 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(x - mu) ** 2 / (2 * sigma ** 2))
    cdf = (1 + scipy.special.erf((x - mu) / np.sqrt(2 * sigma ** 2))) / 2

    output_server("distribution_reveal")

    p = figure(title="Interactive plots",
               background_fill="#E5E5E5")
    p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
           fill_color="#333333", line_color="#E5E5E5", line_width=3)

    # Use `line` renderers to display the PDF and CDF
    p.line(x, pdf, line_color="#348abd", line_width=8, alpha=0.7, legend="PDF")
    p.line(x, cdf, line_color="#7a68a6", line_width=8, alpha=0.7, legend="CDF")

    p.legend.orientation = "top_left"

    p.xaxis.axis_label = 'x'
    p.xgrid[0].grid_line_color = "white"
    p.xgrid[0].grid_line_width = 3

    p.yaxis.axis_label = 'Pr(x)'
    p.ygrid[0].grid_line_color = "white"
    p.ygrid[0].grid_line_width = 3

    push()

    return p, cursession()
Exemple #25
0
def animated():

    from numpy import pi, cos, sin, linspace

    N = 50 + 1
    r_base = 8
    theta = linspace(0, 2 * pi, N)
    r_x = linspace(0, 6 * pi, N - 1)
    rmin = r_base - cos(r_x) - 1
    rmax = r_base + sin(r_x) + 1

    colors = ["FFFFCC", "#C7E9B4", "#7FCDBB", "#41B6C4", "#2C7FB8",
              "#253494", "#2C7FB8", "#41B6C4", "#7FCDBB", "#C7E9B4"] * 5

    output_server("animated_reveal")

    p = figure(title="Animations", x_range=[-11, 11], y_range=[-11, 11])

    p.annular_wedge(
        0, 0, rmin, rmax, theta[:-1], theta[1:],
        inner_radius_units="data",
        outer_radius_units="data",
        fill_color=colors,
        line_color="black",
    )

    push()

    return p, cursession()
Exemple #26
0
 def create_plot(self):
     output_server('animation')
     source = ColumnDataSource(data=dict(x=[], y=[]))
     p = figure(plot_width=800, plot_height=400)
     p.line(x='x', y='y', source=source, name='line')
     push()
     return p, cursession()
Exemple #27
0
def distribution():

    mu, sigma = 0, 0.5

    measured = np.random.normal(mu, sigma, 1000)
    hist, edges = np.histogram(measured, density=True, bins=20)

    x = np.linspace(-2, 2, 1000)
    pdf = 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(x - mu) ** 2 / (2 * sigma ** 2))
    cdf = (1 + scipy.special.erf((x - mu) / np.sqrt(2 * sigma ** 2))) / 2

    output_server("distribution_reveal")

    p = figure(title="Interactive plots",
               background_fill="#E5E5E5")
    p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
           fill_color="#333333", line_color="#E5E5E5", line_width=3)

    # Use `line` renderers to display the PDF and CDF
    p.line(x, pdf, line_color="#348abd", line_width=8, alpha=0.7, legend="PDF")
    p.line(x, cdf, line_color="#7a68a6", line_width=8, alpha=0.7, legend="CDF")

    p.legend.orientation = "top_left"

    p.xaxis.axis_label = 'x'
    p.xgrid[0].grid_line_color = "white"
    p.xgrid[0].grid_line_width = 3

    p.yaxis.axis_label = 'Pr(x)'
    p.ygrid[0].grid_line_color = "white"
    p.ygrid[0].grid_line_width = 3

    push()

    return p, cursession()
Exemple #28
0
def animated():

    from numpy import pi, cos, sin, linspace

    N = 50 + 1
    r_base = 8
    theta = linspace(0, 2 * pi, N)
    r_x = linspace(0, 6 * pi, N - 1)
    rmin = r_base - cos(r_x) - 1
    rmax = r_base + sin(r_x) + 1

    colors = ["FFFFCC", "#C7E9B4", "#7FCDBB", "#41B6C4", "#2C7FB8",
              "#253494", "#2C7FB8", "#41B6C4", "#7FCDBB", "#C7E9B4"] * 5

    output_server("animated_reveal")

    p = figure(title="Animations", x_range=[-11, 11], y_range=[-11, 11])

    p.annular_wedge(
        0, 0, rmin, rmax, theta[:-1], theta[1:],
        inner_radius_units="data",
        outer_radius_units="data",
        fill_color=colors,
        line_color="black",
    )

    push()

    return p, cursession()
Exemple #29
0
    def __init__(self, name, fig_title, url):
        """
        fig_title: Figure Title
        url : str, optional
            Url of the bokeh-server. Ex: when starting the bokeh-server with
            ``bokeh-server --ip 0.0.0.0`` at ``alice``, server_url should be
            ``http://alice:5006``. When not specified the default configured
            by ``bokeh_server`` in ``.blocksrc`` will be used. Defaults to
            ``http://localhost:5006/``.

        Reference: mila-udem/blocks-extras
        """
        Callback.__init__(self)
        self.name = name
        self.fig_title = fig_title
        self.plots = []
        output_server(name, url=url)
        cursession().publish()
Exemple #30
0
    def do(self, which_callback, *args):
        log = self.main_loop.log
        iteration = log.status["iterations_done"]
        i = 0
        for key, value in log.current_row.items():
            if key in self.p_indices:
                if key not in self.plots:
                    fig = self.p[self.p_indices[key]]
                    fig.line([iteration], [value], legend=key, name=key, line_color=self.colors[i % len(self.colors)])
                    i += 1
                    renderer = fig.select(dict(name=key))
                    self.plots[key] = renderer[0].data_source
                else:
                    self.plots[key].data["x"].append(iteration)
                    self.plots[key].data["y"].append(value)

                    cursession().store_objects(self.plots[key])
        push()
def bokeh_animated_colours(data_source):
    """
    Creates a coloured map of London tube stations by zone where the size of the tube station changes
    according to the number of people on the station
    :param data_source:
    :return:
    """
    #create the map
    data_file="/home/winterflower/programming_projects/python-londontube/src/data/londontubes.txt"
    map=simulation_utils.Map(data_file)
    map.initialise_map()
    graph_object=map.graph_object
    map=sim.initialise_commuters(map)
    print "Please make sure the bokeh-server is running before you run the script"
    output_server("bokeh_tube_stations")
    TOOLS="resize,hover,save"
    animated_figure=figure(title="London Underground", tools=TOOLS)
    animated_figure.plot_height=1000
    animated_figure.plot_width=1000
    length=len(data_source.data["longitudes"])
    ########################################
    #Get the sizes
    #######################################
    commuters=get_commuter_numbers(data_source.data["station_names"], map)
    # scale the commuters
    color=map_to_colours(commuters)
    data_source.data["color"]=color
    size=[10 for i in range(length)]
    animated_figure.circle(data_source.data["longitudes"], data_source.data["latitudes"], size=data_source.data["size"], color=data_source.data["color"], alpha=0.8, name="circle")
    show(animated_figure)

    #obtain the glyph renderer
    glyph_renderer=animated_figure.select((dict(name="circle")))
    print glyph_renderer
    figure_data_source=glyph_renderer[0].data_source
    while True:
        map=sim.simulate_one_cycle(map)
        commuters=get_commuter_numbers(data_source.data["station_names"],map)
        color=map_to_colours(commuters)
        size=map_to_comuters(commuters)
        figure_data_source.data["color"]=color
        figure_data_source.data["size"]=size
        cursession().store_objects(figure_data_source)
        time.sleep(0.05)
Exemple #32
0
    def update_plots(self, epoch, monitors):
        """
        Given the calculated monitors (collapsed name and value tuple), add its datapoint to the appropriate figure
        and update the figure in bokeh-server.

        Parameters
        ----------
        epoch : int
            The epoch (x-axis value in the figure).
        monitors : dict
            The dictionary of monitors calculated at this epoch. The dictionary is of the form
            {collapsed_monitor_name: value}. The name is the same that was used in the creation of the
            figures in the plot, so it is used as the key to finding the appropriate figure to add the
            data.
        """
        if BOKEH_AVAILABLE:
            for key, value in monitors.items():
                if key in self.figure_indices:
                    if key not in self.plots:
                        # grab the correct figure by its index for the key (same with the color)
                        fig = self.figures[self.figure_indices[key]]
                        color_idx = self.figure_color_indices[self.figure_indices[key]]
                        # split the channel from the monitor name
                        name = key.split(COLLAPSE_SEPARATOR, 1)
                        if len(name) > 1:
                            name = name[1]
                        else:
                            name = name[0]
                        # create a new line
                        fig.line([epoch], [value], legend=name,
                                 x_axis_label='iterations',
                                 y_axis_label='value', name=name,
                                 line_color=self.colors[color_idx % len(self.colors)])
                        color_idx += 1
                        # set the color index back in the figure list
                        self.figure_color_indices[self.figure_indices[key]] = color_idx
                        # grab the render object and put it in the plots dictionary
                        renderer = fig.select(dict(name=name))
                        self.plots[key] = renderer[0].data_source
                    else:
                        self.plots[key].data['x'].append(epoch)
                        self.plots[key].data['y'].append(value)
                        cursession().store_objects(self.plots[key])
            push()
Exemple #33
0
def update_animation(plot, session):

    from numpy import roll

    renderer = plot.select(dict(type=GlyphRenderer))
    ds = renderer[0].data_source

    while True:

        rmin = ds.data["inner_radius"]
        rmin = roll(rmin, 1)
        ds.data["inner_radius"] = rmin

        rmax = ds.data["outer_radius"]
        rmax = roll(rmax, -1)
        ds.data["outer_radius"] = rmax

        cursession().store_objects(ds)
        time.sleep(0.1)
Exemple #34
0
    def update(self, svid, azimuth, elevation):
        self.data[svid] = SkyCoordinates(azimuth, elevation)
        
        azimuth = asarray([sky.azimuth for sky in self.data.values()]).flatten()
        elevation = asarray([sky.elevation for sky in self.data.values()]).flatten()

        r = 90 - elevation
        theta = pi / 2 - radians(azimuth)
        mask = r < 90
        print(azimuth.shape, elevation.shape, npsum(mask))
        r = r[mask]
        theta = theta[mask]
        x = r * cos(theta)
        y = r * sin(theta)
        print(x.shape, y.shape)
        renderer = self.plot.select(dict(name='points'))[0]
        renderer.data_source.data['x'] = x
        renderer.data_source.data['y'] = y
        cursession().store_objects(renderer.data_source)
Exemple #35
0
 def update(self):
     i_corr_renderer = self.i_corr_plot.select(dict(name='i_corr'))[0]
     q_corr_renderer = self.q_corr_plot.select(dict(name='q_corr'))[0]
     phase_error_renderer = self.phase_error_plot.select(dict(name='phase_error'))[0]
     delay_error_renderer = self.delay_error_plot.select(dict(name='delay_error'))[0]
 
     i_corr_renderer.data_source.data['x'] = self.time.get()
     i_corr_renderer.data_source.data['y'] = self.i_corr.get()
     q_corr_renderer.data_source.data['x'] = self.time.get()
     q_corr_renderer.data_source.data['y'] = self.q_corr.get()
     phase_error_renderer.data_source.data['x'] = self.time.get()
     phase_error_renderer.data_source.data['y'] = self.phase_error.get()
     delay_error_renderer.data_source.data['x'] = self.time.get()
     delay_error_renderer.data_source.data['y'] = self.delay_error.get()
     q_corr_renderer.data_source._dirty = True
     i_corr_renderer.data_source._dirty = True
     phase_error_renderer.data_source._dirty = True
     delay_error_renderer.data_source._dirty = True
     cursession().store_objects(i_corr_renderer.data_source, q_corr_renderer.data_source, phase_error_renderer.data_source, delay_error_renderer.data_source)
Exemple #36
0
def update_animation(plot, session):

    from numpy import roll

    renderer = plot.select(dict(type=GlyphRenderer))
    ds = renderer[0].data_source

    while True:

        rmin = ds.data["inner_radius"]
        rmin = roll(rmin, 1)
        ds.data["inner_radius"] = rmin

        rmax = ds.data["outer_radius"]
        rmax = roll(rmax, -1)
        ds.data["outer_radius"] = rmax

        cursession().store_objects(ds)
        time.sleep(0.1)
Exemple #37
0
    def call(self):
        log = self.manager.main_loop.log
        iteration = log.status.iterations_done
        i = 0
        for key, value in log.current_row:
            if key in self.p_indices:
                if key not in self.plots:
                    fig = self.p[self.p_indices[key]]
                    fig.line([iteration], [value], legend=key,
                             x_axis_label='iterations',
                             y_axis_label='value', name=key,
                             line_color=self.color_mapping[key])
                    i += 1
                    renderer = fig.select(dict(name=key))
                    self.plots[key] = renderer[0].data_source
                else:
                    self.plots[key].data['x'].append(iteration)
                    self.plots[key].data['y'].append(value)

                    cursession().store_objects(self.plots[key])
def background_thread(ds, year_ds, month_ds, timeseries_ds):
    """Plot animation, update data if play is True, otherwise stop"""
    try:
        while True:
            for year_index in np.arange(2000, 2015, 1):
                    year_ds.data["text"] = [str(year_index)]
                    for month_index in np.arange(1, 13, 1):
                        if should_play():  
                            month_ds.data["text"] = [months_str[month_index-1]]
                            image = get_slice(t, year_index, month_index)
                            date = datetime.date(year_index, month_index, 1)
                            timeseries_ds.data["x"] = [date]
                            timeseries_ds.data["y"] = [df[df.datetime == date].moving_average]
                            ds.data["image"] = [image]
                            cursession().store_objects(ds, year_ds, month_ds, timeseries_ds)
                            time.sleep(0.5)
                        time.sleep(0.5)
    except:
        logger.exception("An error occurred")
        raise
Exemple #39
0
    def bokeh_plotting(self, total):
        if self.bokeh_server is not None:
            x = range(len(total))

            if not hasattr(self, 'fig'):
                self.fig = bplt.figure(title='top.Optimizer')
                self.fig.line(x,
                              total,
                              legend='cost',
                              x_axis_label='epoch number',
                              name='top_figure',
                              plot_width=100,
                              plot_height=100)
                bplt.show(self.fig)

            # Update cost function graph
            renderer = self.fig.select(dict(name='top_figure'))
            ds = renderer[0].data_source
            ds.data['y'].append(total[-1])
            ds.data['x'].append(ds.data['x'][-1] + 1)
            bplt.cursession().store_objects(ds)
def on_selection_change(obj, attr, old, new):
    inds = np.array(new)
    if len(inds) == 0 or len(inds) == len(x):
        hhist = hzeros
        vhist = vzeros
        hhist2 = hzeros
        vhist2 = vzeros
    else:
        hhist, _ = np.histogram(x[inds], bins=hedges)
        vhist, _ = np.histogram(y[inds], bins=vedges)
        negative_inds = np.ones_like(x, dtype=np.bool)
        negative_inds[inds] = False
        hhist2, _ = np.histogram(x[negative_inds], bins=hedges)
        vhist2, _ = np.histogram(y[negative_inds], bins=vedges)

    ph_source.data["top"] = hhist
    pv_source.data["right"] = vhist
    ph_source2.data["top"] = -hhist2
    pv_source2.data["right"] = -vhist2

    cursession().store_objects(ph_source, pv_source, ph_source2, pv_source2)
Exemple #41
0
    def do(self, which_callback, *args):
        log = self.main_loop.log
        iteration = log.status['iterations_done']
        i = 0
        for key, value in log.current_row.items():
            if key in self.p_indices:
                if key not in self.plots:
                    fig = self.p[self.p_indices[key]]
                    fig.line([iteration], [value], legend=key,
                             x_axis_label='iterations',
                             y_axis_label='value', name=key,
                             line_color=self.colors[i % len(self.colors)])
                    i += 1
                    renderer = fig.select(dict(name=key))
                    self.plots[key] = renderer[0].data_source
                else:
                    self.plots[key].data['x'].append(iteration)
                    self.plots[key].data['y'].append(value)

                    cursession().store_objects(self.plots[key])
        push()
Exemple #42
0
def draw_bokeh_plot(pop_mat,
                    grid_shape,
                    color_dict,
                    width=800,
                    uniq_id="no-id"):
    #wykres na siatce heksagonalnej
    output_server("stops2" + uniq_id)
    p = figure(plot_width=width, title="STOPS")

    p.ygrid.grid_line_color = "white"
    p.xgrid.grid_line_color = "white"

    m, n = grid_shape
    beta = 0.5
    alpha = beta / math.sqrt(3)
    h = beta / math.sqrt(3)

    points_x = []
    points_y = []
    y = 0
    for i in range(n):
        if i % 2 == 1:
            x = -0.5
        else:
            x = -1
        for j in range(m):
            if i % 2 == 1:
                x += 1
            else:
                x += 1
            points = hexagon_points(x, y, alpha, beta)
            points_x.append(points[0])
            points_y.append(points[1])
        y += 3 * h

    colors, wektor = value_color(pop_mat, color_dict)

    source = ColumnDataSource(data=dict(
        points_x=points_x, points_y=points_y, wektor=wektor, colors=colors))

    p.patches(xs="points_x",
              ys="points_y",
              source=source,
              line_color="blue",
              color="colors",
              line_width=2,
              fill_alpha=0.8)
    hover = HoverTool(plot=p, tooltips=dict(wektor="@wektor"))
    p.tools.append(hover)

    push()

    return p, cursession()
Exemple #43
0
def on_selection_change(obj, attr, old, new):
    inds = np.array(new)
    if len(inds) == 0 or len(inds) == len(x):
        hhist = hzeros
        vhist = vzeros
        hhist2 = hzeros
        vhist2 = vzeros
    else:
        hhist, _ = np.histogram(x[inds], bins=hedges)
        vhist, _ = np.histogram(y[inds], bins=vedges)
        negative_inds = np.ones_like(x, dtype=np.bool)
        negative_inds[inds] = False
        hhist2, _ = np.histogram(x[negative_inds], bins=hedges)
        vhist2, _ = np.histogram(y[negative_inds], bins=vedges)

    ph_source.data["top"] = hhist
    pv_source.data["right"] = vhist
    ph_source2.data["top"] = -hhist2
    pv_source2.data["right"] = -vhist2

    cursession().store_objects(ph_source, pv_source, ph_source2, pv_source2)
Exemple #44
0
    def on_epoch_end(self, epoch, logs={}):
        epoch = self.epochNo
        self.x = np.append(self.x, epoch)
        self.y = np.append(self.y, logs['val_loss'])
        self.bx = np.append(self.bx, epoch)
        self.by = np.append(self.by, self.loss.mean())
        self.loss = np.array([])
        self.cx = np.append(self.cx, epoch)
        renderer = self.p.select(dict(name="line"))
        ds = renderer[0].data_source
        ds.data['x'] = self.x
        ds.data['y'] = self.y
        cursession().store_objects(ds)
        # ds.push_notebook()
        renderer = self.p.select(dict(name="batch_line"))
        ds = renderer[0].data_source
        ds.data['x'] = self.bx
        ds.data['y'] = self.by
        # ds.push_notebook()
        cursession().store_objects(ds)
        # if logs['val_loss'] < self.min_loss:
        if self.predit_funct:
            self.psnr = self.predit_funct(self.model, epoch)
            print("psnr: {}".format(self.psnr))

            self.psnrs = np.append(self.psnrs, self.psnr)
            renderer = self.p2.select(dict(name="psnr"))
            ds = renderer[0].data_source
            ds.data['x'] = self.x
            ds.data['y'] = self.psnrs
            cursession().store_objects(ds)

        self.min_loss = min(self.min_loss, logs['val_loss'])
        self.epochNo += 1
    def on_epoch_end(self, epoch, logs={}):
        epoch = self.epochNo
        self.x = np.append(self.x, epoch)
        self.y = np.append(self.y, logs['val_loss'])
        self.bx = np.append(self.bx, epoch)
        self.by = np.append(self.by, self.loss.mean())
        self.loss = np.array([])
        self.cx = np.append(self.cx, epoch)
        renderer = self.p.select(dict(name="line"))
        ds = renderer[0].data_source
        ds.data['x'] = self.x
        ds.data['y'] = self.y
        cursession().store_objects(ds)
        # ds.push_notebook()
        renderer = self.p.select(dict(name="batch_line"))
        ds = renderer[0].data_source
        ds.data['x'] = self.bx
        ds.data['y'] = self.by
        # ds.push_notebook()
        cursession().store_objects(ds)
        # if logs['val_loss'] < self.min_loss:
        if self.predit_funct:
            self.psnr = self.predit_funct(self.model, epoch)
            print("psnr: {}".format(self.psnr))

            self.psnrs = np.append(self.psnrs, self.psnr)
            renderer = self.p2.select(dict(name="psnr"))
            ds = renderer[0].data_source
            ds.data['x'] = self.x
            ds.data['y'] = self.psnrs
            cursession().store_objects(ds)

        self.min_loss = min(self.min_loss, logs['val_loss'])
        self.epochNo += 1
Exemple #46
0
    def call(self):
        log = self.manager.main_loop.log
        iteration = log.status.iterations_done
        i = 0
        for key, value in log.current_row:
            if key in self.p_indices:
                if key not in self.plots:
                    fig = self.p[self.p_indices[key]]
                    fig.line([iteration], [value],
                             legend=key,
                             x_axis_label='iterations',
                             y_axis_label='value',
                             name=key,
                             line_color=self.color_mapping[key])
                    i += 1
                    renderer = fig.select(dict(name=key))
                    self.plots[key] = renderer[0].data_source
                else:
                    self.plots[key].data['x'].append(iteration)
                    self.plots[key].data['y'].append(value)

                    cursession().store_objects(self.plots[key])
	def __init__(self, mode = 'arduino',serialObject=None): #nof indicates number of json fields
		self.mode = mode
		self.modeset = True
		if mode is 'arduino':
			import serial
			if serialObject is None:
				n=0
				while True:
					try:
						self.ser = serial.Serial(SERIAL_PORT_DEV + str(n), BAUDRATE)
						break
					except serial.serialutil.SerialException:
						print 'Could not open any serial port on {0}{1}. Trying with {0}{2}'.format(SERIAL_PORT_DEV,n,n+1)
						n += 1
			else:
				self.ser = serialObject
				self.ser.open()
		elif mode is 'rpi':
			self.bmp, self.dht = BMP180Wrapper(), DHT22Wrapper() 
			
		self.data = {}
		self.data["temp"], self.data["hum"], self.data["pres"], self.data["timenow"] = [],[],[],[]
		self.lastdata = ''; self.lastjson = None
		
		#charts
		self.tempchart, self.preschart, self.humchart = MeteoStation.MeteoChart('temp', 'Temperature', 'Temperature in *C'), MeteoStation.MeteoChart('pres','Pressure', 'Pressure in hPa'), MeteoStation.MeteoChart('hum','Humidity', 'Humidity in %RH')
		self.charts = [self.tempchart, self.preschart, self.humchart]
		self.figs = [chart.fig for chart in self.charts]
		self.show_all()
		cursession().publish()
	
		#pymongo integration
		try:
			self.db = client['meteo_db']
			self.collection = self.db.colletion['meteo_data_collection']
		except: #retry with object-style formalism
			self.db = client.meteo_db
			self.collection = self.db.collection.meteo_data_collection
Exemple #48
0
def stream(name, width=800, height=500):
    """
    Broken
    """

    output_server(name)

    p = figure(plot_width=width, plot_height=height)
    p.line([1,2,3], [4,5,6], name='ex_line')

    renderer = p.select({'name': 'ex_line'})
    ds = renderer[0].data_source

    while True:

        x, y = yield

        ds.data['x'] = x
        ds.data['y'] = y

        cursession().store_objects(ds)

        show(p)
def background_thread(ds, year_ds, month_ds, timeseries_ds):
    """Plot animation, update data if play is True, otherwise stop"""
    try:
        while True:
            for year_index in np.arange(2000, 2015, 1):
                year_ds.data["text"] = [str(year_index)]
                for month_index in np.arange(1, 13, 1):
                    if should_play():
                        month_ds.data["text"] = [months_str[month_index - 1]]
                        image = get_slice(t, year_index, month_index)
                        date = datetime.date(year_index, month_index, 1)
                        timeseries_ds.data["x"] = [date]
                        timeseries_ds.data["y"] = [
                            df[df.datetime == date].moving_average
                        ]
                        ds.data["image"] = [image]
                        cursession().store_objects(ds, year_ds, month_ds,
                                                   timeseries_ds)
                        time.sleep(0.5)
                    time.sleep(0.5)
    except:
        logger.exception("An error occurred")
        raise
Exemple #50
0
 def on_epoch_end(self, epoch, logs={}):
     if not hasattr(self, 'fig'):
         self.fig = figure(title=self.fig_title)
         for i, v in enumerate(['loss', 'val_loss']):
             if v == 'loss':
                 L = self.totals[v] / self.seen
             else:
                 L = logs.get(v)
             self.fig.line([epoch], [L], legend=v,
                           name=v, line_width=2,
                           line_color=self.colors[i % len(self.colors)])
             renderer = self.fig.select({'name': v})
             self.plots.append(renderer[0].data_source)
         show(self.fig)
     else:
         for i, v in enumerate(['loss', 'val_loss']):
             if v == 'loss':
                 L = self.totals[v] / self.seen
             else:
                 L = logs.get(v)
             self.plots[i].data['y'].append(L)
             self.plots[i].data['x'].append(epoch)
     cursession().store_objects(self.plots[i])
     push()
Exemple #51
0
def animated():

    from numpy import pi, cos, sin, linspace, zeros_like

    N = 50 + 1
    r_base = 8
    theta = linspace(0, 2 * pi, N)
    r_x = linspace(0, 6 * pi, N - 1)
    rmin = r_base - cos(r_x) - 1
    rmax = r_base + sin(r_x) + 1

    colors = [
        "FFFFCC", "#C7E9B4", "#7FCDBB", "#41B6C4", "#2C7FB8", "#253494",
        "#2C7FB8", "#41B6C4", "#7FCDBB", "#C7E9B4"
    ] * 5

    cx = cy = zeros_like(rmin)

    output_server("animated_reveal")

    figure(title="Animations",
           x_range=[-11, 11],
           y_range=[-11, 11],
           tools="pan,wheel_zoom,box_zoom,reset,previewsave")

    hold()

    annular_wedge(
        cx,
        cy,
        rmin,
        rmax,
        theta[:-1],
        theta[1:],
        inner_radius_units="data",
        outer_radius_units="data",
        fill_color=colors,
        line_color="black",
    )

    return curplot(), cursession()
Exemple #52
0
def distribution():

    mu, sigma = 0, 0.5

    measured = np.random.normal(mu, sigma, 1000)
    hist, edges = np.histogram(measured, density=True, bins=20)

    x = np.linspace(-2, 2, 1000)
    pdf = 1 / (sigma * np.sqrt(2 * np.pi)) * np.exp(-(x - mu)**2 /
                                                    (2 * sigma**2))
    cdf = (1 + scipy.special.erf((x - mu) / np.sqrt(2 * sigma**2))) / 2

    output_server("distribution_reveal")

    hold()

    figure(title="Interactive plots",
           tools="pan, wheel_zoom, box_zoom, reset, previewsave",
           background_fill="#E5E5E5")
    quad(top=hist,
         bottom=np.zeros(len(hist)),
         left=edges[:-1],
         right=edges[1:],
         fill_color="#333333",
         line_color="#E5E5E5",
         line_width=3)

    # Use `line` renderers to display the PDF and CDF
    line(x, pdf, line_color="#348abd", line_width=8, alpha=0.7, legend="PDF")
    line(x, cdf, line_color="#7a68a6", line_width=8, alpha=0.7, legend="CDF")

    xgrid().grid_line_color = "white"
    xgrid().grid_line_width = 3
    ygrid().grid_line_color = "white"
    ygrid().grid_line_width = 3

    legend().orientation = "top_left"

    return curplot(), cursession()
Exemple #53
0
# set up callbacks
def on_selection_change(obj, attr, old, new):
    inds = np.array(new)
    if len(inds) == 0 or len(inds) == len(x):
        hhist = hzeros
        vhist = vzeros
        hhist2 = hzeros
        vhist2 = vzeros
    else:
        hhist, _ = np.histogram(x[inds], bins=hedges)
        vhist, _ = np.histogram(y[inds], bins=vedges)
        negative_inds = np.ones_like(x, dtype=np.bool)
        negative_inds[inds] = False
        hhist2, _ = np.histogram(x[negative_inds], bins=hedges)
        vhist2, _ = np.histogram(y[negative_inds], bins=vedges)

    ph_source.data["top"] = hhist
    pv_source.data["right"] = vhist
    ph_source2.data["top"] = -hhist2
    pv_source2.data["right"] = -vhist2

    cursession().store_objects(ph_source, pv_source, ph_source2, pv_source2)


scatter_ds.on_change('selected', on_selection_change)

layout = vbox(hbox(p, pv), hbox(ph, Paragraph()))
show(layout)

cursession().poll_document(curdoc(), 0.05)
Exemple #54
0
p.xgrid.grid_line_color = 'white'
p.ygrid.grid_line_color = 'white'
p.axis.axis_line_color = None
p.axis.major_tick_line_color = None
p.axis.minor_tick_line_color = None
p.yaxis.axis_label = 'Percent'
p.yaxis.axis_label_standoff = ylabel_standoff
p.xaxis.formatter = xformatter
p.yaxis.formatter = yformatter
p.xaxis.axis_label_standoff = 12
p.yaxis.major_label_text_font = 'courier'
p.xaxis.major_label_text_font = 'courier'

push()
ip = load(urlopen('http://jsonip.com'))['ip']
ssn = cursession()
ssn.publish()
tag = embed.autoload_server(p, ssn, public=True).replace('localhost', ip)
html = """
{%% extends "layout.html" %%}
{%% block bokeh %%}
%s
{%% endblock %%}
""" % tag

with open('templates/performance.html', 'w+') as f:
    f.write(html)

renderer = p.select(dict(name='returns'))
ds_returns = renderer[0].data_source
Exemple #55
0
    config_root_logger()
    # main()

    from bokeh.plotting import figure, cursession, show, output_server

    output_server("test doc")

    # plot settings
    plot = figure(title="Combined Streams")
    plot.line([], [], color="blue", name='Sample Streaming Data 1')
    plot.line([], [], color="red", name='Sample Streaming Data 2')

    show(plot)

    ds1 = plot.select(dict(name='Sample Streaming Data 1'))[0].data_source
    ds2 = plot.select(dict(name='Sample Streaming Data 2'))[0].data_source

    for i in range(100, 200):
        # update data into ds
        ds1.data["x"].append(i - 100)
        ds1.data["y"].append(i)

        cursession().store_objects(ds1)

    for i in range(100, 400):

        ds2.data["x"].append(i - 100)
        ds2.data["y"].append(i - 20)

        cursession().store_objects(ds2)
Exemple #56
0
p.annular_wedge(
    cx,
    cy,
    rmin,
    rmax,
    theta[:-1],
    theta[1:],
    inner_radius_units="data",
    outer_radius_units="data",
    fill_color=colors,
    line_color="black",
)

show(p)

renderer = p.select(dict(type=GlyphRenderer))
ds = renderer[0].data_source

while True:

    rmin = ds.data["inner_radius"]
    rmin = roll(rmin, 1)
    ds.data["inner_radius"] = rmin

    rmax = ds.data["outer_radius"]
    rmax = roll(rmax, -1)
    ds.data["outer_radius"] = rmax

    cursession().store_objects(ds)
    time.sleep(.10)