Beispiel #1
0
# plot of sensible heat

p7 = figure(plot_width=900,
            plot_height=450,
            x_axis_type='datetime',
            x_axis_label='Date (local)',
            y_axis_label='H (W/m^2)')

p7.title.text = 'Daily Sensible Heat'        

p7.line(usa_resample.index,     usa_resample.H,     legend='Shrubland H',       color='green',            line_width=2)
p7.line(ca_resample.index,      ca_resample.H,      legend='Boreal H',        color='blue',             line_width=2)



tab1 = Panel(child=p1, title="Sensitivity Monthly Resample")
tab11 = Panel(child=p11, title="Monthly Averaged Resistances")
tab2 = Panel(child=p2, title='Latent Heat Daily Resample and Ratios')
tab3 = Panel(child=p3, title='Latent Heat All Daily Resample')
tab4 = Panel(child=p4, title='Resistances Monthly all 4 yrs Averaged')
tab5 = Panel(child=p5, title='Resistances Daily Averages all 4 yrs avergaed')
tab6 = Panel(child=p6, title='All data')
tab7 = Panel(child=p7, title='Sensible Heat')

tabs = Tabs(tabs=[ tab1,tab11, tab2, tab7, tab3, tab4, tab5, tab6])

show(tabs)



Beispiel #2
0
def hail_metadata(t_path):
    """Create a metadata plot for a Hail Table or MatrixTable.

    Parameters
    ----------
    t_path : str
        Path to the Hail Table or MatrixTable files.

    Returns
    -------
    :class:`bokeh.plotting.figure.Figure` or :class:`bokeh.models.layouts.Column`
    """
    def get_rows_data(rows_files):
        file_sizes = []
        partition_bounds = []
        parts_file = [
            x['path'] for x in rows_files if x['path'].endswith('parts')
        ]
        if parts_file:
            parts = hadoop_ls(parts_file[0])
            for i, x in enumerate(parts):
                index = x['path'].split(f'{parts_file[0]}/part-')[1].split(
                    '-')[0]
                if i < len(parts) - 1:
                    test_index = parts[i + 1]['path'].split(
                        f'{parts_file[0]}/part-')[1].split('-')[0]
                    if test_index == index:
                        continue
                file_sizes.append(x['size_bytes'])
        metadata_file = [
            x['path'] for x in rows_files
            if x['path'].endswith('metadata.json.gz')
        ]
        if metadata_file:
            with hadoop_open(metadata_file[0], 'rb') as f:
                rows_meta = json.load(f)
                try:
                    partition_bounds = [(x['start']['locus']['contig'],
                                         x['start']['locus']['position'],
                                         x['end']['locus']['contig'],
                                         x['end']['locus']['position'])
                                        for x in rows_meta['jRangeBounds']]
                except KeyError:
                    pass
        return partition_bounds, file_sizes

    def scale_file_sizes(file_sizes):
        min_file_size = min(file_sizes) * 1.1
        total_file_size = sum(file_sizes)
        all_scales = [('T', 1e12), ('G', 1e9), ('M', 1e6), ('K', 1e3),
                      ('', 1e0)]
        for overall_scale, overall_factor in all_scales:
            if total_file_size > overall_factor:
                total_file_size /= overall_factor
                break
        for scale, factor in all_scales:
            if min_file_size > factor:
                file_sizes = [x / factor for x in file_sizes]
                break
        total_file_size = f'{total_file_size:.1f} {overall_scale}B'
        return total_file_size, file_sizes, scale

    files = hadoop_ls(t_path)

    rows_file = [x['path'] for x in files if x['path'].endswith('rows')]
    entries_file = [x['path'] for x in files if x['path'].endswith('entries')]
    success_file = [
        x['modification_time'] for x in files if x['path'].endswith('SUCCESS')
    ]

    metadata_file = [
        x['path'] for x in files if x['path'].endswith('metadata.json.gz')
    ]
    if not metadata_file:
        raise FileNotFoundError('No metadata.json.gz file found.')

    with hadoop_open(metadata_file[0], 'rb') as f:
        overall_meta = json.load(f)
        rows_per_partition = overall_meta['components']['partition_counts'][
            'counts']

    if not rows_file:
        raise FileNotFoundError('No rows directory found.')
    rows_files = hadoop_ls(rows_file[0])

    data_type = 'Table'
    if entries_file:
        data_type = 'MatrixTable'
        rows_file = [
            x['path'] for x in rows_files if x['path'].endswith('rows')
        ]
        rows_files = hadoop_ls(rows_file[0])
    row_partition_bounds, row_file_sizes = get_rows_data(rows_files)

    total_file_size, row_file_sizes, row_scale = scale_file_sizes(
        row_file_sizes)

    panel_size = 480
    subpanel_size = 120

    if not row_partition_bounds:
        warning('Table is not partitioned. Only plotting file sizes')
        row_file_sizes_hist, row_file_sizes_edges = np.histogram(
            row_file_sizes, bins=50)
        p_file_size = figure(plot_width=panel_size, plot_height=panel_size)
        p_file_size.quad(right=row_file_sizes_hist,
                         left=0,
                         bottom=row_file_sizes_edges[:-1],
                         top=row_file_sizes_edges[1:],
                         fill_color="#036564",
                         line_color="#033649")
        p_file_size.yaxis.axis_label = f'File size ({row_scale}B)'
        return p_file_size

    all_data = {
        'partition_widths':
        [-1 if x[0] != x[2] else x[3] - x[1] for x in row_partition_bounds],
        'partition_bounds':
        [f'{x[0]}:{x[1]}-{x[2]}:{x[3]}' for x in row_partition_bounds],
        'spans_chromosome': [
            'Spans chromosomes' if x[0] != x[2] else 'Within chromosome'
            for x in row_partition_bounds
        ],
        'row_file_sizes':
        row_file_sizes,
        'row_file_sizes_human':
        [f'{x:.1f} {row_scale}B' for x in row_file_sizes],
        'rows_per_partition':
        rows_per_partition,
        'index':
        list(range(len(rows_per_partition)))
    }

    if entries_file:
        entries_rows_files = hadoop_ls(entries_file[0])
        entries_rows_file = [
            x['path'] for x in entries_rows_files if x['path'].endswith('rows')
        ]
        if entries_rows_file:
            entries_files = hadoop_ls(entries_rows_file[0])
            entry_partition_bounds, entry_file_sizes = get_rows_data(
                entries_files)
            total_entry_file_size, entry_file_sizes, entry_scale = scale_file_sizes(
                entry_file_sizes)
            all_data['entry_file_sizes'] = entry_file_sizes
            all_data['entry_file_sizes_human'] = [
                f'{x:.1f} {entry_scale}B' for x in row_file_sizes
            ]

    title = f'{data_type}: {t_path}'

    msg = f"Rows: {sum(all_data['rows_per_partition']):,}<br/>Partitions: {len(all_data['rows_per_partition']):,}<br/>Size: {total_file_size}<br/>"
    if success_file[0]:
        msg += success_file[0]

    tools = "hover,save,pan,box_zoom,reset,wheel_zoom"

    source = ColumnDataSource(pd.DataFrame(all_data))
    p = figure(tools=tools, plot_width=panel_size, plot_height=panel_size)
    p.title.text = title
    p.xaxis.axis_label = 'Number of rows'
    p.yaxis.axis_label = f'File size ({row_scale}B)'
    color_map = factor_cmap('spans_chromosome',
                            palette=Spectral8,
                            factors=list(set(all_data['spans_chromosome'])))
    p.scatter('rows_per_partition',
              'row_file_sizes',
              color=color_map,
              legend='spans_chromosome',
              source=source)
    p.legend.location = 'bottom_right'
    p.select_one(HoverTool).tooltips = [
        (x, f'@{x}') for x in ('rows_per_partition', 'row_file_sizes_human',
                               'partition_bounds', 'index')
    ]

    p_stats = Div(text=msg)
    p_rows_per_partition = figure(x_range=p.x_range,
                                  plot_width=panel_size,
                                  plot_height=subpanel_size)
    p_file_size = figure(y_range=p.y_range,
                         plot_width=subpanel_size,
                         plot_height=panel_size)

    rows_per_partition_hist, rows_per_partition_edges = np.histogram(
        all_data['rows_per_partition'], bins=50)
    p_rows_per_partition.quad(top=rows_per_partition_hist,
                              bottom=0,
                              left=rows_per_partition_edges[:-1],
                              right=rows_per_partition_edges[1:],
                              fill_color="#036564",
                              line_color="#033649")
    row_file_sizes_hist, row_file_sizes_edges = np.histogram(
        all_data['row_file_sizes'], bins=50)
    p_file_size.quad(right=row_file_sizes_hist,
                     left=0,
                     bottom=row_file_sizes_edges[:-1],
                     top=row_file_sizes_edges[1:],
                     fill_color="#036564",
                     line_color="#033649")

    rows_grid = gridplot([[p_rows_per_partition, p_stats], [p, p_file_size]])

    if 'entry_file_sizes' in all_data:
        title = f'Statistics for {data_type}: {t_path}'

        msg = f"Rows: {sum(all_data['rows_per_partition']):,}<br/>Partitions: {len(all_data['rows_per_partition']):,}<br/>Size: {total_entry_file_size}<br/>"
        if success_file[0]:
            msg += success_file[0]

        source = ColumnDataSource(pd.DataFrame(all_data))
        p = figure(tools=tools, plot_width=panel_size, plot_height=panel_size)
        p.title.text = title
        p.xaxis.axis_label = 'Number of rows'
        p.yaxis.axis_label = f'File size ({entry_scale}B)'
        color_map = factor_cmap('spans_chromosome',
                                palette=Spectral8,
                                factors=list(set(
                                    all_data['spans_chromosome'])))
        p.scatter('rows_per_partition',
                  'entry_file_sizes',
                  color=color_map,
                  legend='spans_chromosome',
                  source=source)
        p.legend.location = 'bottom_right'
        p.select_one(HoverTool).tooltips = [
            (x, f'@{x}')
            for x in ('rows_per_partition', 'entry_file_sizes_human',
                      'partition_bounds', 'index')
        ]

        p_stats = Div(text=msg)
        p_rows_per_partition = figure(x_range=p.x_range,
                                      plot_width=panel_size,
                                      plot_height=subpanel_size)
        p_rows_per_partition.quad(top=rows_per_partition_hist,
                                  bottom=0,
                                  left=rows_per_partition_edges[:-1],
                                  right=rows_per_partition_edges[1:],
                                  fill_color="#036564",
                                  line_color="#033649")
        p_file_size = figure(y_range=p.y_range,
                             plot_width=subpanel_size,
                             plot_height=panel_size)

        row_file_sizes_hist, row_file_sizes_edges = np.histogram(
            all_data['entry_file_sizes'], bins=50)
        p_file_size.quad(right=row_file_sizes_hist,
                         left=0,
                         bottom=row_file_sizes_edges[:-1],
                         top=row_file_sizes_edges[1:],
                         fill_color="#036564",
                         line_color="#033649")
        entries_grid = gridplot([[p_rows_per_partition, p_stats],
                                 [p, p_file_size]])

        return Tabs(tabs=[
            Panel(child=entries_grid, title='Entries'),
            Panel(child=rows_grid, title='Rows')
        ])
    else:
        return rows_grid
Beispiel #3
0
<a href="https://covid19-projections.com/us-ca">A forecast model</a><br>
<a href="https://epiforecasts.io/covid/posts/national/united-states/">Epiforecasts model</a><br>
<a href="https://rt.live/">Estimator of R</a><br>
<br>Vaccines:<br>
<a href="https://vac-lshtm.shinyapps.io/ncov_vaccine_landscape/">Vaccine Tracker w/ Gantt View</a><br>
<a href="https://www.nytimes.com/interactive/2020/science/coronavirus-vaccine-tracker.html">NYT Vaccine Tracker</a><br>
<a href="https://www.raps.org/news-and-articles/news-articles/2020/3/covid-19-vaccine-tracker">RAPS Vaccine Tracker</a><br>
<a href="https://berthub.eu/articles/posts/reverse-engineering-source-code-of-the-biontech-pfizer-vaccine/">Description of the vaccine source code</a><br>
<br>Economic Impacts:<br>
<a href="https://tracktherecovery.org/">Opportunity Insights Tracker</a><br>
<a href="https://help.cuebiq.com/hc/en-us/articles/360041285051-Reading-Cuebiq-s-COVID-19-Mobility-Insights">Cuebiq Mobility Tracker</a><br>
<a href="https://www.jpmorgan.com/global/research">Credit Card Spending</a><br>
<a href="https://www.opentable.com/state-of-industry">OpenTables Reservations</a><br>
<a href="https://www.tsa.gov/coronavirus/passenger-throughput">Flight Volumes</a><br>
"""
about = Panel(child=Div(text=about_html), title='About')

page = Tabs(
    tabs=[nationalcharts, statecharts, countycharts, vaccinecharts, about])
print("saving file to " + fileloc + 'COVID19.html')
logging.info('%s saving file to %sCOVID19.html', datetime.datetime.now(),
             fileloc)

output_file(fileloc + 'COVID19.html')
templateLoader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = os.path.join(dir_path, "home.html")
with open(TEMPLATE_FILE) as file_:
    template = jinja2.Template(file_.read())
save(page, title='COVID19', template=template)
Beispiel #4
0
    def _createmodel(self):

        def on_select_filter(self, a, old, new):
            _logger.debug(f'Switching filter to {new}...')
            # ensure datahandler is stopped
            self._datahandler.stop()
            self._filter = new
            self.updatemodel()
            _logger.debug('Switching filter finished')

        def on_click_nav_action(self):
            if not self._paused:
                self._pause()
            else:
                self._resume()
            refresh(self)

        def on_click_nav_prev(self, steps=1):
            self._pause()
            self._set_data_by_idx(self._datahandler.get_last_idx() - steps)
            update_nav_buttons(self)

        def on_click_nav_next(self, steps=1):
            self._pause()
            self._set_data_by_idx(self._datahandler.get_last_idx() + steps)
            update_nav_buttons(self)

        def refresh(self):
            self.doc.add_next_tick_callback(partial(update_nav_buttons, self))

        def reset_nav_buttons(self):
            btn_nav_prev.disabled = True
            btn_nav_next.disabled = True
            btn_nav_action.label = '❙❙'

        def update_nav_buttons(self):
            last_idx = self._datahandler.get_last_idx()
            last_avail_idx = self._app.get_last_idx(self._figid)

            if last_idx < self.lookback:
                btn_nav_prev.disabled = True
                btn_nav_prev_big.disabled = True
            else:
                btn_nav_prev.disabled = False
                btn_nav_prev_big.disabled = False
            if last_idx >= last_avail_idx:
                btn_nav_next.disabled = True
                btn_nav_next_big.disabled = True
            else:
                btn_nav_next.disabled = False
                btn_nav_next_big.disabled = False
            if self._paused:
                btn_nav_action.label = '▶'
            else:
                btn_nav_action.label = '❙❙'

        # filter selection
        datanames = get_datanames(self._strategy)
        options = [('', 'Strategy')]
        for d in datanames:
            options.append(('D' + d, f'Data: {d}'))
        options.append(('G', 'Plot Group'))
        self._filter = 'D' + datanames[0]
        select_filter = Select(
            value=self._filter,
            options=options)
        select_filter.on_change(
            'value',
            partial(on_select_filter, self))
        # nav
        btn_nav_prev = Button(label='❮', width=self.NAV_BUTTON_WIDTH)
        btn_nav_prev.on_click(partial(on_click_nav_prev, self))
        btn_nav_prev_big = Button(label='❮❮', width=self.NAV_BUTTON_WIDTH)
        btn_nav_prev_big.on_click(partial(on_click_nav_prev, self, 10))
        btn_nav_action = Button(label='❙❙', width=self.NAV_BUTTON_WIDTH)
        btn_nav_action.on_click(partial(on_click_nav_action, self))
        btn_nav_next = Button(label='❯', width=self.NAV_BUTTON_WIDTH)
        btn_nav_next.on_click(partial(on_click_nav_next, self))
        btn_nav_next_big = Button(label='❯❯', width=self.NAV_BUTTON_WIDTH)
        btn_nav_next_big.on_click(partial(on_click_nav_next, self, 10))
        # layout
        controls = row(
            children=[select_filter])
        nav = row(
            children=[btn_nav_prev_big,
                      btn_nav_prev,
                      btn_nav_action,
                      btn_nav_next,
                      btn_nav_next_big])
        # tabs
        tabs = Tabs(
            id='tabs',
            sizing_mode=self._app.scheme.plot_sizing_mode)
        # model
        model = layout(
            [
                # app settings, top area
                [column(controls, width_policy='min'),
                 Spacer(),
                 column(nav, width_policy='min')],
                Spacer(height=15),
                # layout for tabs
                [tabs]
            ],
            sizing_mode='stretch_width')
        return model, partial(refresh, self)
def manager_home():
    allowed, new_page = authenticate("manager")
    if not allowed:
        return redirect(new_page)

    # get menu and ensure items exist in it
    menu = Item.query.all()
    if not menu:
        return render_template('manager_home.html')

    food = [item.name for item in menu]

    _, week1, week2, week3, week4, date_list, total_sums = generate_data_for_vis(
    )

    # Get all the orders and sales generated by each item
    total_orders = []
    total_sales = []
    for f in food:
        item = Item.query.filter_by(name=f).first()
        total_orders.append(item.orders)
        total_sales.append(item.sales)

    # Asrith's code for generating data visualisations
    data = {
        'food': food,
        'week1': week1,
        'week2': week2,
        'week3': week3,
        'week4': week4,
        'total_orders': total_orders,
        'total_sales': total_sales
    }

    source = ColumnDataSource(data=data)

    # construct a plot for total orders
    plot = figure(x_range=food,
                  y_range=(0, max(total_orders)),
                  plot_height=500,
                  plot_width=1000,
                  title="Orders by item",
                  toolbar_location=None,
                  tools="",
                  x_axis_label="Food",
                  y_axis_label="Number of orders")
    plot.vbar(x="food", top="total_orders", width=0.4, source=source)
    plot.x_range.range_padding = 0
    plot.xgrid.grid_line_color = None
    plot.xaxis.major_label_text_font_size = "11pt"
    plot.yaxis.major_label_text_font_size = "11pt"

    tab2 = Panel(child=plot, title="Total orders")

    # construct a plot for total sales
    plot2 = figure(x_range=food,
                   y_range=(0, max(total_sales)),
                   plot_height=500,
                   plot_width=1000,
                   title="Sales by item",
                   toolbar_location=None,
                   tools="",
                   x_axis_label="Food",
                   y_axis_label="Sales ($)")
    plot2.vbar(x="food", top="total_sales", width=0.4, source=source)
    plot2.x_range.range_padding = 0
    plot2.xgrid.grid_line_color = None
    plot2.xaxis.major_label_text_font_size = "11pt"
    plot2.yaxis.major_label_text_font_size = "11pt"

    tab3 = Panel(child=plot2, title="Total sales")

    # construct line graph of sales over time

    plot1 = figure(plot_width=800,
                   title="Orders over time",
                   x_axis_label="Date",
                   y_axis_label="Total Food Orders",
                   plot_height=600,
                   x_range=date_list)
    plot1.line(x=date_list, y=total_sums, line_width=4)
    plot1.circle(x=date_list, y=total_sums, fill_color="white", size=9)
    plot1.xaxis.major_label_text_font_size = "11pt"
    plot1.yaxis.major_label_text_font_size = "11pt"
    tab1 = Panel(child=plot1, title="Weekly Orders")

    # combine all tabs
    tabs = Tabs(tabs=[tab1, tab2, tab3])
    script, div = components(tabs)
    return render_template("manager_home.html", script=script, div=div)
Beispiel #6
0
    def layout(self):
        panels = [None, None, None]

        # Main panel: data
        panels[0] = Panel(
            child=row(
                row(
                    column(
                        self.data.layout(),
                        Spacer(height=10),
                        self.tools.layout(),
                        width=160,
                    ),
                    Spacer(width=10),
                    column(
                        self.xaxis.layout([self.yaxis.widget]),
                        Spacer(height=10),
                        self.size.layout([self.color.widget]),
                    ),
                    css_classes=["panel-inner"],
                ),
                css_classes=["panel-outer"],
            ),
            title="Main Menu",
        )

        # Secondary panel: prix fixe
        panels[1] = Panel(
            child=row(
                row(self.specials.layout(), css_classes=["panel-inner"]),
                css_classes=["panel-outer"],
            ),
            title="Prix Fixe",
        )

        # Tertiary panel: appearance
        checkbox_panel = row(
            row(
                column(
                    Div(
                        text=
                        """<h2>Toppings</h2><h3>Choose axes transforms</h3>""",
                        css_classes=["controls"],
                    ),
                    row(
                        self.checkbox_group,
                        width=160,
                        css_classes=["controls"],
                    ),
                    css_classes=["axes-checkboxes"],
                ),
                css_classes=["panel-inner"],
            ),
            css_classes=["panel-outer"],
        )
        panels[2] = Panel(child=checkbox_panel, title="Garnishes")

        # All tabs
        tabs = Tabs(tabs=panels, css_classes=["tabs"])

        # Logo
        header = Div(
            text=f"""<img src="{LOGO_URL}"></img>""",
            css_classes=["header-image"],
            width=320,
            height=100,
        )

        return row(column(header, tabs), Spacer(width=30), self.plot)
Beispiel #7
0
def average_day(indoor, outdoor, site_number, time_period, shift):
    
     # file path based on the time period
    if time_period == '1':
       # print('1')
        filepath = '/Users/matthew/Desktop/thesis/Final_Figures/In_out_compare_1/'
        y_scale_option = (-0.5, 10)
    elif time_period == '2':
        filepath = '/Users/matthew/Desktop/thesis/Final_Figures/In_out_compare_2/'
        y_scale_option = (-0.5, 7)
    elif time_period == '3':
        filepath = '/Users/matthew/Desktop/thesis/Final_Figures/In_out_compare_3/'
        y_scale_option = (0, 250)
    elif time_period == '4':
        filepath = '/Users/matthew/Desktop/thesis/Final_Figures/In_out_compare_4/'
        y_scale_option = (-0.5, 10)
    elif time_period == '5':
        filepath = '/Users/matthew/Desktop/thesis/Final_Figures/In_out_compare_5/'
        y_scale_option = (0, 90)
    
    
    PlotType = 'HTMLfile'
    
    dates = pd.DataFrame({})

    files = glob('/Users/matthew/Desktop/daily_test/dummy_date*.csv')
    files.sort()
    for file in files:
        dates = pd.concat([dates, pd.read_csv(file)], sort=False)

    indoor_average_day = pd.DataFrame({})
    outdoor_average_day = pd.DataFrame({})
    # use for unshifted corrected data
    if shift == 'unshifted':
        indoor_average_day['PM2_5_hourly_avg'] = indoor['PM2_5_corrected'].groupby(indoor.index.hour).mean()
    # use for shifted corrected data - don't actually need this
   # elif shift == 'shifted':
   #     indoor_average_day['PM2_5_hourly_avg'] = indoor['PM2_5_corrected_shift'].groupby(indoor.index.hour).mean()
        
    indoor_average_day['times'] = pd.to_datetime(dates['times'])
    indoor_average_day = indoor_average_day.sort_values('times')
    indoor_average_day.index = indoor_average_day.times
    
    
    outdoor_average_day['PM2_5_hourly_avg'] = outdoor['PM2_5_corrected'].groupby(outdoor.index.hour).mean()
    outdoor_average_day['times'] = pd.to_datetime(dates['times'])
    outdoor_average_day = outdoor_average_day.sort_values('times')
    outdoor_average_day.index = outdoor_average_day.times
    
    averages = pd.DataFrame({})
    averages[indoor.iloc[0]['Location'] + '_IAQU'] = indoor_average_day.PM2_5_hourly_avg.round(2)
    averages[indoor.iloc[0]['Location'] + '_CN'] = outdoor_average_day.PM2_5_hourly_avg.round(2)
    print(averages)
    #print('outdoor', (outdoor_average_day.PM2_5_hourly_avg).round(2))
    #print('indoor' , (indoor_average_day.PM2_5_hourly_avg).round(2))
        
    if PlotType=='notebook':
        output_notebook()
    else:
        output_file('/Users/matthew/Desktop/clarity_PM2.5_time_series_legend_mute.html')
            
    p1 = figure(plot_width=900,
                        plot_height=450,
                        x_axis_type='datetime',
                        x_axis_label='Time (hrs)',
                        y_axis_label='PM2.5 (ug/m³)',
                        y_range = y_scale_option)
    p1.title.text = site_number
    p1.title.text_font_size = '14pt'
    p1.title.text_font = 'times'
            
    p1.triangle(indoor_average_day.index,     indoor_average_day.PM2_5_hourly_avg, size = 8,             color='black',             line_width=2, muted_color='black', muted_alpha=0.2)
    p1.line(indoor_average_day.index,     indoor_average_day.PM2_5_hourly_avg,             color='black',             line_width=2, muted_color='black', muted_alpha=0.2)
    p1.circle(outdoor_average_day.index,       outdoor_average_day.PM2_5_hourly_avg,    size = 8,          color='black',              line_width=2, muted_color='blue', muted_alpha=0.2)
    p1.line(outdoor_average_day.index,       outdoor_average_day.PM2_5_hourly_avg,              color='black',              line_width=2, muted_color='blue', muted_alpha=0.2)
    
    
    p1.legend.click_policy="mute"
    figure_format(p1)
    p1.legend.location='top_center'
    p1.xaxis.formatter = DatetimeTickFormatter(days="", hours="%H", seconds="" )
    
    p1.yaxis.major_label_text_font = "times"
    p1.xaxis.major_label_text_font = "times"
    
    if shift == 'unshifted':
        export_png(p1, filename=filepath + 'hourly_averages_' + indoor.iloc[0]['Location'] + '.png')

    
    
    tab1 = Panel(child=p1, title="Average Hour Values")
    
    tabs = Tabs(tabs=[ tab1])
    
   # show(tabs) 
    
    return(p1, averages)
Beispiel #8
0
first_state.sort()
first_state = first_state[0]

first_county = list(us_counties.loc[us_counties["state"] == first_state]['county'].unique())
first_county.sort()
first_county = first_county[0]

source = ColumnDataSource(get_county_dataset(first_state, first_county))
source1 = ColumnDataSource(get_county_dataset(state_name, county_name))
source2 = ColumnDataSource(get_county_dataset(first_state, " All Counties"))

p1, q2, q3, q4, q5, q0_trend, q1_trend, title_p1 = gen_figure_1()
p1_log, q2_log, q3_log, q4_log, q5_log, q0_trend_log, q1_trend_log, title_p1_log = gen_figure_1("log")
tab1_lin = Panel(child=p1, title="Linear")
tab1_log = Panel(child=p1_log, title="Logarithmic")
tabs_1 = Tabs(tabs=[tab1_lin, tab1_log], sizing_mode="stretch_width")

p2, s0, s1, s2, s3, s0_trend, s1_trend, title_p2 = gen_figure_2()
p2_log, s0_log, s1_log, s2_log, s3_log, s0_trend_log, s1_trend_log, title_p2_log = gen_figure_2("log")
tab2_lin = Panel(child=p2, title="Linear")
tab2_log = Panel(child=p2_log, title="Logarithmic")
tabs_2 = Tabs(tabs=[tab2_lin, tab2_log], sizing_mode="stretch_width")

p3, t0, t1, t2, t3, title_p3 = gen_figure_3()

p = gridplot([[title_p1],
              [tabs_1],
              [title_p2],
              [tabs_2],
              [title_p3],
              [p3]], sizing_mode="stretch_width")
# plot it
p1 = figure(plot_width=900,
            plot_height=450,
            #x_axis_type='EBAM (ug/m^3',
            x_axis_label='EBAM (ug/m^3)',
            y_axis_label='Audubon_Clarity (ug/m^3)')
            
p1.circle(x,y)
p1.line(x,y_predicted,color='red',legend='y='+str(round(slope,2))+'x+'+str(round(intercept,2)))
#p1.scatter(EBAM_Clarity_batch_1_overlap.PM10,  Hourly_Audubon.PM10,                legend='PM10',       color='gold',     line_width=2)
p1.legend.location='top_left'


tab1 = Panel(child=p1, title="Audubon Clarity PM2_5")

tabs = Tabs(tabs=[ tab1])

show(tabs)

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if PlotType=='notebook':
    output_notebook()
else:
    output_file('/Users/matthew/Desktop/data/calibration/Clarity_batch_1_overlap.html')
#Plot Clarity Batch 1 and EBAM overlap data

p1 = figure(plot_width=900,
            plot_height=450,
            x_axis_type='datetime',
            x_axis_label='Time (local)',
cook_span7 = Span(location = cook7, dimension='height', line_color = 'gray', line_width = 3)
#p1.renderers.extend([cook_span6])
cook_label = Label(x = cook7, y=100,text='Boiling Beans', text_font_size = '8pt')
p1.add_layout(cook_label)

cook_span8 = Span(location = cook8, dimension='height', line_color = 'gray', line_width = 3)
#p1.renderers.extend([cook_span6])
cook_label = Label(x = cook8, y=20,text='Scrambled Eggs', text_font_size = '8pt')
p1.add_layout(cook_label)



p1.legend.location='top_left'

tab1 = Panel(child=p1, title="Prototype PM 2.5")
tabs = Tabs(tabs=[ tab1 ]) 
show(tabs)

export_png(p1, filename="/Users/matthew/Desktop/Apartment/apartment_time_series.png")
#export_png(p1, filename="/Users/matthew/Desktop/Apartment/apartment_time_series_log_y.png")
#%%

# Scatter of Prototype and Sensor 7
# Resampled to 1 minute so data match up

PlotType = 'HTMLfile'
from bokeh.io import export_png
from bokeh.models import Panel, Tabs
from bokeh.io import output_notebook, output_file, show
from bokeh.plotting import figure
from glob import glob
Beispiel #11
0
    def plot_bokeh(self, plot_name=None, show_plot=False, plot_pairwise="most_important"):
        """
        Plot single and pairwise margins in bokeh-plot. Single margins are always plotted (not expensive), pairwise can
        be configured by argument.

        Parameters
        ----------
        plot_name: str
            path where to store the plot, None to not save it
        show_plot: bool
            whether or not to open plot in standard browser
        plot_pairwise: str
            choose from ["none", "most_important", "all"] where "most_important" relies on the fanova module to decide
            what that means

        Returns
        -------
        layout: bokeh.models.Column
            bokeh plot (can be used in notebook or comparted with components)
        """
        vis = Visualizer(self.evaluator, self.cs, directory='.', y_label=self._get_label(self.scenario.run_obj))

        ####################
        # Single marginals #
        ####################
        plots_single = []
        params = list(self.evaluated_parameter_importance.keys())
        pbar = tqdm(deepcopy(params), ascii=True, disable=not self.verbose)
        for param_name in pbar:
            # Try and except pairwise importances that are also saved in evaluated_parameter_importance...
            try:
                param = self.cs.get_hyperparameter(param_name)
            except KeyError as err:
                self.logger.debug(err, exc_info=1)
                continue

            pbar.set_description('Plotting fANOVA (in bokeh) for %s' % param_name)

            incumbents = []
            if not self.incumbents is None:
                incumbents = self.incumbents.copy() if isinstance(self.incumbents, list) else [self.incumbents]
            values = [c[param_name] for c in incumbents if param_name in c and c[param_name] is not None]

            if isinstance(param, (CategoricalHyperparameter, Constant)):
                labels = param.choices if isinstance(param, CategoricalHyperparameter) else str(param)
                mean, std = vis.generate_marginal(param_name)
                inc_indices = [labels.index(val) for val in values]

                p = bokeh_boxplot(labels, mean, std,
                                  x_label=param.name,
                                  y_label="runtime [sec]" if self.scenario.run_obj == "runtime" else "cost",
                                  runtime=self.scenario.run_obj=="runtime",
                                  inc_indices=inc_indices)

            else:
                mean, std, grid = vis.generate_marginal(param_name, 100)
                mean, std = np.asarray(mean), np.asarray(std)
                log_scale = param.log or (np.diff(grid).std() > 0.000001)
                inc_indices = [(np.abs(np.asarray(grid) - val)).argmin() for val in values]

                p = bokeh_line_uncertainty(grid, mean, std, log_scale,
                                           x_label=param.name,
                                           y_label="runtime [sec]" if self.scenario.run_obj == "runtime" else "cost",
                                           inc_indices=inc_indices)

            plots_single.append(Panel(child=Row(p), title=param_name))

        ######################
        # Pairwise marginals #
        ######################
        if plot_pairwise == "all":
            combis = list(it.combinations(self.cs.get_hyperparameters(), 2))
        elif plot_pairwise == "most_important":
            most_important_ones = list(self.evaluated_parameter_importance.keys())[
                                  :min(self.num_single, self.n_most_imp_pairs)]
            most_important_pairwise_marginals = vis.fanova.get_most_important_pairwise_marginals(
                                                params=most_important_ones)
            combis = [(self.cs.get_hyperparameter(name1), self.cs.get_hyperparameter(name2)) for name1, name2 in
                      most_important_pairwise_marginals]
        elif plot_pairwise == "none":
            combis = []
        else:
            raise ValueError("{} not a valid set of pairwise plots to generate...".format(plot_pairwise))

        plots_pairwise = []
        pbar = tqdm(deepcopy(combis), ascii=True, disable=not self.verbose)
        for p1, p2 in pbar:
            pbar.set_description('Plotting pairwise fANOVA (in bokeh) for %s & %s' % (p1.name, p2.name))
            first_is_cat = isinstance(p1, CategoricalHyperparameter)
            second_is_cat = isinstance(p2, CategoricalHyperparameter)
            # There are essentially three cases / different plots:
            # First case: both categorical -> heatmap
            if first_is_cat or second_is_cat:
                choices, zz = vis.generate_pairwise_marginal((p1.name, p2.name), 20)
                # Working with pandas makes life easier
                data = pd.DataFrame(zz, index=choices[0], columns=choices[1])
                # Setting names for rows and columns and make categoricals strings
                data.index.name, data.columns.name = p1.name, p2.name
                data.index = data.index.astype(str) if first_is_cat else data.index
                data.columns = data.columns.astype(str) if second_is_cat else data.columns
                if first_is_cat and second_is_cat:
                    p = bokeh_heatmap_cat(data, p1.name, p2.name)
                else:
                    # Only one of them is categorical -> create multi-line-plot
                    cat_choices = p1.choices if first_is_cat else p2.choices
                    # We want categorical values be represented by columns:
                    if not second_is_cat:
                        data = data.transpose()
                    # Find y_min and y_max BEFORE resetting index (otherwise index max obscure the query)
                    y_limits = (data.min().min(), data.max().max())
                    x_limits = (p1.lower if second_is_cat else p2.lower, p1.upper if second_is_cat else p2.upper)
                    # We want the index as a column (for plotting on x-axis)
                    data = data.reset_index()
                    p = bokeh_multiline(data, x_limits, y_limits,
                                        p1.name if second_is_cat else p2.name,
                                        cat_choices,
                                        y_label="runtime [sec]" if self.scenario.run_obj == "runtime" else "cost",
                                        z_label=p1.name if first_is_cat else p2.name,
                                        )

            else:
                # Third case: both continous
                grid, zz = vis.generate_pairwise_marginal((p1.name, p2.name), 20)
                data = pd.DataFrame(zz, index=grid[0], columns=grid[1])
                data.index.name, data.columns.name = p1.name, p2.name
                p = bokeh_heatmap_num(data, p1.name, p2.name, p1.log, p2.log)

            plots_pairwise.append(Panel(child=Row(p), title=" & ".join([p1.name, p2.name])))

        # Putting both together
        tabs_single = Tabs(tabs=[*plots_single])
        if len(plots_pairwise) > 0:
            tabs_pairwise = Tabs(tabs=[*plots_pairwise])
            layout = Column(tabs_single, tabs_pairwise)
        else:
            layout = Column(tabs_single)

        # Save and show...
        save_and_show(plot_name, show_plot, layout)

        return layout
Beispiel #12
0
    def create_layout(self):
        # create figure
        self.x_range = Range1d(start=self.model.map_extent[0],
                               end=self.model.map_extent[2], bounds=None)
        self.y_range = Range1d(start=self.model.map_extent[3],
                               end=self.model.map_extent[1], bounds=None)
        self.fig = Figure(tools='wheel_zoom,pan,save,box_zoom', title='Color Magnitude Diagram',
                          x_range=self.x_range,
                          y_range=self.y_range,
                          lod_threshold=None,
                          plot_width=self.model.plot_width,
                          plot_height=self.model.plot_height,
                          background_fill_color='white')

        # Labeling will be used to deal with the fact that we cannot get the axes right 
        # this source can then be adjusted with sliders as necessary to reset axis. 
        label_source = ColumnDataSource(data={'x': [-5,-5,-5,-5,-5], 
                                        'y': [-10-0.2,-5-0.2,0-0.2,5-0.2,10-0.2], 'text':['10','5','0','-5','-10']}) 
        label1 = self.fig.text('x','y','text', source=label_source, text_font_size='8pt', text_color='deepskyblue') 

        # edit all the usual bokeh figure properties here 
        self.fig.xaxis.axis_label=self.model.xtitle 
        self.fig.yaxis.axis_label=self.model.ytitle 
        self.fig.yaxis.axis_label_text_font= 'PT Serif' 
        self.fig.yaxis.major_label_text_font = 'PT Serif' 
        self.fig.xaxis.axis_label_text_font= 'PT Serif' 
        self.fig.xaxis.major_label_text_font = 'PT Serif' 
        self.fig.min_border_top = 20
        self.fig.min_border_bottom = 10
        self.fig.min_border_left = 10
        self.fig.min_border_right = 10
        self.fig.axis.visible = False # use this to flip the axis labeling on and off 
        self.fig.xgrid.grid_line_color = '#aaaaaa' 
        self.fig.ygrid.grid_line_color = '#aaaaaa' 
        self.fig.ygrid.grid_line_alpha = 0.1  
        self.fig.xgrid.grid_line_alpha = 0.1  

        # add tiled basemap to class AppView 
        image_url    = 'http://server.arcgisonline.com/arcgis//rest/services/World_Imagery/MapServer/tile/{Z}/{Y}/{X}.png' 
        self.tile_source = WMTSTileSource(url=image_url) 
        self.tile_renderer = TileRenderer(tile_source=self.tile_source)
        self.tile_renderer.alpha = 0.02 
        self.fig.renderers.append(self.tile_renderer) # comment this out and it takes the ds points with it! WHY? 

        # add datashader layer - these are the aggregated data points to class AppView 
        self.image_source = ImageSource(url=self.model.service_url, extra_url_vars=self.model.shader_url_vars)
        self.image_renderer = DynamicImageRenderer(image_source=self.image_source)
        self.image_renderer.alpha = 1.00 
        self.fig.renderers.append(self.image_renderer)

        # add controls 
        controls = []            # empty list for astronomy controls 
        visual_controls = []     # empty list for visual controls 
        self.parameters = {}     # empty dict for astrophyscal pars 

        age_slider = Slider(title="Log Age [Gyr]", value=9.0, start=5.5, end=10.1, step=0.05)
        age_slider.on_change('value', self.on_age_change)
        controls.append(age_slider)
        self.parameters['age'] = age_slider.value 

        aperture_size_slider = Slider(title="Aperture [m]", value=10, start=2,end=20, step=1)
        aperture_size_slider.on_change('value', self.on_aperture_size_change)
        controls.append(aperture_size_slider)
        self.parameters['aperture'] = aperture_size_slider.value 

        exposure_time_slider = Slider(title="Exposure Time [hr]", value=0.1, start=1.0,end=10.0, step=0.1)
        exposure_time_slider.on_change('value', self.on_exposure_time_change)
        controls.append(exposure_time_slider)

        distance_slider = Slider(title="Distance [kpc]", value=100. , start=10.0,end=1000.0, step=100.)
        distance_slider.on_change('value', self.on_distance_change)
        controls.append(distance_slider)

        axes_select = Select(title='Variables', options=list(self.model.axes.keys()))
        axes_select.on_change('value', self.on_axes_change)
        controls.append(axes_select)

        self.field_select = Select(title='Field', options=list(self.model.fields.keys()))
        self.field_select.on_change('value', self.on_field_change)
        #controls.append(self.field_select) - chooses wich field to weight by in aggregation, temporarily omitted for devel 

        self.aggregate_select = Select(title='Aggregate', options=list(self.model.aggregate_functions.keys()))
        self.aggregate_select.on_change('value', self.on_aggregate_change)
        controls.append(self.aggregate_select)

        spread_size_slider = Slider(title="Spread Size (px)", value=1, start=0,end=5, step=1)
        spread_size_slider.on_change('value', self.on_spread_size_change)
        visual_controls.append(spread_size_slider)

        image_opacity_slider = Slider(title="Opacity", value=100, start=0,end=100, step=1)
        image_opacity_slider.on_change('value', self.on_image_opacity_slider_change)
        visual_controls.append(image_opacity_slider) 

        transfer_select = Select(title='Transfer Function', options=list(self.model.transfer_functions.keys()))
        transfer_select.on_change('value', self.on_transfer_function_change)
        visual_controls.append(transfer_select)

        color_ramp_select = Select(title='Colormap', name='Color Ramp', options=list(self.model.color_ramps.keys()))
        color_ramp_select.on_change('value', self.on_color_ramp_change)
        visual_controls.append(color_ramp_select)

        astro_tab = Panel(child=Column(children=controls), title='Stars') 
        visual_tab = Panel(child=Column(children=visual_controls), title='Visuals', width=450)

        self.controls = Tabs(tabs=[astro_tab, visual_tab], width=350)

        self.map_area = Column(width=900, height=600,children=[self.fig])
        self.layout = Row(width=1300, height=600,children=[self.controls, self.fig])
        self.model.fig = self.fig    # identify the fig defined here as the one that will be passed to AppView 
Beispiel #13
0
    clear_btn,
    width=300)
main_tab_row = row(cbg_widgetbox, timelines)
main_tab = Panel(child=main_tab_row, title="Evolution")
top_users_col = Column(top_users_div, top_users_table)
top_pages_col = Column(top_pages_div, top_pages_table)

other_row_1 = row(top_users_col)
other_row_2 = row(top_pages_col)
other_layout = Column(widgetbox(date_div),
                      widgetbox(time_slider),
                      widgetbox(banners_div),
                      other_row_1,
                      other_row_2,
                      sizing_mode=sizing_mode)
other_tab = Panel(child=other_layout, title="Statistics")
curdoc().add_root(Tabs(tabs=[main_tab, other_tab]))

# dh.reset_db()
# wiki_id = dh.load_data("eszelda_pages_full.txt")
# print(wiki_id)
# dashboard(wiki_id)

# if __name__ == "__main__":
# 	if(sys.argv):

# 		dh.reset_db()
# 		wiki_id = dh.load_data(sys.argv[1])
# 		print(wiki_id)
# 		dashboard(wiki_id)
Beispiel #14
0
 def create_configuration_tabs(self) -> Tabs:
     tabs = [self.axes_controls, self.legend_controls]
     return Tabs(tabs=tabs)
Beispiel #15
0
 def create_subtabs(child, name):
     return Tabs(tabs=[Panel(child=child, title=name)])
Beispiel #16
0
def compoundenrichment():
    blacklist_attributes = ["ATTRIBUTE_DatasetAccession", "ATTRIBUTE_Curated_BodyPartOntologyIndex", "filename", "UniqueSubjectID", "UBERONOntologyIndex", "SubjectIdentifierAsRecorded", "SampleCollectionDateandTime", "LatitudeandLongitude", "InternalStandardsUsed", "DepthorAltitudeMeters", "DOIDOntologyIndex", "Country", "ComorbidityListDOIDIndex", "AgeInYears"]

    compoundname = request.form['compoundname']
    compound_db = Compound.select().where(Compound.compoundname == compoundname)

    compound_filenames = [filename.filepath for filename in Filename.select().join(CompoundFilenameConnection).where(CompoundFilenameConnection.compound==compound_db)]

    
    enrichment_list = []

    if "filenames" in request.form:
        filter_filenames = set(json.loads(request.form["filenames"]))
        if len(filter_filenames) == 0:
            filter_filenames = set([filename.filepath for filename in Filename.select()])
    else:
        filter_filenames = set([filename.filepath for filename in Filename.select()])

    all_metadata = FilenameAttributeConnection.select(Attribute.categoryname, AttributeTerm.term, fn.COUNT(FilenameAttributeConnection.filename).alias('ct')).join(Attribute).switch(FilenameAttributeConnection).join(AttributeTerm).group_by(Attribute.categoryname, AttributeTerm.term).dicts()    
     
    for attribute_term_pair in all_metadata:
        # if attribute_term_pair["categoryname"].find("ATTRIBUTE_") == -1:
        #    continue

        if attribute_term_pair["categoryname"] in blacklist_attributes:
            continue
        
        
        attribute_files_db = Filename.select().join(FilenameAttributeConnection).where(FilenameAttributeConnection.attributeterm == attribute_term_pair["term"]).where(FilenameAttributeConnection.attribute == attribute_term_pair["categoryname"])
        attribute_filenames = set([filename.filepath for filename in attribute_files_db]).intersection(filter_filenames)
        
        if len(attribute_filenames) > 0:
            intersection_filenames = set(compound_filenames).intersection(set(attribute_filenames)).intersection(filter_filenames)

            enrichment_dict = {}
            enrichment_dict["attribute_name"] = attribute_term_pair["categoryname"]
            enrichment_dict["attribute_term"] = attribute_term_pair["term"]
            enrichment_dict["totalfiles"] = len(attribute_filenames)
            enrichment_dict["compoundfiles"] = len(intersection_filenames)
            enrichment_dict["percentage"] = len(intersection_filenames)/float(len(attribute_filenames))

            enrichment_list.append(enrichment_dict)

    enrichment_list = sorted(enrichment_list, key=lambda list_object: list_object["percentage"], reverse=True)

    # Creating Bokeh Plot Here
    enrichment_df = pd.DataFrame(enrichment_list)
    
    # Finding all non-zero entries
    enrichment_df = enrichment_df[enrichment_df["totalfiles"] != 0]
    all_attributes = list(set(list(enrichment_df["attribute_name"])))

    from bokeh.models import Panel, Tabs
    from bokeh.plotting import figure
    from bokeh.embed import components
    
    all_tabs = []

    for attribute in all_attributes:
        filtered_df = enrichment_df[enrichment_df["attribute_name"] == attribute]

        all_terms = list(filtered_df["attribute_term"])
        all_percentage = list(filtered_df["percentage"])
        plot = figure(x_range=all_terms, plot_height=600, plot_width=900, title="{} Percentage of Terms".format(attribute))
        plot.vbar(x=all_terms, top=all_percentage, width=0.9)
        tab = Panel(child=plot, title=attribute)

        all_tabs.append(tab)

        # script, div = components(plot)

        # draw_dict = {}
        # draw_dict["script"] = script
        # draw_dict["div"] = div

        # drawing_dict[attribute] = draw_dict

    tabs = Tabs(tabs=all_tabs)
    script, div = components(tabs)

    drawing_dict = {}
    drawing_dict["div"] = div
    drawing_dict["script"] = script

    return_dict = {}
    return_dict["enrichment_list"] = enrichment_list
    return_dict["drawings"] = drawing_dict

    return json.dumps(return_dict)
Beispiel #17
0
p1 = figure(plot_height=350, title="PR Curve")
p1.x_range = Range1d(0, 1)
p1.y_range = Range1d(0, 1)
p1.yaxis.axis_label = "Precision"
p1.xaxis.axis_label = "Recall"
#p1.line([0],[0],name ="line2")

y_score = clf.predict_proba(x_test_original)[:, 1]
precision, recall, _ = precision_recall_curve(y_test_original, y_score)
p1.line(precision, recall, line_width=2, line_alpha=0.6, name="line2")
average_precision = average_precision_score(y_test_original, predictions)
p1.title.text = "Average Precision Score %f" % average_precision

tab2 = Panel(child=p1, title="PR Curve")

tabs = Tabs(tabs=[tab1, tab2])

#p.title.text = "Model Accuracy %f" % accuracy_score(y_test_original,predictions)


def update():
    line = p1.select_one({'name': 'line2'})
    p1.renderers.remove(line)
    line.visible = False
    precision = 0
    recall = 0
    p1.line(precision, recall, line_alpha=0)
    fval = features.value
    print(fval)
    stats.text = "Selected features : " + str(fval)
    df1 = pd.DataFrame(df, columns=fval)
Beispiel #18
0
def generate_plots(results_filename, plot_filename, github_url):
    with open(os.path.join(os.path.dirname(__file__), 'plot.tmpl.html')) as f:
        html_template = Template(f.read())

    with open(results_filename, 'r') as f:
        results = json.load(f)

    name = results['name']
    xlabel = results['xlabel']
    baseline = results['baseline']

    sections = [
        layouts.row(Div(text='''<h1>Example: %s</h1>
            <p><b>Description</b>: %s</p>''' % \
                (results['name'], markdown.render(results['description'])), width=WIDTH)),
    ]
    # Implementations
    sections.append(
        layouts.row(Div(text='<h2>Implementations</h2>', width=WIDTH)))
    source_tabs = []
    for impl in results['implementations']:
        lexer = PythonLexer()
        lexer.add_filter('codetagify', codetags=['NOTE', 'SPEEDTIP'])
        highlighted = highlight(impl['source'], lexer, HtmlFormatter())
        source_tabs.append((impl['name'],
                            Div(text=markdown.render(impl['description']),
                                width=WIDTH), Div(text=highlighted,
                                                  width=WIDTH)))

    tabs = Tabs(tabs=[
        Panel(child=layouts.column(st[1], st[2]), title=st[0])
        for st in source_tabs
    ],
                width=WIDTH)
    sections.append(layouts.row(tabs))

    # Benchmarks
    sections.append(layouts.row(Div(text='<h2>Benchmarks</h2>')))
    for category_results in results['results']:
        category = category_results['category']
        del category_results['category']

        plot_title = name + ': ' + ', '.join(category)

        speedup_p = make_plot(category_results,
                              title=plot_title,
                              xlabel=xlabel,
                              ylabel='Speedup over %s' % baseline,
                              baseline=baseline,
                              ycolname='speedup',
                              yaxis_format='%1.1f')
        throughput_p = make_plot(category_results,
                                 title=plot_title,
                                 xlabel=xlabel,
                                 ylabel='%s / sec' % xlabel,
                                 baseline=baseline,
                                 ycolname='throughput',
                                 yaxis_format='%1.0e')
        raw_p = make_plot(category_results,
                          title=plot_title,
                          xlabel=xlabel,
                          ylabel='Execution time (usec)',
                          baseline=baseline,
                          ycolname='times',
                          yaxis_format='%1.0f')

        tabs = Tabs(tabs=[
            Panel(child=speedup_p, title='Speedup'),
            Panel(child=throughput_p, title='Throughput'),
            Panel(child=raw_p, title='Raw times')
        ],
                    width=WIDTH)
        sections.append(layouts.row(tabs))

    html = file_html(
        layouts.column(sections),
        resources=CDN,
        title='Example: %s' % results['name'],
        template=html_template,
        template_variables=dict(
            pygments_css=HtmlFormatter().get_style_defs('.highlight'),
            github_url=github_url))

    with open(plot_filename, 'w') as f:
        f.write(html)

    return results
Beispiel #19
0
metrica_defence = pvm.lastrow_calc_player_velocities(data_defence,smoothing=False)

# Read in Events
events_dict, events_df = create.create_events(metrica_attack)

# Real Shirt Mapping
shirt_mapping = sm.create_consistent_shirt_mapping(last_row)
events_df = sm.real_shirt_mapping(events_df, shirt_mapping)

# to Bokeh Format
bokeh_attack = mtb.tracking_to_bokeh_format(metrica_attack)
bokeh_defence = mtb.tracking_to_bokeh_format(metrica_defence)

# List of available Matches
match_list = events_df.index.get_level_values(level=0).unique().tolist()

# Surface Colour Map
m_coolwarm_rgb = (255 * cm.coolwarm(range(256))).astype('int')
bokehpalette = [RGB(*tuple(rgb)).to_hex() for rgb in m_coolwarm_rgb]   

# Create each of the tabs
tab1 = goals_overview_tab(events_df, match_list, bokeh_attack, bokeh_defence, shirt_mapping)
tab2 = pitch_surfaces_tab(events_df, metrica_attack, metrica_defence, bokeh_attack, bokeh_defence, shirt_mapping, match_list)
tab3 = player_displacement_value_tab(events_df, metrica_attack, metrica_defence, bokeh_attack, bokeh_defence, shirt_mapping, match_list)

# Put all the tabs into one application
tabs = Tabs(tabs = [tab1, tab2, tab3])

# Put the tabs in the current document for display
curdoc().add_root(tabs)
    p.xaxis.major_label_text_font_size = '12pt'
    p.yaxis.axis_label_text_font_size = '12pt'
    p.yaxis.major_label_text_font_size = '12pt'
    
    return p

def get_dataset(carrier_list):
    subset = by_carrier[by_carrier['name'].isin(carrier_list)]
    new_src = ColumnDataSource(subset)
    
    return new_src

def update(attr, old, new):
    carrier_list = [available_carriers[i] for i in carrier_select.active]
    new_src = get_dataset(carrier_list)
    
    src.data.update(new_src.data)
    
carrier_select = CheckboxGroup(labels=available_carriers,
                               active=[0])
carrier_select.on_change('active', update)

src = get_dataset([available_carriers[i] for i in carrier_select.active])
p = make_plot(src)

layout = row(carrier_select, p)

tab = Panel(child=layout, title='Histogram')
tabs = Tabs(tabs=[tab])

curdoc().add_root(tabs)
Beispiel #21
0
           legend_label="CC MAD (Val)")
    v.line(df_geography.Date[df_geography.Date > max_date_train],
           df_geography.ConfirmedCases_test_lgb[
               df_geography.Date > max_date_train],
           color="red",
           legend_label="CC LGB (Test)")
    v.line(df_geography.Date[df_geography.Date > max_date_train],
           df_geography.ConfirmedCases_test_mad[
               df_geography.Date > max_date_train],
           color="orange",
           legend_label="CC MAD (Test)")
    v.legend.location = "top_left"
    tab = Panel(child=v, title=geography)
    tab_list.append(tab)

tabs = Tabs(tabs=tab_list)
show(tabs)

# %% [code]
## visualizing Fatalities
from bokeh.models import Panel, Tabs
from bokeh.io import output_notebook, show
from bokeh.plotting import figure

output_notebook()

tab_list = []

for geography in df_panel.geography.unique():
    df_geography = df_panel[df_panel.geography == geography]
    v = figure(plot_width=800,
Beispiel #22
0
    def setup_plots(self):

        tools = "pan, wheel_zoom, xwheel_zoom, ywheel_zoom, reset, save"

        # Custom JS callback that will be used when tapping on a run
        # Only switches the view, a server callback is required to update plots
        # (defined inside template to avoid bloating server w/ too much JS code)
        js_tap_callback = "goToInspectRuns();"

        # Box plot
        self.plots["boxplot"] = figure(name="boxplot",
                                       title="Variable distribution over runs",
                                       plot_width=900,
                                       plot_height=400,
                                       x_range=[""],
                                       tools=tools,
                                       sizing_mode="scale_width")

        box_tooltips = [("Git commit", "@is_git_commit"), ("Date", "@date"),
                        ("Hash", "@hash"), ("Author", "@author"),
                        ("Message", "@message"), ("Min", "@min{%0.18e}"),
                        ("Max", "@max{%0.18e}"),
                        ("1st quartile", "@quantile25{%0.18e}"),
                        ("Median", "@quantile50{%0.18e}"),
                        ("3rd quartile", "@quantile75{%0.18e}"),
                        ("μ", "@mu{%0.18e}"), ("p-value", "@pvalue"),
                        ("Number of samples", "@nsamples")]
        box_tooltips_formatters = {
            "@min": "printf",
            "@max": "printf",
            "@quantile25": "printf",
            "@quantile50": "printf",
            "@quantile75": "printf",
            "@mu": "printf"
        }

        plot.fill_boxplot(
            self.plots["boxplot"],
            self.sources["boxplot_source"],
            tooltips=box_tooltips,
            tooltips_formatters=box_tooltips_formatters,
            js_tap_callback=js_tap_callback,
            server_tap_callback=self.inspect_run_callback_boxplot,
        )
        self.doc.add_root(self.plots["boxplot"])

        # Sigma plot (bar plot)
        self.plots["sigma_plot"] = figure(
            name="sigma_plot",
            title="Standard deviation σ over runs",
            plot_width=900,
            plot_height=400,
            x_range=[""],
            tools=tools,
            sizing_mode="scale_width")

        sigma_tooltips = [("Git commit", "@is_git_commit"), ("Date", "@date"),
                          ("Hash", "@hash"), ("Author", "@author"),
                          ("Message", "@message"), ("σ", "@sigma"),
                          ("Number of samples", "@nsamples")]

        plot.fill_dotplot(self.plots["sigma_plot"],
                          self.sources["sigma_source"],
                          "sigma",
                          tooltips=sigma_tooltips,
                          js_tap_callback=js_tap_callback,
                          server_tap_callback=self.inspect_run_callback_sigma,
                          lines=True)
        self.doc.add_root(self.plots["sigma_plot"])

        # s plot (bar plot with 2 tabs)
        self.plots["s10_plot"] = figure(name="s10_plot",
                                        title="Significant digits s over runs",
                                        plot_width=900,
                                        plot_height=400,
                                        x_range=[""],
                                        tools=tools,
                                        sizing_mode="scale_width")

        s10_tooltips = [("Git commit", "@is_git_commit"), ("Date", "@date"),
                        ("Hash", "@hash"), ("Author", "@author"),
                        ("Message", "@message"), ("s", "@s10"),
                        ("s lower bound", "@s10_lower_bound"),
                        ("Number of samples", "@nsamples")]

        plot.fill_dotplot(self.plots["s10_plot"],
                          self.sources["s10_source"],
                          "s10",
                          tooltips=s10_tooltips,
                          js_tap_callback=js_tap_callback,
                          server_tap_callback=self.inspect_run_callback_s10,
                          lines=True,
                          lower_bound=True)
        s10_tab = Panel(child=self.plots["s10_plot"], title="Base 10")

        self.plots["s2_plot"] = figure(name="s2_plot",
                                       title="Significant digits s over runs",
                                       plot_width=900,
                                       plot_height=400,
                                       x_range=[""],
                                       tools=tools,
                                       sizing_mode="scale_width")

        s2_tooltips = [("Git commit", "@is_git_commit"), ("Date", "@date"),
                       ("Hash", "@hash"), ("Author", "@author"),
                       ("Message", "@message"), ("s", "@s2"),
                       ("s lower bound", "@s2_lower_bound"),
                       ("Number of samples", "@nsamples")]

        plot.fill_dotplot(self.plots["s2_plot"],
                          self.sources["s2_source"],
                          "s2",
                          tooltips=s2_tooltips,
                          js_tap_callback=js_tap_callback,
                          server_tap_callback=self.inspect_run_callback_s2,
                          lines=True,
                          lower_bound=True)
        s2_tab = Panel(child=self.plots["s2_plot"], title="Base 2")

        s_tabs = Tabs(name="s_tabs",
                      tabs=[s10_tab, s2_tab],
                      tabs_location="below")

        self.doc.add_root(s_tabs)
Beispiel #23
0
    def modify_document(self, doc):
        self.tb.lock()
        sink = bokehgui.vec_sink_f_proc(self.tb.get_num_channels(), "", 1)
        self.tb.connect((self.mag_to_zW, 0), (sink, 0))
        self.tb.unlock()

        log_cds = ColumnDataSource(data=self.lw.get_table())
        blw = BokehLogWatcher(doc, log_cds)
        logging.getLogger().addHandler(blw)

        def cleanup_session(session_context):
            self.tb.lock()
            self.tb.disconnect((self.mag_to_zW, 0), (sink, 0))
            self.tb.unlock()
            logging.getLogger().removeHandler(blw)

        doc.on_session_destroyed(cleanup_session)

        doc.title = "Gal Scan GUI"

        plot_lst = []

        plot = vec_sink_f(doc, plot_lst, sink, is_message=False)

        plot.initialize(update_time=100, legend_list=[''])
        plot.get_figure().aspect_ratio = 2
        plot.set_y_axis([0, 10])
        plot.set_y_label("Power at feed (zW / Hz)")
        plot.set_x_label("Frequency (MHz)")

        def set_x_values():
            plot.set_x_values(
                np.linspace(
                    self.tb.get_sdr_frequency() -
                    (self.tb.get_output_vector_bandwidth() / 2),
                    self.tb.get_sdr_frequency() +
                    (self.tb.get_output_vector_bandwidth() / 2),
                    self.tb.get_num_channels()) / 1e6)

        set_x_values()
        plot.enable_axis_labels(True)
        plot.set_layout(1, 0)
        plot.enable_max_hold()
        plot.format_line(0, "blue", 1, "solid", None, 1.0)

        azimuth = Knob(title="Azimuth", max=360, min=0, unit="°")
        elevation = Knob(title="Elevation", max=360, min=0, unit="°")
        rx_power = Knob(title="Average RX Power",
                        digits=4,
                        decimals=1,
                        unit="dB(mW/Hz)")
        plot.stream.js_on_change(
            "streaming",
            CustomJS(
                args=dict(rx_power=rx_power),
                code="""
            const data = cb_obj.data
            const average = data['y0'].reduce((a,b) => a+b)/data['y0'].length
            rx_power.value = (10*Math.log10(average))-180
            """,
            ))

        log_table = SortedDataTable(
            source=log_cds,
            columns=[
                TableColumn(field="asctime", title="Time", width=140),
                TableColumn(field="levelname", title="Level", width=60),
                TableColumn(field="message", title="Message", width=1500),
            ],
            autosize_mode="none",
            aspect_ratio=2,
            sizing_mode="stretch_width",
            sortable=True,
        )

        gain = Slider(title="gain",
                      value=self.tb.get_sdr_gain(),
                      start=0,
                      end=65)
        gain.on_change('value', lambda name, old, new: self.set_gain(new))

        rx = ActiveButton(label="RX enabled")
        rx.on_click(lambda: self.set_rx(not rx.active))

        frequency = Knob(title="center frequency",
                         writable=True,
                         value=self.tb.get_sdr_frequency(),
                         digits=10,
                         decimals=0,
                         unit="Hz")
        frequency.on_change('value',
                            lambda name, old, new: self.set_frequency(new))

        bandwidth = Knob(title="filter bandwidth",
                         writable=False,
                         value=self.tb.get_bandwidth(),
                         digits=7,
                         decimals=0,
                         unit="Hz")
        bandwidth.on_change('value',
                            lambda name, old, new: self.set_bandwidth(new))

        reset = Button(label="Reset")

        def on_reset():
            gain.value = run.flowgraph_defaults['sdr_gain']
            frequency.value = run.flowgraph_defaults['sdr_frequency']
            bandwidth.value = run.flowgraph_defaults['bandwidth']

        reset.on_click(on_reset)

        manual = Panel(title="Manual",
                       child=column(
                           row(rx, gain),
                           row(frequency, bandwidth),
                           reset,
                       ))

        run_models = {}
        automated_panels = []
        for group, args in run.arg_groups.items():
            # TODO: show grouping
            panel_models = []
            for key, arg in args.items():
                key = key.replace('-', '_')
                bokeh_args = arg.get('bokeh', {})
                bokeh_args['name'] = key
                bokeh_args['tags'] = ['args']
                if 'default' in arg:
                    bokeh_args['value'] = arg['default']
                if 'help' in arg:
                    bokeh_args['title'] = arg['help']
                    if 'metavar' in arg:
                        bokeh_args['title'] += " (%s)" % (arg['metavar'])
                type = TextInput
                if arg.get('type') in (float, int):
                    type = Spinner
                    if 'bokeh' in arg and 'start' in arg[
                            'bokeh'] and 'end' in arg['bokeh']:
                        type = Slider
                    if 'step' not in bokeh_args:
                        if arg['type'] == int:
                            bokeh_args['step'] = 1
                        else:
                            bokeh_args['step'] = 0.01
                    if arg.get('metavar') == 'Hz':
                        if 'digits' not in bokeh_args:
                            bokeh_args['digits'] = 10
                            if bokeh_args.get('max'):
                                bokeh_args['digits'] = len("%d" %
                                                           bokeh_args['max'])
                        type = functools.partial(Knob,
                                                 decimals=0,
                                                 unit=arg['metavar'])
                        del bokeh_args['step']
                        del bokeh_args['tags']
                        if 'writable' not in bokeh_args:
                            bokeh_args['writable'] = True
                elif 'choices' in arg:
                    type = Select
                    bokeh_args['options'] = [str(x) for x in arg['choices']]
                    if 'value' in bokeh_args:
                        bokeh_args['value'] = str(bokeh_args['value'])
                elif arg.get('action') in ('store_true', 'store_false'):
                    type = Select
                    bokeh_args['options'] = [('0', 'False'), ('1', 'True')]
                    bokeh_args['value'] = str(int(bokeh_args['value']))
                    bokeh_args['tags'] = ['boolean'] + bokeh_args.get(
                        'tags', [])
                if group.startswith("mode="):
                    # Make this smarter if we ever have a mode=gal tab
                    bokeh_args['disabled'] = True
                m = type(**bokeh_args)
                run_models[key] = m
                panel_models.append(m)
            automated_panels.append(
                Panel(title=group, child=grid(panel_models, ncols=2)))
        for panel in automated_panels:
            if panel.title.startswith("mode="):
                mode_str = panel.title.split('=')[1]
                run_models['mode'].js_on_change(
                    'value',
                    CustomJS(
                        args=dict(panel=panel, mode=mode_str),
                        code=
                        """panel.select(Bokeh.require("models/widgets/control").Control).forEach(c => c.disabled = (this.value != mode))""",
                    ))

        plan_p = Paragraph(sizing_mode="stretch_width", )

        load = UploadButton(name="load-settings",
                            accept=".json,application/json",
                            label="Load settings")

        def on_load(attr, old, new):
            data = json.loads(base64.b64decode(new))
            for key, value in data.items():
                if isinstance(run_models[key], Select):
                    value = str(value)
                run_models[key].value = value

        load.on_change('value', on_load)

        save = DownloadButton(label="Save settings",
                              filename="gal_scan_settings.json",
                              mime_type="application/json",
                              data=CustomJS(args=dict(run_models=run_models),
                                            code="""
                const out = {}
                for (let k in run_models) {
                  if (!run_models[k].disabled) {
                    out[k] = run_models[k].value
                    const tags = run_models[k].tags
                    if (tags && tags.indexOf("boolean") >= 0) {
                      out[k] = parseInt(out[k])
                    }
                  }
                }
                return JSON.stringify(out, null, 2);
                """))
        start = Button(label="Start scan")

        def get_args(output_dir):
            return run.parse_args(
                [output_dir],
                {
                    k: int(v.value) if "boolean" in v.tags else v.value
                    for k, v in run_models.items() if not v.disabled
                },
            )

        def on_start():
            try:
                output_dir = os.path.join(
                    self.runs_dir, "run_" +
                    datetime.datetime.now().replace(microsecond=0).isoformat())
                args = get_args(output_dir)
                self.enqueue_run(args)
            except SystemExit:
                pass

        start.on_click(on_start)
        automated = Panel(title="Plan",
                          child=column(Tabs(tabs=automated_panels), plan_p,
                                       row(load, save, start)))

        # TODO: Show cancel buttons for active or queued actions
        queue_cds = ColumnDataSource(data=self.get_queue_data())
        action_column = ActionMenuColumn(
            field="id",
            title="Action",
            menu=[
                ("Cancel", "cancel"),
            ],
        )

        def on_action_menu_click(event):
            if event.item == "cancel":
                self.cancel_action(event.value)
            else:
                logging.warn("Unknown action clicked: %s", event.item)

        action_column.on_event(ActionMenuClick, on_action_menu_click)
        queue_table = SortedDataTable(
            source=queue_cds,
            columns=[
                TableColumn(
                    field="time",
                    title="Time",
                    formatter=DateFormatter(format="%Y-%m-%d %H:%M:%S"),
                ),
                TableColumn(field="user", title="User"),
                TableColumn(field="name", title="Job"),
                action_column,
            ],
            highlight_field="active",
            sort_ascending=True,
            autosize_mode="fit_viewport",
            aspect_ratio=2,
            sizing_mode="stretch_width",
        )
        queue = Panel(title="Queue", child=queue_table)

        results_cds = ColumnDataSource(data={"name": [], "mtime": []})
        results_table = SortedDataTable(
            source=results_cds,
            columns=[
                TableColumn(
                    field="mtime",
                    title="Time",
                    formatter=DateFormatter(format="%Y-%m-%d %H:%M:%S"),
                ),
                TableColumn(
                    field="name",
                    title="Name",
                    formatter=HTMLTemplateFormatter(
                        template=
                        '<a href="/runs/<%= value %>/" target="_blank"><%= value %></a>'
                    )),
            ],
            autosize_mode="fit_viewport",
            aspect_ratio=2,
            sizing_mode="stretch_width",
            sortable=True,
        )
        results = Panel(title="Results", child=results_table)

        tabs = Tabs(tabs=[manual, automated, queue, results])

        status_p = Paragraph(sizing_mode="stretch_width", )

        controls = column(row(azimuth, elevation, rx_power), status_p, tabs,
                          log_table)

        def get_survey_data():
            pointers = {
                'ra': [],
                'dec': [],
                'label': [],
                'colour': [],
            }
            for o in self.messier:
                pointers['ra'].append(o['ra'])
                pointers['dec'].append(o['dec'])
                pointers['label'].append(o['label'])
                pointers['colour'].append('')
            survey = self.active_action.get('survey')
            out = {
                'pointers': pointers,
                'status_message': 'Idle',
                'plan_message': 'Invalid parameters'
            }
            if survey:
                groups = survey.coord_groups
                i = 0
                for sc, colour in zip(reversed(groups),
                                      ('rgb(0, 192, 0)', 'rgb(192, 0, 0)')):
                    sc = sc.icrs
                    for sc in sc:
                        pointers['ra'].append(sc.ra.to(u.degree).value)
                        pointers['dec'].append(sc.dec.to(u.degree).value)
                        pointers['label'].append(str(i + 1))
                        pointers['colour'].append(colour)
                        i += 1
                out['status_message'] = 'Time remaining on current survey: %s' % (
                    survey.time_remaining.to_datetime())
            survey = None
            try:
                survey = run.Survey(get_args('bogus'))
                out['plan_message'] = 'Estimated runtime: %s' % (
                    survey.time_remaining.to_datetime())
                if tabs.tabs[tabs.active] == automated:
                    # TODO: Use the underlying numpy arrays
                    sc = survey.iterator.coords_now.icrs
                    for i, sc in enumerate(sc[:1000]):
                        pointers['ra'].append(sc.ra.to(u.degree).value)
                        pointers['dec'].append(sc.dec.to(u.degree).value)
                        pointers['label'].append(str(i + 1))
                        pointers['colour'].append('rgb(148,0,211)')
            except:
                logging.getLogger('stderr').exception('Invalid parameters')
            return out

        sd = get_survey_data()
        pointers_cds = ColumnDataSource(data=sd['pointers'])

        def update_pointers(attr, old, new):
            logging.debug('Updating pointers')
            sd = get_survey_data()
            pointers_cds.data = sd['pointers']
            plan_p.text = sd['plan_message']
            status_p.text = sd['status_message']

        update_pointers(None, None, None)

        log_cds.on_change('data', update_pointers)
        tabs.on_change('active', update_pointers)
        for m in run_models.values():
            m.on_change('value', update_pointers)

        skymap = Skymap(
            height=600,
            sizing_mode="stretch_height",
            pointer_data_source=pointers_cds,
        )
        skymap.on_event(Tap, lambda event: self.point(event.x, event.y))

        doc.add_root(row(
            column(
                skymap,
                plot.get_figure(),
            ),
            controls,
        ), )

        async def update_status(last_status={}):
            set_x_values()
            status = self.client.status
            skymap.latlon = (status['Latitude'], status['Longitude'])
            skymap.azel = (status['AzPos'], status['ElPos'])
            if status['CommandAzFlags'] == 'POSITION' or status[
                    'CommandElFlags'] == 'POSITION':
                skymap.targetAzel = (status['CommandAzPos'],
                                     status['CommandElPos'])
            else:
                skymap.targetAzel = None
            azimuth.value = status['AzPos']
            elevation.value = status['ElPos']
            rx_active = status['Sequencer']['Bands'][0]['CommandRX']
            if not last_status or rx_active != last_status['Sequencer'][
                    'Bands'][0]['CommandRX']:
                if rx_active:
                    rx.label = "RX enabled"
                else:
                    rx.label = "RX disabled (50Ω load)"
                rx.active = rx_active
            queue_data = self.get_queue_data()
            if queue_cds.data != queue_data:
                queue_cds.data = queue_data
            with os.scandir(self.runs_dir) as it:
                files = list(
                    sorted(it, reverse=True, key=lambda f: f.stat().st_mtime))
                results_data = {
                    "name": [f.name for f in files],
                    "mtime": [int(f.stat().st_mtime * 1000) for f in files],
                }
                if results_data != results_cds.data:
                    results_cds.data = results_data
            last_status.update(status)

        doc.add_periodic_callback(update_status, 200)
Beispiel #24
0
div3 = Div(
    text=
    "Symptomatic Infecteds become hospitalized at a rate of 0.1 and hospitalized individuals have a longer recovery time and higher death rate because their cases are more severe.",
    margin=(10, 20, 10, 20),
    width=750)
div4 = Div(
    text=
    "Once a vaccine is introduced, individuals can move directly from the susceptible class to the recovered class. The vaccine is assumed to be 98% effective and be distributed at a rate of 0.01 once it is introduced. <br> The inclusion of social distancing will reduce the rate of infection.",
    margin=(10, 20, 10, 20),
    width=750)
div5 = Div(
    text=
    "By adding hospital beds and ventilators, the health capacity of the population increases. If the amount of hospitalized symptomatic individuals surpasses the health capacity then hospitalized deaths will increase and recovery rate will decrease due to the health system being overwhelmed.",
    margin=(10, 20, 10, 20),
    width=750)
div6 = Div(
    text=
    "There is assumed to be a natural birth rate of .001 and a natural death rate of 0.0002. This accounts for individuals entering and exiting the system, for causes unrelated to the outbreak.",
    margin=(10, 20, 10, 20),
    width=750)
text_descriptions = column(div1, div2, div3, div4, div5, div6)

tabC = Panel(child=text_descriptions, title="Model Description")  #third panel

##########################
# Putting it all together
tabs = Tabs(tabs=[tabA, tabB, tabC])

curdoc().add_root(tabs)
curdoc().title = "Modeling Infectious Disease Outbreaks"
    def plot_bokeh(self, plot_name=None, show_plot=False):
        """
        Plot local parameter importance in an interactive bokeh-plot.

        Parameters
        ----------
        plot_name: str
            path where to store the plot, None to not save it
        show_plot: bool
            whether or not to open plot in standard browser

        Returns
        -------
        layout: bokeh.models.Row
            bokeh plot (can be used in notebook or comparted with components)
        """
        plots = []
        pbar = tqdm(deepcopy(list(self.incumbent.keys())),
                    ascii=True,
                    disable=not self.verbose)
        for param in pbar:
            pbar.set_description('Plotting results (in bokeh) for %s' % param)
            if param in self.performance_dict:
                # Data to be plotted:
                p, v = self.performance_dict[param], self.variance_dict[param]
                std = np.array(list(map(lambda s: np.sqrt(s), v))).flatten()

                # Find incumbent indices
                inc_indices = [
                    n_idx for n_idx, neighbor in enumerate(
                        self.neighborhood_dict[param][1])
                    if neighbor == self.incumbent[param]
                ]

                # Boxplot if categorical, else line
                if isinstance(
                        self.incumbent.configuration_space.get_hyperparameter(
                            param), CategoricalHyperparameter):
                    p = bokeh_boxplot(
                        self.neighborhood_dict[param][1],
                        p,
                        std,
                        y_label="runtime [sec]"
                        if self.scenario.run_obj == "runtime" else "cost",
                        x_label=param,
                        runtime=self.scenario.run_obj == "runtime",
                        inc_indices=inc_indices)
                else:
                    p = bokeh_line_uncertainty(
                        self.neighborhood_dict[param][1],
                        p,
                        std,
                        self.cs.get_hyperparameter(param).log,
                        y_label="runtime [sec]"
                        if self.scenario.run_obj == "runtime" else "cost",
                        x_label=param,
                        inc_indices=inc_indices)

            # Add as Panel so it can be easily put into Tabs
            plots.append(Panel(child=Row(p), title=param))

        # Putting the Tabs together
        layout = Tabs(tabs=[*plots])

        save_and_show(plot_name, show_plot, layout)

        return layout
Beispiel #26
0
 def test_props_defaults(self) -> None:
     from bokeh.models import Tabs
     tab = Tabs()
     assert tab.tabs == []
     assert tab.active == 0
                <b>Total Cases</b>: {:,} <br> <br>
                <b>Pearson Correlation (R\u00b2):</b> {:.2} <br><br>""".format(
    latest_date, cases_tests.iloc[-1]['totalSamplesTested'].astype('int64'),
    cases_summary[cases_summary['day'] == latest_date]['totalConfirmed'].sum(),
    correlation),
          width=200,
          height=100)

layout = row(fig, div)

div = Div(text="""<b>Source:</b>
                COVID-19 REST API for India: <a href='https://api.rootnet.in/covid19-in/stats/testing/raw' target="_blank"> The Ministry of Health and Family Welfare</a> """,
          width=300,
          height=50,
          align='start')

layout = column(layout, div, sizing_mode='scale_both')

tab11 = Panel(child=layout, title="Correlation - Tests Vs Cases")

tabs = Tabs(
    tabs=[tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8, tab9, tab10, tab11])
bokeh_doc.add_root(tabs)

#output_file('Statewise Cases and Deaths-Bokeh.html')
script, div = components(tabs, CDN)
curdoc().template_variables["script"] = script
curdoc().template_variables["div"] = div

#bokeh_doc.add_root(tabs)
Beispiel #28
0
def render_hq_comparison(entries: [BenchmarkEntry], ):
    def create_subtabs(child, name):
        return Tabs(tabs=[Panel(child=child, title=name)])

    reports = [entry.report for entry in entries]
    widgets = {
        "Profiling data": [],
        "Global usage": [],
        "Node usage": [],
        "Process usage": [],
    }

    # Render profiling data
    for report in reports:
        name = report.directory.name
        if report.profiling_data:
            widgets["Profiling data"].append(
                create_subtabs(render_profiling_data(report), name))

    # Render Global usage
    for report in reports:
        per_node_df = create_global_resources_df(report.monitoring)
        name = report.directory.name
        if not per_node_df.empty:
            widgets["Global usage"].append(
                create_subtabs(
                    render_global_resource_usage(report, per_node_df), name))

    # Render Node usage
    node_maxes = {}
    for report in reports:
        per_node_df = create_global_resources_df(report.monitoring)
        name = report.directory.name

        if not per_node_df.empty:
            # Get y-axis max
            nodes_subtab = render_nodes_resource_usage(report, per_node_df)
            for fig in nodes_subtab.children[0].children[1].children:
                figmax = fig.y_range.end
                if node_maxes.get(fig.title.text) is not None:
                    node_maxes[fig.title.text] = max(
                        figmax, node_maxes.get(fig.title.text))
                else:
                    node_maxes[fig.title.text] = figmax
            widgets["Node usage"].append(create_subtabs(nodes_subtab, name))

    # Update y-axis to max
    for w in widgets["Node usage"]:
        for fig in w.tabs[0].child.children[0].children[1].children:
            fig.y_range.end = node_maxes[fig.title.text]

    # Render Process usage
    for report in reports:
        per_process_df = create_per_process_resources_df(report.monitoring)
        name = report.directory.name
        if not per_process_df.empty:
            process = render_process_resource_usage(report, per_process_df)
            widgets["Process usage"].append(create_subtabs(process, name))

    tabs = []
    for key in widgets:
        # Show only widgets that are full
        if len(widgets[key]) == len(reports):
            tabs.append(Panel(child=row(widgets[key]), title=key))
    return Tabs(tabs=tabs)
Beispiel #29
0
# -*- coding: utf-8 -*-
"""
Created on Thu May  2 11:15:26 2019

@author: Chris
"""

from bokeh.models import Panel, Tabs
from bokeh.io import output_file, show
from bokeh.plotting import figure
import allTheSquiggles
import tidalvwind
import twinRidgePlot
import govtDataPlot

from bokeh.io import curdoc
from bokeh.layouts import column, row

#output_file("C:/Users/Chris/Documents/Documents/Python2018/DataVisCW/Plots/panels"+nowtime()+".html")

tab1 = Panel(child=allTheSquiggles.layout, title='Squiggles')
tab2 = Panel(child=twinRidgePlot.layout, title='Ridges')
tab3 = Panel(child=govtDataPlot.layout, title='Trends')
tab4 = Panel(child=tidalvwind.layout, title='Tidal v wind')

tabs = Tabs(tabs=[tab1, tab2, tab3, tab4])

curdoc().add_root(tabs)
Beispiel #30
0
                    S_fill=main_source_list[-3],
                    S_save=save_source_list[-1],
                    mainy=fig_list[1].y_range,
                    main_laby=fig_list[1].yaxis[0],
                    fill_lab=fig_list[2].xaxis[0],
                    dt=data_table,
                ),
                code=input_code + key_source_code.replace('cb_obj', 'S_main'))

            # layout the final grid
            notebox = widgetbox(select_text, data_table, notes, width=650)
            dropbox_0 = widgetbox(
                dum, input_0, width=210
            )  # I use the dummy div widget to have the input button ~aligned with the center of the figure
            dropbox_1 = widgetbox(dum2, input_1, width=210)

            grid = gridplot([[fig_list[0], dropbox_0],
                             [fig_list[1], dropbox_1], [fig_list[2], notebox]],
                            toolbar_location='left')

        tabs.append(Panel(child=grid, title=panel_key))

    if len(tabs) == 1:
        final = tabs[0].child
    else:
        final = Tabs(tabs=tabs)

    print('\nWritting', save_name, '...')
    outfile = open(os.path.join(save_path, save_name), 'w')
    outfile.write(file_html(final, CDN, tab_name))
    outfile.close()