def add_row(self): i = self.rows dropdown = bokeh.models.Dropdown( menu=self.menu, label="Model/observation", width=230, ) autolabel(dropdown) dropdown.on_change('value', self.on_dropdown(i)) group = bokeh.models.CheckboxButtonGroup(labels=self.labels, width=50) group.on_change("active", self.on_radio(i)) self.groups.append(group) row = bokeh.layouts.row(dropdown, group) self.column.children.insert(-1, row)
def __init__(self, color_mapper, name, number): self.name = name self.number = number self.palettes = bokeh.palettes.all_palettes self.color_mapper = color_mapper names = sorted(self.palettes.keys()) menu = list(zip(names, names)) self.names = bokeh.models.Dropdown(label="Palettes", value=self.name, menu=menu) autolabel(self.names) self.names.on_change("value", self.on_name) numbers = sorted(self.palettes[self.name].keys()) self.numbers = bokeh.models.Dropdown(label="N", value=str(self.number), menu=self.numbers_menu(numbers)) autolabel(self.numbers) self.numbers.on_change("value", self.on_number) self.reverse = False self.checkbox = bokeh.models.CheckboxButtonGroup(labels=["Reverse"], active=[]) self.checkbox.on_change("active", self.on_reverse) # Invisible color settings self.invisible_on = False self.low = 0 self.invisible_checkbox = bokeh.models.CheckboxButtonGroup( labels=["Invisible"], active=[]) self.invisible_checkbox.on_change("active", self.on_invisible_checkbox) self.invisible_input = bokeh.models.TextInput(title="Low:", value="0") self.invisible_input.on_change("value", self.on_invisible_input) self.layout = bokeh.layouts.column(self.names, self.numbers, self.checkbox, self.invisible_checkbox, self.invisible_input)
def __init__(self, steps): self.steps = steps self.labels = ["T{:+}".format(int(s)) for s in self.steps] self.plus = bokeh.models.Button(label="+", width=80) self.plus.on_click(self.on_plus) self.minus = bokeh.models.Button(label="-", width=80) self.minus.on_click(self.on_minus) self.dropdown = bokeh.models.Dropdown( label="Time step", menu=list(zip(self.labels, self.labels)), width=80) autolabel(self.dropdown) self.dropdown.on_click(self.on_dropdown) sizing_mode = "fixed" self.layout = bokeh.layouts.row( bokeh.layouts.column(self.minus, width=90, sizing_mode=sizing_mode), bokeh.layouts.column(self.dropdown, width=100, sizing_mode=sizing_mode), bokeh.layouts.column(self.plus, width=90, sizing_mode=sizing_mode), width=300) super().__init__()
def main(): args = parse_args.parse_args() database = db.Database.connect(args.database) with open(args.config_file) as stream: config = parse_args.load_config(stream) # Access latest files data.FILE_DB.sync() # Full screen map lon_range = (0, 30) lat_range = (0, 30) x_range, y_range = geo.web_mercator( lon_range, lat_range) figure = bokeh.plotting.figure( x_range=x_range, y_range=y_range, x_axis_type="mercator", y_axis_type="mercator", active_scroll="wheel_zoom") tile = bokeh.models.WMTSTileSource( url="https://maps.wikimedia.org/osm-intl/{Z}/{X}/{Y}.png", attribution="" ) figures = [figure] for _ in range(2): f = bokeh.plotting.figure( x_range=figure.x_range, y_range=figure.y_range, x_axis_type="mercator", y_axis_type="mercator", active_scroll="wheel_zoom") figures.append(f) for f in figures: f.axis.visible = False f.toolbar.logo = None f.toolbar_location = None f.min_border = 0 f.add_tile(tile) figure_row = bokeh.layouts.row(*figures, sizing_mode="stretch_both") figure_row.children = [figures[0]] # Trick to keep correct sizing modes figure_drop = bokeh.models.Dropdown( label="Figure", menu=[(str(i), str(i)) for i in [1, 2, 3]]) def on_change(attr, old, new): if int(new) == 1: figure_row.children = [ figures[0]] elif int(new) == 2: figure_row.children = [ figures[0], figures[1]] elif int(new) == 3: figure_row.children = [ figures[0], figures[1], figures[2]] figure_drop.on_change("value", on_change) color_mapper = bokeh.models.LinearColorMapper( low=0, high=1, palette=bokeh.palettes.Plasma[256]) for figure in figures: colorbar = bokeh.models.ColorBar( color_mapper=color_mapper, orientation="horizontal", background_fill_alpha=0., location="bottom_center", major_tick_line_color="black", bar_line_color="black") figure.add_layout(colorbar, 'center') for name, pattern in config.patterns: if name not in data.LOADERS: locator = db.Locator( database.connection, directory=args.directory) loader = data.DBLoader(name, pattern, locator) data.add_loader(name, loader) renderers = {} viewers = {} for name, loader in data.LOADERS.items(): if isinstance(loader, rdt.Loader): viewer = rdt.View(loader) elif isinstance(loader, earth_networks.Loader): viewer = earth_networks.View(loader) elif isinstance(loader, data.GPM): viewer = view.GPMView(loader, color_mapper) elif isinstance(loader, satellite.EIDA50): viewer = view.EIDA50(loader, color_mapper) else: viewer = view.UMView(loader, color_mapper) viewers[name] = viewer renderers[name] = [ viewer.add_figure(f) for f in figures] artist = Artist(viewers, renderers) renderers = [] for _, r in artist.renderers.items(): renderers += r image_sources = [] for name, viewer in artist.viewers.items(): if isinstance(viewer, (view.UMView, view.GPMView, view.EIDA50)): image_sources.append(viewer.source) # image_loaders = [] # for name, loader in data.LOADERS.items(): # if isinstance(loader, (data.UMLoader, data.GPM)): # image_loaders.append(loader) # Lakes for figure in figures: add_feature(figure, data.LAKES, color="lightblue") features = [] for figure in figures: features += [ add_feature(figure, data.COASTLINES), add_feature(figure, data.BORDERS)] # Disputed borders for figure in figures: add_feature(figure, data.DISPUTED, color="red") toggle = bokeh.models.CheckboxButtonGroup( labels=["Coastlines"], active=[0], width=135) def on_change(attr, old, new): if len(new) == 1: for feature in features: feature.visible = True else: for feature in features: feature.visible = False toggle.on_change("active", on_change) dropdown = bokeh.models.Dropdown( label="Color", menu=[ ("Black", "black"), ("White", "white")], width=50) autolabel(dropdown) def on_change(attr, old, new): for feature in features: feature.glyph.line_color = new dropdown.on_change("value", on_change) slider = bokeh.models.Slider( start=0, end=1, step=0.1, value=1.0, show_value=False) custom_js = bokeh.models.CustomJS( args=dict(renderers=renderers), code=""" renderers.forEach(function (r) { r.glyph.global_alpha = cb_obj.value }) """) slider.js_on_change("value", custom_js) colors_controls = colors.Controls( color_mapper, "Plasma", 256) mapper_limits = MapperLimits(image_sources, color_mapper) menu = [(n, n) for n in data.FILE_DB.names] for k, _ in config.patterns: menu.append((k, k)) image_controls = images.Controls(menu) def on_change(attr, old, new): if int(new) == 1: image_controls.labels = ["Show"] elif int(new) == 2: image_controls.labels = ["L", "R"] elif int(new) == 3: image_controls.labels = ["L", "C", "R"] figure_drop.on_change("value", on_change) image_controls.subscribe(artist.on_visible) div = bokeh.models.Div(text="", width=10) border_row = bokeh.layouts.row( bokeh.layouts.column(toggle), bokeh.layouts.column(div), bokeh.layouts.column(dropdown)) # Add prototype database controls controls = db.Controls(database, patterns=config.patterns) locator = db.Locator( database.connection, directory=args.directory) text = db.View(text="", locator=locator) controls.subscribe(text.on_state) controls.subscribe(artist.on_state) tabs = bokeh.models.Tabs(tabs=[ bokeh.models.Panel( child=bokeh.layouts.column( bokeh.models.Div(text="Navigate:"), controls.layout, bokeh.models.Div(text="Compare:"), bokeh.layouts.row(figure_drop), image_controls.column, text.div), title="Control" ), bokeh.models.Panel( child=bokeh.layouts.column( border_row, bokeh.layouts.row(slider), colors_controls.layout, bokeh.layouts.row(mapper_limits.low_input), bokeh.layouts.row(mapper_limits.high_input), bokeh.layouts.row(mapper_limits.checkbox), ), title="Settings") ]) # Series sub-figure widget series_figure = bokeh.plotting.figure( plot_width=400, plot_height=200, x_axis_type="datetime", toolbar_location=None, border_fill_alpha=0) series_figure.toolbar.logo = None series_row = bokeh.layouts.row( series_figure, name="series") def place_marker(figure, source): figure.circle( x="x", y="y", color="red", source=source) def cb(event): source.data = { "x": [event.x], "y": [event.y]} return cb marker_source = bokeh.models.ColumnDataSource({ "x": [], "y": []}) series = Series(series_figure) controls.subscribe(series.on_state) for f in figures: f.on_event(bokeh.events.Tap, series.on_tap) f.on_event(bokeh.events.Tap, place_marker(f, marker_source)) # Minimise controls to ease navigation compact_button = bokeh.models.Button( label="Compact") compact_minus = bokeh.models.Button(label="-", width=50) compact_plus = bokeh.models.Button(label="+", width=50) compact_navigation = bokeh.layouts.column( compact_button, bokeh.layouts.row( compact_minus, compact_plus, width=100)) control_root = bokeh.layouts.column( compact_button, tabs, name="controls") display = "large" def on_compact(): nonlocal display if display == "large": control_root.height = 100 control_root.width = 120 compact_button.width = 100 compact_button.label = "Expand" control_root.children = [ compact_navigation] display = "compact" else: control_root.height = 500 control_root.width = 300 compact_button.width = 300 compact_button.label = "Compact" control_root.children = [compact_button, tabs] display = "large" compact_button.on_click(on_compact) document = bokeh.plotting.curdoc() document.title = "FOREST" document.add_root(control_root) document.add_root(series_row) document.add_root(figure_row)