示例#1
0
    def __init__(self, scheduler, width=600, **kwargs):
        with log_errors():
            self.last = 0
            self.scheduler = scheduler
            self.source = ColumnDataSource({'nprocessing': [1, 2],
                                            'nprocessing-half': [0.5, 1],
                                            'nprocessing-color': ['red', 'blue'],
                                            'nbytes': [1, 2],
                                            'nbytes-half': [0.5, 1],
                                            'worker': ['a', 'b'],
                                            'y': [1, 2],
                                            'nbytes-color': ['blue', 'blue'],
                                            'bokeh_address': ['', '']})

            processing = figure(title='Tasks Processing', tools='resize', id='bk-nprocessing-plot',
                                width=int(width / 2), **kwargs)
            processing.rect(source=self.source,
                            x='nprocessing-half', y='y',
                            width='nprocessing', height=1,
                            color='nprocessing-color')
            processing.x_range.start = 0

            nbytes = figure(title='Bytes stored', tools='resize',
                            id='bk-nbytes-worker-plot', width=int(width / 2),
                            **kwargs)
            nbytes.rect(source=self.source,
                        x='nbytes-half', y='y',
                        width='nbytes', height=1,
                        color='nbytes-color')
            nbytes.xaxis[0].formatter = NumeralTickFormatter(format='0.0 b')
            nbytes.xaxis.major_label_orientation = -math.pi / 12
            nbytes.x_range.start = 0

            for fig in [processing, nbytes]:
                fig.xaxis.minor_tick_line_alpha = 0
                fig.yaxis.visible = False
                fig.ygrid.visible = False

                tap = TapTool(callback=OpenURL(url='http://@bokeh_address/'))
                fig.add_tools(tap)

                fig.toolbar.logo = None
                fig.toolbar_location = None
                fig.yaxis.visible = False

            hover = HoverTool()
            hover.tooltips = "@worker : @nprocessing tasks.  Click for worker page"
            hover.point_policy = 'follow_mouse'
            processing.add_tools(hover)

            hover = HoverTool()
            hover.tooltips = "@worker : @nbytes bytes.  Click for worker page"
            hover.point_policy = 'follow_mouse'
            nbytes.add_tools(hover)

            self.processing_figure = processing
            self.nbytes_figure = nbytes

            processing.y_range = nbytes.y_range
            self.root = row(nbytes, processing, sizing_mode='scale_width')
示例#2
0
    def __init__(self, scheduler, **kwargs):
        self.scheduler = scheduler
        self.steal = scheduler.extensions['stealing']
        self.last = 0
        self.source = ColumnDataSource({'time': [time() - 20, time()],
                                        'level': [0, 15],
                                        'color': ['white', 'white'],
                                        'duration': [0, 0], 'radius': [1, 1],
                                        'cost_factor': [0, 10], 'count': [1, 1]})

        x_range = DataRange1d(follow='end', follow_interval=20000, range_padding=0)

        fig = figure(title="Stealing Events",
                     x_axis_type='datetime', y_axis_type='log',
                     height=250, tools='', x_range=x_range, **kwargs)

        fig.circle(source=self.source, x='time', y='cost_factor', color='color',
                   size='radius', alpha=0.5)
        fig.yaxis.axis_label = "Cost Multiplier"

        hover = HoverTool()
        hover.tooltips = "Level: @level, Duration: @duration, Count: @count, Cost factor: @cost_factor"
        hover.point_policy = 'follow_mouse'

        fig.add_tools(
            hover,
            ResetTool(reset_size=False),
            PanTool(dimensions="width"),
            WheelZoomTool(dimensions="width")
        )

        self.root = fig
示例#3
0
    def __init__(self, **kwargs):
        data = self.processing_update({'processing': {}, 'ncores': {}})
        self.source = ColumnDataSource(data)

        x_range = Range1d(-1, 1)
        fig = figure(
            title='Processing and Pending', tools='resize',
             x_range=x_range, id='bk-processing-stacks-plot', **kwargs)
        fig.quad(source=self.source, left=0, right='right', color=Spectral9[0],
                 top='top', bottom='bottom')

        fig.xaxis.minor_tick_line_alpha = 0
        fig.yaxis.visible = False
        fig.ygrid.visible = False

        hover = HoverTool()
        fig.add_tools(hover)
        hover = fig.select(HoverTool)
        hover.tooltips = """
        <div>
            <span style="font-size: 14px; font-weight: bold;">Host:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Processing:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@processing</span>
        </div>
        """
        hover.point_policy = 'follow_mouse'

        self.root = fig
示例#4
0
    def __init__(self, scheduler, **kwargs):
        with log_errors():
            self.scheduler = scheduler
            self.source = ColumnDataSource({
                'occupancy': [0, 0],
                'worker': ['a', 'b'],
                'x': [0.0, 0.1],
                'y': [1, 2],
                'ms': [1, 2]
            })

            fig = figure(title='Occupancy',
                         tools='resize',
                         id='bk-occupancy-plot',
                         x_axis_type='datetime',
                         **kwargs)
            fig.rect(source=self.source,
                     x='x',
                     width='ms',
                     y='y',
                     height=1,
                     color='blue')

            fig.xaxis.minor_tick_line_alpha = 0
            fig.yaxis.visible = False
            fig.ygrid.visible = False
            # fig.xaxis[0].formatter = NumeralTickFormatter(format='0.0s')
            fig.x_range.start = 0

            hover = HoverTool()
            hover.tooltips = "@worker : @occupancy s"
            hover.point_policy = 'follow_mouse'
            fig.add_tools(hover)

            self.root = fig
示例#5
0
    def __init__(self, scheduler, **kwargs):
        with log_errors():
            self.scheduler = scheduler
            self.source = ColumnDataSource({'occupancy': [0, 0],
                                            'worker': ['a', 'b'],
                                            'x': [0.0, 0.1],
                                            'y': [1, 2],
                                            'ms': [1, 2],
                                            'color': ['red', 'blue'],
                                            'bokeh_address': ['', '']})

            fig = figure(title='Occupancy', tools='', id='bk-occupancy-plot',
                         x_axis_type='datetime', **kwargs)
            rect = fig.rect(source=self.source, x='x', width='ms', y='y', height=1,
                            color='color')
            rect.nonselection_glyph = None

            fig.xaxis.minor_tick_line_alpha = 0
            fig.yaxis.visible = False
            fig.ygrid.visible = False
            # fig.xaxis[0].formatter = NumeralTickFormatter(format='0.0s')
            fig.x_range.start = 0

            tap = TapTool(callback=OpenURL(url='http://@bokeh_address/'))

            hover = HoverTool()
            hover.tooltips = "@worker : @occupancy s."
            hover.point_policy = 'follow_mouse'
            fig.add_tools(hover, tap)

            self.root = fig
示例#6
0
def nbytes_plot(**kwargs):
    data = {'name': [], 'left': [], 'right': [], 'center': [], 'color': [],
            'percent': [], 'MB': [], 'text': []}
    source = ColumnDataSource(data)
    fig = figure(title='Memory Use', tools='', toolbar_location=None, **kwargs)
    fig.quad(source=source, top=1, bottom=0,
             left='left', right='right', color='color', alpha=1)

    fig.grid.grid_line_color = None
    fig.grid.grid_line_color = None
    fig.axis.visible = None
    fig.outline_line_color = None

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Percent:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@percent</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">MB:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@MB</span>
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
def nbytes_plot(**kwargs):
    data = {'name': [], 'left': [], 'right': [], 'center': [], 'color': [],
            'percent': [], 'MB': [], 'text': []}
    source = ColumnDataSource(data)
    fig = figure(title='Memory Use', tools='', toolbar_location=None, **kwargs)
    fig.quad(source=source, top=1, bottom=0,
             left='left', right='right', color='color', alpha=0.8)
    fig.text(source=source, x='center', y=0.5, text='text',
             text_baseline='middle', text_align='center')

    fig.grid.grid_line_color = None
    fig.grid.grid_line_color = None
    fig.axis.visible = None
    fig.outline_line_color = None

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Percent:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@percent</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">MB:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@MB</span>
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
示例#8
0
def nbytes_plot(**kwargs):
    data = {"name": [], "left": [], "right": [], "center": [], "color": [], "percent": [], "MB": [], "text": []}
    source = ColumnDataSource(data)
    fig = figure(title="Memory Use", tools="", toolbar_location=None, id="bk-nbytes-plot", **kwargs)
    fig.quad(source=source, top=1, bottom=0, left="left", right="right", color="color", alpha=1)

    fig.grid.grid_line_color = None
    fig.grid.grid_line_color = None
    fig.axis.visible = None
    fig.outline_line_color = None

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Percent:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@percent</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">MB:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@MB</span>
    </div>
    """
    hover.point_policy = "follow_mouse"

    return source, fig
示例#9
0
    def __init__(self, scheduler, **kwargs):
        with log_errors():
            self.scheduler = scheduler
            self.source = ColumnDataSource({'occupancy': [0, 0],
                                            'worker': ['a', 'b'],
                                            'x': [0.0, 0.1],
                                            'y': [1, 2],
                                            'ms': [1, 2]})

            fig = figure(title='Occupancy', tools='resize', id='bk-occupancy-plot',
                         x_axis_type='datetime', **kwargs)
            fig.rect(source=self.source, x='x', width='ms', y='y', height=1,
                     color='blue')

            fig.xaxis.minor_tick_line_alpha = 0
            fig.yaxis.visible = False
            fig.ygrid.visible = False
            # fig.xaxis[0].formatter = NumeralTickFormatter(format='0.0s')
            fig.x_range.start = 0

            hover = HoverTool()
            hover.tooltips = "@worker : @occupancy s"
            hover.point_policy = 'follow_mouse'
            fig.add_tools(hover)

            self.root = fig
示例#10
0
def task_stream_plot(height=400, width=800, follow_interval=5000, **kwargs):
    data = {
        'start': [],
        'duration': [],
        'key': [],
        'name': [],
        'color': [],
        'worker': [],
        'y': [],
        'worker_thread': [],
        'alpha': []
    }

    source = ColumnDataSource(data)
    if follow_interval:
        x_range = DataRange1d(follow='end',
                              follow_interval=follow_interval,
                              range_padding=0)
    else:
        x_range = None

    fig = figure(width=width,
                 height=height,
                 x_axis_type='datetime',
                 tools=['xwheel_zoom', 'xpan', 'reset', 'resize', 'box_zoom'],
                 responsive=True,
                 x_range=x_range,
                 **kwargs)
    fig.rect(x='start',
             y='y',
             width='duration',
             height=0.9,
             fill_color='color',
             line_color='gray',
             alpha='alpha',
             source=source)
    if x_range:
        fig.circle(x=[1, 2], y=[1, 2], alpha=0.0)
    fig.xaxis.axis_label = 'Time'
    fig.yaxis.axis_label = 'Worker Core'
    fig.min_border_right = 10
    fig.ygrid.grid_line_alpha = 0.4
    fig.xgrid.grid_line_alpha = 0.0

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Key:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Duration:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@duration</span>
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
示例#11
0
def data_usage_plot(df):
    def create_data_source(df):
        return ColumnDataSource(data=dict(filesystem=df['filesystem'],total_size=df['total_size'],used=df['used'],available=df['available'],use_percent=df['use_percent'],mounted=['mounted'],submittime=[x.strftime("%Y-%m-%d") for x in df['submittime']]))

    hover = HoverTool(names=['points'])
    TOOLS = [BoxZoomTool(),PanTool(),ResetTool(),WheelZoomTool(),hover]
    Colors = ['red','navy','olive','firebrick','lightskyblue','yellowgreen','lightcoral','yellow', 'green','blue','gold']

    # Change percents to format bokeh can use
    fp_list = []
    for row in df['use_percent']:
        fp_list.append(float(row.replace('%','')))
    df['f_percent'] = fp_list

    # Begin Plotting
    x_max = datetime.now()
    p = figure(height=500, width=1000, x_axis_type="datetime", x_range=((x_max-timedelta(14)),x_max), y_axis_label='Percent Full', tools=TOOLS, title='Data Usage by Filesystem')

    # Points with hover info
    p.scatter(x=df['submittime'], y=df['f_percent'], name='points', source=create_data_source(df), color='black', size=6)
    df = df.groupby(by = ['filesystem'])

    # Connecting lines
    count = 0
    for filesystem, group in df:
        count += 1
        p.line(x=group['submittime'] ,y=group['f_percent'], color=Colors[count], legend=str(filesystem), line_width=3)

    # Formating
    p.legend.orientation = "top_left"
    hover.point_policy = "follow_mouse"
    hover.tooltips = [("Filesystem", "@filesystem"),("Size","@total_size"),("Available","@available"),("Percent Used","@use_percent"),("Time","@submittime")]

    return p
示例#12
0
    def __init__(self, **kwargs):
        data = self.processing_update({'processing': {}, 'ncores': {}})
        self.source = ColumnDataSource(data)

        x_range = Range1d(-1, 1)
        fig = figure(title='Processing and Pending', tools='',
                     x_range=x_range, id='bk-processing-stacks-plot', **kwargs)
        fig.quad(source=self.source, left=0, right='right', color=Spectral9[0],
                 top='top', bottom='bottom')

        fig.xaxis.minor_tick_line_alpha = 0
        fig.yaxis.visible = False
        fig.ygrid.visible = False

        hover = HoverTool()
        fig.add_tools(hover)
        hover = fig.select(HoverTool)
        hover.tooltips = """
        <div>
            <span style="font-size: 14px; font-weight: bold;">Host:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Processing:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@processing</span>
        </div>
        """
        hover.point_policy = 'follow_mouse'

        self.root = fig
示例#13
0
def plot_coords(df, filename):
    lat = 'Latitude|"Degrees"|-180.0|180.0|10'
    long = 'Longitude|"Degrees"|-180.0|180.0|10'
    speed = 'Speed|"mph"|0.0|150.0|10'
    df.loc[df[lat] == 0, lat] = np.nan
    df.loc[df[long] == 0, long] = np.nan
    coord_source = ColumnDataSource(df)
    coord_source.add(df['Interval|"ms"|0|0|1'], name='Time')

    coord = figure(sizing_mode='scale_both',
                   width=700,
                   height=600,
                   title='GPS Data_{}'.format(filename))

    # TODO figure out why this is broken
    # mapper = linear_cmap(field_name='Speed"|"mph"|0.0|150.0|10', palette=Spectral6, low=min(speed), high=max(speed))

    coord.circle(x=lat, y=long, source=coord_source, size=3, color='darkcyan')

    # TODO figure out how to make the points be connected
    # coord.line(x=lat, y=long, source=coord_source, line_width=2, color='red')

    # Tools
    hover = HoverTool()
    hover.tooltips = [('Lat', '$x{0.000000}'), ('Long', '$y{0.000000}'),
                      ('Time', '@Time')]
    hover.point_policy = 'follow_mouse'
    coord.add_tools(hover)

    return coord
示例#14
0
    def __init__(self, scheduler, name, height=150, **kwargs):
        self.scheduler = scheduler
        self.action_ys = dict()
        self.last = 0
        self.name = name
        self.source = ColumnDataSource({'time': [], 'action': [], 'hover': [],
                                        'y': [], 'color': []})

        x_range = DataRange1d(follow='end', follow_interval=200000)

        fig = figure(title=name, x_axis_type='datetime',
                     height=height, tools='', x_range=x_range, **kwargs)

        fig.circle(source=self.source, x='time', y='y', color='color',
                   size=50, alpha=0.5, legend='action')
        fig.yaxis.axis_label = "Action"
        fig.legend.location = 'top_left'

        hover = HoverTool()
        hover.tooltips = "@action<br>@hover"
        hover.point_policy = 'follow_mouse'

        fig.add_tools(
            hover,
            ResetTool(reset_size=False),
            PanTool(dimensions="width"),
            WheelZoomTool(dimensions="width")
        )

        self.root = fig
示例#15
0
def task_stream_plot(sizing_mode="scale_width", **kwargs):
    data = {
        "start": [],
        "duration": [],
        "key": [],
        "name": [],
        "color": [],
        "worker": [],
        "y": [],
        "worker_thread": [],
        "alpha": [],
    }

    source = ColumnDataSource(data)
    x_range = DataRange1d(range_padding=0)

    fig = figure(
        x_axis_type="datetime",
        title="Task stream",
        tools="xwheel_zoom,xpan,reset,box_zoom",
        toolbar_location="above",
        sizing_mode=sizing_mode,
        x_range=x_range,
        id="bk-task-stream-plot",
        **kwargs
    )
    fig.rect(
        x="start",
        y="y",
        width="duration",
        height=0.8,
        fill_color="color",
        line_color="color",
        line_alpha=0.6,
        alpha="alpha",
        line_width=3,
        source=source,
    )
    fig.xaxis.axis_label = "Time"
    fig.yaxis.axis_label = "Worker Core"
    fig.ygrid.grid_line_alpha = 0.4
    fig.xgrid.grid_line_color = None
    fig.min_border_right = 35
    fig.yaxis[0].ticker.num_minor_ticks = 0

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 12px; font-weight: bold;">@name:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@duration</span>
        <span style="font-size: 10px;">ms</span>&nbsp;
    </div>
    """
    hover.point_policy = "follow_mouse"

    return source, fig
示例#16
0
def worker_table_plot(**kwargs):
    """ Column data source and plot for host table """
    with log_errors():
        # names = ['host', 'cpu', 'memory_percent', 'memory', 'cores', 'processes',
        #          'processing', 'latency', 'last-seen', 'disk-read', 'disk-write',
        #          'network-send', 'network-recv']
        names = ['processes', 'disk-read', 'cores', 'cpu', 'disk-write',
                 'memory', 'last-seen', 'memory_percent', 'host']
        source = ColumnDataSource({k: [] for k in names})

        columns = {name: TableColumn(field=name,
                                     title=name.replace('_percent', ' %'))
                   for name in names}

        cnames = ['host', 'cores', 'processes', 'memory', 'cpu', 'memory_percent']

        formatters = {'cpu': NumberFormatter(format='0.0 %'),
                      'memory_percent': NumberFormatter(format='0.0 %'),
                      'memory': NumberFormatter(format='0 b'),
                      'latency': NumberFormatter(format='0.00000'),
                      'last-seen': NumberFormatter(format='0.000'),
                      'disk-read': NumberFormatter(format='0 b'),
                      'disk-write': NumberFormatter(format='0 b'),
                      'net-send': NumberFormatter(format='0 b'),
                      'net-recv': NumberFormatter(format='0 b')}

        table = DataTable(source=source, columns=[columns[n] for n in cnames],
                          **kwargs)
        for name in cnames:
            if name in formatters:
                table.columns[cnames.index(name)].formatter = formatters[name]

        x_range = Range1d(0, 1)
        y_range = Range1d(-.1, .1)
        mem_plot = figure(title="Memory Usage (%)",
                          tools='box_select', height=90, width=600,
                          x_range=x_range, y_range=y_range, toolbar_location=None)
        mem_plot.circle(source=source, x='memory_percent', y=0, size=10,
                        alpha=0.5)
        mem_plot.yaxis.visible = False
        mem_plot.xaxis.minor_tick_line_width = 0
        mem_plot.ygrid.visible = False
        mem_plot.xaxis.minor_tick_line_alpha = 0

        hover = HoverTool()
        mem_plot.add_tools(hover)
        hover = mem_plot.select(HoverTool)
        hover.tooltips = """
        <div>
          <span style="font-size: 10px; font-family: Monaco, monospace;">@host: </span>
          <span style="font-size: 10px; font-family: Monaco, monospace;">@memory_percent</span>
        </div>
        """
        hover.point_policy = 'follow_mouse'

    return source, [mem_plot, table]
示例#17
0
def progress_plot(height=300, width=800, **kwargs):
    from ..diagnostics.progress_stream import progress_quads
    data = progress_quads({'all': {}, 'in_memory': {},
                           'erred': {}, 'released': {}})

    source = ColumnDataSource(data)
    fig = figure(width=width, height=height, tools=['resize'],
                 responsive=True, **kwargs)
    fig.quad(source=source, top='top', bottom='bottom',
             left=0, right=1, color='#aaaaaa', alpha=0.2)
    fig.quad(source=source, top='top', bottom='bottom',
             left=0, right='released_right', color='#0000FF', alpha=0.4)
    fig.quad(source=source, top='top', bottom='bottom',
             left='released_right', right='in_memory_right',
             color='#0000FF', alpha=0.8)
    fig.quad(source=source, top='top', bottom='bottom',
             left='erred_left', right=1,
             color='#000000', alpha=0.3)
    fig.text(source=source, text='fraction', y='center', x=-0.01,
             text_align='right', text_baseline='middle')
    fig.text(source=source, text='name', y='center', x=1.01,
             text_align='left', text_baseline='middle')
    fig.scatter(x=[-0.2, 1.4], y=[0, 5], alpha=0)
    fig.xgrid.grid_line_color = None
    fig.ygrid.grid_line_color = None
    fig.axis.visible = None
    fig.min_border_left = 0
    fig.min_border_right = 10
    fig.min_border_top = 0
    fig.min_border_bottom = 0
    fig.outline_line_color = None

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">All:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@all</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">In Memory:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@in_memory</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Erred:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@erred</span>
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
示例#18
0
def task_stream_plot(sizing_mode='scale_width', **kwargs):
    data = {
        'start': [],
        'duration': [],
        'key': [],
        'name': [],
        'color': [],
        'worker': [],
        'y': [],
        'worker_thread': [],
        'alpha': []
    }

    source = ColumnDataSource(data)
    x_range = DataRange1d(range_padding=0)

    fig = figure(x_axis_type='datetime',
                 title="Task stream",
                 tools='xwheel_zoom,xpan,reset,box_zoom',
                 toolbar_location='above',
                 sizing_mode=sizing_mode,
                 x_range=x_range,
                 id='bk-task-stream-plot',
                 **kwargs)
    fig.rect(x='start',
             y='y',
             width='duration',
             height=0.8,
             fill_color='color',
             line_color='color',
             line_alpha=0.6,
             alpha='alpha',
             line_width=3,
             source=source)
    fig.xaxis.axis_label = 'Time'
    fig.yaxis.axis_label = 'Worker Core'
    fig.ygrid.grid_line_alpha = 0.4
    fig.xgrid.grid_line_color = None
    fig.min_border_right = 35
    fig.yaxis[0].ticker.num_minor_ticks = 0

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 12px; font-weight: bold;">@name:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@duration</span>
        <span style="font-size: 10px;">ms</span>&nbsp;
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
示例#19
0
def progress_plot(**kwargs):
    from ..diagnostics.progress_stream import progress_quads
    data = progress_quads({'all': {}, 'in_memory': {},
                           'erred': {}, 'released': {}})

    x_range = Range1d(-0.5, 1.5)
    y_range = Range1d(5.1, -0.1)
    source = ColumnDataSource(data)
    fig = figure(tools='', toolbar_location=None, y_range=y_range, x_range=x_range, **kwargs)
    fig.quad(source=source, top='top', bottom='bottom',
             left=0, right=1, color='#aaaaaa', alpha=0.2)
    fig.quad(source=source, top='top', bottom='bottom',
             left=0, right='released_right', color=Spectral9[0], alpha=0.4)
    fig.quad(source=source, top='top', bottom='bottom',
             left='released_right', right='in_memory_right',
             color=Spectral9[0], alpha=0.8)
    fig.quad(source=source, top='top', bottom='bottom',
             left='erred_left', right=1,
             color='#000000', alpha=0.3)
    fig.text(source=source, text='fraction', y='center', x=-0.01,
             text_align='right', text_baseline='middle')
    fig.text(source=source, text='name', y='center', x=1.01,
             text_align='left', text_baseline='middle')
    fig.xgrid.grid_line_color = None
    fig.ygrid.grid_line_color = None
    fig.axis.visible = None
    fig.outline_line_color = None

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">All:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@all</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">In Memory:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@in_memory</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Erred:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@erred</span>
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
示例#20
0
    def _draw_contigCirclePlot(self):
        hover = HoverTool(tooltips=[('Length', '@contigs')])
        hover.point_policy = "follow_mouse"
        plot = figure(x_axis_type=None, y_axis_type=None, tools=[hover], title='Contig lengths')
        plot.annular_wedge(x=0, y=0, inner_radius=0.5, outer_radius=0.7,
                           start_angle='start', end_angle='stop',
                           color='colors', alpha=0.9, source=self.contig_dist_src)
        plot.yaxis.axis_label_text_font_size = '14pt'
        plot.xaxis.axis_label_text_font_size = '14pt'
        plot.yaxis.major_label_text_font_size = '14pt'
        plot.xaxis.major_label_text_font_size = '14pt'
        plot.title.text_font_size = '16pt'

        return plot
示例#21
0
def progress_plot(**kwargs):
    with log_errors():
        from ..diagnostics.progress_stream import progress_quads
        data = progress_quads({'all': {}, 'memory': {},
                               'erred': {}, 'released': {}})

        y_range = Range1d(-8, 0)
        source = ColumnDataSource(data)
        fig = figure(tools='', toolbar_location=None, y_range=y_range, **kwargs)
        fig.quad(source=source, top='top', bottom='bottom',
                 left='left', right='right', color='#aaaaaa', alpha=0.2)
        fig.quad(source=source, top='top', bottom='bottom',
                 left='left', right='released-loc', color=Spectral9[0], alpha=0.4)
        fig.quad(source=source, top='top', bottom='bottom',
                 left='released-loc', right='memory-loc', color=Spectral9[0], alpha=0.8)
        fig.quad(source=source, top='top', bottom='bottom',
                 left='erred-loc', right='erred-loc', color='#000000', alpha=0.3)
        fig.text(source=source, text='show-name', y='bottom', x='left',
                x_offset=5, text_font_size='10pt')
        fig.text(source=source, text='done', y='bottom', x='right', x_offset=-5,
                text_align='right', text_font_size='10pt')
        fig.xaxis.visible = False
        fig.yaxis.visible = False
        fig.grid.grid_line_alpha = 0

        hover = HoverTool()
        fig.add_tools(hover)
        hover = fig.select(HoverTool)
        hover.tooltips = """
        <div>
            <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">All:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@all</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Memory:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@memory</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Erred:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@erred</span>
        </div>
        """
        hover.point_policy = 'follow_mouse'

        return source, fig
示例#22
0
def progress_plot(**kwargs):
    with log_errors():
        from ..diagnostics.progress_stream import progress_quads

        data = progress_quads({"all": {}, "memory": {}, "erred": {}, "released": {}})

        y_range = Range1d(-8, 0)
        source = ColumnDataSource(data)
        fig = figure(tools="", toolbar_location=None, y_range=y_range, id="bk-progress-plot", **kwargs)
        fig.quad(source=source, top="top", bottom="bottom", left="left", right="right", color="#aaaaaa", alpha=0.2)
        fig.quad(source=source, top="top", bottom="bottom", left="left", right="released-loc", color="color", alpha=0.6)
        fig.quad(
            source=source, top="top", bottom="bottom", left="released-loc", right="memory-loc", color="color", alpha=1
        )
        fig.quad(
            source=source, top="top", bottom="bottom", left="erred-loc", right="erred-loc", color="#000000", alpha=0.3
        )
        fig.text(source=source, text="show-name", y="bottom", x="left", x_offset=5, text_font_size="10pt")
        fig.text(
            source=source, text="done", y="bottom", x="right", x_offset=-5, text_align="right", text_font_size="10pt"
        )
        fig.xaxis.visible = False
        fig.yaxis.visible = False
        fig.grid.grid_line_alpha = 0

        hover = HoverTool()
        fig.add_tools(hover)
        hover = fig.select(HoverTool)
        hover.tooltips = """
        <div>
            <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">All:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@all</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Memory:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@memory</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Erred:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@erred</span>
        </div>
        """
        hover.point_policy = "follow_mouse"

        return source, fig
示例#23
0
def progress_plot(**kwargs):
    with log_errors():
        from ..diagnostics.progress_stream import progress_quads
        data = progress_quads({'all': {}, 'memory': {},
                               'erred': {}, 'released': {}})

        y_range = Range1d(-8, 0)
        source = ColumnDataSource(data)
        fig = figure(tools='', toolbar_location=None, y_range=y_range, **kwargs)
        fig.quad(source=source, top='top', bottom='bottom',
                 left='left', right='right', color='#aaaaaa', alpha=0.2)
        fig.quad(source=source, top='top', bottom='bottom',
                 left='left', right='released-loc', color='color', alpha=0.6)
        fig.quad(source=source, top='top', bottom='bottom',
                 left='released-loc', right='memory-loc', color='color', alpha=1)
        fig.quad(source=source, top='top', bottom='bottom',
                 left='erred-loc', right='erred-loc', color='#000000', alpha=0.3)
        fig.text(source=source, text='show-name', y='bottom', x='left',
                x_offset=5, text_font_size='10pt')
        fig.text(source=source, text='done', y='bottom', x='right', x_offset=-5,
                text_align='right', text_font_size='10pt')
        fig.xaxis.visible = False
        fig.yaxis.visible = False
        fig.grid.grid_line_alpha = 0

        hover = HoverTool()
        fig.add_tools(hover)
        hover = fig.select(HoverTool)
        hover.tooltips = """
        <div>
            <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">All:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@all</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Memory:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@memory</span>
        </div>
        <div>
            <span style="font-size: 14px; font-weight: bold;">Erred:</span>&nbsp;
            <span style="font-size: 10px; font-family: Monaco, monospace;">@erred</span>
        </div>
        """
        hover.point_policy = 'follow_mouse'

        return source, fig
示例#24
0
def createHoverTool(simg, cols):
    """
    """
    # Make the hovertool only follow the patches (still a hack)
    htline = simg

    ht = HoverTool()
    ht.tooltips = [("Time", "@index{%F %T}")]
    for col in cols:
        fStr = "@%s{0.00}" % (col)
        ht.tooltips.append((col, fStr))

    ht.formatters = {'index': 'datetime'}
    ht.show_arrow = False
    ht.point_policy = 'follow_mouse'
    ht.line_policy = 'nearest'
    ht.renderers = [htline]

    return ht
示例#25
0
def task_stream_plot(height=400, width=800, follow_interval=5000, **kwargs):
    data = {'start': [], 'duration': [],
            'key': [], 'name': [], 'color': [],
            'worker': [], 'y': [], 'worker_thread': []}

    source = ColumnDataSource(data)
    if follow_interval:
        x_range = DataRange1d(follow='end', follow_interval=follow_interval,
                              range_padding=0)
    else:
        x_range = None

    fig = figure(width=width, height=height, x_axis_type='datetime',
                 tools=['xwheel_zoom', 'xpan', 'reset', 'resize', 'box_zoom'],
                 responsive=True, x_range=x_range, **kwargs)
    fig.rect(x='start', width='duration',
             y='y', height=0.9,
             fill_color='color', line_color='gray', source=source)
    if x_range:
        fig.circle(x=[1, 2], y=[1, 2], alpha=0.0)
    fig.xaxis.axis_label = 'Time'
    fig.yaxis.axis_label = 'Worker Core'
    fig.min_border_right = 10
    fig.ygrid.grid_line_alpha = 0.4
    fig.xgrid.grid_line_alpha = 0.0

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Key:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Duration:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@duration</span>
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
示例#26
0
def task_stream_plot(sizing_mode='scale_width', **kwargs):
    data = {'start': [], 'duration': [],
            'key': [], 'name': [], 'color': [],
            'worker': [], 'y': [], 'worker_thread': [], 'alpha': []}

    source = ColumnDataSource(data)
    x_range = DataRange1d(range_padding=0)

    fig = figure(
        x_axis_type='datetime', title="Task stream",
        tools='xwheel_zoom,xpan,reset,box_zoom', toolbar_location='above',
        sizing_mode=sizing_mode, x_range=x_range, **kwargs
    )
    fig.rect(
        x='start', y='y', width='duration', height=0.8,
        fill_color='color', line_color='color', line_alpha=0.6, alpha='alpha',
        line_width=3, source=source
    )
    fig.xaxis.axis_label = 'Time'
    fig.yaxis.axis_label = 'Worker Core'
    fig.ygrid.grid_line_alpha = 0.4
    fig.xgrid.grid_line_color = None
    fig.min_border_right = 35
    fig.yaxis[0].ticker.num_minor_ticks = 0

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Key:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Duration:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@duration</span>
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
示例#27
0
    def plot_stats():
        """Creates and returns a figure."""

        pos = [positions[i] for i in select_position.active]
        team = select_team.value
        ds = create_ds(team, pos)
        source = ColumnDataSource(ds)

        p = figure(plot_height=600,
                   plot_width=800,
                   title=f'{x.value} vs {y.value}',
                   tools='pan,box_zoom,reset')

        p.circle(x=x.value,
                 y=y.value,
                 size='Size',
                 color='Color',
                 alpha=0.5,
                 source=source,
                 hover_color='navy')

        hover = HoverTool(tooltips=[('Player', '@name'), (
            'Team',
            '@team'), (f'{x.value}',
                       f'@{{{x.value}}}'), (
                           f'{y.value}',
                           f'@{{{y.value}}}'), (f'Opponent', f'@Opponent')])

        if size.value != 'None':
            hover.tooltips.append((f'{size.value}', f'@{{{size.value}}}'))
        if color.value != 'None':
            hover.tooltips.append((f'{color.value}', f'@{{{color.value}}}'))
        hover.point_policy = 'follow_mouse'

        p.add_tools(hover)
        p.xaxis.axis_label = x.value
        p.yaxis.axis_label = y.value

        return p
示例#28
0
    def _draw_contigCirclePlot(self):
        hover = HoverTool(tooltips=[('Length', '@contigs')])
        hover.point_policy = "follow_mouse"
        plot = figure(x_axis_type=None,
                      y_axis_type=None,
                      tools=[hover],
                      title='Contig lengths')
        plot.annular_wedge(x=0,
                           y=0,
                           inner_radius=0.5,
                           outer_radius=0.7,
                           start_angle='start',
                           end_angle='stop',
                           color='colors',
                           alpha=0.9,
                           source=self.contig_dist_src)
        plot.yaxis.axis_label_text_font_size = '14pt'
        plot.xaxis.axis_label_text_font_size = '14pt'
        plot.yaxis.major_label_text_font_size = '14pt'
        plot.xaxis.major_label_text_font_size = '14pt'
        plot.title.text_font_size = '16pt'

        return plot
示例#29
0
def plot_filtering(time, raw, filtered):
    """

    :param time:
    :param raw:
    :param filtered:
    :return:
    """

    hover = HoverTool()
    hover.point_policy = 'snap_to_data'
    hover.line_policy = 'nearest'
    TOOLS = ['pan,wheel_zoom,box_zoom']

    time = np.arange(0, raw.size)
    p1 = figure(title="Timeseries SSH (raw vs filtered)",
                tools=TOOLS,
                plot_width=1000)
    p1.grid.grid_line_alpha = 0.3
    p1.xaxis.axis_label = 'Date (Julian days)'
    p1.yaxis.axis_label = 'SSH'
    p1.circle(time, raw, color='lightseagreen')
    p1.line(time, raw, legend='raw', color='lightseagreen')
    p1.circle(time, filtered, color='royalblue')
    p1.line(time, filtered, legend='filtered',
            color='royalblue')  #, line_width=4)

    p1.add_tools(
        HoverTool(tooltips=[
            ('date', '@x'),
            ('SSH', '@y m'),
        ], mode='mouse'))

    p1.legend.location = "top_left"
    # output_file("Hss_timeseries.html", title="Hss_timeseries")
    show(p1, plot_width=1000, plot_height=400)
示例#30
0
def progress_plot(height=300, width=800, **kwargs):
    from ..diagnostics.progress_stream import progress_quads
    data = progress_quads({
        'all': {},
        'in_memory': {},
        'erred': {},
        'released': {}
    })

    source = ColumnDataSource(data)
    fig = figure(width=width,
                 height=height,
                 tools=['resize'],
                 responsive=True,
                 **kwargs)
    fig.quad(source=source,
             top='top',
             bottom='bottom',
             left=0,
             right=1,
             color='#aaaaaa',
             alpha=0.2)
    fig.quad(source=source,
             top='top',
             bottom='bottom',
             left=0,
             right='released_right',
             color='#0000FF',
             alpha=0.4)
    fig.quad(source=source,
             top='top',
             bottom='bottom',
             left='released_right',
             right='in_memory_right',
             color='#0000FF',
             alpha=0.8)
    fig.quad(source=source,
             top='top',
             bottom='bottom',
             left='erred_left',
             right=1,
             color='#000000',
             alpha=0.3)
    fig.text(source=source,
             text='fraction',
             y='center',
             x=-0.01,
             text_align='right',
             text_baseline='middle')
    fig.text(source=source,
             text='name',
             y='center',
             x=1.01,
             text_align='left',
             text_baseline='middle')
    fig.scatter(x=[-0.2, 1.4], y=[0, 5], alpha=0)
    fig.xgrid.grid_line_color = None
    fig.ygrid.grid_line_color = None
    fig.axis.visible = None
    fig.min_border_left = 0
    fig.min_border_right = 10
    fig.min_border_top = 0
    fig.min_border_bottom = 0
    fig.outline_line_color = None

    hover = HoverTool()
    fig.add_tools(hover)
    hover = fig.select(HoverTool)
    hover.tooltips = """
    <div>
        <span style="font-size: 14px; font-weight: bold;">Name:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@name</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">All:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@all</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">In Memory:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@in_memory</span>
    </div>
    <div>
        <span style="font-size: 14px; font-weight: bold;">Erred:</span>&nbsp;
        <span style="font-size: 10px; font-family: Monaco, monospace;">@erred</span>
    </div>
    """
    hover.point_policy = 'follow_mouse'

    return source, fig
示例#31
0
x = [0, 1, 2, 3, 4, 5]
y = [0, 1, 4, 9, 16, 25]

# set output to static HTML file
output_file("quad.html")

# create a new plot with a title and axis labels
p = figure(title="x^2 example",
           x_axis_label='x',
           y_axis_label='y',
           active_scroll="wheel_zoom")

# add a line renderer with legend and line thickness
p.line(x, y, legend_label="x-val legend label", line_width=2)

# customize the hover_tool/tooltip

hover_tool = HoverTool(tooltips=[("x val", "$x"), ("y val", "$y")])
hover_tool.point_policy = "snap_to_data"
hover_tool.line_policy = "interp"  # interpolate if between data points, makes it more continuous
hover_tool.mode = "vline"  #shows value if in line vertically (no need to be directly on top of graph line)

p.add_tools(hover_tool)

# remove tools on the right and logo for clean look
p.toolbar.logo = None
p.toolbar_location = None

# show graph
show(p)
#leitura do arquivo de dados
df = pd.DataFrame()
df = pd.read_csv('/home/bh/Documentos/DoubleMuRun2011A.csv',
                 engine='python')  #Lê o arquivo com os dados.

btn_bin = Button(label="calcular fit")

options = [("Breit-Wigner", "Breit-Wigner"),
           ("Duas Gaussianas + Exponencial", "Duas Gaussianas + Exponencial"),
           ("CrystalBall + Exponencial", "CrystalBall + Exponencial")]
dropdown = Dropdown(label="fit selection", button_type="warning", menu=options)

#add hover
hover = HoverTool(tooltips=[('Counts',
                             '@inv_mass'), ('Invariant mass (GeV)', '$x')])
hover.point_policy = "follow_mouse"
bins = 500


def plot(newbin, begin, end, y_type='linear'):

    weights = []
    for i in df["M"]:
        weights.append(newbin / np.log(10) / i)

    #create histogram
    hist, edges = np.histogram(df["M"],
                               bins=np.logspace(begin, end, num=newbin + 1),
                               weights=weights)

    # Put the information in a dataframe
示例#33
0
def plot_coadd(all_df, processed_df, band_df, tag):
    def create_processed_data_source(df):
        return ColumnDataSource(data=dict(tilename=df['tilename'],status=df['status'],attnum=df['attnum'],reqnum=df['reqnum'],id=df['id'],dmedian=df['dmedian']))
    def create_all_data_source(df):
        return ColumnDataSource(data=dict(tilename=df['tilename'],dmedian=df['dmedian'])) 

    Colors=['green','blue','blue','blue','blue','blue','blue','blue','blue','blue']

    ### All_df data prep ###
    new_all_df = pd.DataFrame()
    xlist, ylist, tilelist =[],[],[]
    for i, row in all_df.iterrows():
        # Fixes wrapping issue
        if (row['rac3']-row['rac4']) > 100:
            row['rac4']=360 + row['rac4']
            row['rac1']=360 + row['rac1']
        # Shifts image so that tank is visable
        if row['rac3'] < 180:
            row['rac1'] = row['rac1']+360
            row['rac2'] = row['rac2']+360
            row['rac3'] = row['rac3']+360
            row['rac4'] = row['rac4']+360
        xlist.append([row['rac1'], row['rac2'], row['rac3'], row['rac4']])
        ylist.append([row['decc1'], row['decc2'], row['decc3'], row['decc4']])
        tilelist.append(row['tilename'])

    new_all_df['x']=xlist
    new_all_df['y']=ylist
    new_all_df['tilename']=tilelist 

    # Band_df data prep
    band_df = band_df.groupby(by = ['tilename'])

    new_band_df = pd.DataFrame()
    maxdepth=20
    tilelist, depthlist, alphalist = [],[],[]
    for tile,group in band_df:
        depth,count = 0,0
        for i,row in group.iterrows():
            count += 1
            depth += row['dmedian']
        depth = depth/count
        #if depth > 3:
        tilelist.append(tile)
        alphalist.append(depth/maxdepth)
        depthlist.append(depth)

    new_band_df['tilename'] = tilelist
    new_band_df['dmedian'] = depthlist
    new_band_df['alphas'] = alphalist   
 
    # Merge all dfs
    new_all_df = pd.merge(new_all_df, new_band_df, how='outer', on=['tilename'])
    new_all_df.fillna(0, inplace=True)
    fn_df = pd.merge(new_all_df, processed_df, how='inner', on=['tilename'])
    fn_df.fillna('None', inplace=True)

    ### Avg band plot ###
    all_hover = HoverTool(names=['all'])
    TOOLS = [BoxZoomTool(),PanTool(),ResetTool(),WheelZoomTool(),all_hover]

    p = figure(height=1000, width=1000, x_axis_label='RA (Deg)', y_axis_label='DEC (Deg)', tools=TOOLS, title=str(tag)+
' Coadd Map')

    p.patches(xs=new_all_df['x'], ys=new_all_df['y'], source=create_all_data_source(new_all_df), name='all', fill_color='blue', fill_alpha=new_all_df['alphas'], line_color='black')

    ### Add each unitname to plot ### 
    p.patches(xs=fn_df['x'], ys=fn_df['y'], source=create_processed_data_source(fn_df), name='all', fill_color='green', fill_alpha=0.95, line_color='black')

    all_hover.point_policy = "follow_mouse"
    all_hover.tooltips = [("Tilename", "@tilename"),('Pfw_attempt_id','@id'),("Depth","@dmedian")]

    return p
示例#34
0
def contour_plot_bokeh(
        model,
        xlabel=None,
        ylabel=None,
        main=None,
        xlim=(-3.2, 3.2),
        ylim=(-3.2, 3.2),
        colour_function="terrain",
        show=True,
        show_expt_data=True,
        figsize=(10, 10),
        dpi=50,
        other_factors=None,
):

    # TODO: show labels of contour plot

    # https://stackoverflow.com/questions/33533047/how-to-make-a-contour-plot-in-python-using-bokeh-or-other-libs

    dpi_max = dpi**3.5
    N = min(dpi, np.power(dpi_max, 0.5))

    h_grid = np.linspace(xlim[0], xlim[1], num=N)
    v_grid = np.linspace(ylim[0], ylim[1], num=N)
    H, V = np.meshgrid(h_grid, v_grid)
    h_grid, v_grid = H.ravel(), V.ravel()

    pure_factors = model.get_factor_names(level=1)
    if xlabel is None:
        xlabel = pure_factors[0]
    else:
        xlabel = str(xlabel)

    if ylabel is None:
        ylabel = pure_factors[1]
    else:
        ylabel = str(ylabel)

    kwargs = {xlabel: h_grid, ylabel: v_grid}
    if other_factors is not None and isinstance(other_factors, dict):
        kwargs = kwargs.update(other_factors)

    # Look at which factors are included, and pop them out. The remaining
    # factors are specified at their zero level

    unspecified_factors = [i for i in pure_factors if i not in kwargs.keys()]
    for factor in unspecified_factors:
        kwargs[factor] = np.zeros_like(h_grid)

    assert sorted(kwargs.keys()) == sorted(pure_factors), ("Not all factors "
                                                           "were specified.")
    Z = predict(model, **kwargs)
    Z = Z.values.reshape(N, N)
    z_min, z_max = Z.min(), Z.max()
    levels = np.linspace(z_min, z_max, N)

    from matplotlib.pyplot import contour, clabel
    import matplotlib.pyplot as plt
    import matplotlib

    matplotlib.use("Agg")
    # Turn interactive plotting off
    plt.ioff()
    CS = contour(H, V, Z, levels=levels, linestyles="dotted")
    clabel(CS, inline=True, fontsize=10, fmt="%1.0f")
    # contour_labels = [(float(q._x), float(q._y), float(q._text))\
    #                                                 for q in CS.labelTexts]

    # Convert the Matplotlib colour mapper to Bokeh
    # https://stackoverflow.com/questions/49931311/using-matplotlibs-colormap-for-bokehs-color-bar
    mapper = getattr(cm, colour_function)
    colours = (255 * mapper(range(256))).astype("int")
    colour_palette = [RGB(*tuple(rgb)).to_hex() for rgb in colours]
    color_mapper = LinearColorMapper(palette=colour_palette,
                                     low=z_min,
                                     high=z_max)

    # Another alternative:
    # https://stackoverflow.com/questions/35315259/using-colormap-with-bokeh-scatter
    # colors = ["#%02x%02x%02x" % (int(r), int(g), int(b)) for \
    #        r, g, b, _ in 255*mpl.cm.viridis(mpl.colors.Normalize()(radii))]

    p = figure(
        x_range=xlim,
        y_range=ylim,
        # https://github.com/bokeh/bokeh/issues/2351
        tools="pan,wheel_zoom,box_zoom,box_select,lasso_select,reset,save",
    )
    # Create the image layer
    source = {"Xax": [h_grid], "Yax": [v_grid], "predictions": [Z]}
    h_image = p.image(
        source=source,
        image="predictions",
        x=xlim[0],
        y=ylim[0],
        dw=xlim[1] - xlim[0],
        dh=ylim[1] - ylim[0],
        color_mapper=color_mapper,
        global_alpha=0.5,  # with some transparency
        name="contour_image",
    )
    h1 = HoverTool(
        tooltips=[
            (xlabel, "@{Xax}{0.4g}"),
            (ylabel, "@{Yax}{0.4f}"),
            ("Predicted", "@{predictions}{0.4g}"),
        ],
        renderers=[h_image],
        formatters={
            "Predicted": "printf",
            xlabel: "printf",
            ylabel: "printf"
        },
    )

    color_bar = ColorBar(
        color_mapper=color_mapper,
        major_label_text_font_size="8pt",
        ticker=BasicTicker(max_interval=(z_max - z_min) / N * 2),
        formatter=PrintfTickFormatter(format="%.2f"),
        label_standoff=6,
        border_line_color=None,
        location=(0, 0),
    )

    p.add_layout(color_bar, "right")

    # Contour lines using Scipy:
    # scaler_y = (ylim[1] - ylim[0]) / (N - 1)
    # scaler_x = (xlim[1] - xlim[0]) / (N - 1)
    # for level in levels:
    # contours = measure.find_contours(Z, level)
    # for contour in contours:
    # x = contour[:, 1] * scaler_y + ylim[0]
    # y = contour[:, 0] * scaler_x + xlim[0]

    for _, cccontour in enumerate(CS.allsegs):
        if cccontour:
            x = cccontour[0][:, 0]
            y = cccontour[0][:, 1]
            p.line(x, y, line_dash="dashed", color="darkgrey", line_width=1)

    # TODO: bigger experimental markers
    # TODO: hover for the data point shows the factor settings for the data point

    if show_expt_data:

        source = ColumnDataSource(data=dict(
            x=model.data[xlabel],
            y=model.data[ylabel],
            output=model.data[model.get_response_name()].to_list(),
        ))
        h_expts = p.circle(
            x="x",
            y="y",
            color="black",
            source=source,
            # linestyle='',
            # marker='o',
            size=10,
            line_width=2,
            name="experimental_points",
        )
        # custom tooltip for the experimental points
        h2 = HoverTool(
            tooltips=[
                (xlabel, "$x{0.4g}"),
                (ylabel, "$y{0.4g}"),
                ("Actual value", "@{output}{0.4g}"),  # why not working???
            ],
            renderers=[h_expts],
            formatters={
                "Actual value": "printf",
                xlabel: "printf",
                ylabel: "printf"
            },
        )
        h2.point_policy = "snap_to_data"
        h2.line_policy = "none"

    # Axis labels:
    p.xaxis.axis_label_text_font_size = "14pt"
    p.xaxis.axis_label = xlabel
    p.xaxis.major_label_text_font_size = "14pt"
    p.xaxis.axis_label_text_font_style = "bold"
    p.xaxis.bounds = (xlim[0], xlim[1])

    p.yaxis.major_label_text_font_size = "14pt"
    p.yaxis.axis_label = ylabel
    p.yaxis.axis_label_text_font_size = "14pt"
    p.yaxis.axis_label_text_font_style = "bold"
    p.yaxis.bounds = (ylim[0], ylim[1])

    # Add the hover tooltips:
    p.add_tools(h1)
    p.add_tools(h2)

    if show:
        show_plot(p)
    return p
示例#35
0
文件: rca.py 项目: smartyal/21datalab
def rca2(functionNode):
    logger = functionNode.get_logger()
    logger.info("==>>>> in rca2 (root cause analysis " +
                functionNode.get_browse_path())
    progressNode = functionNode.get_child("control").get_child("progress")
    progressNode.set_value(0.1)
    m = functionNode.get_model()

    report = '<i>REPORT</i><br><div style="font-size:85%">'

    annotations = functionNode.get_child("annotations").get_leaves()
    #order = ["Step"+str(no) for no in range(1,19)]
    order = ["Phase" + str(no) for no in range(3, 28)]
    order = functionNode.get_child("annotationsOrder").get_value()
    annotations = data_cleaning(annotations, order=order,
                                logger=logger)  #Step1,Step2,...Step18
    report += (f"found {len(annotations)} valid processes <br>")

    #for now, flatten them out
    annotations = [
        subprocess for process in annotations for subprocess in process
    ]

    algo = functionNode.get_child("selectedAlgorithm").get_value()
    target = functionNode.get_child("selectedTarget").get_target()

    progressNode.set_value(0.3)
    #now we are building up the table by iterating all the children in "selection"
    entries = functionNode.get_child("selection").get_children()

    table = {"target": []}
    firstVariable = True

    for entry in entries:
        logger.debug(f"entry {entry.get_name()}")
        #each entry is a combination of variable, tags and feature
        vars = entry.get_child("selectedVariables").get_targets()
        tags = entry.get_child("selectedTags").get_value()
        features = entry.get_child("selectedFeatures").get_value()
        #for iterate over variables
        for var in vars:
            logger.debug(
                f"processing variable: {var.get_name()} with tags {tags} and features {features}"
            )
            #columnName = var.get_name()+str(tags)+m.getRandomId()
            for tag in tags:
                row = 0
                #table[columnName]=[]# make a column
                for idx, anno in enumerate(annotations):
                    if anno.get_child("type").get_value() != "time":
                        continue
                    if tag in anno.get_child("tags").get_value():
                        startTime = anno.get_child("startTime").get_value()
                        endTime = anno.get_child("endTime").get_value()
                        data = var.get_time_series(startTime,
                                                   endTime)["values"]
                        #we take only the values "inside" the annotation
                        if len(data) > 2:
                            data = data[1:-1]
                        #now create the features
                        for feature in features:
                            feat = calc_feature(data, feature)
                            columnName = var.get_name(
                            ) + "_" + tag + "_" + feature
                            if not columnName in table:
                                table[columnName] = []
                            table[columnName].append(feat)

                        targetValue = get_target(
                            target,
                            (date2secs(startTime) + date2secs(endTime)) / 2)
                        if targetValue:
                            if firstVariable:
                                #for the first variable we also write the target
                                table["target"].append(targetValue)
                            else:
                                #for all others we make sure we have the same target value for that case (sanity check)
                                if table["target"][row] != targetValue:
                                    logger.warning(
                                        f'problem target {table["target"][row]} !=> {targetValue}'
                                    )
                            row = row + 1
                        else:
                            logger.warning(
                                f"no corrrect target value for {startTime} - {endTime}"
                            )

                firstVariable = False
    #now we have the table, plot it
    import json
    #print(json.dumps(table,indent=2))
    progressNode.set_value(0.5)
    #try a model

    algo = functionNode.get_child("selectedAlgorithm").get_value()
    if algo == "lasso":
        reg = linear_model.LassoCV()
        report += " using lasso Regression with auto-hyperparams <br>"
    else:
        #default
        report += " using linear Regression <br>"
        reg = linear_model.LinearRegression()  #try rigde, lasso

    columnNames = []
    dataTable = []
    for k, v in table.items():
        if k == "target":
            continue
        dataTable.append(v)
        columnNames.append(k)

    dataTable = numpy.asarray(dataTable)
    x = dataTable.T
    y = table["target"]
    x_train, x_test, y_train, y_test = train_test_split(x, y)
    reg.fit(x_train, y_train)

    print(reg.coef_)
    y_hat = reg.predict(x_test)
    y_repeat = reg.predict(x_train)
    print(f"predict: {y_hat} vs real: {y_test}")

    #check over/underfitting
    r_train = r2_score(y_train, y_repeat)
    r_test = r2_score(y_test, y_hat)

    report += "R<sup>2</sup> train= %.4g, R<sup>2</sup> test = %.4g <br>" % (
        r_train, r_test)

    pearsons = []
    for col in x.T:
        pearsons.append(pearsonr(col, y)[0])

    #and finally the correlations between y and yhat
    y_pearson_train = pearsonr(y_train, y_repeat)[0]
    y_pearson_test = pearsonr(y_test, y_hat)[0]

    report += "pearsonCorr y/y_hat train:%.4g , test:%.4g <br>" % (
        y_pearson_train, y_pearson_test)

    report += "regression coefficients, pearsons correlations:<br>"
    for col, coef, pear in zip(columnNames, reg.coef_, pearsons):
        report += "&nbsp &nbsp %s:%.4g, &nbsp %.4g <br>" % (col, coef, pear)

    #write report
    progressNode.set_value(0.8)
    report += "<div>"  #close the style div
    functionNode.get_child("report").set_value(report)
    #make a plot
    hover1 = HoverTool(tooltips=[('x,y', '$x,$y')], mode='mouse')
    hover1.point_policy = 'snap_to_data'
    hover1.line_policy = "nearest"
    tools = [
        PanTool(),
        WheelZoomTool(),
        BoxZoomTool(),
        ResetTool(),
        SaveTool(), hover1
    ]
    title = "prediction results on " + functionNode.get_child(
        "selectedAlgorithm").get_value()
    fig = figure(title=title, tools=tools, plot_height=400, plot_width=500)
    fig.toolbar.logo = None

    curdoc().theme = Theme(json=themes.darkTheme)
    fig.xaxis.major_label_text_color = themes.darkTickColor
    fig.yaxis.major_label_text_color = themes.darkTickColor
    fig.xaxis.axis_label = target.get_name()
    fig.xaxis.axis_label_text_color = "white"
    fig.yaxis.axis_label = "predicted Values for " + target.get_name()
    fig.yaxis.axis_label_text_color = "white"
    fig.circle(y_train,
               y_repeat,
               size=4,
               line_color="white",
               fill_color="white",
               name="train",
               legend_label="train")
    fig.circle(y_test,
               y_hat,
               line_color="#d9b100",
               fill_color="#d9b100",
               size=4,
               name="test",
               legend_label="test")

    fileName = functionNode.get_child("outputFileName").get_value()
    filePath = os.path.join(myDir, './../web/customui/' + fileName)
    fig.legend.location = "top_left"
    output_file(filePath, mode="inline")
    save(fig)

    return True
示例#36
0
def worker_table_plot(**kwargs):
    """ Column data source and plot for host table """
    with log_errors():
        # names = ['host', 'cpu', 'memory_percent', 'memory', 'cores', 'processes',
        #          'processing', 'latency', 'last-seen', 'disk-read', 'disk-write',
        #          'network-send', 'network-recv']
        names = [
            'processes', 'disk-read', 'cores', 'cpu', 'disk-write', 'memory',
            'last-seen', 'memory_percent', 'host'
        ]
        source = ColumnDataSource({k: [] for k in names})

        columns = {
            name: TableColumn(field=name, title=name.replace('_percent', ' %'))
            for name in names
        }

        cnames = [
            'host', 'cores', 'processes', 'memory', 'cpu', 'memory_percent'
        ]

        formatters = {
            'cpu': NumberFormatter(format='0.0 %'),
            'memory_percent': NumberFormatter(format='0.0 %'),
            'memory': NumberFormatter(format='0 b'),
            'latency': NumberFormatter(format='0.00000'),
            'last-seen': NumberFormatter(format='0.000'),
            'disk-read': NumberFormatter(format='0 b'),
            'disk-write': NumberFormatter(format='0 b'),
            'net-send': NumberFormatter(format='0 b'),
            'net-recv': NumberFormatter(format='0 b')
        }

        table = DataTable(source=source,
                          columns=[columns[n] for n in cnames],
                          **kwargs)
        for name in cnames:
            if name in formatters:
                table.columns[cnames.index(name)].formatter = formatters[name]

        x_range = Range1d(0, 1)
        y_range = Range1d(-.1, .1)
        mem_plot = figure(title="Memory Usage (%)",
                          tools='box_select',
                          height=90,
                          width=600,
                          x_range=x_range,
                          y_range=y_range,
                          toolbar_location=None)
        mem_plot.circle(source=source,
                        x='memory_percent',
                        y=0,
                        size=10,
                        alpha=0.5)
        mem_plot.yaxis.visible = False
        mem_plot.xaxis.minor_tick_line_width = 0
        mem_plot.ygrid.visible = False
        mem_plot.xaxis.minor_tick_line_alpha = 0

        hover = HoverTool()
        mem_plot.add_tools(hover)
        hover = mem_plot.select(HoverTool)
        hover.tooltips = """
        <div>
          <span style="font-size: 10px; font-family: Monaco, monospace;">@host: </span>
          <span style="font-size: 10px; font-family: Monaco, monospace;">@memory_percent</span>
        </div>
        """
        hover.point_policy = 'follow_mouse'

    return source, [mem_plot, table]
示例#37
0
# instantiate shared generic plot settings
# hover tool
hoverm = HoverTool(tooltips=[
    ("Age", "(@Age)"),
    ("Incidents", "(@Males{0,0.000})"),
],
                   mode='vline')

hoverf = HoverTool(tooltips=[
    ("Age", "(@Age)"),
    ("Incidents", "(@Females{0,0.000})"),
],
                   mode='hline')

hoverm.point_policy = 'snap_to_data'
hoverm.line_policy = 'nearest'

# graph tool bar
toolsm = ["box_select", hoverm, "reset"]
toolsf = ["box_select", hoverf, "reset"]


#create the main plot
def create_figure(*args):
    #create new plot with sizing & labels
    mplot = figure(x_range=label,
                   plot_width=900,
                   plot_height=400,
                   tools=toolsm,
                   title="Cancer Incidents in Males 2016")
示例#38
0
    def map(self, func, x=None, y=None, tooltips=[], rotate=0, **kwargs):
        is_new = (len(self.plots) == 0)

        if not isinstance(x, list):
            x = [x]

        if self.hue is not None:
            x += [self.hue]
            self.update_cmap(self.data)
            self.data['color'] = [
                self.cmap[lvl] for lvl in self.data[self.hue]
            ]
            kwargs['fill_color'] = 'color'
            kwargs['hue_order'] = self.ordering['hue']

        (factor_combs, factor_values) = self.get_row_col_combs()
        for i, pair in enumerate(factor_combs):
            data = self.data.loc[(factor_values == pair)].copy()

            if data.size == 0:
                self.plots.append(None)
                continue

            prev_plot = None
            if not is_new: prev_plot = self.plots[i]

            if self.hue is not None:
                tooltips = np.append(tooltips, self.hue)
                if is_new:
                    kwargs['legend_field'] = self.hue

            x = [xi for xi in x if xi is not None]
            if len(x) == 1 and 'legend_field' in kwargs:
                kwargs.pop('legend_field')

            p = func(x=x,
                     y=y,
                     data=data,
                     p=prev_plot,
                     width=self.width,
                     height=self.height,
                     name=func.__name__,
                     **kwargs)

            if rotate != 0:
                p.xaxis.major_label_orientation = rotate

            tooltips_fmt = pd.Series(tooltips,
                                     dtype='object').drop_duplicates()
            tooltips_fmt = list(zip(tooltips_fmt, '@' + tooltips_fmt))
            hover_tool = HoverTool(tooltips=tooltips_fmt,
                                   names=[func.__name__])
            hover_tool.point_policy = 'snap_to_data'
            p.add_tools(hover_tool)

            # Add facet info in subtitle
            if is_new and pair != True:
                subtitle = Title(text=', '.join(
                    '{}: {}'.format(*it)
                    for it in zip(factor_combs.names, pair)),
                                 text_font_size=CFG['subtitle_fs'],
                                 text_font_style="italic")
                p.add_layout(subtitle, 'above')

            # Format legend and put in outside the plot area
            if 'legend_field' in kwargs:
                legends = format_legend(p)
                p.legend.items.clear()
                for legend in legends:
                    p.add_layout(legend, 'right')

            if len(self.plots) < len(factor_combs):
                self.plots.append(p)
示例#39
0
test_list = []
x_range = []
# for level in range (1,7):
#     search_str_list.append ("LTE.*RSSI Level " + str(level))
#
# print (search_str_list)

hover = HoverTool(tooltips=[
    ("index", "$index"),
    ("Power", "@y"),
    ("desc", "@desc"),
],
                  names=["foo"],
                  mode='vline')

hover.point_policy = "snap_to_data"
hover.line_policy = "nearest"
p = figure(
    plot_width=800,
    plot_height=800,
    title="LTE RSSI",
    tools=[hover,
           BoxZoomTool(),
           ResetTool(),
           PanTool(),
           BoxSelectTool()])

for row in reader:

    if row['Product'] == "Upper Limits----->":
        for field in search_fieldlist:
示例#40
0
def plot_classification_probabilities(
    x,
    y,
    cv_results,
    output_html=None,
    width=500,
    height=500,
    sizing_mode="stretch_both",
):
    """Plot the classification probabilities for each cross-validation split

    Parameters
    ----------
    x : numpy.ndarray
        The original feature matrix

    y : numpy.ndarray
        The target array (i.e. "ground truth")

    cv_results : list of SGLResult namedtuples
        Results of each cross-validation split

    output_html : string or None, default=None
        Filename for bokeh html output. If None, figure will not be saved

    width : int, default=500
        Width of each beta plot (in pixels)

    height : int, default=500
        Height of each beta plot (in pixels)

    sizing_mode : string
        One of ("fixed", "stretch_both", "scale_width", "scale_height",
        "scale_both"). Specifies how will the items in the layout resize to
        fill the available space. Default is "stretch_both". For more
        information on the different modes see
        https://bokeh.pydata.org/en/latest/docs/reference/models/layouts.html#bokeh.models.layouts.LayoutDOM
    """
    p = figure(plot_width=width, plot_height=height, toolbar_location="above")
    p.title.text = "Classification probabilities for each CV split"
    p.add_layout(
        Title(
            text="Click on legend entries to hide/show corresponding lines",
            align="left",
        ),
        "right",
    )

    names = ["cv_idx = {i:d}".format(i=i) for i in range(len(cv_results))]

    hover = HoverTool(tooltips=[("Subject", "$index")], mode="vline")
    hover.point_policy = "snap_to_data"
    hover.line_policy = "nearest"

    for res, color, name in zip(cv_results, Spectral10, names):
        p.line(
            np.arange(len(y)),
            _sigmoid(x.dot(res.beta_hat)),
            line_width=2,
            color=color,
            alpha=0.8,
            legend=name,
        )

    p.line(np.arange(len(y)), y, line_width=3, alpha=0.8, legend="ground truth")
    p.line(
        np.arange(len(y)),
        0.5 * np.ones(len(y)),
        line_width=2,
        line_dash="dashed",
        alpha=0.8,
        legend="threshold",
    )
    p.add_tools(hover)
    p.legend.location = "top_right"
    p.legend.click_policy = "hide"
    p.xaxis.axis_label = "Subject ID"
    p.xaxis.major_tick_line_color = None  # turn off x-axis major ticks
    p.xaxis.minor_tick_line_color = None  # turn off x-axis minor ticks
    p.xaxis.major_label_text_font_size = "0pt"  # turn off x-axis tick labels
    p.yaxis.axis_label = "Classification Probability"
    p.sizing_mode = sizing_mode

    if output_html is not None:
        html = file_html(p, CDN, "my plot")
        with open(op.abspath(output_html), "w") as fp:
            fp.write(html)
    else:
        show(p)
示例#41
0
def bokehTile(tileFile,
              jsonFile,
              TT=[0, 0, 0],
              DD=[2019, 10, 1],
              dynamic=False,
              plotTitle=''):
    citls, h = fitsio.read(tileFile, header=True)
    w = (np.where(citls['IN_DESI'] == 1)[0])
    inci = citls[w]

    if jsonFile is not None:
        with open(jsonFile, "r") as read_file:
            data = json.load(read_file)

    ## Coloring scheme
    palette = ['green', 'red', 'white']
    dye = []

    for tile in citls['TILEID']:

        rang = 2  # 'orange'

        if jsonFile is not None:
            if str(tile) in data:
                rang = 0  # 'green' #green default
                if len(data[str(tile)]
                       ['unassigned']) > 0:  # not assigned (red)
                    rang = 1  # 'red' #'red'
                if (0 in data[str(tile)]['gfa_stars_percam']):
                    print(data[str(tile)]['gfa_stars_percam'])
                    rang = 1  # 'cyan'
        else:
            rang = 0  # green if qa.json is not provided

        dye.append(rang)

    dye = np.asarray(dye)
    w = (np.where(dye < 2)[0])
    citls = citls[w]
    dye = dye[w]
    mapper = linear_cmap(field_name='DYE', palette=palette, low=0, high=2)

    #########################################################
    TOOLS = [
        'pan', 'tap', 'wheel_zoom', 'box_zoom', 'reset', 'save', 'box_select'
    ]

    obsTime = dt(DD[0], DD[1], DD[2], TT[0], TT[1], TT[2])
    # print(get_kp_twilights(TT,DD))

    if plotTitle == '' or plotTitle is None:
        PTITLE = ''
    else:
        PTITLE = 'Program: ' + plotTitle

    p = figure(tools=TOOLS,
               toolbar_location="right",
               plot_width=800,
               plot_height=450,
               title=PTITLE,
               active_drag='box_select')  # str(DD[1])+" - 2019")
    p.title.text_font_size = '16pt'
    p.title.text_color = 'black'
    p.grid.grid_line_color = "gainsboro"

    ###############################  adding ecliptic plane+ hour grid ####################3
    add_plane(p, color='red', plane='ecliptic', projection='equatorial')

    tiledata = dict(
        RA=citls['RA'],
        DEC=citls['DEC'],
        TILEID=citls['TILEID'],
        BRIGHTRA=citls['BRIGHTRA'][:, 0],
        BRIGHTDEC=citls['BRIGHTDEC'][:, 0],
        BRIGHTVTMAG=citls['BRIGHTVTMAG'][:, 0],
        EBV_MED=np.round(citls['EBV_MED'], 3),
        STAR_DENSITY=citls['STAR_DENSITY'],
        DYE=dye,
        program=citls['PROGRAM'],
        selected=np.ones(len(citls), dtype=bool),
    )

    for colname in ['STAR_DENSITY', 'EBV_MED']:
        if colname in citls.dtype.names:
            tiledata[colname] = citls[colname]

    tiles = ColumnDataSource(data=tiledata)

    colformat = bktables.NumberFormatter(format='0,0.00')
    columns = [
        bktables.TableColumn(field='TILEID', title='TILEID', width=80),
        bktables.TableColumn(field='RA', title='RA', formatter=colformat),
        bktables.TableColumn(field='DEC', title='DEC', formatter=colformat),
    ]

    for colname in ['STAR_DENSITY', 'EBV_MED']:
        if colname in tiledata:
            columns.append(
                bktables.TableColumn(field=colname,
                                     title=colname,
                                     formatter=colformat))

    columns.append(bktables.TableColumn(field='selected', title='Selected'))

    tiletable = bktables.DataTable(columns=columns, source=tiles, width=800)

    tiles.selected.js_on_change(
        'indices',
        CustomJS(args=dict(s1=tiles),
                 code="""
        var inds = cb_obj.indices;
        var d1 = s1.data;
        for (var i=0; i<d1['selected'].length; i++) {
            d1['selected'][i] = false;
        }
        for (var i = 0; i < inds.length; i++) {
            d1['selected'][inds[i]] = true;
        }
        s1.change.emit();
    """))

    render = p.circle(
        'RA',
        'DEC',
        source=tiles,
        size=9,
        line_color='chocolate',
        color=mapper,
        alpha=0.4,
        hover_color='orange',
        hover_alpha=1,
        hover_line_color='red',

        # set visual properties for selected glyphs
        selection_fill_color='orange',
        selection_line_color='white',
        # set visual properties for non-selected glyphs
        nonselection_fill_alpha=0.4,
        nonselection_fill_color=mapper)

    p.xaxis.axis_label = 'RA [deg]'
    p.yaxis.axis_label = 'Dec. [deg]'
    p.xaxis.axis_label_text_font_size = "14pt"
    p.yaxis.axis_label_text_font_size = "14pt"
    p.grid.grid_line_color = "gainsboro"
    p.yaxis.major_label_text_font_size = "12pt"
    p.xaxis.major_label_text_font_size = "12pt"

    p.x_range = Range1d(360, 0)
    p.y_range = Range1d(-40, 95)
    p.toolbar.logo = None
    p.toolbar_location = None

    # mytext = Label(x=180, y=-35, text="S", text_color='gray', text_font_size='12pt') ; p.add_layout(mytext)
    # mytext = Label(x=180, y=88, text="N", text_color='gray', text_font_size='12pt') ; p.add_layout(mytext)
    # mytext = Label(x=350, y=45, text="E", text_color='gray', text_font_size='12pt', angle=np.pi/2) ; p.add_layout(mytext)
    # mytext = Label(x=4, y=45, text="W", text_color='gray', text_font_size='12pt', angle=np.pi/2) ; p.add_layout(mytext)

    ## Javascript code to open up custom html pages, once user click on a tile
    code = """
        var index_selected = source.selected['1d']['indices'][0];
        var tileID = source.data['TILEID'][index_selected];
        if (tileID!==undefined) {
        var win = window.open("http://www.astro.utah.edu/~u6022465/cmx/ALL_SKY/dr8/allSKY_ci_tiles/sub_pages/tile-"+tileID+".html", " ");
        try {win.focus();} catch (e){} }
    """

    taptool = p.select(type=TapTool)
    taptool.callback = CustomJS(args=dict(source=tiles), code=code)

    ## The html code for the hover window that contain tile infrormation
    ttp = """
        <div>
            <div>
                <span style="font-size: 14px; color: blue;">Tile ID:</span>
                <span style="font-size: 14px; font-weight: bold;">@TILEID{int}</span>
            </div>
            <div>
                <span style="font-size: 14px; color: blue;">RA:</span>
                <span style="font-size: 14px; font-weight: bold;">@RA</span>
            </div>  
            <div>
                <span style="font-size: 14px; color: blue;">Dec:</span>
                <span style="font-size: 14px; font-weight: bold;">@DEC</span>
            </div>     
            <div>
                <span style="font-size: 14px; color: blue;">EBV_MED:</span>
                <span style="font-size: 14px; font-weight: bold;">@EBV_MED{0.000}</span>
            </div> 
            <div>
                <span style="font-size: 14px; color: blue;">STAR_DENSITY:</span>
                <span style="font-size: 14px; font-weight: bold;">@STAR_DENSITY{0}</span>
            </div> 
            <div>
                <span style="font-size: 14px; color: blue;">BRIGHTEST_STAR_VTMAG:</span>
                <span style="font-size: 14px; font-weight: bold;">@BRIGHTVTMAG</span>
            </div> 
            <div>
                <span style="font-size: 14px; color: blue;">BRIGHTEST_STAR_LOC:</span>
                <span style="font-size: 14px; font-weight: bold;">(@BRIGHTRA, @BRIGHTDEC)</span>
            </div> 
        </div>
    """

    hover = HoverTool(tooltips=ttp, renderers=[render])

    hover.point_policy = 'snap_to_data'
    hover.line_policy = 'nearest'
    # hover.mode='vline'
    p.add_tools(hover)

    cross = CrosshairTool()
    # cross.dimensions='height'
    cross.line_alpha = 0.3
    cross.line_color = 'gray'
    p.add_tools(cross)

    # Setting the second y axis range name and range
    p.extra_y_ranges = {"foo": p.y_range}
    p.extra_x_ranges = {"joo": p.x_range}

    # Adding the second axis to the plot.
    p.add_layout(LinearAxis(y_range_name="foo"), 'right')
    p.add_layout(LinearAxis(x_range_name="joo"), 'above')

    p.xaxis.major_label_text_font_size = "12pt"
    p.yaxis.major_label_text_font_size = "12pt"

    if dynamic:

        # twilight_source = get_kp_twilights(TT,DD)   # evening and morning twilights at every TT and DD
        circleSource_1 = skyCircle(TT, DD, 1.5)
        p.circle('RA', 'DEC', source=circleSource_1, size=1.5, color='black')
        circleSource_2 = skyCircle(TT, DD, 2.0)
        p.circle('RA', 'DEC', source=circleSource_2, size=0.5, color='gray')

    else:
        circleSource = skyCircle(TT, DD, 1.5)
        p.circle('RA', 'DEC', source=circleSource, size=1.5, color=None)

    ### Dealing with the Moon and Jupiter
    inFile = 'moonLoc_jupLoc_fracPhase.csv'  # 'moon_loc_jup_loc_fracPhase_namePhase.csv'
    tbl_moon_jup = np.genfromtxt(inFile,
                                 delimiter=',',
                                 filling_values=-1,
                                 names=True,
                                 dtype=None)  # , dtype=np.float)

    loc = EarthLocation.of_site('Kitt Peak')
    kp_lat = 31, 57, 48
    kp_lon = -111, 36, 00
    mooninfo_obj = pylunar.MoonInfo((kp_lat), (kp_lon))

    m_ra, m_dec, frac_phase, name_phase = moonLoc(TT, DD, loc, mooninfo_obj)
    j_ra, j_dec = jupLoc(TT, DD, loc)

    #moonSource = ColumnDataSource({"moon_RAS": tbl_moon_jup['moon_ra'], "moon_DECS": tbl_moon_jup['moon_dec'],
    #                               "Phase_frac": tbl_moon_jup['moon_phase_frac']})

    moonSource = ColumnDataSource({
        "moon_RAS":
        tbl_moon_jup['moon_ra'],
        "moon_DECS":
        tbl_moon_jup['moon_dec'],
        "Phase_frac":
        np.round(100 * tbl_moon_jup['moon_phase_frac'])
    })

    ####moon_RADEC = ColumnDataSource({"moon_ra": [m_ra.deg], "moon_dec": [m_dec.deg], "phase_frac": [frac_phase]})
    moon_RADEC_ = ColumnDataSource({
        "moon_ra": [m_ra.deg - 360],
        "moon_dec": [m_dec.deg],
        "phase_frac": [frac_phase]
    })
    moon_RADEC = ColumnDataSource({
        "moon_ra": [m_ra.deg],
        "moon_dec": [m_dec.deg],
        "phase_frac": [frac_phase]
    })

    render_moon = p.circle('moon_ra',
                           'moon_dec',
                           source=moon_RADEC,
                           size=170,
                           color='cyan',
                           alpha=0.2)
    render_moon = p.circle('moon_ra',
                           'moon_dec',
                           source=moon_RADEC,
                           size=4,
                           color='blue')

    render_moon = p.circle('moon_ra',
                           'moon_dec',
                           source=moon_RADEC_,
                           size=170,
                           color='cyan',
                           alpha=0.2)
    render_moon = p.circle('moon_ra',
                           'moon_dec',
                           source=moon_RADEC_,
                           size=4,
                           color='blue')

    jupSource = ColumnDataSource({
        "jup_RAS": tbl_moon_jup['jup_ra'],
        "jup_DECS": tbl_moon_jup['jup_dec']
    })
    jup_RADEC = ColumnDataSource({
        "jup_ra": [j_ra.deg],
        "jup_dec": [j_dec.deg]
    })

    twilight = get_kp_twilights(
        TT, DD)  # evening and morning twilights at every TT and DD
    twilight_source = ColumnDataSource({
        "eve_twilight": [twilight[0]],
        "mor_twilight": [twilight[1]]
    })

    render_jup = p.circle('jup_ra',
                          'jup_dec',
                          source=jup_RADEC,
                          size=5,
                          color='blue')
    render_jup = p.circle('jup_ra',
                          'jup_dec',
                          source=jup_RADEC,
                          size=4,
                          color='gold')

    from bokeh.models.glyphs import Text
    TXTsrc = ColumnDataSource(
        dict(x=[350],
             y=[85],
             text=['Moon Phase: ' + "%.0f" % (frac_phase * 100) + "%"]))
    glyph = Text(x="x", y="y", text="text", angle=0, text_color="black")
    p.add_glyph(TXTsrc, glyph)

    TXTsrc_moon = ColumnDataSource(
        dict(x=[m_ra.deg + 10], y=[m_dec.deg - 10], text=['Moon']))
    glyph = Text(x="x",
                 y="y",
                 text="text",
                 angle=0,
                 text_color="blue",
                 text_alpha=0.3,
                 text_font_size='10pt')
    p.add_glyph(TXTsrc_moon, glyph)

    TXTsrc_jup = ColumnDataSource(
        dict(x=[j_ra.deg + 5], y=[j_dec.deg - 8], text=['Jup.']))
    glyph = Text(x="x",
                 y="y",
                 text="text",
                 angle=0,
                 text_color="black",
                 text_alpha=0.3,
                 text_font_size='10pt')
    p.add_glyph(TXTsrc_jup, glyph)

    callback = CustomJS(args=dict(source_sky1=circleSource_1,
                                  source_sky2=circleSource_2,
                                  source_moon=moonSource,
                                  source_moon_RADEC=moon_RADEC,
                                  source_moon_RADEC_=moon_RADEC_,
                                  source_jup=jupSource,
                                  source_jup_RADEC=jup_RADEC,
                                  sourceTXT=TXTsrc,
                                  sourceTXTmoon=TXTsrc_moon,
                                  sourceTXTjup=TXTsrc_jup),
                        code="""
                // First set times as if they were UTC
                var t = new Date(time_slider.value);
                var d = new Date(date_slider.value);
                var data1 = source_sky1.data;
                var ra_1 = data1['RA'];
                var ra0_1 = data1['RA0'];
                
                var data2 = source_sky2.data;
                var ra_2 = data2['RA'];
                var ra0_2 = data2['RA0'];
                
                var data_moon = source_moon.data;
                var ras_moon = data_moon['moon_RAS'];
                var decs_moon = data_moon['moon_DECS'];
                var phase_frac = data_moon['Phase_frac'];
                
                var moonRADEC = source_moon_RADEC.data;
                var moon_ra = moonRADEC['moon_ra'];
                var moon_dec = moonRADEC['moon_dec'];
     
                var moonRADEC_ = source_moon_RADEC_.data;
                var moon_ra_ = moonRADEC_['moon_ra'];
                var moon_dec_ = moonRADEC_['moon_dec'];
                
                var data_jup = source_jup.data;
                var ras_jup = data_jup['jup_RAS'];
                var decs_jup = data_jup['jup_DECS'];
                
                var jupRADEC = source_jup_RADEC.data;
                var jup_ra = jupRADEC['jup_ra'];
                var jup_dec = jupRADEC['jup_dec'];


                var Hour  = t.getUTCHours();
                var Day   = d.getDate();
                var Month = d.getMonth();
                
                var Year = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
                var all_FULdays = 0;
                for (var i = 0; i < Month; i++)
                    all_FULdays=all_FULdays+Year[i];
                all_FULdays = all_FULdays + (Day-1);
                
                if (Hour<12) all_FULdays=all_FULdays+1;
                
                var all_minutes = all_FULdays*24+Hour;
                
                if (all_minutes<8800) {
                    moon_ra[0] = ras_moon[all_minutes];
                    moon_dec[0] = decs_moon[all_minutes];   
                    moon_ra_[0] = ras_moon[all_minutes]-360.;
                    moon_dec_[0] = decs_moon[all_minutes];   
                                        
                }


                var jupTXTdata = sourceTXTjup.data;
                var x_jup = jupTXTdata['x'];
                var y_jup = jupTXTdata['y'];
                var text_jup = jupTXTdata['text'];  
                
                
                if (all_minutes<8800) {
                    jup_ra[0] = ras_jup[all_minutes];
                    jup_dec[0] = decs_jup[all_minutes];   
                    x_jup[0] = jup_ra[0]+5;
                    y_jup[0] = jup_dec[0]-8;                     
                }
                 
                                
                if (t.getUTCHours() < 12) {
                    d.setTime(date_slider.value + 24*3600*1000);
                } else {
                    d.setTime(date_slider.value);
                }
                d.setUTCHours(t.getUTCHours());
                d.setUTCMinutes(t.getUTCMinutes());
                d.setUTCSeconds(0);        
                
                // Correct to KPNO local time
                // d object still thinks in UTC, which is 7 hours ahead of KPNO
                d.setTime(d.getTime() + 7*3600*1000);
                // noon UT on 2000-01-01
                var reftime = new Date();
                reftime.setUTCFullYear(2000);
                reftime.setUTCMonth(0);   // Months are 0-11 (!)
                reftime.setUTCDate(1);    // Days are 1-31 (!)
                reftime.setUTCHours(12);
                reftime.setUTCMinutes(0);
                reftime.setUTCSeconds(0);
                
                // time difference in days (starting from milliseconds)
                var dt = (d.getTime() - reftime.getTime()) / (24*3600*1000);

                // Convert to LST
                var mayall_longitude_degrees = -(111 + 35/60. + 59.6/3600);
                var LST_hours = ((18.697374558 + 24.06570982441908 * dt) + mayall_longitude_degrees/15) % 24;
                var LST_degrees = LST_hours * 15;
                
                

                for (var i = 0; i < ra_1.length; i++) {
                    ra_1[i] = (ra0_1[i] + LST_degrees) % 360;
                }
                
                for (var i = 0; i < ra_2.length; i++) {
                    ra_2[i] = (ra0_2[i] + LST_degrees) % 360;
                }                

                //// Here we gtake care of the moon phasde text
                var TXTdata = sourceTXT.data;
                var x = TXTdata['x'];
                var y = TXTdata['y'];
                var text = TXTdata['text'];
                
                var moonTXTdata = sourceTXTmoon.data;
                var x_moon = moonTXTdata['x'];
                var y_moon = moonTXTdata['y'];
                var text_moon = moonTXTdata['text'];   

                // x[0] = 1;
                // y[0] = 40;
                if (all_minutes<8800) {
                    text[0] = 'Moon Phase: ' + phase_frac[all_minutes]+'%';
                    x_moon[0] = moon_ra[0]+10;
                    y_moon[0] = moon_dec[0]-10;
                }

                sourceTXT.change.emit();
                /////////////////////////////// Moon phase code ends.

                source_sky1.change.emit();
                source_sky2.change.emit();
                //source_moon_RADEC.change.emit();
                //source_moon_RADEC_.change.emit();
                //source_jup_RADEC.change.emit();
                sourceTXTmoon.change.emit();
                sourceTXTjup.change.emit();

                //alert(d);
    """)

    if dynamic:
        ### TIME
        Timeslider = DateSlider(start=dt(2019, 9, 1, 16, 0, 0),
                                end=dt(2019, 9, 2, 8, 0, 0),
                                value=dt(2019, 9, 1, 16, 0, 0),
                                step=1,
                                title="KPNO local time(hh:mm)",
                                format="%H:%M",
                                width=800)

        ## DATE
        Dateslider = DateSlider(start=dt(2019, 9, 1, 16, 0, 0),
                                end=dt(2020, 8, 31, 8, 0, 0),
                                value=dt(2019, 10, 1, 16, 0, 0),
                                step=1,
                                title="Date of sunset(4pm-8am)",
                                format="%B:%d",
                                width=800)

        callback.args['time_slider'] = Timeslider
        callback.args['date_slider'] = Dateslider

        Dateslider.js_on_change('value', callback)
        Timeslider.js_on_change('value', callback)

        layout = column(p, Dateslider, Timeslider, tiletable)
        # show(p)
        return layout

    return p
示例#42
0
def plot_model(
        model,
        x_column,
        y_column=None,
        fig=None,
        x_slider=None,
        y_slider=None,
        show_expt_data=True,
        figsize=(10, 10),
        dpi=100,
        **kwargs,
):
    """
    Plots a `model` object with a given model input as `x_column` against
    the model's output: `y_column`. If `y_column` is not specified, then it
    found from the `model`.

    For model's with more than 1 inputs, the `y_column` is the variable to be
    plotted on the y-axis, and then the plot type is a contour plot.
    """
    pure_factors = model.get_factor_names(level=1)
    dpi_max = dpi**3.5  # should be reasonable for most modern computers
    per_axis_points = min(dpi, np.power(dpi_max, 1 / len(pure_factors)))

    # `oneD=True`: the x-variable is a model input, and the y-axis is a response
    oneD = False
    if y_column and y_column not in pure_factors:
        oneD = True
        y_column = model.get_response_name()

    param_names = [
        model.get_response_name(),
    ]
    param_names.extend(model.get_factor_names())

    # Not always a great test: y = I(1/d) does not pick up that "d" is the model
    # even though it is via the term encapsulated in I(...)
    # assert x_column in param_names, "x_column must exist in the model."
    assert y_column in param_names, "y_column must exist in the model."

    xrange = model.data[x_column].min(), model.data[x_column].max()
    xdelta = xrange[1] - xrange[0]
    xlim = kwargs.get("xlim",
                      (xrange[0] - xdelta * 0.05, xrange[1] + xdelta * 0.05))
    h_grid = np.linspace(xlim[0], xlim[1], num=per_axis_points)
    plotdata = {x_column: h_grid}

    if not oneD:
        yrange = model.data[y_column].min(), model.data[y_column].max()
        ydelta = yrange[1] - yrange[0]
        ylim = kwargs.get(
            "ylim", (yrange[0] - ydelta * 0.05, yrange[1] + ydelta * 0.05))

        v_grid = np.linspace(ylim[0], ylim[1], num=per_axis_points)
        H, V = np.meshgrid(h_grid, v_grid)
        h_grid, v_grid = H.ravel(), V.ravel()
        plotdata[x_column] = h_grid
        plotdata[y_column] = v_grid

    # TODO: handle the 2D case later

    # if other_factors is not None and isinstance(other_factors, dict):
    # plotdata = kwargs.update(other_factors)

    ## Look at which factors are included, and pop them out. The remaining
    ## factors are specified at their zero level

    # unspecified_factors = [i for i in pure_factors if i not in kwargs.keys()]
    # for factor in unspecified_factors:
    # plotdata[factor] = np.zeros_like(h_grid)

    # assert sorted(kwargs.keys()) == sorted(pure_factors), ("Not all factors "
    # "were specified.")

    Z = predict(model, **plotdata)

    if not oneD:
        assert False
    else:
        plotdata[y_column] = Z
        yrange = Z.min(), Z.max()
        ydelta = yrange[1] - yrange[0]
        ylim = kwargs.get(
            "ylim", (yrange[0] - ydelta * 0.05, yrange[1] + ydelta * 0.05))

    if fig:
        p = fig
        prior_figure = True
    else:
        prior_figure = False
        p = figure(
            x_range=xlim,
            y_range=ylim,
            # https://github.com/bokeh/bokeh/issues/2351
            tools="pan,wheel_zoom,box_zoom, box_select,lasso_select,reset,save",
        )

    h_line = p.line(
        plotdata[x_column],
        plotdata[y_column],
        line_dash="solid",
        color=kwargs.get("color", "black"),
        line_width=kwargs.get("line_width", 2),
    )
    y_units = model.data.pi_units[y_column]

    tooltips = [(x_column, "$x")]
    if y_units:
        tooltips.append((f"Prediction of {y_column} [{y_units}]", "$y"))
    else:
        tooltips.append((f"Prediction of {y_column}", "$y"))

    tooltips.append(("Source", model.name or ""))

    # custom tooltip for the predicted prediction line
    h1 = HoverTool(tooltips=tooltips, renderers=[h_line])
    h1.line_policy = "nearest"

    if show_expt_data:
        source = ColumnDataSource(data=dict(
            x=model.data[x_column],
            y=model.data[y_column],
            output=model.data[model.get_response_name()].to_list(),
        ))
        h_expts = p.circle(
            x="x",
            y="y",
            color="black",
            source=source,
            size=10,
            line_width=2,
            name="Experimental_points",
        )
        h2 = HoverTool(
            tooltips=[
                (x_column, "$x"),
                (y_column, "$y"),
                ("Experimental value", "@output"),
            ],
            renderers=[h_expts],
        )

        h2.point_policy = "snap_to_data"
        h2.line_policy = "none"

    # Axis labels:
    p.xaxis.axis_label_text_font_size = "14pt"
    p.xaxis.axis_label = x_column
    p.xaxis.major_label_text_font_size = "14pt"
    p.xaxis.axis_label_text_font_style = "bold"

    p.yaxis.major_label_text_font_size = "14pt"
    p.yaxis.axis_label = y_column
    p.yaxis.axis_label_text_font_size = "14pt"
    p.yaxis.axis_label_text_font_style = "bold"
    if prior_figure:

        # p.xaxis.bounds =
        p.x_range = Range1d(
            min(xlim[0], p.x_range.start, min(model.data[x_column])),
            max(xlim[1], p.x_range.end, max(model.data[x_column])),
        )
        p.y_range = Range1d(
            min(ylim[0], p.y_range.start, min(model.data[y_column])),
            max(ylim[1], p.y_range.end, max(model.data[y_column])),
        )

    else:
        p.x_range = Range1d(xlim[0], xlim[1])
        p.y_range = Range1d(ylim[0], ylim[1])

    # Add the hover tooltips:
    p.add_tools(h1)
    p.add_tools(h2)

    show_plot(p)
    return p
示例#43
0
source_rc = ColumnDataSource(data=dict(x=x, y=y6))
source_im = ColumnDataSource(data=dict(x=x, y=y7))
source_na = ColumnDataSource(data=dict(x=x, y=y8))
source_ra = ColumnDataSource(data=dict(x=x, y=y9))
source_da = ColumnDataSource(data=dict(x=x, y=y10))
source_ic = ColumnDataSource(data=dict(x=x, y=y11))
source_pr = ColumnDataSource(data=dict(x=x, y=y12))

# Incidence vs Rt
source_phase_space = ColumnDataSource(data=dict(x=y5, y=y11))

# plot 1

hover = HoverTool(tooltips=[(PLOT_X_LABEL, "@x{0}"), (PLOT_Y_LABEL, "@y{0}")],
                  mode="vline")
hover.point_policy = 'snap_to_data'
hover.line_policy = 'nearest'

plot = figure(
    plot_height=PLOT_HEIGHT,
    plot_width=PLOT_WIDTH,
    title=PLOT_TITLE,
    tools=PLOT_TOOLS,
    x_range=[0, DAYS],
)

plot.line('x',
          'y',
          source=source_active,
          line_width=PLOT_LINE_WIDTH,
          line_alpha=PLOT_LINE_ALPHA,
示例#44
0
    def __init__(self, scheduler, width=600, **kwargs):
        with log_errors():
            self.last = 0
            self.scheduler = scheduler
            self.source = ColumnDataSource({
                "memory": [1, 2],
                "memory-half": [0.5, 1],
                "memory_text": ["1B", "2B"],
                "utilization": [1, 2],
                "utilization-half": [0.5, 1],
                "worker": ["a", "b"],
                "gpu-index": [0, 0],
                "y": [1, 2],
                "escaped_worker": ["a", "b"],
            })

            memory = figure(title="GPU Memory",
                            tools="",
                            id="bk-gpu-memory-worker-plot",
                            width=int(width / 2),
                            name="gpu_memory_histogram",
                            **kwargs)
            rect = memory.rect(
                source=self.source,
                x="memory-half",
                y="y",
                width="memory",
                height=1,
                color="#76B900",
            )
            rect.nonselection_glyph = None

            utilization = figure(title="GPU Utilization",
                                 tools="",
                                 id="bk-gpu-utilization-worker-plot",
                                 width=int(width / 2),
                                 name="gpu_utilization_histogram",
                                 **kwargs)
            rect = utilization.rect(
                source=self.source,
                x="utilization-half",
                y="y",
                width="utilization",
                height=1,
                color="#76B900",
            )
            rect.nonselection_glyph = None

            memory.axis[0].ticker = BasicTicker(mantissas=[1, 256, 512],
                                                base=1024)
            memory.xaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
            memory.xaxis.major_label_orientation = -math.pi / 12
            memory.x_range.start = 0

            for fig in [memory, utilization]:
                fig.xaxis.minor_tick_line_alpha = 0
                fig.yaxis.visible = False
                fig.ygrid.visible = False

                tap = TapTool(callback=OpenURL(
                    url="./info/worker/@escaped_worker.html"))
                fig.add_tools(tap)

                fig.toolbar.logo = None
                fig.toolbar_location = None
                fig.yaxis.visible = False

            hover = HoverTool()
            hover.tooltips = "@worker : @utilization %"
            hover.point_policy = "follow_mouse"
            utilization.add_tools(hover)

            hover = HoverTool()
            hover.tooltips = "@worker : @memory_text"
            hover.point_policy = "follow_mouse"
            memory.add_tools(hover)

            self.memory_figure = memory
            self.utilization_figure = utilization

            self.utilization_figure.y_range = memory.y_range
            self.utilization_figure.x_range.start = 0
            self.utilization_figure.x_range.end = 100
示例#45
0
        color = loc_color,
        rprice = price,
        dis = distance,
        addr = address,
        restaurant = food,
        cafe = cafes,
        pub = pubs,
        size = sqft,
    )
)
circle = Circle(x = 'lon', y = 'lat', fill_color = 'color', size = 10, fill_alpha=0.6, line_color=None)
plot.add_glyph(source, circle)

# Hover
hover = HoverTool()
hover.point_policy = "follow_mouse"
hover.tooltips = [
    ("Address", "@addr"),
    ("Price per Room", "@rprice"),
    ("Distance to Campus", "@dis"),
    ("Food Quality", "@restaurant"),
    ("Number of cafes", "@cafe"),
    ("Number of pubs", "@pub"),
    ("Room size", "@size"),
]

tools = [PanTool(), WheelZoomTool(), hover]
plot.add_tools(*tools)

output_file("gmap_plot.html")
show(plot)
示例#46
0
    def plot_team_stat(comparison_stat, agg_func):
        """Creates figures with bars plots of teams stats.

        :param comparison_stat: str. Statistic to plot.
        :param agg_func: str. 'mean' or 'sum'.
        :return: bokeh figures.
        """

        map_agg_func = ('mean', 'sum')
        data = create_data_source(comparison_stat, map_agg_func[agg_func])
        source = ColumnDataSource(data=data)
        teams = list(source.data['team'])

        # Plot avg stat per game

        p_1 = figure(x_range=FactorRange(factors=teams),
                     plot_height=400,
                     plot_width=700)

        hover = HoverTool(tooltips=[('', '@{Total}')])
        hover.point_policy = 'follow_mouse'
        p_1.add_tools(hover)

        p_1.vbar(x='team',
                 top='Total',
                 source=source,
                 width=0.4,
                 color=Spectral4[0])

        p_1.x_range.range_padding = 0.05
        p_1.xaxis.major_label_orientation = 1
        p_1.xaxis.major_label_text_font_size = "10pt"
        p_1.toolbar_location = None

        # Plot breakdown by match result

        p_2 = figure(x_range=FactorRange(factors=teams),
                     plot_height=400,
                     plot_width=700,
                     tools='hover',
                     tooltips='@$name',
                     title='Breakdown by Match Result')

        w = p_2.vbar(x=dodge('team', -0.25, range=p_2.x_range),
                     top='w',
                     width=0.2,
                     source=source,
                     color=Spectral4[1],
                     name='w')
        d = p_2.vbar(x=dodge('team', 0.0, range=p_2.x_range),
                     top='d',
                     width=0.2,
                     source=source,
                     color=Spectral4[2],
                     name='d')
        l = p_2.vbar(x=dodge('team', 0.25, range=p_2.x_range),
                     top='l',
                     width=0.2,
                     source=source,
                     color=Spectral4[3],
                     name='l')

        legend_it = [('Won', [w]), ('Drew', [d]), ('Lost', [l])]
        legend = Legend(items=legend_it, location=(0, 155))

        p_2.add_layout(legend, 'right')
        p_2.title.text_font_size = '12pt'
        p_2.x_range.range_padding = 0.05
        p_2.xgrid.grid_line_color = None
        p_2.xaxis.major_label_text_font_size = "10pt"
        p_2.xaxis.major_label_orientation = 1
        p_2.toolbar_location = None

        return p_1, p_2