Example #1
0
from bokeh.io import curdoc
from bokeh.models import Button, Slider, TextInput, Select, CustomJS
from bokeh.layouts import widgetbox, gridplot

start_button = Button(label="Start the experiment")
stop_button = Button(label="Stop", disabled=True)
m1_text = TextInput(title="mass of puck1 =", value="570")
spark_timer = Slider(value=0, start=0, end=100, step=1, title="Title")

button_list = ["Start_Button", "Stop_Button", "Mass_of_m1", "Spark"]

button_call = Select(title="Button call",
                     options=sorted(button_list),
                     value="Start_Button",
                     width=200)

select_code = """
to_show = cb_obj.value;
options = cb_obj.options

for (i=0;i<options.length;i++) {
	box = document.getElementsByClassName(options[i])[0];
	if (!box.className.includes("hidden")) {box.className+=" hidden";}
	if (box.className.includes(to_show)) {box.className=box.className.replace(" hidden","");}
}
"""

button_call.callback = CustomJS(code=select_code)

box_1 = widgetbox(start_button, css_classes=['Start_Button'])
box_2 = widgetbox(stop_button, css_classes=['Stop_Button', 'hidden'])
Example #2
0
    except:
        display_columns = df.columns
        for col_name in display_columns:
            # if col_name not in [X,Y]:
            dictionary[col_name] = []

        datapoints_source.data = dictionary
        pre.text = '<h4 style="border-top: 2px solid #778899;width: 1600px"><br><b style="color:slategray">Error! Try expanding date slider</b><br></h4>'
        #print(dictionary)
    #pre.text= """Filtered Idle spots:"""+str(len(df))

    pdict['active'] = radio_button_group.active
    completed.text = '<b>Update Completed!</b>'


sdate_input = TextInput(value="2020-01-03 00:00:00",
                        title="Start Date: (YYYY-MM-DD HH:MM:SS)")
#sdate_input.on_change("value", my_slider_handler)

edate_input = TextInput(value="2020-01-03 01:00:00",
                        title="End Date: (YYYY-MM-DD HH:MM:SS)")
#edate_input.on_change("value", my_slider_handler)

date_range_slider = DateRangeSlider(title="Data Filter Date Range: ",
                                    start=datetime.datetime(2020, 1, 3, 0),
                                    end=datetime.datetime(2020, 3, 20, 1),
                                    value=(datetime.datetime(2020, 1, 3, 0),
                                           datetime.datetime(2020, 1, 3, 1)),
                                    format="%x,%X")

date_range_start = TextInput(
    value="2020-01-03 00:00:00",
Example #3
0

"""
Interface layout
"""


def create_hover_tool(list_of_keys):
    tooltips = [('date', '@date{%F %T}')] + [(s, '@' + s)
                                             for s in list_of_keys]
    return HoverTool(tooltips=tooltips,
                     formatters={'@date': 'datetime'},
                     mode='mouse')


remote_ip_text = TextInput(title="Remote IP", value=DEFAULT_REMOTE_IP)
self_ip_text = TextInput(title="Self IP", value=DEFAULT_SELF_IP)

route_button = Button(label="Route telemetry")
route_button.on_event(ButtonClick, route_telemetry_command)

raw_command_text = TextInput(title="Raw command (hex)")

send_raw_command_button = Button(label="Send raw command")
send_raw_command_button.on_event(ButtonClick, send_raw_command)

command_info_div = Div(text="")

command_block = column(remote_ip_text, self_ip_text, route_button,
                       raw_command_text, send_raw_command_button,
                       command_info_div)
Example #4
0
checkbox_button_group = CheckboxButtonGroup(
    labels=["Option 1", "Option 2", "Option 3"], active=[0, 1])
radio_button_group = RadioButtonGroup(
    labels=["Option 1", "Option 2", "Option 3"], active=0)

checkbox_button_group_vertical = CheckboxButtonGroup(
    labels=["Option 1", "Option 2", "Option 3"],
    active=[0, 1],
    orientation="vertical")
radio_button_group_vertical = RadioButtonGroup(
    labels=["Option 1", "Option 2", "Option 3"],
    active=0,
    orientation="vertical")

text_input = TextInput(placeholder="Enter value ...")

completions = ["aaa", "aab", "aac", "baa", "caa"]
autocomplete_input = AutocompleteInput(
    placeholder="Enter value (auto-complete) ...", completions=completions)

text_area = TextAreaInput(placeholder="Enter text ...",
                          cols=20,
                          rows=10,
                          value="uuu")

select = Select(options=["Option 1", "Option 2", "Option 3"])

multi_select = MultiSelect(options=["Option %d" % (i + 1) for i in range(16)],
                           size=6)
Example #5
0
def home():
    #Open file and create sources
    dictionary = open_file_into_dictionary('SampleCSV2.csv')
    keys = list(key.title() for key in dictionary.keys())
    values = [value for value in dictionary.values()]
    xy_source = ColumnDataSource(data=dict(xs=[values[0]], ys=[values[1]], labels = [keys[1]],
    colors = ['red', 'green', 'blue', 'purple', 'brown', 'aqua']))
    variables_source = ColumnDataSource(data = dict(keys = keys, values = values))




    #Create general plot
    plot = figure(plot_width=800, plot_height=600, toolbar_location = 'left')
    plot.title.text_font= 'helvetica'
    plot.title.text_font_size = '24pt'
    plot.title.align = 'center'
    plot.title.text_font_style = 'normal'
    plot.multi_line(xs = 'xs', ys = 'ys', legend = 'labels', line_color = 'colors', source = xy_source)


    #Define callbacks
    x_axis_callback = CustomJS(args=dict(xy_source = xy_source, variables_source = variables_source,
     axis = plot.xaxis[0]), code="""
        var xy_data = xy_source.data;
        var variables_data = variables_source.data;
        var index = cb_obj.active;
        var values = variables_data.values;

        var y_length = xy_data['ys'].length;
        if (y_length == 0){
            y_length = 1}
        var new_list = [];
        for (i = 0; i < y_length; i++) {
        new_list.push(values[index])}
        xy_data['xs'] = new_list;

        xy_source.change.emit();

        var keys = variables_data.keys;
        var label = keys[index];
        axis.axis_label = label;
    """)

    y_axis_callback = CustomJS(args=dict(xy_source = xy_source, variables_source = variables_source,
     axis = plot.yaxis[0]), code="""

        var xy_data = xy_source.data;
        var variables_data = variables_source.data;
        var index_list = cb_obj.active;

        var values = variables_data.values;
        var index_length = index_list.length;
        var keys = variables_data.keys;

        var new_ys = [];
        var new_labels = [];
        for (i = 0; i < index_length; i++) {
            new_ys.push(values[index_list[i]]);
            new_labels.push(keys[index_list[i]])}
        xy_data['labels'] = new_labels;
        xy_data['ys'] = new_ys;

        if (index_length > 0){
            var x_variable = xy_data['xs'][0];
            var new_x = [];
            for (i = 0; i < index_length; i++) {
                new_x.push(x_variable)}
            xy_data['xs'] = new_x;}

        xy_source.change.emit();

        var y_axis_name = keys[[index_list[0]]];
        for (i = 1; i < index_length; i++) {
            y_axis_name += ", " + keys[[index_list[i]]];}
        axis.axis_label = y_axis_name;
    """)

    title_callback = CustomJS(args= dict(title = plot.title), code="""
        var title_text = cb_obj.value;
        title.text = title_text;

    """)
    x_name_callback = CustomJS(args=dict(axis = plot.xaxis[0]), code="""
        var label_text = cb_obj.value;
        axis.axis_label = label_text;
         """)

    y_name_callback = CustomJS(args=dict(axis = plot.yaxis[0]), code="""
        var label_text = cb_obj.value;
        axis.axis_label = label_text;
         """)


    #Create toolbox
    label_x = Div(text="""X-Axis""", width=200)
    x_axis = RadioButtonGroup(labels=keys, active=0, callback = x_axis_callback)
    label_y = Div(text="""Y-Axis""", width=200)
    y_axis = CheckboxButtonGroup(labels=keys, active=[1], callback = y_axis_callback)
    label_axes = Div(text="""<br />Modify Labels""", width=200)

    title_name = TextInput(title="Title", value='Default Title')
    plot.title.text = title_name.value
    title_name.js_on_change('value', title_callback)

    x_name = TextInput(title="X-Axis", value='Default X Label')
    plot.xaxis.axis_label = keys[0]
    x_name.js_on_change('value', x_name_callback)
    y_name = TextInput(title="Y-Axis", value='Default Y Label')
    plot.yaxis.axis_label = keys[1]
    y_name.js_on_change('value', y_name_callback)

    toolbox = widgetbox(label_x, x_axis, label_y, y_axis, label_axes, title_name, x_name, y_name)





    #Integrate with html
    parts = dict(toolbox = toolbox, plot = plot)
    script, div = components(parts, INLINE)
    return render_template('plotpage.html',
                           script=script,
                           toolbox_div=div['toolbox'],
                           plot_div=div['plot'],
                           js_resources=INLINE.render_js(),
                           css_resources=INLINE.render_css())
Example #6
0

class CowsayPreText(PreText):
    __javascript__ = ["extensions/static/js/cowsay_lib.js"]
    __implementation__ = "cowsay.ts"

    cow_type = String("DEFAULT")


class CowsaySelect(Select):
    __javascript__ = ["extensions/static/js/cowsay_lib.js"]
    __implementation__ = "cowsay_select.ts"


cowsay = CowsayPreText(text="", cow_type="DEFAULT")
cow_input = TextInput()
select = CowsaySelect()


def on_cow_input_changed(attr, old, new):
    cowsay.text = new


def on_select_changed(attr, old, new):
    cowsay.cow_type = new


cow_input.on_change("value_input", on_cow_input_changed)
select.on_change("value", on_select_changed)

curdoc().add_root(column(cowsay, cow_input, select))
Example #7
0
pNc0_results_text = TextAreaInput(value='<results file>',
                                  disabled=True,
                                  rows=5)

# select_host_case = Select(title='Select Host', options=list(source_cases.keys()))
p0c0_select_host_case = Select(title='Select Host', options=[])
p0c0_select_host_case.on_change('value', p0c0_on_host_click)

p0c0_select_donor_cases = MultiSelect(
    title='Select Donor(s) <ctrl+click to multiselect>', options=[], size=20)
p0c0_select_donor_cases.on_change('value', p0c0_on_donor_change)

p0c0_export_template = Button(label='Export Template', button_type='warning')
p0c0_export_template.on_click(p0c0_on_export_template_click)

p0c0_enter_host_name = TextInput(title='Enter Host Name',
                                 value='<type host name here>')
p1c0_enter_host_name = TextInput(title='Enter Host Name',
                                 value='<type host name here>')

p1c0_select_template = Button(label='Select Template', button_type='success')
p1c0_select_template.on_click(p1c0_on_select_template_click)
p1c0_template_text = TextAreaInput(value='<template file>', disabled=True)

p1c0_select_samples = MultiSelect(
    title='Select Sample(s) <ctrl+click to multiselect>', options=[], size=20)
p1c0_select_samples.on_change('value', p1c0_on_select_samples_change)

p1c0_export_results = Button(label='Export Results To Excel File',
                             button_type='warning')
p1c0_export_results.on_click(p1c0_on_export_results_click)
Example #8
0
from ctypes import *

from scipy.stats import gamma

import numpy as np

from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider, Select, Range1d, TextInput, Spacer, HoverTool
from bokeh.plotting import Figure, curdoc

pd = cdll.LoadLibrary("./libprobdet.so")
pd.probdet.argtypes = [c_float, c_float, c_float, c_float]
pd.probdet.restype = c_float

pfa = TextInput(title='False Alarm Probability', value='1e-6')
slider1 = Slider(start=1, end=10, value=1, step=1, title="Number of Pulses")
slider2 = Slider(start=.5,
                 end=10,
                 value=1,
                 step=0.5,
                 title="Target Gamma K parameter")
case = Select(
    title="Swerling Case",
    value="Case 2",
    options=["Case 1", "Case 2", "Case 3", "Case 4", "Non-fluctuating"])
space = Spacer(height=30, width=400)

PFA = float(pfa.value)
N = slider1.value
Yb = gamma.ppf(1 - PFA, N)
K = 1 * N
Example #9
0
        Y0B += 2
        Y1B = Y0B + 1
        if Y0B != -0.5:
            p.segment(x0=range(0, 120, 4),
                      y0=[Y0B] * 60,
                      x1=range(a, (a + 120), 4),
                      y1=[Y1B] * 60,
                      color=black,
                      line_width=linewidth * 1.8)
    if Y0B >= 56:
        textbox.title = 'Your text_ile is done. Please save it with the floppy icon to your desktop'
        return


textbox = TextInput(
    value="",
    title='Please click into the textbox to start typing')  # text input glyph


def weave(
        attr, old, new
):  # black warps exchange visibility, weft moves up, weaving is created
    if warpB.visible:
        warpB.visible = False
        warpB2.visible = True
        weftmove2(attr, old, new)
        weave_black(attr, old, new)
        patterncolor(attr, old, new)
    else:
        warpB.visible = True
        warpB2.visible = False
def make_document(doc):

    frame_ratio = 320 / 180

    # Frames from Pipelines
    raw_image_win = init_image_win("Raw Image")
    motion_mask_win = init_image_win("Motion Mask")
    cv_mask_win = init_image_win("CV Mask")
    new_alert_win = init_image_win("New Alert Snapshot")

    pipeline_win_height = 225
    pipeline_grid_plot = gridplot(
        [
            raw_image_win,
            motion_mask_win,
            cv_mask_win,
            new_alert_win,
        ],
        ncols=1,
        plot_width=int(pipeline_win_height * frame_ratio),
        plot_height=pipeline_win_height,
        toolbar_location=None,
    )
    pipeline_col = column(pipeline_grid_plot)

    # Frames from Motion
    h264_win = init_image_win("H.264")
    fd_win = init_image_win("FD")
    mog2_win = init_image_win("MOG2")
    amf_win = init_image_win("AMF")
    display_detection_win = init_image_win("Motion Detection")

    motion_win_height = 225
    motion_grid_plot = gridplot(
        children=[
            [h264_win, fd_win],
            [mog2_win, amf_win],
        ],
        plot_width=int(motion_win_height * frame_ratio),
        plot_height=motion_win_height,
        toolbar_location=None,
    )

    motion_col = column(display_detection_win, motion_grid_plot)

    # Motion Control Panel
    motion_checkbox_group = CheckboxGroup(
        labels=["H.264", "FD", "MOG2", "AMF", "Show Motion Detections"])
    motion_select = Select(title="Motion Filter Type",
                           value="h264",
                           options=["h264", "fd", "mog2", "amf"])
    motion_interval_slider = Slider(start=0.05,
                                    end=30,
                                    value=1.5,
                                    step=0.01,
                                    title="Motion Interval")
    motion_threshold_slider = Slider(start=0,
                                     end=200,
                                     value=50,
                                     step=1,
                                     title="Motion Threshold(H.264 only)")
    motion_bbx_area_threshold_slider = Slider(
        start=25,
        end=200,
        value=200,
        step=1,
        title="Motion BBX Area Threshold(OpenCV only)",
    )

    # AMF only configs
    variance_threshold_slider = Slider(start=10,
                                       end=500,
                                       value=500,
                                       step=1,
                                       title="Variance Threshold(AMF only)")
    amf_checkbox_group = CheckboxGroup(
        labels=["History Variance(AMF only)", "Frame Reduction(AMF only)"],
        active=[1])

    # Config Control Panel
    show_configs_checkbox_group = CheckboxGroup(
        labels=["Show CV Config", "Show Event Config"])
    override_cv_config_input = TextInput(value=json.dumps({}),
                                         title="Override CV Config")
    override_event_config_input = TextInput(value=json.dumps({}),
                                            title="Override Event Config")
    env_select = Select(title="Environment",
                        value="staging",
                        options=["staging", "rc", "production"])
    jumbo_id_input = TextInput(value="", title="Jumbo ID")
    api_token_input = TextInput(value="", title="API Token")

    panel_col = column(
        Div(text="<h4> Config Control Panel </h4>"),
        show_configs_checkbox_group,
        override_cv_config_input,
        override_event_config_input,
        env_select,
        jumbo_id_input,
        api_token_input,
        Div(text="<h4> Motion Control Panel </h4>"),
        motion_checkbox_group,
        motion_select,
        motion_interval_slider,
        motion_threshold_slider,
        motion_bbx_area_threshold_slider,
        variance_threshold_slider,
        amf_checkbox_group,
        sizing_mode="scale_width",
    )

    main_row = row(
        pipeline_col,
        panel_col,
        motion_col,
    )

    doc.title = "StreamDebugger"
    doc.add_root(main_row)
Example #11
0
    Toggle(label="Primary Toggle 2", button_type="primary"),
    Toggle(label="Success Toggle 3", button_type="success"),

    Dropdown(label="Default Dropdown 1", button_type="default", menu=menu),
    Dropdown(label="Primary Dropdown 2", button_type="primary", menu=menu),
    Dropdown(label="Success Dropdown 3", button_type="success", menu=menu),

    CheckboxButtonGroup(labels=["Checkbox Option 1", "Checkbox Option 2", "Checkbox Option 3"], button_type="default", active=[0, 1]),
    CheckboxButtonGroup(labels=["Checkbox Option 4", "Checkbox Option 5", "Checkbox Option 6"], button_type="primary", active=[1, 2]),
    CheckboxButtonGroup(labels=["Checkbox Option 7", "Checkbox Option 8", "Checkbox Option 9"], button_type="success", active=[0, 2]),

    RadioButtonGroup(labels=["Radio Option 1", "Radio Option 2", "Radio Option 3"], button_type="default", active=0),
    RadioButtonGroup(labels=["Radio Option 4", "Radio Option 5", "Radio Option 6"], button_type="primary", active=1),
    RadioButtonGroup(labels=["Radio Option 7", "Radio Option 8", "Radio Option 9"], button_type="success", active=2),

    TextInput(placeholder="TextInput 1"),
    TextInput(placeholder="TextInput 2"),
    TextInput(placeholder="TextInput 3"),

    AutocompleteInput(placeholder="AutocompleteInput 1 ...", completions=["aaa", "aab", "aac", "baa", "caa"]),
    AutocompleteInput(placeholder="AutocompleteInput 2 ...", completions=["AAA", "AAB", "AAC", "BAA", "CAA"]),
    AutocompleteInput(placeholder="AutocompleteInput 3 ...", completions=["000", "001", "002", "100", "200"]),

    DatePicker(value=date(2018, 9, 1)),
    DatePicker(value=date(2018, 9, 2)),
    DatePicker(value=date(2018, 9, 3)),
)

    #Slider(value=10, start=0, end=100, step=0.5),
    #RangeSlider(value=[20, 30], start=0, end=100, step=0.5),
    #DateSlider(value=date(2018, 9, 1), start=date(2018, 1, 1), end=date(2018, 12, 31)),
Example #12
0
myMapOpt = GMapOptions(lat=40.730610, lng=-73.935242, map_type='roadmap', zoom=11)

myMap = gmap("AIzaSyAD0M7aeSE_Rn01x6W5BTsy8hO45s7VDoI", myMapOpt, title="NY Fire Dept Locations")

dfFire = pd.read_excel('data/FDNY_Locations.xlsx')
dfZip = pd.read_excel('data/ZipcodeLatLong.xlsx')

dfCode = dfZip.set_index(keys="ZIP", drop=False)

cdsFire = ColumnDataSource(data=dict(lat=dfFire['Latitude'],
                                     long=dfFire['Longitude'],
                                     name=dfFire['FacilityName'],
                                     addr=dfFire['FacilityAddress'])
        )


zipcode = TextInput(title="Enter 5 digit zipcode",
                    width=100,
                    value="10010")

myMap.circle(x='long', y='lat', source=cdsFire, size=10)

mapHover = HoverTool(tooltips=[("Name","@name"),
                               ("Address", "@addr")])

myMap.add_tools(mapHover)


zipcode.on_change('value', updateMap)
curdoc().add_root(Column(zipcode, myMap))
Example #13
0
def update():
    try:
        expr = sy.sympify(text.value, dict(x=xs))
    except Exception as exception:
        errbox.text = str(exception)
    else:
        errbox.text = ""
    x, fy, ty = taylor(expr, xs, slider.value, (-2 * sy.pi, 2 * sy.pi), 200)

    p.title.text = "Taylor (n=%d) expansion comparison for: %s" % (
        slider.value, expr)
    legend.items[0].label = value(f"{expr}")
    legend.items[1].label = value(f"taylor({expr})")
    source.data = dict(x=x, fy=fy, ty=ty)


slider = Slider(start=1, end=20, value=1, step=1, title="Order")
slider.on_change('value', lambda attr, old, new: update())

text = TextInput(value=str(expr), title="Expression:")
text.on_change('value', lambda attr, old, new: update())

errbox = PreText()

update()

inputs = column(text, slider, errbox, width=400)

curdoc().add_root(column(inputs, p))
Example #14
0
    def __init__(self, type):

        self.test = False 

        self.report_type = type
        self.utc = TimezoneInfo()
        self.kp_zone = TimezoneInfo(utc_offset=-7*u.hour)
        self.zones = [self.utc, self.kp_zone]
        self.datefmt = DateFormatter(format="%m/%d/%Y %H:%M:%S")

        self.inst_style = {'font-size':'150%'}
        self.subt_style = {'font-size':'200%','font-style':'bold'}
        self.title_style = {'font-size':'250%','font-style':'bold'}
        self.alert_style = {'font-size':'150%','color':'red'}

        self.nl_file = None

        self.intro_subtitle = Div(text="Connect to Night Log",css_classes=['subt-style'])
        self.time_note = Div(text="<b> Note: </b> Enter all times as HHMM (1818 = 18:18 = 6:18pm) in Kitt Peak local time. Either enter the time or hit the <b> Now </b> button if it just occured.", css_classes=['inst-style'])

        hostname = socket.gethostname()
        ip_address = socket.gethostbyname(hostname)
        if 'desi' in hostname:
            self.location = 'kpno'
            #self.conn = psycopg2.connect(host="desi-db", port="5442", database="desi_dev", user="******", password="******")
        elif 'app' in hostname: #this is not true. Needs to change.
            self.location = 'nersc'
        else:
            self.location = 'other'
        nw_dirs = {'nersc':'/global/cfs/cdirs/desi/spectro/nightwatch/nersc/', 'kpno':'/exposures/nightwatch/', 'other':None}
        self.nw_dir = nw_dirs[self.location]
        self.nl_dir = os.environ['NL_DIR']

        self.your_name = TextInput(title ='Your Name', placeholder = 'John Smith')
        self.os_name_1 = TextInput(title ='Observing Scientist 1', placeholder = 'Ruth Bader Ginsberg')
        self.os_name_2 = TextInput(title ='Observing Scientist 2', placeholder = "Sandra Day O'Connor")
        self.lo_names = ['None ','Liz Buckley-Geer','Ann Elliott','Parker Fagrelius','Satya Gontcho A Gontcho','James Lasker','Martin Landriau','Claire Poppett','Michael Schubnell','Luke Tyas','Other ']
        self.oa_names = ['None ','Karen Butler','Amy Robertson','Anthony Paat','Dave Summers','Doug Williams','Other ']
        self.intro_txt = Div(text=' ')
        self.comment_txt = Div(text=" ", css_classes=['inst-style'], width=1000)

        self.date_init = Select(title="Existing Night Logs")
        self.time_title = Paragraph(text='Time* (Kitt Peak local time)', align='center')
        self.now_btn = Button(label='Now', css_classes=['now_button'], width=50)
        days = [d for d in os.listdir(self.nl_dir) if os.path.isdir(os.path.join(self.nl_dir, d))]
        init_nl_list = np.sort([day for day in days if 'nightlog_meta.json' in os.listdir(os.path.join(self.nl_dir,day))])[::-1][0:10]
        self.date_init.options = list(init_nl_list)
        self.date_init.value = init_nl_list[0]
        self.connect_txt = Div(text=' ', css_classes=['alert-style'])

        self.connect_bt = Button(label="Connect to Existing Night Log", css_classes=['connect_button'])

        self.exp_info = Div(text="Fill In Only Relevant Data. Mandatory fields have an asterisk*.", css_classes=['inst-style'],width=500)
        self.exp_comment = TextAreaInput(title ='Comment/Remark', placeholder = 'Humidity high for calibration lamps',value=None,rows=10, cols=5,width=800,max_length=5000)
        self.exp_time = TextInput(placeholder = '20:07',value=None, width=100) #title ='Time in Kitt Peak local time*', 
        self.exp_btn = Button(label='Add', css_classes=['add_button'])
        self.exp_type = Select(title="Exposure Type", value = None, options=['None','Zero','Focus','Dark','Arc','FVC','DESI'])
        self.exp_alert = Div(text=' ', css_classes=['alert-style'])
        self.exp_exposure_start = TextInput(title='Exposure Number: First', placeholder='12345', value=None)
        self.exp_exposure_finish = TextInput(title='Exposure Number: Last', placeholder='12346', value=None)

        self.nl_subtitle = Div(text="Current DESI Night Log: {}".format(self.nl_file), css_classes=['subt-style'])
        self.nl_btn = Button(label='Get Current DESI Night Log', css_classes=['connect_button'])
        self.nl_text = Div(text=" ", css_classes=['inst-style'], width=1000)
        self.nl_alert = Div(text='You must be connected to a Night Log', css_classes=['alert-style'], width=500)
        self.nl_info = Div(text="Night Log Info:", css_classes=['inst-style'], width=500)
        self.exptable_alert = Div(text=" ",css_classes=['alert-style'], width=500)

        self.checklist = CheckboxGroup(labels=[])
        self.check_time = TextInput(placeholder = '20:07', value=None) #title ='Time in Kitt Peak local time*', 
        self.check_alert = Div(text=" ", css_classes=['alert-style'])
        self.check_btn = Button(label='Submit', css_classes=['add_button'])
        self.check_comment = TextAreaInput(title='Comment', placeholder='comment if necessary', rows=3, cols=3)

        self.prob_subtitle = Div(text="Problems", css_classes=['subt-style'])
        self.prob_inst = Div(text="Describe problems as they come up and at what time they occur. If there is an Alarm ID associated with the problem, include it, but leave blank if not. If possible, include a description of the remedy.", css_classes=['inst-style'], width=1000)
        self.prob_time = TextInput(placeholder = '20:07', value=None, width=100) #title ='Time in Kitt Peak local time*', 
        self.prob_input = TextAreaInput(placeholder="NightWatch not plotting raw data", rows=10, cols=3, title="Problem Description*:")
        self.prob_alarm = TextInput(title='Alarm ID', placeholder='12', value=None, width=100)
        self.prob_action = TextAreaInput(title='Resolution/Action',placeholder='description',rows=10, cols=3)
        self.prob_btn = Button(label='Add', css_classes=['add_button'])
        self.prob_alert = Div(text=' ', css_classes=['alert-style'])

        self.img_subtitle = Div(text="Images", css_classes=['subt-style'])
        self.img_upinst = Div(text="Include images in the Night Log by uploading a png image from your local computer. Select file, write a comment and click Add", css_classes=['inst-style'], width=1000)
        self.img_upinst2 = Div(text="           Choose image to include with comment:  ", css_classes=['inst-style'])
        self.img_upload = FileInput(accept=".png")
        self.img_upload.on_change('value', self.upload_image)
        self.img_upload_comments = FileInput(accept=".png")
        self.img_upload_comments.on_change('value', self.upload_image_comments)
        self.img_upload_comments_os = FileInput(accept=".png")
        self.img_upload_comments_os.on_change('value', self.upload_image_comments_os)
        self.img_upload_problems = FileInput(accept=".png")
        self.img_upload_problems.on_change('value', self.upload_image_problems)
        self.img_inst = Div(text="Include images in the Night Log by entering the location of the images on the desi cluster", css_classes=['inst-style'], width=1000)
        self.img_input = TextInput(title='image file location on desi cluster', placeholder='/n/home/desiobserver/image.png',value=None)
        self.img_comment = TextAreaInput(placeholder='comment about image', rows=8, cols=3, title='Image caption')
        self.img_btn = Button(label='Add', css_classes=['add_button'])
        self.img_alert = Div(text=" ",width=1000)

        self.plot_subtitle = Div(text="Telemetry Plots", css_classes=['subt-style'])

        self.DESI_Log = None
        self.save_telem_plots = False
Example #15
0
def create():
    det_data = []
    fit_params = {}
    js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""]))

    def proposal_textinput_callback(_attr, _old, new):
        proposal = new.strip()
        for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS:
            proposal_path = os.path.join(zebra_proposals_path, proposal)
            if os.path.isdir(proposal_path):
                # found it
                break
        else:
            raise ValueError(f"Can not find data for proposal '{proposal}'.")

        file_list = []
        for file in os.listdir(proposal_path):
            if file.endswith((".ccl", ".dat")):
                file_list.append((os.path.join(proposal_path, file), file))
        file_select.options = file_list
        file_open_button.disabled = False
        file_append_button.disabled = False

    proposal_textinput = TextInput(title="Proposal number:", width=210)
    proposal_textinput.on_change("value", proposal_textinput_callback)

    def _init_datatable():
        scan_list = [s["idx"] for s in det_data]
        file_list = []
        for scan in det_data:
            file_list.append(os.path.basename(scan["original_filename"]))

        scan_table_source.data.update(
            file=file_list,
            scan=scan_list,
            param=[None] * len(scan_list),
            fit=[0] * len(scan_list),
            export=[True] * len(scan_list),
        )
        scan_table_source.selected.indices = []
        scan_table_source.selected.indices = [0]

        scan_motor_select.options = det_data[0]["scan_motors"]
        scan_motor_select.value = det_data[0]["scan_motor"]
        param_select.value = "user defined"

    file_select = MultiSelect(title="Available .ccl/.dat files:",
                              width=210,
                              height=250)

    def file_open_button_callback():
        nonlocal det_data
        det_data = []
        for f_name in file_select.value:
            with open(f_name) as file:
                base, ext = os.path.splitext(f_name)
                if det_data:
                    append_data = pyzebra.parse_1D(file, ext)
                    pyzebra.normalize_dataset(append_data,
                                              monitor_spinner.value)
                    det_data.extend(append_data)
                else:
                    det_data = pyzebra.parse_1D(file, ext)
                    pyzebra.normalize_dataset(det_data, monitor_spinner.value)
                    js_data.data.update(
                        fname=[base + ".comm", base + ".incomm"])

        _init_datatable()
        append_upload_button.disabled = False

    file_open_button = Button(label="Open New", width=100, disabled=True)
    file_open_button.on_click(file_open_button_callback)

    def file_append_button_callback():
        for f_name in file_select.value:
            with open(f_name) as file:
                _, ext = os.path.splitext(f_name)
                append_data = pyzebra.parse_1D(file, ext)

            pyzebra.normalize_dataset(append_data, monitor_spinner.value)
            det_data.extend(append_data)

        _init_datatable()

    file_append_button = Button(label="Append", width=100, disabled=True)
    file_append_button.on_click(file_append_button_callback)

    def upload_button_callback(_attr, _old, new):
        nonlocal det_data
        det_data = []
        for f_str, f_name in zip(new, upload_button.filename):
            with io.StringIO(base64.b64decode(f_str).decode()) as file:
                base, ext = os.path.splitext(f_name)
                if det_data:
                    append_data = pyzebra.parse_1D(file, ext)
                    pyzebra.normalize_dataset(append_data,
                                              monitor_spinner.value)
                    det_data.extend(append_data)
                else:
                    det_data = pyzebra.parse_1D(file, ext)
                    pyzebra.normalize_dataset(det_data, monitor_spinner.value)
                    js_data.data.update(
                        fname=[base + ".comm", base + ".incomm"])

        _init_datatable()
        append_upload_button.disabled = False

    upload_div = Div(text="or upload new .ccl/.dat files:",
                     margin=(5, 5, 0, 5))
    upload_button = FileInput(accept=".ccl,.dat", multiple=True, width=200)
    upload_button.on_change("value", upload_button_callback)

    def append_upload_button_callback(_attr, _old, new):
        for f_str, f_name in zip(new, append_upload_button.filename):
            with io.StringIO(base64.b64decode(f_str).decode()) as file:
                _, ext = os.path.splitext(f_name)
                append_data = pyzebra.parse_1D(file, ext)

            pyzebra.normalize_dataset(append_data, monitor_spinner.value)
            det_data.extend(append_data)

        _init_datatable()

    append_upload_div = Div(text="append extra files:", margin=(5, 5, 0, 5))
    append_upload_button = FileInput(accept=".ccl,.dat",
                                     multiple=True,
                                     width=200,
                                     disabled=True)
    append_upload_button.on_change("value", append_upload_button_callback)

    def monitor_spinner_callback(_attr, _old, new):
        if det_data:
            pyzebra.normalize_dataset(det_data, new)
            _update_plot()

    monitor_spinner = Spinner(title="Monitor:",
                              mode="int",
                              value=100_000,
                              low=1,
                              width=145)
    monitor_spinner.on_change("value", monitor_spinner_callback)

    def scan_motor_select_callback(_attr, _old, new):
        if det_data:
            for scan in det_data:
                scan["scan_motor"] = new
            _update_plot()

    scan_motor_select = Select(title="Scan motor:", options=[], width=145)
    scan_motor_select.on_change("value", scan_motor_select_callback)

    def _update_table():
        fit_ok = [(1 if "fit" in scan else 0) for scan in det_data]
        scan_table_source.data.update(fit=fit_ok)

    def _update_plot():
        _update_single_scan_plot(_get_selected_scan())
        _update_overview()

    def _update_single_scan_plot(scan):
        scan_motor = scan["scan_motor"]

        y = scan["counts"]
        x = scan[scan_motor]

        plot.axis[0].axis_label = scan_motor
        plot_scatter_source.data.update(x=x,
                                        y=y,
                                        y_upper=y + np.sqrt(y),
                                        y_lower=y - np.sqrt(y))

        fit = scan.get("fit")
        if fit is not None:
            x_fit = np.linspace(x[0], x[-1], 100)
            plot_fit_source.data.update(x=x_fit, y=fit.eval(x=x_fit))

            x_bkg = []
            y_bkg = []
            xs_peak = []
            ys_peak = []
            comps = fit.eval_components(x=x_fit)
            for i, model in enumerate(fit_params):
                if "linear" in model:
                    x_bkg = x_fit
                    y_bkg = comps[f"f{i}_"]

                elif any(val in model
                         for val in ("gaussian", "voigt", "pvoigt")):
                    xs_peak.append(x_fit)
                    ys_peak.append(comps[f"f{i}_"])

            plot_bkg_source.data.update(x=x_bkg, y=y_bkg)
            plot_peak_source.data.update(xs=xs_peak, ys=ys_peak)

            fit_output_textinput.value = fit.fit_report()

        else:
            plot_fit_source.data.update(x=[], y=[])
            plot_bkg_source.data.update(x=[], y=[])
            plot_peak_source.data.update(xs=[], ys=[])
            fit_output_textinput.value = ""

    def _update_overview():
        xs = []
        ys = []
        param = []
        x = []
        y = []
        par = []
        for s, p in enumerate(scan_table_source.data["param"]):
            if p is not None:
                scan = det_data[s]
                scan_motor = scan["scan_motor"]
                xs.append(scan[scan_motor])
                x.extend(scan[scan_motor])
                ys.append(scan["counts"])
                y.extend([float(p)] * len(scan[scan_motor]))
                param.append(float(p))
                par.extend(scan["counts"])

        if det_data:
            scan_motor = det_data[0]["scan_motor"]
            ov_plot.axis[0].axis_label = scan_motor
            ov_param_plot.axis[0].axis_label = scan_motor

        ov_plot_mline_source.data.update(xs=xs,
                                         ys=ys,
                                         param=param,
                                         color=color_palette(len(xs)))

        if y:
            mapper["transform"].low = np.min([np.min(y) for y in ys])
            mapper["transform"].high = np.max([np.max(y) for y in ys])
        ov_param_plot_scatter_source.data.update(x=x, y=y, param=par)

        if y:
            interp_f = interpolate.interp2d(x, y, par)
            x1, x2 = min(x), max(x)
            y1, y2 = min(y), max(y)
            image = interp_f(
                np.linspace(x1, x2, ov_param_plot.inner_width // 10),
                np.linspace(y1, y2, ov_param_plot.inner_height // 10),
                assume_sorted=True,
            )
            ov_param_plot_image_source.data.update(image=[image],
                                                   x=[x1],
                                                   y=[y1],
                                                   dw=[x2 - x1],
                                                   dh=[y2 - y1])
        else:
            ov_param_plot_image_source.data.update(image=[],
                                                   x=[],
                                                   y=[],
                                                   dw=[],
                                                   dh=[])

    def _update_param_plot():
        x = []
        y = []
        fit_param = fit_param_select.value
        for s, p in zip(det_data, scan_table_source.data["param"]):
            if "fit" in s and fit_param:
                x.append(p)
                y.append(s["fit"].values[fit_param])

        param_plot_scatter_source.data.update(x=x, y=y)

    # Main plot
    plot = Plot(
        x_range=DataRange1d(),
        y_range=DataRange1d(only_visible=True),
        plot_height=450,
        plot_width=700,
    )

    plot.add_layout(LinearAxis(axis_label="Counts"), place="left")
    plot.add_layout(LinearAxis(axis_label="Scan motor"), place="below")

    plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
    plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))

    plot_scatter_source = ColumnDataSource(
        dict(x=[0], y=[0], y_upper=[0], y_lower=[0]))
    plot_scatter = plot.add_glyph(
        plot_scatter_source, Scatter(x="x", y="y", line_color="steelblue"))
    plot.add_layout(
        Whisker(source=plot_scatter_source,
                base="x",
                upper="y_upper",
                lower="y_lower"))

    plot_fit_source = ColumnDataSource(dict(x=[0], y=[0]))
    plot_fit = plot.add_glyph(plot_fit_source, Line(x="x", y="y"))

    plot_bkg_source = ColumnDataSource(dict(x=[0], y=[0]))
    plot_bkg = plot.add_glyph(
        plot_bkg_source,
        Line(x="x", y="y", line_color="green", line_dash="dashed"))

    plot_peak_source = ColumnDataSource(dict(xs=[[0]], ys=[[0]]))
    plot_peak = plot.add_glyph(
        plot_peak_source,
        MultiLine(xs="xs", ys="ys", line_color="red", line_dash="dashed"))

    fit_from_span = Span(location=None, dimension="height", line_dash="dashed")
    plot.add_layout(fit_from_span)

    fit_to_span = Span(location=None, dimension="height", line_dash="dashed")
    plot.add_layout(fit_to_span)

    plot.add_layout(
        Legend(
            items=[
                ("data", [plot_scatter]),
                ("best fit", [plot_fit]),
                ("peak", [plot_peak]),
                ("linear", [plot_bkg]),
            ],
            location="top_left",
            click_policy="hide",
        ))

    plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
    plot.toolbar.logo = None

    # Overview multilines plot
    ov_plot = Plot(x_range=DataRange1d(),
                   y_range=DataRange1d(),
                   plot_height=450,
                   plot_width=700)

    ov_plot.add_layout(LinearAxis(axis_label="Counts"), place="left")
    ov_plot.add_layout(LinearAxis(axis_label="Scan motor"), place="below")

    ov_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
    ov_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))

    ov_plot_mline_source = ColumnDataSource(
        dict(xs=[], ys=[], param=[], color=[]))
    ov_plot.add_glyph(ov_plot_mline_source,
                      MultiLine(xs="xs", ys="ys", line_color="color"))

    hover_tool = HoverTool(tooltips=[("param", "@param")])
    ov_plot.add_tools(PanTool(), WheelZoomTool(), hover_tool, ResetTool())

    ov_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
    ov_plot.toolbar.logo = None

    # Overview perams plot
    ov_param_plot = Plot(x_range=DataRange1d(),
                         y_range=DataRange1d(),
                         plot_height=450,
                         plot_width=700)

    ov_param_plot.add_layout(LinearAxis(axis_label="Param"), place="left")
    ov_param_plot.add_layout(LinearAxis(axis_label="Scan motor"),
                             place="below")

    ov_param_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
    ov_param_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))

    ov_param_plot_image_source = ColumnDataSource(
        dict(image=[], x=[], y=[], dw=[], dh=[]))
    ov_param_plot.add_glyph(
        ov_param_plot_image_source,
        Image(image="image", x="x", y="y", dw="dw", dh="dh"))

    ov_param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[], param=[]))
    mapper = linear_cmap(field_name="param", palette=Turbo256, low=0, high=50)
    ov_param_plot.add_glyph(
        ov_param_plot_scatter_source,
        Scatter(x="x", y="y", line_color=mapper, fill_color=mapper, size=10),
    )

    ov_param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
    ov_param_plot.toolbar.logo = None

    # Parameter plot
    param_plot = Plot(x_range=DataRange1d(),
                      y_range=DataRange1d(),
                      plot_height=400,
                      plot_width=700)

    param_plot.add_layout(LinearAxis(axis_label="Fit parameter"), place="left")
    param_plot.add_layout(LinearAxis(axis_label="Parameter"), place="below")

    param_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
    param_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))

    param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[]))
    param_plot.add_glyph(param_plot_scatter_source, Scatter(x="x", y="y"))

    param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
    param_plot.toolbar.logo = None

    def fit_param_select_callback(_attr, _old, _new):
        _update_param_plot()

    fit_param_select = Select(title="Fit parameter", options=[], width=145)
    fit_param_select.on_change("value", fit_param_select_callback)

    # Plot tabs
    plots = Tabs(tabs=[
        Panel(child=plot, title="single scan"),
        Panel(child=ov_plot, title="overview"),
        Panel(child=ov_param_plot, title="overview map"),
        Panel(child=column(param_plot, row(fit_param_select)),
              title="parameter plot"),
    ])

    # Scan select
    def scan_table_select_callback(_attr, old, new):
        if not new:
            # skip empty selections
            return

        # Avoid selection of multiple indicies (via Shift+Click or Ctrl+Click)
        if len(new) > 1:
            # drop selection to the previous one
            scan_table_source.selected.indices = old
            return

        if len(old) > 1:
            # skip unnecessary update caused by selection drop
            return

        _update_plot()

    def scan_table_source_callback(_attr, _old, _new):
        _update_preview()

    scan_table_source = ColumnDataSource(
        dict(file=[], scan=[], param=[], fit=[], export=[]))
    scan_table_source.on_change("data", scan_table_source_callback)

    scan_table = DataTable(
        source=scan_table_source,
        columns=[
            TableColumn(field="file", title="file", width=150),
            TableColumn(field="scan", title="scan", width=50),
            TableColumn(field="param",
                        title="param",
                        editor=NumberEditor(),
                        width=50),
            TableColumn(field="fit", title="Fit", width=50),
            TableColumn(field="export",
                        title="Export",
                        editor=CheckboxEditor(),
                        width=50),
        ],
        width=410,  # +60 because of the index column
        editable=True,
        autosize_mode="none",
    )

    def scan_table_source_callback(_attr, _old, _new):
        if scan_table_source.selected.indices:
            _update_plot()

    scan_table_source.selected.on_change("indices", scan_table_select_callback)
    scan_table_source.on_change("data", scan_table_source_callback)

    def _get_selected_scan():
        return det_data[scan_table_source.selected.indices[0]]

    def param_select_callback(_attr, _old, new):
        if new == "user defined":
            param = [None] * len(det_data)
        else:
            param = [scan[new] for scan in det_data]

        scan_table_source.data["param"] = param
        _update_param_plot()

    param_select = Select(
        title="Parameter:",
        options=["user defined", "temp", "mf", "h", "k", "l"],
        value="user defined",
        width=145,
    )
    param_select.on_change("value", param_select_callback)

    def fit_from_spinner_callback(_attr, _old, new):
        fit_from_span.location = new

    fit_from_spinner = Spinner(title="Fit from:", width=145)
    fit_from_spinner.on_change("value", fit_from_spinner_callback)

    def fit_to_spinner_callback(_attr, _old, new):
        fit_to_span.location = new

    fit_to_spinner = Spinner(title="to:", width=145)
    fit_to_spinner.on_change("value", fit_to_spinner_callback)

    def fitparams_add_dropdown_callback(click):
        # bokeh requires (str, str) for MultiSelect options
        new_tag = f"{click.item}-{fitparams_select.tags[0]}"
        fitparams_select.options.append((new_tag, click.item))
        fit_params[new_tag] = fitparams_factory(click.item)
        fitparams_select.tags[0] += 1

    fitparams_add_dropdown = Dropdown(
        label="Add fit function",
        menu=[
            ("Linear", "linear"),
            ("Gaussian", "gaussian"),
            ("Voigt", "voigt"),
            ("Pseudo Voigt", "pvoigt"),
            # ("Pseudo Voigt1", "pseudovoigt1"),
        ],
        width=145,
    )
    fitparams_add_dropdown.on_click(fitparams_add_dropdown_callback)

    def fitparams_select_callback(_attr, old, new):
        # Avoid selection of multiple indicies (via Shift+Click or Ctrl+Click)
        if len(new) > 1:
            # drop selection to the previous one
            fitparams_select.value = old
            return

        if len(old) > 1:
            # skip unnecessary update caused by selection drop
            return

        if new:
            fitparams_table_source.data.update(fit_params[new[0]])
        else:
            fitparams_table_source.data.update(
                dict(param=[], value=[], vary=[], min=[], max=[]))

    fitparams_select = MultiSelect(options=[], height=120, width=145)
    fitparams_select.tags = [0]
    fitparams_select.on_change("value", fitparams_select_callback)

    def fitparams_remove_button_callback():
        if fitparams_select.value:
            sel_tag = fitparams_select.value[0]
            del fit_params[sel_tag]
            for elem in fitparams_select.options:
                if elem[0] == sel_tag:
                    fitparams_select.options.remove(elem)
                    break

            fitparams_select.value = []

    fitparams_remove_button = Button(label="Remove fit function", width=145)
    fitparams_remove_button.on_click(fitparams_remove_button_callback)

    def fitparams_factory(function):
        if function == "linear":
            params = ["slope", "intercept"]
        elif function == "gaussian":
            params = ["amplitude", "center", "sigma"]
        elif function == "voigt":
            params = ["amplitude", "center", "sigma", "gamma"]
        elif function == "pvoigt":
            params = ["amplitude", "center", "sigma", "fraction"]
        elif function == "pseudovoigt1":
            params = ["amplitude", "center", "g_sigma", "l_sigma", "fraction"]
        else:
            raise ValueError("Unknown fit function")

        n = len(params)
        fitparams = dict(
            param=params,
            value=[None] * n,
            vary=[True] * n,
            min=[None] * n,
            max=[None] * n,
        )

        if function == "linear":
            fitparams["value"] = [0, 1]
            fitparams["vary"] = [False, True]
            fitparams["min"] = [None, 0]

        elif function == "gaussian":
            fitparams["min"] = [0, None, None]

        return fitparams

    fitparams_table_source = ColumnDataSource(
        dict(param=[], value=[], vary=[], min=[], max=[]))
    fitparams_table = DataTable(
        source=fitparams_table_source,
        columns=[
            TableColumn(field="param", title="Parameter"),
            TableColumn(field="value", title="Value", editor=NumberEditor()),
            TableColumn(field="vary", title="Vary", editor=CheckboxEditor()),
            TableColumn(field="min", title="Min", editor=NumberEditor()),
            TableColumn(field="max", title="Max", editor=NumberEditor()),
        ],
        height=200,
        width=350,
        index_position=None,
        editable=True,
        auto_edit=True,
    )

    # start with `background` and `gauss` fit functions added
    fitparams_add_dropdown_callback(types.SimpleNamespace(item="linear"))
    fitparams_add_dropdown_callback(types.SimpleNamespace(item="gaussian"))
    fitparams_select.value = ["gaussian-1"]  # add selection to gauss

    fit_output_textinput = TextAreaInput(title="Fit results:",
                                         width=750,
                                         height=200)

    def proc_all_button_callback():
        for scan, export in zip(det_data, scan_table_source.data["export"]):
            if export:
                pyzebra.fit_scan(scan,
                                 fit_params,
                                 fit_from=fit_from_spinner.value,
                                 fit_to=fit_to_spinner.value)
                pyzebra.get_area(
                    scan,
                    area_method=AREA_METHODS[area_method_radiobutton.active],
                    lorentz=lorentz_checkbox.active,
                )

        _update_plot()
        _update_table()

        for scan in det_data:
            if "fit" in scan:
                options = list(scan["fit"].params.keys())
                fit_param_select.options = options
                fit_param_select.value = options[0]
                break
        _update_param_plot()

    proc_all_button = Button(label="Process All",
                             button_type="primary",
                             width=145)
    proc_all_button.on_click(proc_all_button_callback)

    def proc_button_callback():
        scan = _get_selected_scan()
        pyzebra.fit_scan(scan,
                         fit_params,
                         fit_from=fit_from_spinner.value,
                         fit_to=fit_to_spinner.value)
        pyzebra.get_area(
            scan,
            area_method=AREA_METHODS[area_method_radiobutton.active],
            lorentz=lorentz_checkbox.active,
        )

        _update_plot()
        _update_table()

        for scan in det_data:
            if "fit" in scan:
                options = list(scan["fit"].params.keys())
                fit_param_select.options = options
                fit_param_select.value = options[0]
                break
        _update_param_plot()

    proc_button = Button(label="Process Current", width=145)
    proc_button.on_click(proc_button_callback)

    area_method_div = Div(text="Intensity:", margin=(5, 5, 0, 5))
    area_method_radiobutton = RadioGroup(labels=["Function", "Area"],
                                         active=0,
                                         width=145)

    lorentz_checkbox = CheckboxGroup(labels=["Lorentz Correction"],
                                     width=145,
                                     margin=(13, 5, 5, 5))

    export_preview_textinput = TextAreaInput(title="Export file preview:",
                                             width=450,
                                             height=400)

    def _update_preview():
        with tempfile.TemporaryDirectory() as temp_dir:
            temp_file = temp_dir + "/temp"
            export_data = []
            for s, export in zip(det_data, scan_table_source.data["export"]):
                if export:
                    export_data.append(s)

            # pyzebra.export_1D(export_data, temp_file, "fullprof")

            exported_content = ""
            file_content = []
            for ext in (".comm", ".incomm"):
                fname = temp_file + ext
                if os.path.isfile(fname):
                    with open(fname) as f:
                        content = f.read()
                        exported_content += f"{ext} file:\n" + content
                else:
                    content = ""
                file_content.append(content)

            js_data.data.update(content=file_content)
            export_preview_textinput.value = exported_content

    save_button = Button(label="Download File(s)",
                         button_type="success",
                         width=220)
    save_button.js_on_click(
        CustomJS(args={"js_data": js_data}, code=javaScript))

    fitpeak_controls = row(
        column(fitparams_add_dropdown, fitparams_select,
               fitparams_remove_button),
        fitparams_table,
        Spacer(width=20),
        column(fit_from_spinner, lorentz_checkbox, area_method_div,
               area_method_radiobutton),
        column(fit_to_spinner, proc_button, proc_all_button),
    )

    scan_layout = column(scan_table,
                         row(monitor_spinner, scan_motor_select, param_select))

    import_layout = column(
        proposal_textinput,
        file_select,
        row(file_open_button, file_append_button),
        upload_div,
        upload_button,
        append_upload_div,
        append_upload_button,
    )

    export_layout = column(export_preview_textinput, row(save_button))

    tab_layout = column(
        row(import_layout, scan_layout, plots, Spacer(width=30),
            export_layout),
        row(fitpeak_controls, fit_output_textinput),
    )

    return Panel(child=tab_layout, title="param study")
Example #16
0
    def layout(self):

        # define text font, colors
        self.text1 = Div(text="""<h1 style="color:blue">COVID-19 Simulator for Kazakhstan</h1>""", width=500, height=50)
        self.text4 = Div(text="""<h1 style="color:blue"> </h1>""", width=900, height=50)

        self.text2 =  Div(text="<b>Select parameters for each region</b>", style={'font-size': '150%', 'color': 'green'},width=350)
        self.text3 =  Div(text="<b>Select global parameters </b>", style={'font-size': '150%', 'color': 'green'}   )
        self.text5 =  Div(text="<b>Change transition matrix</b>", style={'font-size': '150%', 'color': 'green'})

        # select region - dropdown menu
        regions = config.region_names

        initial_region = 'Almaty'
        region_selection = Select(value=initial_region, title=' ', options=regions, width=250, height=15)
        region_selection.on_change('value', self.SelectRegionHandler)

        # select parameters - sliders
        self.sus_to_exp_slider = Slider(start=0.0,end=50.0,step=0.5,value=config.param_beta_exp[config.region], title='Susceptible to Exposed transition constant (%)')
        self.sus_to_exp_slider.on_change('value', self.handler_beta_exp)

        self.param_qr_slider = Slider(start=0.0,end=25.0,step=0.25,value=config.param_qr[config.region], title='Daily Quarantine rate of the Exposed (%)')
        self.param_qr_slider.on_change('value', self.handler_param_qr)

        self.param_sir = Slider(start=0.0,end=5.0,step=0.05,value=config.param_sir[config.region], title='Daily Infected to Severe Infected transition rate (%)')
        self.param_sir.on_change('value', self.handler_param_sir)

        self.param_eps_exp = Slider(start=0,end=100,step=1.0,value=config.param_eps_exp[config.region], title='Disease transmission rate of Exposed compared to Infected (%)')
        self.param_eps_exp.on_change('value', self.handler_param_eps_exp)

        self.param_eps_qua = Slider(start=0,end=100,step=1.0,value=config.param_eps_qua[config.region], title='Disease transmission rate of Quarantined compared to Infected (%)')
        self.param_eps_qua.on_change('value', self.handler_param_eps_qua)

        self.param_eps_sev = Slider(start=0,end=100,step=1.0,value=config.param_eps_sev[config.region], title='Disease transmission rate of Severe Infected compared to Infected (%)')
        self.param_eps_sev.on_change('value', self.handler_param_eps_sev)

        self.param_hosp_capacity = Slider(start=0,end=10000,step=1,value=config.param_hosp_capacity[config.region], title='Hospital Capacity')
        self.param_hosp_capacity.on_change('value', self.handler_param_hosp_capacity)

        self.param_gamma_mor1 = Slider(start=0,end=100,step=1.0,value=config.param_gamma_mor1[config.region], title='Severe Infected to Dead transition probability (%)')
        self.param_gamma_mor1.on_change('value', self.handler_param_gamma_mor1)

        self.param_gamma_mor2 = Slider(start=0,end=100,step=1,value=config.param_gamma_mor2[config.region], title='Severe Infected to Dead transition probability (Hospital Cap. Exceeded) (%)')
        self.param_gamma_mor2.on_change('value', self.handler_param_gamma_mor2)

        self.param_gamma_im = Slider(start=0,end=100,step=1,value=config.param_gamma_im[config.region], title='Infected to Recovery Immunized transition probability (%)')
        self.param_gamma_im.on_change('value', self.handler_param_gamma_im)

        self.param_sim_len = Slider(start=1,end=100,step=1,value=config.loop_num, title='Length of simulation (Days)')
        self.param_sim_len.on_change('value', self.handler_param_sim_len)

        self.param_t_exp = Slider(start=1,end=20,step=1,value=config.param_t_exp[0], title='Incubation period (Days) ')
        self.param_t_exp.on_change('value', self.handler_param_t_exp)

        self.param_t_inf = Slider(start=1,end=20,step=1,value=config.param_t_inf[0], title=' Infection  period (Days) ')
        self.param_t_inf.on_change('value', self.handler_param_t_inf)

        self.init_exposed = Slider(start=0,end=100,step=1,value=config.param_init_exposed[config.region], title='Initial Exposed')
        self.init_exposed.on_change('value', self.handler_init_exposed)

        self.param_tr_scale = Slider(start=0.0,end=1,step=0.01,value=config.param_transition_scale[0], title='Traffic ratio')
        self.param_tr_scale.on_change('value', self.handler_param_tr_scale)

        self.param_tr_leakage = Slider(start=0.0,end=1,step=0.01,value=config.param_transition_leakage[0], title='Leakage ratio')
        self.param_tr_leakage.on_change('value', self.handler_param_tr_leakage)

        dumdiv = Div(text='',width=10)
        dumdiv2= Div(text='',width=10)
        dumdiv3= Div(text='',width=200)
        dumdiv3ss= Div(text='',width=120)

        # Buttons
        reset_button = Button(label = 'Reset data', button_type='primary', background = "red")
        save_button_result = Button(label='Save current plot to .csv in directory results/', button_type='primary')
        run_button = Button(label='Run the simulation',button_type='primary')
        load_button = Button(label='Load data from directory results/', button_type='primary')

        run_button.on_click(self.run_click)
        reset_button.on_click(self.reset_click)
        save_button_result.on_click(self.save_file_click)
        load_button.on_click(self.load_click)

        # input folder name
        text_save = TextInput(value="foldername", title="")
        text_save.on_change('value', self.handler_param_save_file)

        # transition matrix - checkbox
        div_cb1 = Div(text = 'Airways', width = 150)
        div_cb2 = Div(text = 'Railways', width = 150)
        div_cb3 = Div(text = 'Highways', width = 150)

        self.checkbox_group1 = CheckboxGroup(labels=regions, active = list(range(0, 17)))
        self.checkbox_group2 = CheckboxGroup(labels=regions, active= list(range(0, 17)))
        self.checkbox_group3 = CheckboxGroup(labels=regions, active= list(range(0, 17)))

        self.checkbox_group1.on_click(self.handler_checkbox_group1)
        self.checkbox_group2.on_click(self.handler_checkbox_group2)
        self.checkbox_group3.on_click(self.handler_checkbox_group3)

        # transition matrix - table
        self.data1 = dict(
                        c00 =  regions,
                        c0= [(config.transition_matrix[0,i]) for i in range(0,17)],
                        c1= [(config.transition_matrix[1,i]) for i in range(0,17)],
                        c2= [(config.transition_matrix[2,i]) for i in range(0,17)],
                        c3=[(config.transition_matrix[3,i]) for i in range(0,17)],
                        c4=[(config.transition_matrix[4,i]) for i in range(0,17)],
                        c5=[(config.transition_matrix[5,i]) for i in range(0,17)],
                        c6=[(config.transition_matrix[6,i]) for i in range(0,17)],
                        c7=[(config.transition_matrix[7,i]) for i in range(0,17)],
                        c8=[(config.transition_matrix[8,i]) for i in range(0,17)],
                        c9=[(config.transition_matrix[9,i]) for i in range(0,17)],
                        c10=[(config.transition_matrix[10,i]) for i in range(0,17)],
                        c11=[(config.transition_matrix[11,i]) for i in range(0,17)],
                        c12=[(config.transition_matrix[12,i]) for i in range(0,17)],
                        c13=[(config.transition_matrix[13,i]) for i in range(0,17)],
                        c14=[(config.transition_matrix[14,i]) for i in range(0,17)],
                        c15=[(config.transition_matrix[15,i]) for i in range(0,17)],
                        c16=[(config.transition_matrix[16,i]) for i in range(0,17)],)

        columns = [
                    TableColumn(field="c00", title=" ",),
                    TableColumn(field="c0", title="Almaty",),
                    TableColumn(field="c1", title="Almaty Qalasy",),
                    TableColumn(field="c2", title="Aqmola",),
                    TableColumn(field="c3", title="Aqtobe",),
                    TableColumn(field="c4", title="Atyrau",),
                    TableColumn(field="c5", title="West Kazakhstan",),
                    TableColumn(field="c6", title="Jambyl",),
                    TableColumn(field="c7", title="Mangystau",),
                    TableColumn(field="c8", title="Nur-Sultan",),
                    TableColumn(field="c9", title="Pavlodar",),
                    TableColumn(field="c10", title="Qaragandy",),
                    TableColumn(field="c11", title="Qostanai",),
                    TableColumn(field="c12", title="Qyzylorda",),
                    TableColumn(field="c13", title="East Kazakhstan",),
                    TableColumn(field="c14", title="Shymkent",),
                    TableColumn(field="c15", title="North Kazakhstan",),
                    TableColumn(field="c16", title="Turkistan",),]

        self.sourceT = ColumnDataSource(self.data1)
        self.data_tableT = DataTable(source=self.sourceT, columns=columns, width=1750, height=500, sortable = False)

        # select start date - calendar
        self.datepicker = DatePicker(title="Starting date of simulation", min_date=datetime(2015,11,1), value=datetime.today())
        self.datepicker.on_change('value',self.get_date)

        # place the widgets on the layout

        sliders_1 = column(self.init_exposed, self.sus_to_exp_slider, self.param_qr_slider, self.param_sir)
        sliders_2 = column(self.param_hosp_capacity, self.param_gamma_mor1, self.param_gamma_mor2, self.param_gamma_im)
        sliders_0 = column(self.param_eps_exp, self.param_eps_qua, self.param_eps_sev)

        sliders = row(sliders_1, dumdiv3ss, sliders_2, dumdiv3, sliders_0)

        sliders_3 = row(self.param_t_exp, self.param_t_inf, self.param_sim_len,self.datepicker,)
        text2 = Div(text="""<h1 style='color:black'>   issai.nu.edu.kz/episim </h1>""", width = 500, height = 100)
        text_footer_1 = Div(text="""<h3 style='color:green'> Developed by ISSAI Researchers : Askat Kuzdeuov, Daulet Baimukashev, Bauyrzhan Ibragimov, Aknur Karabay, Almas Mirzakhmetov, Mukhamet Nurpeiissov and Huseyin Atakan Varol </h3>""", width = 1500, height = 10)
        text_footer_2 = Div(text="""<h3 style='color:red'> Disclaimer : This simulator is a research tool. The simulation results will show general trends based on entered parameters and initial conditions  </h3>""", width = 1500, height = 10)
        text_footer = column(text_footer_1, text_footer_2)
        text = column(self.text1, text2)

        draw_map_js = CustomJS(code=""" uStates.draw("#statesvg", currRegionData, tooltipHtml); """)
        run_button.js_on_click(draw_map_js)

        layout_t = row(save_button_result, text_save, load_button)
        buttons = row(reset_button,run_button, layout_t)

        reg1 = row(self.text2, region_selection)

        buttons = column(buttons, reg1)

        params =  column(sliders, self.text3, sliders_3, self.text5)

        sliders_4 = column(self.param_tr_scale, self.param_tr_leakage)
        check_table = row(column(div_cb1,self.checkbox_group1), column(div_cb2,self.checkbox_group2), column(div_cb3,self.checkbox_group3), sliders_4)
        check_trans = row(self.data_tableT)

        ###
        dummy_div = Div(text=""" """, height=25);
        dummy_div11 = Div(text=""" """, height=5);
        layout = column(self.pAll, buttons)
        layout = column (layout, dummy_div11, params, check_table)

        layout = column (layout, check_trans, self.text4)

        layout = column (layout)
        layout = column (layout,self.text4)     # text_footer

        self.doc.title = 'ISSAI Covid-19 Simulator'
        self.doc.add_root(layout)
Example #17
0
    df = df.iloc[s_:e_]
    source = ColumnDataSource(df)
    return source

def update_data():
    t = ticker_input.value
    s = start.value
    e = end.value
    src = stocks_data(t, s, e)
    source.data.update(src.data)
    price.y_range.start = min(src.data['Close'].min(), src.data['MA_50'].min(), src.data['MA_200'].min())
    price.y_range.end = max(src.data['Close'].max(), src.data['MA_50'].max(), src.data['MA_200'].max())
    price.extra_y_ranges['Volume'].start = src.data['Volume'].min()
    price.extra_y_ranges['Volume'].end = src.data['Volume'].max()

ticker_input = TextInput(value='GE', title='Company Symbol: ')
button = Button(label='Show', button_type='success')

start = DatePicker(title='Start Date: ', value=date.today()-timedelta(weeks=13), min_date=date(2010, 1, 1), max_date=date.today(), width=375)
end = DatePicker(title='End Date: ', value=date.today(), min_date=date(2010, 1, 1), max_date=date.today(), width=375)
source = stocks_data(ticker_input.value, start.value, end.value)

tool_bar = 'crosshair, reset, save'
minimum = min(source.data['Close'].min(), source.data['MA_50'].min(), source.data['MA_200'].min())
maximum = max(source.data['Close'].max(), source.data['MA_50'].max(), source.data['MA_200'].max())

price = figure(plot_height=400, plot_width=750, title="Stock Price", tools=tool_bar, x_axis_type='datetime', x_axis_label = 'Date', y_axis_label = 'Adjusted Close Price ($)')
# First Axis for Close price
price.line('Date', 'Close', source=source, legend_label='Close', color='black') # Close
price.line('Date', 'MA_50', source=source, legend_label='MA(50)', color='blue') # MA_50
price.line('Date', 'MA_200', source=source, legend_label='MA(200)', color='pink') # MA_200
Example #18
0
x = np.linspace(0, 4 * np.pi, N)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))

# Set up plot
plot = figure(plot_height=400,
              plot_width=400,
              title="my sine wave",
              tools="crosshair,pan,reset,save,wheel_zoom",
              x_range=[0, 4 * np.pi],
              y_range=[-2.5, 2.5])

plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

# Set up widgets
text = TextInput(title="title", value='my sine wave')
offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1)
amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0, step=0.1)
phase = Slider(title="phase", value=0.0, start=0.0, end=2 * np.pi)
freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1, step=0.1)


# Set up callbacks
def update_title(attrname, old, new):
    plot.title.text = text.value


text.on_change('value', update_title)


def update_data(attrname, old, new):
def generate_gui(tsne, cut_extracellular_data, all_extra_spike_times, time_axis, cluster_info_file,
                 use_existing_cluster, autocor_bin_number, sampling_freq, prb_file=None, k4=False, verbose=False):

    if k4:
        tsne_figure_size = [1000, 800]
        tsne_min_border_left = 50
        spike_figure_size = [500, 500]
        hist_figure_size = [500, 500]
        heatmap_plot_size = [200, 800]
        clusters_table_size = [400, 300]
        layout_size = [1500, 1400]
        slider_size = [300, 100]
        user_info_size = [700, 80]
    else:
        tsne_figure_size = [850, 600]
        tsne_min_border_left = 10
        spike_figure_size = [450, 300]
        hist_figure_size = [450, 300]
        heatmap_plot_size = [200, 800]
        clusters_table_size = [400, 400]
        layout_size = [1200, 800]
        slider_size = [270, 80]
        user_info_size = [450, 80]
    # Plots ------------------------------
    # scatter plot
    global non_selected_points_alpha
    global selected_points_size
    global non_selected_points_size
    global update_old_selected_switch
    global previously_selected_spike_indices

    tsne_fig_tools = "pan,wheel_zoom,box_zoom,box_select,lasso_select,tap,resize,reset,save"
    tsne_figure = figure(tools=tsne_fig_tools, plot_width=tsne_figure_size[0], plot_height=tsne_figure_size[1],
                         title='T-sne', min_border=10, min_border_left=tsne_min_border_left, webgl=True)

    tsne_source = ColumnDataSource({'tsne-x': tsne[0], 'tsne-y': tsne[1]})

    tsne_selected_points_glyph = Circle(x='tsne-x', y='tsne-y', size=selected_points_size,
                                        line_alpha=0, fill_alpha=1, fill_color='red')
    tsne_nonselected_points_glyph = Circle(x='tsne-x', y='tsne-y', size=non_selected_points_size,
                                           line_alpha=0, fill_alpha=non_selected_points_alpha, fill_color='blue')
    tsne_invisible_points_glyph = Circle(x='tsne-x', y='tsne-y', size=selected_points_size, line_alpha=0, fill_alpha=0)

    tsne_nonselected_glyph_renderer = tsne_figure.add_glyph(tsne_source, tsne_nonselected_points_glyph,
                                                            selection_glyph=tsne_invisible_points_glyph,
                                                            nonselection_glyph=tsne_nonselected_points_glyph,
                                                            name='tsne_nonselected_glyph_renderer')
        # note: the invisible glyph is required to be able to change the size of the selected points, since the
        # use of selection_glyph is usefull only for colors and alphas
    tsne_invinsible_glyph_renderer = tsne_figure.add_glyph(tsne_source, tsne_invisible_points_glyph,
                                                           selection_glyph=tsne_selected_points_glyph,
                                                           nonselection_glyph=tsne_invisible_points_glyph,
                                                           name='tsne_invinsible_glyph_renderer')


    tsne_figure.select(BoxSelectTool).select_every_mousemove = False
    tsne_figure.select(LassoSelectTool).select_every_mousemove = False


    def on_tsne_data_update(attr, old, new):
        global previously_selected_spike_indices
        global currently_selected_spike_indices
        global non_selected_points_alpha
        global non_selected_points_size
        global selected_points_size
        global checkbox_find_clusters_of_selected_points

        previously_selected_spike_indices = np.array(old['1d']['indices'])
        currently_selected_spike_indices = np.array(new['1d']['indices'])
        num_of_selected_spikes = len(currently_selected_spike_indices)

        if num_of_selected_spikes > 0:
            if verbose:
                print('Num of selected spikes = ' + str(num_of_selected_spikes))

            # update t-sne plot
            tsne_invisible_points_glyph.size = selected_points_size
            tsne_nonselected_points_glyph.size = non_selected_points_size
            tsne_nonselected_points_glyph.fill_alpha = non_selected_points_alpha

            # update spike plot
            avg_x = np.mean(cut_extracellular_data[:, :, currently_selected_spike_indices], axis=2)
            spike_mline_plot.data_source.data['ys'] = avg_x.tolist()
            print('Finished avg spike plot')

            # update autocorelogram
            diffs, norm = crosscorrelate_spike_trains(all_extra_spike_times[currently_selected_spike_indices].astype(np.int64),
                                                      all_extra_spike_times[currently_selected_spike_indices].astype(np.int64), lag=1500)
            hist, edges = np.histogram(diffs, bins=autocor_bin_number)
            hist_plot.data_source.data["top"] = hist
            hist_plot.data_source.data["left"] = edges[:-1] / sampling_freq
            hist_plot.data_source.data["right"] = edges[1:] / sampling_freq
            print('finished autocorelogram')

            # update heatmap
            if prb_file is not None:
                print('Doing heatmap')
                data = cut_extracellular_data[:, :, currently_selected_spike_indices]
                final_image, (x_size, y_size) = spike_heatmap.create_heatmap(data, prb_file, rotate_90=True,
                                                                             flip_ud=True, flip_lr=False)
                new_image_data = dict(image=[final_image], x=[0], y=[0], dw=[x_size], dh=[y_size])
                heatmap_data_source.data.update(new_image_data)
                print('Finished heatmap')

    tsne_source.on_change('selected', on_tsne_data_update)

    # spike plot
    spike_fig_tools = 'pan,wheel_zoom,box_zoom,reset,save'
    spike_figure = figure(toolbar_location='below', plot_width=spike_figure_size[0], plot_height=spike_figure_size[1],
                          tools=spike_fig_tools, title='Spike average', min_border=10, webgl=True, toolbar_sticky=False)

    num_of_channels = cut_extracellular_data.shape[0]
    num_of_time_points = cut_extracellular_data.shape[1]
    xs = np.repeat(np.expand_dims(time_axis, axis=0), repeats=num_of_channels, axis=0).tolist()
    ys = np.ones((num_of_channels, num_of_time_points)).tolist()
    spike_mline_plot = spike_figure.multi_line(xs=xs, ys=ys)

    # autocorelogram plot
    hist, edges = np.histogram([], bins=autocor_bin_number)
    hist_fig_tools = 'pan,wheel_zoom,box_zoom,save,reset'

    hist_figure = figure(toolbar_location='below', plot_width=hist_figure_size[0], plot_height=hist_figure_size[1],
                         tools=hist_fig_tools, title='Autocorrelogram', min_border=10, webgl=True, toolbar_sticky=False)
    hist_plot = hist_figure.quad(bottom=0, left=edges[:-1], right=edges[1:], top=hist, color="#3A5785", alpha=0.5,
                                 line_color="#3A5785")
    # heatmap plot
    heatmap_plot = figure(toolbar_location='right', plot_width=1, plot_height=heatmap_plot_size[1],
                          x_range=(0, 1), y_range=(0, 1), title='Probe heatmap',
                          toolbar_sticky=False)
    if prb_file is not None:
        data = np.zeros(cut_extracellular_data.shape)
        final_image, (x_size, y_size) = spike_heatmap.create_heatmap(data, prb_file, rotate_90=True,
                                                                     flip_ud=True, flip_lr=False)
        final_image[:, :, ] = 4294967295  # The int32 for the int8 255 (white)
        plot_width = max(heatmap_plot_size[0], int(heatmap_plot_size[1] * y_size / x_size))
        heatmap_plot = figure(toolbar_location='right', plot_width=plot_width, plot_height=heatmap_plot_size[1],
                              x_range=(0, x_size), y_range=(0, y_size), title='Probe heatmap',
                              toolbar_sticky=False)

        heatmap_data_source = ColumnDataSource(data=dict(image=[final_image], x=[0], y=[0], dw=[x_size], dh=[y_size]))
        heatmap_renderer = heatmap_plot.image_rgba(source=heatmap_data_source, image='image', x='x', y='y',
                                                   dw='dw', dh='dh', dilate=False)
        heatmap_plot.axis.visible = None
        heatmap_plot.xgrid.grid_line_color = None
        heatmap_plot.ygrid.grid_line_color = None
    # ---------------------------------------
    # --------------- CONTROLS --------------
    # Texts and Tables
    # the clusters DataTable
    if use_existing_cluster:
        cluster_info = load_cluster_info(cluster_info_file)
    else:
        cluster_info = create_new_cluster_info_file(cluster_info_file, len(tsne))
    cluster_info_data_source = ColumnDataSource(cluster_info)
    clusters_columns = [TableColumn(field='Cluster', title='Clusters'),
                        TableColumn(field='Num_of_Spikes', title='Number of Spikes')]
    clusters_table = DataTable(source=cluster_info_data_source, columns=clusters_columns, selectable=True,
                               editable=False, width=clusters_table_size[0], height=clusters_table_size[1],
                               scroll_to_selection=True)

    def on_select_cluster_info_table(attr, old, new):
        global selected_cluster_names
        cluster_info = load_cluster_info(cluster_info_file)
        indices = list(chain.from_iterable(cluster_info.iloc[new['1d']['indices']].Spike_Indices.tolist()))
        selected_cluster_names = list(cluster_info.index[new['1d']['indices']])
        old = new = tsne_source.selected
        tsne_source.selected['1d']['indices'] = indices
        tsne_source.trigger('selected', old, new)
        user_info_edit.value = 'Selected clusters = ' + ', '.join(selected_cluster_names)

    cluster_info_data_source.on_change('selected', on_select_cluster_info_table)

    def update_data_table():
        cluster_info_data_source = ColumnDataSource(load_cluster_info(cluster_info_file))
        cluster_info_data_source.on_change('selected', on_select_cluster_info_table)
        clusters_table.source = cluster_info_data_source
        options = list(cluster_info_data_source.data['Cluster'])
        options.insert(0, 'No cluster selected')
        select_cluster_to_move_points_to.options = options

    # cluster TextBox that adds cluster to the DataTable
    new_cluster_name_edit = TextInput(value='give the new cluster a name',
                                      title='Put selected points into a new cluster')

    def on_text_edit_new_cluster_name(attr, old, new):
        global currently_selected_spike_indices
        global clusters_of_all_spikes

        new_cluster_name = new_cluster_name_edit.value

        spike_indices_to_delete_from_existing_clusters = {}
        for spike_index in currently_selected_spike_indices:
            if clusters_of_all_spikes[spike_index] != -1:
                cluster_index = clusters_of_all_spikes[spike_index]
                if cluster_index not in spike_indices_to_delete_from_existing_clusters:
                    spike_indices_to_delete_from_existing_clusters[cluster_index] = [spike_index]
                else:
                    spike_indices_to_delete_from_existing_clusters[cluster_index].append(spike_index)
        cluster_info = load_cluster_info(cluster_info_file)
        for cluster_index in spike_indices_to_delete_from_existing_clusters.keys():
            cluster_name = cluster_info.iloc[cluster_index].name
            remove_spikes_from_cluster(cluster_info_file, cluster_name,
                                       spike_indices_to_delete_from_existing_clusters[cluster_index], unassign=False)

        add_cluster_to_cluster_info(cluster_info_file, new_cluster_name, currently_selected_spike_indices)

        update_data_table()

    new_cluster_name_edit.on_change('value', on_text_edit_new_cluster_name)

    # user information Text
    user_info_edit = TextInput(value='', title='User information',
                               width=user_info_size[0], height=user_info_size[1])

    # Buttons ------------------------
    # show all clusters Button
    button_show_all_clusters = Toggle(label='Show all clusters', button_type='primary')

    def on_button_show_all_clusters(state, *args):
        global tsne_clusters_scatter_plot

        if state:
            cluster_info = load_cluster_info(cluster_info_file)
            num_of_clusters = cluster_info.shape[0]
            indices_list_of_lists = cluster_info['Spike_Indices'].tolist()
            indices = [item for sublist in indices_list_of_lists for item in sublist]
            cluster_indices = np.arange(num_of_clusters)

            if verbose:
                print('Showing all clusters in colors... wait for it...')

            colors = []
            for c in cluster_indices:
                r = np.random.random(size=1) * 255
                g = np.random.random(size=1) * 255
                for i in np.arange(len(indices_list_of_lists[c])):
                    colors.append("#%02x%02x%02x" % (int(r), int(g), 50))

            first_time = True
            for renderer in tsne_figure.renderers:
                if renderer.name == 'tsne_all_clusters_glyph_renderer':
                    renderer.data_source.data['fill_color'] = renderer.data_source.data['line_color'] = colors
                    renderer.glyph.fill_color = 'fill_color'
                    renderer.glyph.line_color = 'line_color'
                    first_time = False
                    break
            if first_time:
                tsne_clusters_scatter_plot = tsne_figure.scatter(tsne[0][indices], tsne[1][indices], size=1,
                                                                 color=colors, alpha=1,
                                                                 name='tsne_all_clusters_glyph_renderer')
            tsne_clusters_scatter_plot.visible = True
            button_show_all_clusters.label = 'Hide all clusters'
        else:
            if verbose:
                print('Hiding clusters')
            button_show_all_clusters.update()
            tsne_clusters_scatter_plot.visible = False
            button_show_all_clusters.label = 'Show all clusters'

    button_show_all_clusters.on_click(on_button_show_all_clusters)


    # select the clusters that the selected points belong to Button
    # (that will then drive the selection of these spikes on t-sne through the update of the clusters_table source)
    button_show_clusters_of_selected_points = Button(label='Show clusters of selected points')

    def on_button_show_clusters_change():
        print('Hello')
        global clusters_of_all_spikes
        currently_selected_spike_indices = tsne_source.selected['1d']['indices']
        cluster_info = load_cluster_info(cluster_info_file)
        clusters_selected = []
        new_indices_to_select = []
        update_data_table()
        for spike_index in currently_selected_spike_indices:
            if clusters_of_all_spikes[spike_index] not in clusters_selected:
                clusters_selected.append(clusters_of_all_spikes[spike_index])
                indices_in_cluster = cluster_info.iloc[clusters_of_all_spikes[spike_index]].Spike_Indices
                new_indices_to_select.append(indices_in_cluster)
        if len(new_indices_to_select) > 0:
            old = clusters_table.source.selected
            clusters_table.source.selected['1d']['indices'] = clusters_selected
            new = clusters_table.source.selected
            clusters_table.source.trigger('selected', old, new)
            for c in np.arange(len(clusters_selected)):
                clusters_selected[c] = cluster_info.index[clusters_selected[c]]


    button_show_clusters_of_selected_points.on_click(on_button_show_clusters_change)

    # merge clusters Button
    button_merge_clusters_of_selected_points = Button(label='Merge clusters of selected points')

    def on_button_merge_clusters_change():
        global clusters_of_all_spikes
        currently_selected_spike_indices = tsne_source.selected['1d']['indices']
        cluster_info = load_cluster_info(cluster_info_file)
        clusters_selected = []
        for spike_index in currently_selected_spike_indices:
            if clusters_of_all_spikes[spike_index] not in clusters_selected:
                clusters_selected.append(clusters_of_all_spikes[spike_index])
        if len(clusters_selected) > 0:
            clusters_selected = np.sort(clusters_selected)
            clusters_selected_names = []
            for cluster_index in clusters_selected:
                clusters_selected_names.append(cluster_info.iloc[cluster_index].name)
            cluster_name = clusters_selected_names[0]
            add_cluster_to_cluster_info(cluster_info_file, cluster_name, currently_selected_spike_indices)
            i = 0
            for c in np.arange(1, len(clusters_selected)):
                cluster_info = remove_cluster_from_cluster_info(cluster_info_file,
                                                                cluster_info.iloc[clusters_selected[c] - i].name,
                                                                unassign=False)
                i = i + 1 # Every time you remove a cluster the original index of the remaining clusters drops by one

            update_data_table()
            user_info_edit.value = 'Clusters '+ ', '.join(clusters_selected_names) + ' merged to cluster ' + cluster_name

    button_merge_clusters_of_selected_points.on_click(on_button_merge_clusters_change)

    # delete cluster Button
    button_delete_cluster = Button(label='Delete selected cluster(s)')

    def on_button_delete_cluster():
        global selected_cluster_names
        for cluster_name in selected_cluster_names:
            remove_cluster_from_cluster_info(cluster_info_file, cluster_name)
        user_info_edit.value = 'Deleted clusters: ' + ', '.join(selected_cluster_names)
        update_data_table()

    button_delete_cluster.on_click(on_button_delete_cluster)

    # select cluster to move selected points to Select
    select_cluster_to_move_points_to = Select(title="Assign selected points to cluster:", value="No cluster selected")

    options = list(cluster_info_data_source.data['Cluster'])
    options.insert(0, 'No cluster selected')
    select_cluster_to_move_points_to.options = options


    def move_selected_points_to_cluster(attr, old, new):
        global currently_selected_spike_indices
        if len(currently_selected_spike_indices) > 0 and new is not 'No cluster selected':
            remove_spikes_from_all_clusters(cluster_info_file, currently_selected_spike_indices)
            add_spikes_to_cluster(cluster_info_file, new, currently_selected_spike_indices)
            update_data_table()
            select_cluster_to_move_points_to.value = 'No cluster selected'
            user_info_edit.value = 'Selected clusters = ' + new

    select_cluster_to_move_points_to.on_change('value', move_selected_points_to_cluster)


    # undo selection button
    undo_selected_points_button = Button(label='Undo last selection')

    def on_button_undo_selection():
        global previously_selected_spike_indices
        tsne_source.selected['1d']['indices'] = previously_selected_spike_indices
        old = new = tsne_source.selected
        tsne_source.trigger('selected', old, new)

    undo_selected_points_button.on_click(on_button_undo_selection)

    # Sliders -------------------
    # use the fake data trick to call the callback only when the mouse is released (mouseup only works for CustomJS)

    # change visibility of non selected points Slider
    slider_non_selected_visibility = Slider(start=0, end=1, value=0.2, step=.02, callback_policy='mouseup',
                                            title='Alpha of not selected points',
                                            width=slider_size[0], height=slider_size[1])

    def on_slider_change_non_selected_visibility(attrname, old, new):
        global non_selected_points_alpha
        if len(source_fake_nsv.data['value']) > 0:
            non_selected_points_alpha = source_fake_nsv.data['value'][0]
            old = new = tsne_source.selected
            tsne_source.trigger('selected', old, new)

    source_fake_nsv = ColumnDataSource(data=dict(value=[]))
    source_fake_nsv.on_change('data', on_slider_change_non_selected_visibility)

    slider_non_selected_visibility.callback = CustomJS(args=dict(source=source_fake_nsv),
                                                       code="""
                                                            source.data = { value: [cb_obj.value] }
                                                            """)

    # change size of non selected points Slider
    slider_non_selected_size = Slider(start=0.5, end=10, value=2, step=0.5, callback_policy='mouseup',
                                      title='Size of not selected points',
                                      width=slider_size[0], height=slider_size[1])

    def on_slider_change_non_selected_size(attrname, old, new):
        global non_selected_points_size
        if len(source_fake_nss.data['value']) > 0:
            non_selected_points_size = source_fake_nss.data['value'][0]
            old = new = tsne_source.selected
            tsne_source.trigger('selected', old, new)

    source_fake_nss = ColumnDataSource(data=dict(value=[]))
    source_fake_nss.on_change('data', on_slider_change_non_selected_size)

    slider_non_selected_size.callback = CustomJS(args=dict(source=source_fake_nss),
                                                 code="""
                                                      source.data = { value: [cb_obj.value] }
                                                      """)

    # change size of selected points Slider
    slider_selected_size = Slider(start=0.5, end=10, value=2, step=0.5, callback_policy='mouseup',
                                  title='Size of selected points',
                                  width=slider_size[0], height=slider_size[1])

    def on_slider_change_selected_size(attrname, old, new):
        global selected_points_size
        if len(source_fake_ss.data['value']) > 0:
            selected_points_size = source_fake_ss.data['value'][0]
            old = new = tsne_source.selected
            tsne_source.trigger('selected', old, new)

    source_fake_ss = ColumnDataSource(data=dict(value=[]))
    source_fake_ss.on_change('data', on_slider_change_selected_size)

    slider_selected_size.callback = CustomJS(args=dict(source=source_fake_ss),
                                             code="""
                                                  source.data = { value: [cb_obj.value] }
                                                  """)

    # -------------------------------------------

    # Layout and session setup ------------------
    # align and make layout
    spike_figure.min_border_top = 50
    spike_figure.min_border_right = 10
    hist_figure.min_border_top = 50
    hist_figure.min_border_left = 10
    tsne_figure.min_border_right = 50

    if k4:
        lay = row(column(tsne_figure,
                         row(slider_non_selected_visibility, slider_non_selected_size, slider_selected_size),
                         row(spike_figure, hist_figure),
                         user_info_edit),
                 column(clusters_table,
                        button_show_clusters_of_selected_points,
                        button_merge_clusters_of_selected_points,
                        button_delete_cluster,
                        select_cluster_to_move_points_to,
                        new_cluster_name_edit,
                        button_show_all_clusters,
                        undo_selected_points_button,
                        heatmap_plot))
    else:
        lay = row(column(tsne_figure,
                         row(spike_figure, hist_figure)),
                  column(row(heatmap_plot, column(slider_non_selected_visibility,
                                                  slider_non_selected_size,
                                                  slider_selected_size)),
                         user_info_edit),
                  column(clusters_table,
                         button_show_clusters_of_selected_points,
                         button_merge_clusters_of_selected_points,
                         button_delete_cluster,
                         select_cluster_to_move_points_to,
                         new_cluster_name_edit,
                         button_show_all_clusters,
                         undo_selected_points_button))


    session = push_session(curdoc())
    session.show(lay)  # open the document in a browser
    session.loop_until_closed()  # run forever, requires stopping the interpreter in order to stop :)
Example #20
0
    def __init__(self):

        ### Methods
        self.args = Settings()
        self.index = None
        self.data_getter = None
        self.filter = None
        self._data = None
        self._model_type = None
        self._model_dir = self.args.models_path + 'unique_object/'
        self.controls = {}
        self.scene_plotter = ScenePlotter(self._set_head_selection)

        ### initialization of the interface

        ## Model type selector

        def update_select_net():
            if self._model_dir is not None:
                file_list = [fn for fn in os.listdir(self._model_dir) if os.path.isfile(os.path.join(self._model_dir, fn))]
                file_list.sort(key=lambda fn: os.stat(os.path.join(self._model_dir, fn)).st_mtime, reverse=True)
                file_list = [os.path.splitext(fn)[0] for fn in file_list]
                self.controls['net'].options = file_list
                # print(self._model_dir)
                # print('file_list')
                # print(file_list)
                if len(file_list) > 0:
                    self.controls['net'].value = file_list[0]
                else:
                    self.controls['net'].value = None

        def update_model_type():
            if self.controls['multi_mono_object'].active == 0:
                self._model_type = 'mono'
                self._model_dir = self.args.models_path + 'unique_object/'
            elif self.controls['multi_mono_object'].active == 1:
                self._model_type = 'multi_obj'
                self._model_dir = self.args.models_path + 'multi_objects/'
            elif self.controls['multi_mono_object'].active == 2:
                self._model_type = 'multi_pred'
                self._model_dir = self.args.models_path + 'multi_pred/'
            model_types = ['CV', 'CA', 'Bicycle', 'CV_LSTM', 'CA_LSTM', 'Bicycle_LSTM',  'nn_attention']
            existing_types = [type for type in model_types if os.path.isdir(self._model_dir + type)]
            self.controls['model_sub_type'].options = existing_types
            print('existing types')
            print(existing_types)
            if len(existing_types) > 0 and not self.controls['model_sub_type'].value in existing_types:
                self.controls['model_sub_type'].value = existing_types[0]
                return
            set_model_sub_type()
            update_select_net()

        def set_model_sub_type():
            if self.controls['model_sub_type'].value is not None:
                self._model_dir = self._model_dir + self.controls['model_sub_type'].value + '/'
                self.args.model_type = self.controls['model_sub_type'].value
            else:
                self._model_dir = None

        def update_multi_mono_object(attr, old, new):
            update_model_type()
            print(self._model_dir)
            self._set_data_getter()
            print('___')

        multi_mono_object = RadioButtonGroup(labels=["Mono-object", "Multi-objects", "Multi-pred"], active=1)
        self.controls['multi_mono_object'] = multi_mono_object
        multi_mono_object.on_change('active', update_multi_mono_object)

        ## Model sub type selector
        model_types = ['CV', 'CA', 'Bicycle', 'CV_LSTM', 'CA_LSTM', 'Bicycle_LSTM',  'nn_attention']
        model_sub_type = Select(title='Select model type:', value=model_types[3], options=model_types)
        self.controls['model_sub_type'] = model_sub_type
        model_sub_type.on_change('value', lambda att, old, new: update_model_type())

        ## Model selector
        select = Select(title="Select parameter file:", value=None, options=[])
        self.controls['net'] = select
        select.on_change('value', lambda att, old, new: self._set_data_getter())

        ## Select dataset to use
        dataset_list = ['Argoverse', 'Fusion', 'NGSIM']
        select = Select(title='Dataset:', value=dataset_list[0], options=dataset_list)
        self.controls['dataset'] = select
        select.on_change('value', lambda att, old, new: self._set_data_getter(change_index=True))

        ## Set what to draw
        checkbox_group = CheckboxGroup(
            labels=['Draw lanes', 'Draw history', 'Draw true future', 'Draw forecast', 'Draw forecast covariance'],
            active=[0, 1, 2, 3, 4])
        self.controls['check_box'] = checkbox_group
        checkbox_group.on_change('active',
                                 lambda att, old, new: (self._update_cov(), self._update_lanes(), self._update_path()))

        ## Set the number of pred
        n_pred = Slider(start=1, end=6, step=1, value=1, title='Number of prediction hypothesis')
        self.controls['n_pred'] = n_pred
        n_pred.on_change('value', lambda att, old, new: (self._update_cov(), self._update_path()))

        ## Sequence ID input
        text_input = TextInput(title="Sequence ID to plot:", value="Random")
        self.controls['sequence_id'] = text_input

        ## Head selection input
        multi_select_head = MultiSelect(title='Attention head multiple selection:',
                                             value=[], options=[])
        self.controls['Head_selection'] = multi_select_head
        multi_select_head.on_change('value', self.scene_plotter.set_active_heads)

        ## Refresh all sample
        button = Button(label="Refresh", button_type="success")
        self.controls['refresh'] = button
        button.on_click(
            lambda event: (self._set_index(), self._set_data()))
        # button.js_on_click(CustomJS(args=dict(p=self.image), code="""p.reset.emit()"""))

        update_multi_mono_object(None, None, None)

        ## Set the interface layout
        inputs = column(*(self.controls.values()), width=320, height=1000)
        inputs.sizing_mode = "fixed"
        lay = layout([[inputs, self.scene_plotter.get_image()]], sizing_mode="scale_both")
        curdoc().add_root(lay)

        self.scene_plotter._tap_on_veh('selected', [], [0])
Example #21
0
        mapZip=fdLoc['Postcode']
        ))

# Creating the google map options. Make sure you have imported it
map_opt = GMapOptions(lat=40.730610, lng=-73.935242, map_type="roadmap", zoom=11)

# creating gmap object. Make sure you have imported it 
# first part is Google API Key. I will keep this key active for one week so that you can practice bokeh
# charts for class purposed. After one week, I will be deactivating this key. 
# Please remember to not use this key for purposes other than the class work.
myMap = gmap("AIzaSyAD0M7aeSE_Rn01x6W5BTsy8hO45s7VDoI", map_opt, title="NYC")
myMap.width=800
myMap.height=600

# Adding the TEXTINPUT widget to allow user to enter zipcode value
zipcode = TextInput(value="", title="Enter 5 digit Zipcode...", width=100)

# Adding circle glyph with lat lng values of FDNY locations. 
myMap.circle(y='mapLat', x='mapLng', source=cdsFDLoc, size=10)

# Adding the hover tool with name and address of FDNY location
mapHover = HoverTool(tooltips=[("Name","@mapName"),("Addr","@mapAddr")])
myMap.add_tools(mapHover)

# Capturing the event change for TEXTINPUT widget
zipcode.on_change('value', updateMap)

# Adding chart and widgets to Curdoc's root so that they are rendered in the browser
curdoc().add_root(column(zipcode, myMap))

Example #22
0
def create_html(distances, text_list, file_path, num_similar_shown):

    source = ColumnDataSource(data=dict(
        ids=range(len(text_list)),
        distances=distances.tolist(),
        text=text_list,
        display_text=text_list,
        display_ids=range(len(text_list)),
    ))

    display_source = ColumnDataSource(data=dict(
        closest_text=[""] * num_similar_shown,
        closest_dist=[0] * num_similar_shown,
    ))

    columns = [
        TableColumn(field="display_text", title="Text"),
    ]

    closest_columns = [
        TableColumn(field="closest_text",
                    title="Closest examples",
                    width=510,
                    editor=TextEditor()),
        TableColumn(field="closest_dist",
                    title="Distance",
                    width=10,
                    editor=TextEditor()),
    ]

    str_search_input = TextInput(value="", title="Search feedback")

    callback = CustomJS(args=dict(source=source,
                                  display_source=display_source,
                                  search_text=str_search_input),
                        code="""
        const data = source.data;
        // ##################
        // First search
        // ##################
        const search_text_str = search_text.value.toLowerCase();
        const display_texts = [];
        const display_ids = [];
        data['text'].map(function(e, i) {
            const text_val = data['text'][i];
            const text_id = data['ids'][i];
            if (text_val.toLowerCase().includes(search_text_str)){
                display_texts.push(text_val);
                display_ids.push(text_id);
            }
        });
        data['display_text'] = display_texts;
        data['display_ids'] = display_ids;
        source.change.emit();
        // ##################
        // Then show selected
        // ##################
        const num_similar_shown = data['num_similar'];
        if(source.selected.indices.length >= 1){
            const selected_table_idx = source.selected.indices[0];
            if (selected_table_idx >= data['display_ids'].length){
                console.log("Empty cell selected")
            }else{
                const selected_idx = data['display_ids'][selected_table_idx];
                console.log(selected_idx)
                const texts = data['text'];
                const list_of_dist = data['distances'];
                const selected_dist = list_of_dist[selected_idx];
                function indexOfNMin(arr, n) {
                    if (arr.length < n) {
                        return [arr, [...Array(arr.length).keys()]];
                    }
                    var min_arr = arr.slice(0, n);
                    var min_idxs = [...Array(n).keys()];
                    for (var i = n; i < arr.length; i++) {
                        const max_selected = Math.max(...min_arr);
                        if (arr[i] < max_selected) {
                            var idx_max = min_arr.indexOf(max_selected);
                            min_arr[idx_max] = arr[i];
                            min_idxs[idx_max] = i;
                        }
                    }
                    return [min_arr, min_idxs];
                }
                const closest_dist_values = indexOfNMin(selected_dist, """ +
                        str(num_similar_shown) + """);
                const closest_dist =  [].slice.call(closest_dist_values[0]);
                const closest_dist_idx = closest_dist_values[1];
                function sortWithIndices(inputArray) {
                    const toSort = inputArray.slice();
                    for (var i = 0; i < toSort.length; i++) {
                        toSort[i] = [toSort[i], i];
                    }
                    toSort.sort(function(left, right) {
                        return left[0] < right[0] ? -1 : 1;
                    });
                    var sortIndices = [];
                    for (var j = 0; j < toSort.length; j++) {
                        sortIndices.push(toSort[j][1]);
                    }
                    return sortIndices;
                }
                const sorted_closest_dist_idx_idx = sortWithIndices(closest_dist);
                const sorted_closest_dist_idx = sorted_closest_dist_idx_idx.map(i => closest_dist_idx[i]);
                const closest_texts = sorted_closest_dist_idx.map(i => texts[i]);
                const display_data = display_source.data;
                display_data['closest_text'] = closest_texts;
                display_data['closest_dist'] = closest_dist.sort(function(a, b){return a - b}).map(i => i.toFixed(3));
                display_source.change.emit();
            }
        }
    """)

    source.selected.js_on_change('indices', callback)
    str_search_input.js_on_change('value', callback)

    data_table = DataTable(source=source,
                           columns=columns,
                           width=600,
                           height=420,
                           selectable=True)
    closest_data_table = DataTable(source=display_source,
                                   columns=closest_columns,
                                   fit_columns=False,
                                   height=800,
                                   editable=True)

    title = Div(text="""<b>Feedback Finder</b><br><br>
    The left hand side will allow you to look at ALL feedback for this given app.<br><br>
    Click on a row to see the closest matches to this row (and the embedding distance of each match) on the right side.<br><br>
    Try using the search bar to narrow down feedback that you want to find. <br>For example, if you are looking for performance related bug reports, then try typing 'lag' into the search bar, and hitting enter.<br> Then click on one of the results on the left to see other related bits of feedback that do not explicitly mention the word 'lag' on the right.<br><br>""",
                width=1000,
                height=180)

    layout = column(
        title,
        row(column(str_search_input, data_table), column(closest_data_table)))

    # output to static HTML file
    output_file(f"{file_path}.html")

    save(layout)
Example #23
0
    def setup_widgets(self):

        # Initial selection

        # Test/var/backend combination (we select all first elements at init)
        if not self.data.empty:
            self.tests = self.data\
                .index.get_level_values("test").drop_duplicates().tolist()

            self.vars = self.data.loc[self.tests[0]]\
                .index.get_level_values("variable").drop_duplicates().tolist()

            self.backends = self.data.loc[self.tests[0], self.vars[0]]\
                .index.get_level_values("vfc_backend").drop_duplicates().tolist()

        else:
            self.tests = ["None"]
            self.vars = ["None"]
            self.backends = ["None"]

        # Custom JS callback that will be used client side to filter selections
        filter_callback_js = """
        selector.options = options.filter(e => e.includes(cb_obj.value));
        """

        # Test selector widget

        # Number of runs to display
        # The dict structure allows us to get int value from the display string
        # in O(1)
        self.n_runs_dict = {
            "Last 3 runs": 3,
            "Last 5 runs": 5,
            "Last 10 runs": 10,
            "All runs": 0
        }

        # Contains all options strings
        n_runs_display = list(self.n_runs_dict.keys())

        # Will be used when updating plots (contains actual number to diplay)
        self.current_n_runs = self.n_runs_dict[n_runs_display[1]]

        # Selector widget
        self.widgets["select_deterministic_test"] = Select(
            name="select_deterministic_test",
            title="Test :",
            value=self.tests[0],
            options=self.tests)
        self.doc.add_root(self.widgets["select_deterministic_test"])
        self.widgets["select_deterministic_test"].on_change(
            "value", self.update_test)
        self.widgets["select_deterministic_test"].on_change(
            "options", self.update_test)

        # Filter widget
        self.widgets["deterministic_test_filter"] = TextInput(
            name="deterministic_test_filter", title="Tests filter:")
        self.widgets["deterministic_test_filter"].js_on_change(
            "value",
            CustomJS(args=dict(
                options=self.tests,
                selector=self.widgets["select_deterministic_test"]),
                     code=filter_callback_js))
        self.doc.add_root(self.widgets["deterministic_test_filter"])

        # Number of runs to display

        self.widgets["select_n_deterministic_runs"] = Select(
            name="select_n_deterministic_runs",
            title="Display :",
            value=n_runs_display[1],
            options=n_runs_display)
        self.doc.add_root(self.widgets["select_n_deterministic_runs"])
        self.widgets["select_n_deterministic_runs"].on_change(
            "value", self.update_n_runs)

        # Variable selector widget

        self.widgets["select_deterministic_var"] = Select(
            name="select_deterministic_var",
            title="Variable :",
            value=self.vars[0],
            options=self.vars)
        self.doc.add_root(self.widgets["select_deterministic_var"])
        self.widgets["select_deterministic_var"].on_change(
            "value", self.update_var)
        self.widgets["select_deterministic_var"].on_change(
            "options", self.update_var)

        # Backend selector widget

        self.widgets["select_deterministic_backend"] = Select(
            name="select_deterministic_backend",
            title="Verificarlo backend (deterministic) :",
            value=self.backends[0],
            options=self.backends)
        self.doc.add_root(self.widgets["select_deterministic_backend"])
        self.widgets["select_deterministic_backend"].on_change(
            "value", self.update_backend)

        # Outliers filtering checkbox

        self.widgets["outliers_filtering_deterministic"] = CheckboxGroup(
            name="outliers_filtering_deterministic",
            labels=["Filter outliers"],
            active=[])
        self.doc.add_root(self.widgets["outliers_filtering_deterministic"])
        self.widgets["outliers_filtering_deterministic"]\
            .on_change("active", self.update_outliers_filtering)
Example #24
0
    def __init__(self):
        self.pull_thread = None
        self.pulling = False
        if not reactor.running:
            self.start_reactor_thread()

        self.text = PreText(text='Restart the process to clear all events.',
                            width=500,
                            height=100)
        self.ip_text_input = TextInput(value='localhost')
        self.port_text_input = TextInput(value='8001')
        self.single_pull_button = Button(label="single pull", width=150)
        self.single_pull_button.on_click(
            partial(self.single_pull, self.ip_text_input,
                    self.port_text_input))
        self.pulling_button = Button(label="start/stop pulling", width=150)
        self.pulling_button.on_click(
            partial(self.toggle_pulling, self.ip_text_input,
                    self.port_text_input))

        self.all_events = {}
        self.member_id_to_x = {}
        self.n_nodes = 10

        plot = figure(
            plot_height=800,
            plot_width=1800,
            y_range=(0, 30),
            x_range=(0, self.n_nodes - 1),
            tools=[
                PanTool(),  # dimensions=[Dimensions.height, Dimensions.width]
                HoverTool(
                    tooltips=[('id', '@id'), (
                        'from',
                        '@from'), ('height', '@height'), (
                            'witness',
                            '@witness'), ('round', '@round'), ('data',
                                                               '@data'),
                              ('famous',
                               '@famous'), ('round_received',
                                            '@round_received'),
                              ('consensus_timestamp', '@consensus_timestamp')])
            ])
        plot.add_tools(WheelZoomTool())

        plot.xgrid.grid_line_color = None
        plot.xaxis.minor_tick_line_color = None
        plot.ygrid.grid_line_color = None
        plot.yaxis.minor_tick_line_color = None

        self.index_counter = 0
        self.links_src = ColumnDataSource(data={
            'x0': [],
            'y0': [],
            'x1': [],
            'y1': [],
            'width': []
        })

        self.links_rend = plot.segment(color='#777777',
                                       x0='x0',
                                       y0='y0',
                                       x1='x1',
                                       y1='y1',
                                       source=self.links_src,
                                       line_width='width')

        self.events_src = ColumnDataSource(
            data={
                'x': [],
                'y': [],
                'round_color': [],
                'line_alpha': [],
                'round': [],
                'id': [],
                'payload': [],
                'time': [],
                'from': [],
                'height': [],
                'data': [],
                'witness': [],
                'famous': [],
                'round_received': [],
                'consensus_timestamp': []
            })

        self.events_rend = plot.circle(x='x',
                                       y='y',
                                       size=20,
                                       color='round_color',
                                       line_alpha='line_alpha',
                                       source=self.events_src,
                                       line_width=5)

        control_row = row(self.text, self.ip_text_input, self.port_text_input,
                          self.single_pull_button, self.pulling_button)
        main_row = column([control_row, plot])
        doc.add_root(main_row)
Example #25
0
global source
global level
global current_rpm
global sack
global hist

base = dnf.Base()
conf = base.conf
conf.cachedir = '/tmp/my_cache_dir'
# this seems to take time at first launch. Needed to have list of non installed packages
base.read_all_repos()
sack = base.fill_sack(load_system_repo=False)
level = 2
hist = []
current_rpm = "rpm"
field = TextInput(value=current_rpm, title="Select package: ")
level_slider = Slider(start=1, end=5, step=1, value=level, title="Depth")
back_bt = Button(label="Back")


def add_requires(ref, depth, G):
    '''
    Add all kind od dependencies
    '''
    global level
    global sack
    process = [(ref.requires, "blue"), (ref.recommends, "green"),
               (ref.suggests, "orange"), (ref.supplements, "braun")]
    for query, link_color in process:
        previous = ""
        i = 1
Example #26
0
    bar_chart_source.data = wrangle_data_for_bar_chart(user_inputs)
    stacked_chart_positive_source.data = wrangle_pos_data_for_stacked_chart(
        user_inputs)
    stacked_chart_negative_source.data = wrangle_neg_data_for_stacked_chart(
        user_inputs)


pop_slider = Slider(start=-100,
                    end=100,
                    value=0,
                    step=10,
                    title="% Change in Population")
pop_slider.on_change("value", callback)

urban_pop_percent_text_input = TextInput(
    value=str(round(URBAN_POP_PERCENT, 1)),
    title="% of Population Living in Urban Municipalities",
)
urban_pop_percent_text_input.on_change("value", callback)

suburban_pop_percent_text_input = TextInput(
    value=str(round(SUBURBAN_POP_PERCENT, 1)),
    title="% of Population Living in Suburban Municipalities",
)
suburban_pop_percent_text_input.on_change("value", callback)

rural_pop_percent_text_input = TextInput(
    value=str(round(RURAL_POP_PERCENT, 1)),
    title="% of Population Living in Rural Municipalities",
)
rural_pop_percent_text_input.on_change("value", callback)
Example #27
0
def createCurrBloodInputFields():
    insText = TextInput(title="Insulin(uIU/mL)                       ",
                        value=str(initialBlood[0]))
    tgText = TextInput(title="Triglycerides(mmol/L)                 ",
                       value=str(initialBlood[1]))
    hdl_cText = TextInput(title="HDL_C(mmol/L)                         ",
                          value=str(initialBlood[2]))
    ldl_cText = TextInput(title="LDL_C(mmol/L)                         ",
                          value=str(initialBlood[3]))
    ureaText = TextInput(title="Urea(mmol/L)                          ",
                         value=str(initialBlood[4]))
    uaText = TextInput(title="Uric_acid(mg/dL)                      ",
                       value=str(initialBlood[5]))
    apo_aText = TextInput(title="APO-A(g/L)                            ",
                          value=str(initialBlood[6]))
    lp_aText = TextInput(title="Lipoprotein-A (mg/dL)                  ",
                         value=str(initialBlood[7]))
    hs_crpText = TextInput(title="High-sensitivity_CRP(mg/dL)           ",
                           value=str(initialBlood[8]))
    creText = TextInput(title="Creatinine(μMol/L)                    ",
                        value=str(initialBlood[9]))
    apo_bText = TextInput(title="APO-B(mg/dL)                          ",
                          value=str(initialBlood[10]))
    mgText = TextInput(title="Magnesium(mmol/L)                     ",
                       value=str(initialBlood[11]))
    fetText = TextInput(title="Ferritin(ng/ML)                       ",
                        value=str(initialBlood[12]))
    hgbText = TextInput(title="Hemoglobin(g/L)                       ",
                        value=str(initialBlood[13]))
    wbcText = TextInput(title="White_blood_cell_count(10^9)          ",
                        value=str(initialBlood[14]))
    rbcText = TextInput(title="Red_blood_cell_count(10^9)            ",
                        value=str(initialBlood[15]))
    pltText = TextInput(title="Platelet_count(10^9)                  ",
                        value=str(initialBlood[16]))
    glu_fieldText = TextInput(title="Glucose_field(mmol/L)                 ",
                              value=str(initialBlood[17]))
    hba1cText = TextInput(title="HbA1c(mmol/L)                         ",
                          value=str(initialBlood[18]))
    tpText = TextInput(title="Total_protein(g/L)                    ",
                       value=str(initialBlood[19]))
    albText = TextInput(title="Albumin(g/L)                          ",
                        value=str(initialBlood[20]))
    glucoseText = TextInput(title="Glucose(mmol/L)                       ",
                            value=str(initialBlood[21]))
    tcText = TextInput(title="Total_cholesterol(g/L)                ",
                       value=str(initialBlood[22]))
    altText = TextInput(title="Alanine_aminotransferase(U/L)         ",
                        value=str(initialBlood[23]))
    trfText = TextInput(title="Transferrin(g/L)                      ",
                        value=str(initialBlood[24]))
    trf_rText = TextInput(title="Transferrin_receptor(mg/L)            ",
                          value=str(initialBlood[25]))

    clearButton = Button(label='Clear my test')

    currBloodInputFields = [
        insText, tgText, hdl_cText, ldl_cText, ureaText, uaText, apo_aText,
        lp_aText, hs_crpText, creText, apo_bText, mgText, fetText, hgbText,
        wbcText, rbcText, pltText, glu_fieldText, hba1cText, tpText, albText,
        glucoseText, tcText, altText, trfText, trf_rText
    ]

    r = 0
    tmp0 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               currBloodInputFields[r * 3 + 2])
    r = 1
    tmp1 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               currBloodInputFields[r * 3 + 2])
    r = 2
    tmp2 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               currBloodInputFields[r * 3 + 2])
    r = 3
    tmp3 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               currBloodInputFields[r * 3 + 2])
    r = 4
    tmp4 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               currBloodInputFields[r * 3 + 2])
    r = 5
    tmp5 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               currBloodInputFields[r * 3 + 2])
    r = 6
    tmp6 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               currBloodInputFields[r * 3 + 2])
    r = 7
    tmp7 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               currBloodInputFields[r * 3 + 2])
    r = 8
    tmp8 = row(currBloodInputFields[r * 3], currBloodInputFields[r * 3 + 1],
               clearButton)
    currBloodInputLayout = column(tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6,
                                  tmp7, tmp8)

    return currBloodInputFields, currBloodInputLayout, insText, tgText, ureaText, uaText, apo_aText, lp_aText, hs_crpText, creText, hdl_cText, ldl_cText, apo_bText, mgText, fetText, hgbText, wbcText, rbcText, pltText, glu_fieldText, hba1cText, tpText, albText, glucoseText, tcText, altText, trfText, trf_rText, clearButton
Example #28
0
def create(palm):
    doc = curdoc()

    # Calibration averaged waveforms per photon energy
    waveform_plot = Plot(
        title=Title(text="eTOF calibration waveforms"),
        x_range=DataRange1d(),
        y_range=DataRange1d(),
        plot_height=760,
        plot_width=PLOT_CANVAS_WIDTH,
        toolbar_location="right",
    )

    # ---- tools
    waveform_plot.toolbar.logo = None
    waveform_plot_hovertool = HoverTool(
        tooltips=[("energy, eV", "@en"), ("eTOF bin", "$x{0.}")])

    waveform_plot.add_tools(PanTool(), BoxZoomTool(), WheelZoomTool(),
                            ResetTool(), waveform_plot_hovertool)

    # ---- axes
    waveform_plot.add_layout(LinearAxis(axis_label="eTOF time bin"),
                             place="below")
    waveform_plot.add_layout(LinearAxis(axis_label="Intensity",
                                        major_label_orientation="vertical"),
                             place="left")

    # ---- grid lines
    waveform_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
    waveform_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))

    # ---- multiline glyphs
    waveform_ref_source = ColumnDataSource(dict(xs=[], ys=[], en=[]))
    waveform_ref_multiline = waveform_plot.add_glyph(
        waveform_ref_source, MultiLine(xs="xs", ys="ys", line_color="blue"))

    waveform_str_source = ColumnDataSource(dict(xs=[], ys=[], en=[]))
    waveform_str_multiline = waveform_plot.add_glyph(
        waveform_str_source, MultiLine(xs="xs", ys="ys", line_color="red"))

    # ---- legend
    waveform_plot.add_layout(
        Legend(items=[(
            "reference",
            [waveform_ref_multiline]), ("streaked",
                                        [waveform_str_multiline])]))
    waveform_plot.legend.click_policy = "hide"

    # ---- vertical spans
    photon_peak_ref_span = Span(location=0,
                                dimension="height",
                                line_dash="dashed",
                                line_color="blue")
    photon_peak_str_span = Span(location=0,
                                dimension="height",
                                line_dash="dashed",
                                line_color="red")
    waveform_plot.add_layout(photon_peak_ref_span)
    waveform_plot.add_layout(photon_peak_str_span)

    # Calibration fit plot
    fit_plot = Plot(
        title=Title(text="eTOF calibration fit"),
        x_range=DataRange1d(),
        y_range=DataRange1d(),
        plot_height=PLOT_CANVAS_HEIGHT,
        plot_width=PLOT_CANVAS_WIDTH,
        toolbar_location="right",
    )

    # ---- tools
    fit_plot.toolbar.logo = None
    fit_plot.add_tools(PanTool(), BoxZoomTool(), WheelZoomTool(), ResetTool())

    # ---- axes
    fit_plot.add_layout(LinearAxis(axis_label="Photoelectron peak shift"),
                        place="below")
    fit_plot.add_layout(LinearAxis(axis_label="Photon energy, eV",
                                   major_label_orientation="vertical"),
                        place="left")

    # ---- grid lines
    fit_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
    fit_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))

    # ---- circle glyphs
    fit_ref_circle_source = ColumnDataSource(dict(x=[], y=[]))
    fit_ref_circle = fit_plot.add_glyph(
        fit_ref_circle_source, Circle(x="x", y="y", line_color="blue"))
    fit_str_circle_source = ColumnDataSource(dict(x=[], y=[]))
    fit_str_circle = fit_plot.add_glyph(fit_str_circle_source,
                                        Circle(x="x", y="y", line_color="red"))

    # ---- line glyphs
    fit_ref_line_source = ColumnDataSource(dict(x=[], y=[]))
    fit_ref_line = fit_plot.add_glyph(fit_ref_line_source,
                                      Line(x="x", y="y", line_color="blue"))
    fit_str_line_source = ColumnDataSource(dict(x=[], y=[]))
    fit_str_line = fit_plot.add_glyph(fit_str_line_source,
                                      Line(x="x", y="y", line_color="red"))

    # ---- legend
    fit_plot.add_layout(
        Legend(items=[
            ("reference", [fit_ref_circle, fit_ref_line]),
            ("streaked", [fit_str_circle, fit_str_line]),
        ]))
    fit_plot.legend.click_policy = "hide"

    # Calibration results datatables
    def datatable_ref_source_callback(_attr, _old_value, new_value):
        for en, ps, use in zip(new_value["energy"], new_value["peak_pos_ref"],
                               new_value["use_in_fit"]):
            palm.etofs["0"].calib_data.loc[
                en, "calib_tpeak"] = ps if ps != "NaN" else np.nan
            palm.etofs["0"].calib_data.loc[en, "use_in_fit"] = use

        calib_res = {}
        for etof_key in palm.etofs:
            calib_res[etof_key] = palm.etofs[etof_key].fit_calibration_curve()
        update_calibration_plot(calib_res)

    datatable_ref_source = ColumnDataSource(
        dict(energy=["", "", ""],
             peak_pos_ref=["", "", ""],
             use_in_fit=[True, True, True]))
    datatable_ref_source.on_change("data", datatable_ref_source_callback)

    datatable_ref = DataTable(
        source=datatable_ref_source,
        columns=[
            TableColumn(field="energy",
                        title="Photon Energy, eV",
                        editor=IntEditor()),
            TableColumn(field="peak_pos_ref",
                        title="Reference Peak",
                        editor=IntEditor()),
            TableColumn(field="use_in_fit",
                        title=" ",
                        editor=CheckboxEditor(),
                        width=80),
        ],
        index_position=None,
        editable=True,
        height=300,
        width=250,
    )

    def datatable_str_source_callback(_attr, _old_value, new_value):
        for en, ps, use in zip(new_value["energy"], new_value["peak_pos_str"],
                               new_value["use_in_fit"]):
            palm.etofs["1"].calib_data.loc[
                en, "calib_tpeak"] = ps if ps != "NaN" else np.nan
            palm.etofs["1"].calib_data.loc[en, "use_in_fit"] = use

        calib_res = {}
        for etof_key in palm.etofs:
            calib_res[etof_key] = palm.etofs[etof_key].fit_calibration_curve()
        update_calibration_plot(calib_res)

    datatable_str_source = ColumnDataSource(
        dict(energy=["", "", ""],
             peak_pos_str=["", "", ""],
             use_in_fit=[True, True, True]))
    datatable_str_source.on_change("data", datatable_str_source_callback)

    datatable_str = DataTable(
        source=datatable_str_source,
        columns=[
            TableColumn(field="energy",
                        title="Photon Energy, eV",
                        editor=IntEditor()),
            TableColumn(field="peak_pos_str",
                        title="Streaked Peak",
                        editor=IntEditor()),
            TableColumn(field="use_in_fit",
                        title=" ",
                        editor=CheckboxEditor(),
                        width=80),
        ],
        index_position=None,
        editable=True,
        height=350,
        width=250,
    )

    # eTOF calibration folder path text input
    def path_textinput_callback(_attr, _old_value, _new_value):
        path_periodic_update()
        update_load_dropdown_menu()

    path_textinput = TextInput(title="eTOF calibration path:",
                               value=os.path.join(os.path.expanduser("~")),
                               width=510)
    path_textinput.on_change("value", path_textinput_callback)

    # eTOF calibration eco scans dropdown
    def scans_dropdown_callback(_attr, _old_value, new_value):
        scans_dropdown.label = new_value

    scans_dropdown = Dropdown(label="ECO scans",
                              button_type="default",
                              menu=[])
    scans_dropdown.on_change("value", scans_dropdown_callback)

    # ---- etof scans periodic update
    def path_periodic_update():
        new_menu = []
        if os.path.isdir(path_textinput.value):
            for entry in os.scandir(path_textinput.value):
                if entry.is_file() and entry.name.endswith(".json"):
                    new_menu.append((entry.name, entry.name))
        scans_dropdown.menu = sorted(new_menu, reverse=True)

    doc.add_periodic_callback(path_periodic_update, 5000)

    # Calibrate button
    def calibrate_button_callback():
        try:
            palm.calibrate_etof_eco(eco_scan_filename=os.path.join(
                path_textinput.value, scans_dropdown.value))
        except Exception:
            palm.calibrate_etof(folder_name=path_textinput.value)

        datatable_ref_source.data.update(
            energy=palm.etofs["0"].calib_data.index.tolist(),
            peak_pos_ref=palm.etofs["0"].calib_data["calib_tpeak"].tolist(),
            use_in_fit=palm.etofs["0"].calib_data["use_in_fit"].tolist(),
        )

        datatable_str_source.data.update(
            energy=palm.etofs["0"].calib_data.index.tolist(),
            peak_pos_str=palm.etofs["1"].calib_data["calib_tpeak"].tolist(),
            use_in_fit=palm.etofs["1"].calib_data["use_in_fit"].tolist(),
        )

    def update_calibration_plot(calib_res):
        etof_ref = palm.etofs["0"]
        etof_str = palm.etofs["1"]

        shift_val = 0
        etof_ref_wf_shifted = []
        etof_str_wf_shifted = []
        for wf_ref, wf_str in zip(etof_ref.calib_data["waveform"],
                                  etof_str.calib_data["waveform"]):
            shift_val -= max(wf_ref.max(), wf_str.max())
            etof_ref_wf_shifted.append(wf_ref + shift_val)
            etof_str_wf_shifted.append(wf_str + shift_val)

        waveform_ref_source.data.update(
            xs=len(etof_ref.calib_data) *
            [list(range(etof_ref.internal_time_bins))],
            ys=etof_ref_wf_shifted,
            en=etof_ref.calib_data.index.tolist(),
        )

        waveform_str_source.data.update(
            xs=len(etof_str.calib_data) *
            [list(range(etof_str.internal_time_bins))],
            ys=etof_str_wf_shifted,
            en=etof_str.calib_data.index.tolist(),
        )

        photon_peak_ref_span.location = etof_ref.calib_t0
        photon_peak_str_span.location = etof_str.calib_t0

        def plot_fit(time, calib_a, calib_b):
            time_fit = np.linspace(np.nanmin(time), np.nanmax(time), 100)
            en_fit = (calib_a / time_fit)**2 + calib_b
            return time_fit, en_fit

        def update_plot(calib_results, circle, line):
            (a, c), x, y = calib_results
            x_fit, y_fit = plot_fit(x, a, c)
            circle.data.update(x=x, y=y)
            line.data.update(x=x_fit, y=y_fit)

        update_plot(calib_res["0"], fit_ref_circle_source, fit_ref_line_source)
        update_plot(calib_res["1"], fit_str_circle_source, fit_str_line_source)

        calib_const_div.text = f"""
        a_str = {etof_str.calib_a:.2f}<br>
        b_str = {etof_str.calib_b:.2f}<br>
        <br>
        a_ref = {etof_ref.calib_a:.2f}<br>
        b_ref = {etof_ref.calib_b:.2f}
        """

    calibrate_button = Button(label="Calibrate eTOF",
                              button_type="default",
                              width=250)
    calibrate_button.on_click(calibrate_button_callback)

    # Photon peak noise threshold value text input
    def phot_peak_noise_thr_spinner_callback(_attr, old_value, new_value):
        if new_value > 0:
            for etof in palm.etofs.values():
                etof.photon_peak_noise_thr = new_value
        else:
            phot_peak_noise_thr_spinner.value = old_value

    phot_peak_noise_thr_spinner = Spinner(title="Photon peak noise threshold:",
                                          value=1,
                                          step=0.1)
    phot_peak_noise_thr_spinner.on_change(
        "value", phot_peak_noise_thr_spinner_callback)

    # Electron peak noise threshold value text input
    def el_peak_noise_thr_spinner_callback(_attr, old_value, new_value):
        if new_value > 0:
            for etof in palm.etofs.values():
                etof.electron_peak_noise_thr = new_value
        else:
            el_peak_noise_thr_spinner.value = old_value

    el_peak_noise_thr_spinner = Spinner(title="Electron peak noise threshold:",
                                        value=10,
                                        step=0.1)
    el_peak_noise_thr_spinner.on_change("value",
                                        el_peak_noise_thr_spinner_callback)

    # Save calibration button
    def save_button_callback():
        palm.save_etof_calib(path=path_textinput.value)
        update_load_dropdown_menu()

    save_button = Button(label="Save", button_type="default", width=250)
    save_button.on_click(save_button_callback)

    # Load calibration button
    def load_dropdown_callback(_attr, _old_value, new_value):
        if new_value:
            palm.load_etof_calib(os.path.join(path_textinput.value, new_value))

            datatable_ref_source.data.update(
                energy=palm.etofs["0"].calib_data.index.tolist(),
                peak_pos_ref=palm.etofs["0"].calib_data["calib_tpeak"].tolist(
                ),
                use_in_fit=palm.etofs["0"].calib_data["use_in_fit"].tolist(),
            )

            datatable_str_source.data.update(
                energy=palm.etofs["0"].calib_data.index.tolist(),
                peak_pos_str=palm.etofs["1"].calib_data["calib_tpeak"].tolist(
                ),
                use_in_fit=palm.etofs["1"].calib_data["use_in_fit"].tolist(),
            )

            # Drop selection, so that this callback can be triggered again on the same dropdown menu
            # item from the user perspective
            load_dropdown.value = ""

    def update_load_dropdown_menu():
        new_menu = []
        calib_file_ext = ".palm_etof"
        if os.path.isdir(path_textinput.value):
            for entry in os.scandir(path_textinput.value):
                if entry.is_file() and entry.name.endswith((calib_file_ext)):
                    new_menu.append(
                        (entry.name[:-len(calib_file_ext)], entry.name))
            load_dropdown.button_type = "default"
            load_dropdown.menu = sorted(new_menu, reverse=True)
        else:
            load_dropdown.button_type = "danger"
            load_dropdown.menu = new_menu

    doc.add_next_tick_callback(update_load_dropdown_menu)
    doc.add_periodic_callback(update_load_dropdown_menu, 5000)

    load_dropdown = Dropdown(label="Load", menu=[], width=250)
    load_dropdown.on_change("value", load_dropdown_callback)

    # eTOF fitting equation
    fit_eq_div = Div(
        text="""Fitting equation:<br><br><img src="/palm/static/5euwuy.gif">"""
    )

    # Calibration constants
    calib_const_div = Div(text=f"""
        a_str = {0}<br>
        b_str = {0}<br>
        <br>
        a_ref = {0}<br>
        b_ref = {0}
        """)

    # assemble
    tab_layout = column(
        row(
            column(waveform_plot, fit_plot),
            Spacer(width=30),
            column(
                path_textinput,
                scans_dropdown,
                calibrate_button,
                phot_peak_noise_thr_spinner,
                el_peak_noise_thr_spinner,
                row(save_button, load_dropdown),
                row(datatable_ref, datatable_str),
                calib_const_div,
                fit_eq_div,
            ),
        ))

    return Panel(child=tab_layout, title="eTOF Calibration")
Example #29
0
max_year = Slider(title="End Year released",
                  start=1940,
                  end=2014,
                  value=2014,
                  step=1)
oscars = Slider(title="Minimum number of Oscar wins",
                start=0,
                end=4,
                value=0,
                step=1)
boxoffice = Slider(title="Dollars at Box Office (millions)",
                   start=0,
                   end=800,
                   value=0,
                   step=1)
director = TextInput(title="Director name contains")
cast = TextInput(title="Cast names contains")
x_axis = Select(title="X Axis",
                options=sorted(axis_map.keys()),
                value="Tomato Meter")
y_axis = Select(title="Y Axis",
                options=sorted(axis_map.keys()),
                value="Number of Reviews")

# Create Column Data Source that will be used by the plot
source = ColumnDataSource(
    data=dict(x=[], y=[], color=[], title=[], year=[], revenue=[], alpha=[]))

TOOLTIPS = [("Title", "@title"), ("Year", "@year"), ("$", "@revenue")]

p = figure(plot_height=600,
Example #30
0
# Panel for displaying messages to users
message_panel = Div()

# Get an existing file for default values
init_time, init_date, init_model = find_initial()

# Initialization time selector
init_options = ['00Z', '06Z', '12Z', '18Z']
wrf_init_time_select = Select(title="Initialized Time",
                              value=init_time,
                              options=init_options)
wrf_init_time_select.on_change('value', update_datasource)

# Initialization date selector
initial_date = date.today().strftime("%Y/%m/%d")
wrf_init_date_input = TextInput(title="Initialized Date",
                                value=init_date)
wrf_init_date_input.on_change('value', validate_date)

# Model select widget
wrf_model_options = ['GFS', 'NAM']
wrf_model_select = Select(title="Model",
                          value=init_model,
                          options=wrf_model_options)
wrf_model_select.on_change('value', update_datasource)

# Time Select widget
time_slider = Slider(start=0, end=1,
                     value=0, step=1,
                     title="Timestep")
time_slider.on_change('value', update_datasource)