def fullscreen_mode(view): player = view.player player._create_all_widgets() b = player._display() b.layout.width = '400px' b.layout.align_self = 'stretch' bb = GridBox([view, b], layout=Layout(grid_template_columns='70% 30%')) class_id = f'nglview-{uuid4()}' bb.add_class(class_id) btn = Button(description='Fullscreen', icon='fullscreen') def on_click(b): view._execute_js_code(""" var ele = document.getElementsByClassName("%s")[0]; this.stage.viewer.container.style.height = window.screen.height + 'px' console.log(window.innerHeight) this.stage.toggleFullscreen(ele); """ % class_id) btn.on_click(on_click) player.widget_general.children = list( player.widget_general.children) + [btn] return bb
def __init__(self, value): self.taille_ligne = len(value.board.plateau[0]) self.value = value self.items = [] GridBox.__init__(self) self.layout = ipywidgets.Layout(grid_template_columns="repeat(" + str(self.taille_ligne) + ", 50px)", grid_column_gap="1px") self.create()
def generate_analyze_grid(show_imbalance_selectmultiple, show_imbalance_button, correlations_dendogram_button, correlations_matrix_button) -> GridBox: return GridBox( children=[ Label(layout=Layout(width='auto', height='auto'), value='Features to analyze: '), Button(layout=Layout(width='auto', height='auto'), disabled=True, style=ButtonStyle(button_color='white')), Button(layout=Layout(width='auto', height='auto'), disabled=True, style=ButtonStyle(button_color='white')), show_imbalance_selectmultiple, Button(layout=Layout(width='auto', height='auto'), disabled=True, style=ButtonStyle(button_color='white')), Button(layout=Layout(width='auto', height='auto'), disabled=True, style=ButtonStyle(button_color='white')), show_imbalance_button, correlations_dendogram_button, correlations_matrix_button ], layout=Layout( width='auto', grid_template_columns='33% 33% 33%', align_items='center', # grid_template_columns='auto auto auto', # grid_template_rows='auto auto auto', grid_gap='2px 1px'))
def generate_pdp_feature_selection_grid(models: list) -> GridBox: children = [] # Row 1 children.append( Label(layout=Layout(width='auto', height='auto'), value='Feature 1 for ...')) children.append( Label(layout=Layout(width='auto', height='auto'), value='(optional) Feature 2 for ...')) for model in models: # Row 2 -> Row (2 + len(models)) # if you change the description of this widget, # you have to also adjust it in the notebook function call. features = model.features_ohe.copy() features.insert(0, 'None') children.append( Select(description="... " + model.name, options=model.features_ohe, disabled=False)) children.append( Select(description="... " + model.name, options=features, value='None', disabled=False)) return GridBox(children=children, layout=Layout(width='auto', grid_template_columns="50% 50%", grid_template_rows='auto', align_items='center', grid_gap='3px 3px'))
def generate_pdp_grid(models: list) -> GridBox: children = [] # Row 1 children.append( Label(layout=Layout(width='auto', height='auto'), value='Choose a PDP method')) children.append( Label(layout=Layout(width='auto', height='auto'), value='Choose one or more model(s)')) # Row 2 # if you change the description of this widget, # you have to also adjust it in the notebook function call. children.append( Select(description='Type', options=[elem.name for elem in PDPType], disabled=False)) # if you change the description of this widget, # you have to also adjust it in the notebook function call. children.append( SelectMultiple(description='Model(s)', options=[model.name for model in models], disabled=False)) return GridBox(children=children, layout=Layout(width='auto', grid_template_columns="50% 50%", grid_template_rows='auto', align_items='center', grid_gap='3px 3px'))
def _layout_create(self, orientation='vertical'): if orientation == 'vertical': layout = VBox() elif orientation == 'horizontal': layout = HBox() else: assert orientation == 'grid' layout = GridBox() return layout
def generate_local_interpretation_grid(models: list) -> GridBox: children = [] # Row 1 children.append( Label(layout=Layout(width='auto', height='auto'), value='Choose an interpretation method')) children.append( Label(layout=Layout(width='auto', height='auto'), value='Choose one or more model(s)')) # Row 2 # if you change the description of this widget, # you have to also adjust it in the notebook function call. children.append( Select(description='Type', options=[elem.name for elem in LocalInterpreterType], disabled=False)) # if you change the description of this widget, # you have to also adjust it in the notebook function call. children.append( SelectMultiple(description='Model(s)', options=[model.name for model in models], disabled=False)) # Row 3 # if you change the description of this widget, # you have to also adjust it in the notebook function call. children.append( RadioButtons(options=[elem.name for elem in ExampleType], layout={'width': 'max-content'}, description='Example(s) type:', disabled=False)) # if you change the description of this widget, # you have to also adjust it in the notebook function call. children.append( IntSlider( value=1, min=1, max=10, step=1, description='Number of examples:', disabled=False, continuous_update=False, orientation='horizontal', readout=True, readout_format='d', )) return GridBox(children=children, layout=Layout(width='auto', grid_template_columns="50% 50%", grid_template_rows='auto', align_items='center', grid_gap='3px 3px'))
def __init__(self, obj): self.value = obj children = [] for p in get_properties(obj): val = getattr(obj, p.name).__call__() children.append(Label(p.prop_label)) children.append(ExplorableValue(val)) #children.append(Label("?")) super(ExplorerProperties, self).__init__( (GridBox(children, layout=Layout(grid_template_columns='25% 75%')),), layout=Layout(border='1px solid red') )
def _make_widget(self): fig = GridBox(children=[self.voigt_fig, self.abs_fig, self.int_fig, self.source_fig], layout=Layout(width='100%', min_height='600px', height='100%', grid_template_rows='49% 49%', grid_template_columns='49% 49%', grid_gap='0px 0px')) a_slider = FloatSlider(min=-5, max=0., step=0.01, value=self.a, description='lg(a)') opa_cont_slider = FloatSlider(min=0., max=6., step=0.01, value=self.opa_cont, description=r"$\kappa_c / \kappa_{500}$") opa_line_slider = FloatSlider(min=0., max=7., step=0.01, value=self.opa_line, description=r"$\kappa_l / \kappa_{500}$") mu_slider = FloatSlider(min=0.01, max=1., step=0.01, value=self.mu, description=r'$\mu$') xmax_slider = IntSlider(min=1, max=100, step=1, value=self.xmax, description='xmax') source_slider = Dropdown(options=self.SFUNCTIONS.keys(), value=self.source, description='Source Function', style={'description_width': 'initial'}) w = interactive(self._update_plot, a=a_slider, opa_cont=opa_cont_slider, opa_line=opa_line_slider, mu=mu_slider, xmax=xmax_slider, source=source_slider) controls = GridBox(children=[w.children[5], w.children[0], w.children[2], w.children[4], w.children[3], w.children[1]], layout=Layout(min_height='80px', min_width='600px', grid_template_rows='49% 49%', grid_template_columns='31% 31% 31%', grid_gap='10px')) self.widget = GridBox(children=[controls, fig], layout=Layout(grid_template_rows='8% 90%', width='100%', min_height='650px', height='100%', grid_gap='10px'))
def display_frame(evaluation_dataset, sources, chorale, frame, model, models, context=1, context_separate=False, nmf=False): dataset_dir = f'/Users/matan/gdrive/Grad/Thesis/Data/Synthesized/{evaluation_dataset}/' mix = f'{dataset_dir}/mix/chorale_{chorale}_mix.wav' items = [Label(l) for l in ['Name', 'Reference', 'Estimate']] items += [ Label('Mix (context)'), load_audio_frame(mix, frame, context), Label('') ] if context_separate: items += [Label('Mix'), load_audio_frame(mix, frame, 0), Label('')] for source in sources: reference = f'{dataset_dir}/audio_mono/chorale_{chorale}_{source}.wav' multi_source = False if nmf else models.loc[model].multi_source estimate = get_estimate_filename(evaluation_dataset, model, chorale, source, multi_source, nmf) items += [ Label(source + ' (context)'), load_audio_frame(reference, frame, context), load_audio_frame(estimate, frame, context) ] if context_separate: items += [ Label(source), load_audio_frame(reference, frame, 0), load_audio_frame(estimate, frame, 0) ] display( GridBox(items, layout={ 'grid_template_columns': '120px 350px 350px', 'justify-items': 'center' }))
def layout(self) -> GridBox: layout: GridBox = GridBox( [ HBox([ self._placeholder, VBox([HTML("<b>Keyness</b>"), self._keyness]), VBox([HTML("<b>Top count</b>"), self._top_count]), VBox([HTML("<b>Grouping</b>"), self._temporal_key]), VBox([HTML("<b>Kind</b>"), self._kind]), VBox([ self._compute, self._download, ]), VBox([HTML("📌"), self._alert]), self._download_output, ]), ] + ([] if self.simple_display else [self._table]) + ([self._output] if self.simple_display else []), layout=Layout(width='auto'), ) return layout
def display_for_input(self) -> 'OptionsForm': """Displays the widgets to take user inputs.""" from IPython.display import display from ipywidgets import GridBox from ipywidgets import Label from ipywidgets import Layout from ipywidgets import Text widgets = [] for entry in self.entries: text_label = Label(value=entry.label) text_input = entry.input if entry.input else Text( value=entry.default if entry.default else '') text_help = Label(value=entry.help) entry.input = text_input widgets.append(text_label) widgets.append(text_input) widgets.append(text_help) grid = GridBox(widgets, layout=Layout(grid_template_columns='1fr 2fr 6fr')) display(grid) self.display_actions() return self
def create_panel(self): # images button https://fontawesome.com/v4.7.0/icons/ items_layout = Layout( width='80px' ) # override the default width of the button to 'auto' to let the button grow box_layout = Layout(display='flex', flex_flow='column', align_items='stretch', border='solid') self.label_game_status = Label('Подключение к серверу...') self.panel_users = GridBox( children=[], layout=Layout(grid_template_columns="80px 80px 30px")) self.feature_label = Label('Состояния игрока') # панель запуска-остановки-паузы #b_play = Button(description='ИГРА',icon = 'fa-play', layout = items_layout) b_stop = Button(description='СТОП', icon='fa-stop', layout=items_layout) #b_play.on_click(self.client.start) # client.start) b_stop.on_click(self.client.stop) panel = VBox([ HBox([Label('Сервер:'), Label(self.client.server['name'])]), self.label_game_status, HBox([Label('Игрок:'), Label(self.client.user_name), b_stop]), self.feature_label, self.panel_users ], layout=box_layout) return panel
def interact_distributions(): from ipywidgets import FloatSlider, Label, GridBox, interactive, Layout, VBox, \ HBox, Checkbox, IntSlider, Box, Button, widgets fx0 = FloatSlider(value=2, description=" ", min=.5, max=4., step=.2, continuous_update=False, layout=Layout(width='auto', grid_area='vx0')) fy0 = FloatSlider(value=3, description=" ", min=.5, max=4., step=.2, continuous_update=False, layout=Layout(width='auto', grid_area='vy0')) fs0 = FloatSlider(value=1, description=" ", min=.1, max=4., step=.2, continuous_update=False, layout=Layout(width='auto', grid_area='vs0')) fd0 = FloatSlider(value=.9, description=" ", min=-2., max=2., step=.1, continuous_update=False, layout=Layout(width='auto', grid_area='vd0')) fx1 = FloatSlider(value=2, description=" ", min=.5, max=4., step=.2, continuous_update=False, layout=Layout(width='auto', grid_area='vx1')) fy1 = FloatSlider(value=2, description=" ", min=.5, max=4., step=.2, continuous_update=False, layout=Layout(width='auto', grid_area='vy1')) fs1 = FloatSlider(value=1, description=" ", min=.1, max=4., step=.2, continuous_update=False, layout=Layout(width='auto', grid_area='vs1')) fd1 = FloatSlider(value=-.3, description=" ", min=-2., max=2., step=.1, continuous_update=False, layout=Layout(width='auto', grid_area='vd1')) fdummy = FloatSlider(value=2, description=" ", min=1, max=4, step=1) l = lambda s, p, w="auto": Label(s, layout=Layout(width=w, grid_area=p)) bay = Checkbox(value=False, description='show NATURAL frontiers', disabled=False, indent=False, layout=Layout(width="80%")) resample = Button(description="resample data points") from IPython.core.display import clear_output def resample_onclick(_): global do_resample_points do_resample_points = True tmp = fdummy.value fdummy.value = tmp + (1 if tmp < 3 else -1) do_resample_points = False resample.on_click(resample_onclick) w = interactive(display_distributions, x0=fx0, y0=fy0, s0=fs0, d0=fd0, x1=fx1, y1=fy1, s1=fs1, d1=fd1, show_bayesians=bay, dummy=fdummy, continuous_update=False) w.children[-1].layout = Layout(width='auto', grid_area='fig') controls = Box([bay, resample], layout=Layout(grid_area="ctr", display="flex-flow", justify_content="flex-start", flex_flow="column", align_items='flex-start')) gb = GridBox(children=[ fx0, fy0, fs0, fd0, fx1, fy1, fs1, fd1, l("AMERICAN TRILOBYTE", "h0"), l("AFRICAN TRILOBYTE", "h1"), l("size", "lx0"), l("weight", "ly0"), l("spread", "ls0"), l("tilt", "ld0"), l("size", "lx1"), l("weight", "ly1"), l("spread", "ls1"), l("tilt", "ld1"), controls ], layout=Layout( width='100%', grid_template_rows='auto auto auto auto auto auto auto', grid_template_columns='5% 30% 5% 30% 30%', grid_template_areas=''' "h0 h0 h1 h1 ." "lx0 vx0 lx1 vx1 ." "ly0 vy0 ly1 vy1 ctr" "ls0 vs0 ls1 vs1 ctr" "ld0 vd0 ld1 vd1 ctr" "fig fig fig fig fig" ''')) def limit_fd0(*args): fd0.max = fs0.value + fs0.value * 0.5 fd0.min = -fs0.value * 0.5 def limit_fd1(*args): fd1.max = fs1.value + fs1.value * 0.5 fd1.min = -fs1.value * 0.5 fs0.observe(limit_fd0, "value") fd0.observe(limit_fd0, "value") fs1.observe(limit_fd1, "value") fd1.observe(limit_fd1, "value") w.children[0].value = 1 widget1 = VBox([gb, w.children[-1]]) display(widget1) return fx0, fy0, fs0, fd0, fx1, fy1, fs1, fd1
def FlyingCameraNetworkDisplay(): import random import pandas as pd import pickle as pkl import numpy as np import tensorflow as tf import matplotlib.pyplot as plt from random import randrange import random from ipywidgets import interactive, interact, FloatSlider, widgets, VBox, HBox, interactive_output, Layout, Output, GridBox from IPython.display import display, HTML, clear_output, Markdown from scipy.interpolate import UnivariateSpline clear_output() display( Markdown( "## loading...(Might take a minute) Please go back up to read the rest of the instructions" )) #Network layers def hyperspectral(input_, n_o_input, keep_prob, filter_width=1, stride_size=1, relu_alpha=0.2): n_o_strides = int( (n_o_input - filter_width) / stride_size) + 1 #round down Hyper_layer = [] def dense(input_, start, keep_prob, filter_width, stride_size, relu_alpha): nn_input = tf.slice(input_, [0, start], [-1, filter_width]) dropout1 = tf.nn.dropout(nn_input, keep_prob) dense1 = tf.layers.dense(dropout1, 1) relu1 = tf.maximum(relu_alpha * dense1, dense1) return relu1 for step in range(n_o_strides): start = step * stride_size output = dense(input_, start, keep_prob, filter_width, stride_size, relu_alpha) Hyper_layer.append(output) if (n_o_input - filter_width) % stride_size > 0: start = n_o_input - filter_width output = dense(input_, start, keep_prob, filter_width, stride_size, relu_alpha) Hyper_layer.append(output) Hyper_l_stacked = tf.concat(Hyper_layer, 1) return Hyper_l_stacked, n_o_strides def Classifier(input_, n_o_class, n_o_input, keep_prob, relu_alpha=0.2): if n_o_input == 3: is_RGB = True elif n_o_input == 571: is_RGB = False else: raise ValueError('A very specific bad thing happened.' + str(n_o_input)) if is_RGB: dense0 = tf.layers.dense(input_, 3) relu0 = tf.maximum(relu_alpha * dense0, dense0) first_layer_out = tf.nn.dropout(relu0, keep_prob) else: first_layer_out, n_o_input = hyperspectral(input_, n_o_input, keep_prob, filter_width=30, stride_size=1, relu_alpha=0.2) hidden_size = n_o_input * 2 / 3 hidden_nodes = int(hidden_size) + 1 # rounding dense1 = tf.layers.dense(first_layer_out, hidden_nodes) relu1 = tf.maximum(relu_alpha * dense1, dense1) dropout1 = tf.nn.dropout(relu1, keep_prob) class_logits = tf.layers.dense(dropout1, n_o_class) return class_logits def softmax(input_, m_class, n_class, n_o_input, keep_prob, relu_alpha=0.2, sub_scaling=1): n_o_class = m_class + n_class #raw output logits = Classifier(input_, n_o_class, n_o_input, keep_prob, relu_alpha=0.2) subclass_softmax = tf.nn.softmax(logits) #Reduce outputs from 8 subclasses to 2 main classes m_class_logit, n_class_logit = tf.split(logits, [m_class, n_class], 1) m_class_logit1 = tf.reduce_sum(m_class_logit, 1, keepdims=True) n_class_logit1 = tf.reduce_sum(n_class_logit, 1, keepdims=True) main_class_logits = tf.concat([m_class_logit1, n_class_logit1], 1) main_class_softmax = tf.nn.softmax(main_class_logits) return subclass_softmax, main_class_softmax #Defining the training parameters tf.reset_default_graph() n_class = 3 m_class = 5 n_o_class = m_class + n_class epochs = 10 keep_probability = 0.95 sub_scaling = 1 g1 = tf.Graph() with g1.as_default() as g_1: H_keep_prob = tf.placeholder(tf.float32) H_n_o_input = 571 H_input_ = tf.placeholder(tf.float32, [None, H_n_o_input]) H_subclass_softmax, H_main_class_softmax = softmax( H_input_, m_class, n_class, H_n_o_input, H_keep_prob, relu_alpha=0.2, sub_scaling=sub_scaling) #Relectance spectrum g2 = tf.Graph() with g2.as_default() as g_2: R_keep_prob = tf.placeholder(tf.float32) R_n_o_input = 3 R_input_ = tf.placeholder(tf.float32, [None, R_n_o_input]) R_subclass_softmax, R_main_class_softmax = softmax( R_input_, m_class, n_class, R_n_o_input, R_keep_prob, relu_alpha=0.2, sub_scaling=sub_scaling) #Display network result clear_output() display(Markdown("## View Classification")) display( Markdown( " Scroll back up to Step 2 if instruction is needed." )) RGB = [] hyperspectral = [] box1 = Output(layout=Layout(width='100%', border='1px solid #E0E0E0', padding='0px 0px 0px 20px', fill="black")) box2 = Output(layout=Layout( width='100%', border='1px solid #E0E0E0', padding='0px 20px 0px 20px')) box3 = Output(layout=Layout( width='100%', border='1px solid #E0E0E0', padding='0px 0px 0px 20px')) box4 = Output(layout=Layout( width='100%', border='1px solid #E0E0E0', padding='0px 0px 0px 20px')) box5 = Output(layout=Layout( width='100%', border='1px solid #E0E0E0', padding='0px 20px 0px 20px')) box6 = Output(layout=Layout( width='100%', border='1px solid #E0E0E0', padding='0px 20px 0px 20px')) markdown = Output(layout=Layout(width='95%')) with markdown: display(Markdown("#### Adjust The Wavelengths")) display( Markdown( "###### Click The cirlce, hold the mouse down and drag to customise your own RGB & hyperspectral input. When you are done, click the 'Run Classification' button at the bottom " )) slider1 = FloatSlider(min=0, max=1, step=0.01, value=0.5, description='380nm', layout=Layout(width='99%')) slider2 = FloatSlider(min=0, max=1, step=0.01, value=0.5, description='450nm', layout=Layout(width='99%')) slider3 = FloatSlider(min=0, max=1, step=0.01, value=0.5, description='550nm', layout=Layout(width='99%')) slider4 = FloatSlider(min=0, max=1, step=0.01, value=0.5, description='650nm', layout=Layout(width='99%')) slider5 = FloatSlider(min=0, max=1, step=0.01, value=0.5, description='750nm', layout=Layout(width='99%')) slider6 = FloatSlider(min=0, max=1, step=0.01, value=0.5, description='850nm', layout=Layout(width='99%')) slider7 = FloatSlider(min=0, max=1, step=0.01, value=0.5, description='950nm', layout=Layout(width='99%')) def click(event): global hyperspectral global RGB classify(RGB, hyperspectral) button = widgets.Button(description='Run Classification', layout={ 'width': '130px', 'margin': '0px 0px 10px 15%' }) button.on_click(click) slider_list = [ markdown, slider1, slider2, slider3, slider4, slider5, slider6, slider7, button ] for slider in slider_list: with box3: display(slider) def classify(RGB, hyperspectral): keep_probability = 1 def print_network_output(save_model_path, title, subclass_softmax, main_class_softmax, input_, reflectance_data, n_o_input, g, keep_prob): clear_output(wait=True) print("""Loading...(Might take a minute) *The next classification doesn't load until this one is completed""") with tf.Session(graph=g) as sess: sess.run(tf.global_variables_initializer()) loader = tf.train.import_meta_graph(save_model_path + '.meta') loader.restore(sess, save_model_path) subclass_softmax_p, main_class_softmax_p = sess.run( [subclass_softmax, main_class_softmax], feed_dict={ input_: reflectance_data, keep_prob: keep_probability }) clear_output(wait=True) display(Markdown("#### " + title)) display(Markdown("##### __Main Class__")) main_class_softmax_p = main_class_softmax_p[0] if main_class_softmax_p[0] > .5: display( Markdown("✔ Non-scat: " + str(main_class_softmax_p[0]))) display( Markdown("✖ Scat : " + str(main_class_softmax_p[1]))) else: display( Markdown("✖ Non-scat: " + str(main_class_softmax_p[0]))) display( Markdown("✔ Scat : " + str(main_class_softmax_p[1]))) display(Markdown("##### __Subclass__")) subclass_softmax_p = subclass_softmax_p[0] subclass_name = [ "Leaf Litter ", "Ground ", "Wood ", "Bird Scat ", "Mammal Scat ", "Amphibian Scat", "Reptile Scat ", "Reptile Urea " ] max_ = max(subclass_softmax_p) for subclass, name in zip(subclass_softmax_p, subclass_name): if subclass == max_: display(Markdown("✔ " + name + ": " + str(subclass))) else: display(Markdown("✖ " + name + ": " + str(subclass))) with box4: print_network_output('../training_rgb', "RGB Network Classification", R_subclass_softmax, R_main_class_softmax, R_input_, [RGB], 3, g_2, R_keep_prob) with box5: print_network_output('../training_Hyperspectral', "Hyperspectral Network Classification", H_subclass_softmax, H_main_class_softmax, H_input_, [hyperspectral], 571, g_1, H_keep_prob) def f(z, a, b, c, d, e, f, g): if z == "Select": for slider in slider_list: slider.layout.display = 'none' return 0 data_path = "../Training data/averaged all.csv" data = pd.read_csv(data_path) data.head() target_fields = 'Class' data = data.drop(["Class code"], axis=1) features0, targets0 = data.drop(target_fields, axis=1), data[target_fields] features, targets = np.array(features0), np.array(targets0) dic = {} for feature, target in zip(features, targets): dic[target] = list(feature) if z == "Make your own spectrum": x = [380, 450, 550, 650, 750, 850, 950] y = [a, b, c, d, e, f, g] plt.scatter(x, y) plt.plot(x, y, 'o') else: x = [x for x in range(380, 951)] y = dic[z.replace("Average ", "")] for slider in slider_list: slider.layout.display = 'none' graph = UnivariateSpline(x, y, s=0) xs = np.linspace(380, 950, 100) ys = graph(xs) with box2: clear_output(wait=True) display(Markdown("#### Hyperspectral Reflectance")) plt.ylim(0, 1) plt.xlim(380, 950) plt.plot(xs, ys) plt.title("Reflectance Intensity") plt.show() global hyperspectral global RGB hyperspectral = [ min(max(round(float(graph(x)), 7), 0), 1) for x in range(380, 951) ] red = min(max(round(float(graph(680)), 4), 0), 1) green = min(max(round(float(graph(530)), 4), 0), 1) blue = min(max(round(float(graph(465)), 4), 0), 1) RGB = [red, green, blue] with box1: clear_output(wait=True) red_rgb = int(red * 255) green_rgb = int(green * 255) blue_rgb = int(blue * 255) display(Markdown("#### RGB Reflectance")) html = '<svg height="100" width="100%"><rect x="0" y="10px" width="100" height="100" fill="rgb(' + str( red_rgb) + "," + str(green_rgb) + "," + str( blue_rgb) + ')" /></svg>' display(HTML(html)) display(Markdown("R(680nm): " + str(red))) display(Markdown("G(530nm): " + str(green))) display(Markdown("B(465nm): " + str(blue))) if z == "Make your own spectrum": with box4: clear_output(wait=False) with box5: clear_output(wait=False) for slider in slider_list: slider.layout.display = 'flex' else: classify(RGB, hyperspectral) material = widgets.Dropdown( options=[ "Select", "Make your own spectrum", 'Average Amphibian Scat', 'Average Bird Scat', 'Average Ground', "Average Leaf Litter", "Average Mammal Scat", "Average Reptile Scat", "Average Reptile Urea", "Average Wood" ], value='Select', description='Material:', ) output = interactive_output( f, { "z": material, 'a': slider1, 'b': slider2, 'c': slider3, 'd': slider4, 'e': slider5, 'f': slider6, 'g': slider7 }) display(material) grid = GridBox(children=[box1, box2, box3, box4, box5, box6], layout=Layout(width='97%', grid_template_columns='30% 30% 30%', grid_template_rows='auto auto', grid_gap='5px 15px', margin="10px 0px 0px 25px")) display(grid)
def __init__(self, volume=None, default_directory=os.getcwd(), title='', enhancement_steps=1000, **kwargs): def on_chosen_path_change(old_path, new_path): self.dataset = FolderDataset(new_path) # TODO: If the path doesn't contain images, display a warning # A widget for changing the image folder self.pathchooser = PathChooser( chosen_path_desc='Image folder:', default_directory=default_directory, on_chosen_path_change=on_chosen_path_change, ) self.pathchooser.layout.margin = '0 0 10px 0' # The number of increments of the min/max slider self.enhancement_steps = enhancement_steps self.scales = { 'x': LinearScale(), 'y': LinearScale(), } # The currently displayed image will be in bytes at `self.image_plot.image.value` self.image_plot = BQImage( image=IPyImage(), scales=self.scales, ) self.figure = Figure( marks=[self.image_plot], padding_x=0, padding_y=0, animation_duration=1000, fig_margin={ 'top': 0, 'right': 0, 'bottom': 0, 'left': 0, }, layout=Layout( grid_area='figure', margin='0', width='320px', height='320px', ), ) # Custom toolbar toolbar_width = '100%' toolbar_margin = '0px 0 2px 0' self.pan_zoom = PanZoom(scales={ 'x': [self.scales['x']], 'y': [self.scales['y']], }, ) self.save_button = Button( description='Save Image', tooltip='Save Image', icon='save', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, ), ) self.save_button.on_click(self.save_current_image) self.hide_button = Button( description='Hide Image', tooltip='Hide Image', icon='eye-slash', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, )) self.hide_button.on_click(self.hide_current_image) self.pan_zoom_toggle_button = ToggleButton( description='Pan / Zoom', tooltip='Pan/Zoom', icon='arrows', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, ), ) self.pan_zoom_toggle_button.observe(self.on_pan_zoom_toggle, names='value') self.reset_pan_zoom_button = Button( description='Undo Zoom', tooltip='Reset pan/zoom', icon='refresh', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, ), ) self.reset_pan_zoom_button.on_click(self.reset_pan_zoom) self.reset_enhancements_button = Button( description='Un-Enhance', tooltip='Reset enhancements', icon='ban', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, ), ) self.reset_enhancements_button.on_click(self.reset_enhancements) self.mini_map = IPyImage(layout=Layout( grid_area='mini-map', margin='0', )) self.mini_map.width = 180 self.mini_map.height = 180 # PERFORMANCE CONCERN # Ideally instead of four observations, this would observe 'scales' on `self.pan_zoom` # However, it doesn't fire updates # Ref: https://github.com/bloomberg/bqplot/issues/800 self.image_plot.scales['x'].observe(self.on_pan_zoom_change('x_min'), names='min') self.image_plot.scales['x'].observe(self.on_pan_zoom_change('x_max'), names='max') self.image_plot.scales['y'].observe(self.on_pan_zoom_change('y_min'), names='min') self.image_plot.scales['y'].observe(self.on_pan_zoom_change('y_max'), names='max') self.plane_toggle = ToggleButtons( options=['yz', 'xz', 'xy'], description='', disabled=False, button_style='', tooltips=[ 'Step in x direction', 'Step in y direction', 'Step in z direction' ], layout=Layout( width='200px', # flex='1 1 auto', margin='7px 0 auto auto', ), ) self.plane_toggle.style.button_width = 'auto' self.plane_toggle.observe(self.on_plane_change, names='value') self.toolbar = VBox( children=[ self.save_button, self.hide_button, self.pan_zoom_toggle_button, self.reset_pan_zoom_button, self.reset_enhancements_button, ], layout=Layout( grid_area='toolbar', margin='0', ), ) # Image enhancements self.min_max_slider = FloatRangeSlider( value=[0, 255], min=0, max=255, step=255 / self.enhancement_steps, description='Min/Max:', orientation='horizontal', readout=True, readout_format='.1f', continuous_update=True, layout=Layout( grid_area='min-max-slider', margin='10px 0 10px -10px', width='100%', ), ) self.min_max_slider.observe(self.on_min_max_change, names='value') self.index_slider = IntSlider( value=0, min=0, max=1, step=1, description='Index:', orientation='horizontal', readout=True, readout_format='d', continuous_update=True, layout=Layout( grid_area='index-slider', margin='8px -20px 10px -36px', width='100%', ), ) self.index_slider.observe(self.on_image_index_change, names='value') # Animation self.play = Play( value=self.index_slider.value, min=self.index_slider.min, max=self.index_slider.max, step=self.index_slider.step, ) jslink((self.play, 'value'), (self.index_slider, 'value')) # Keep 'max' in sync as well self.index_slider.observe(self.on_index_slider_max_change, names='max') self.bottom_bar = HBox( children=[ self.play, self.index_slider, self.plane_toggle, ], layout=Layout( grid_area='bottom-bar', margin=f'10px -20px 0 0', # overflow='hidden', )) # Layout self.gridbox = GridBox(children=[ self.figure, self.toolbar, self.mini_map, self.min_max_slider, self.bottom_bar, ], ) # Initially hidden without data self.gridbox.layout.display = 'none' self._dataset = None if volume is not None: self.dataset = VolumeDataset(volume) # Hide pathchooser when using a volume self.pathchooser.layout.display = 'none' # Call VBox super class __init__ super().__init__( children=[ self.pathchooser, self.gridbox, ], layout=Layout(width='auto'), **kwargs, )
def show(self): display(self.__out) next_move = Button( icon="step-forward", layout=Layout(width="60px", grid_area="right"), disabled=self.__next_move >= self.__num_moves, ) prev_move = Button( icon="step-backward", layout=Layout(width="60px", grid_area="left"), disabled=self.__next_move == 0, ) reset = Button( icon="stop", layout=Layout(width="60px", grid_area="middle"), disabled=self.__next_move == 0, ) if self.__next_move == 0: white_move = None black_move = None else: white_move = (self.__white_moves[self.__next_move // 2] if (self.__next_move % 2) == 1 else None) black_move = (self.__black_moves[self.__next_move // 2 - 1] if (self.__next_move % 2) == 0 else None) white_move_list = Select( options=self.__white_moves, value=white_move, rows=max(self.__move_list_len, 24), disabled=False, layout=Layout(width="80px"), ) black_move_list = Select( options=self.__black_moves, value=black_move, rows=max(self.__move_list_len, 24), disabled=False, layout=Layout(width="80px"), ) white_move_list.observe(self.__white_select_change) black_move_list.observe(self.__black_select_change) move_number_width = 3 + len(str(self.__move_list_len)) * 10 move_number = Select( options=range(1, self.__move_list_len + 1), value=None, disabled=True, rows=max(self.__move_list_len, 24), layout=Layout(width=f"{move_number_width}px"), ) move_list = HBox( [move_number, white_move_list, black_move_list], layout=Layout(height="407px", grid_area="moves"), ) next_move.on_click(self.__next_click) prev_move.on_click(self.__prev_click) reset.on_click(self.__reset_click) with self.__out: grid_box = GridBox( children=[next_move, prev_move, reset, self.svg, move_list], layout=Layout( width=f"{390+move_number_width+160}px", grid_template_rows="90% 10%", grid_template_areas=""" "top top top top top moves" ". left middle right . moves" """, ), ) clear_output(wait=True) display(grid_box)
def __init__(self, path=os.getcwd(), filename='', title='', select_desc='Select', change_desc='Change', show_hidden=False, directory=False, **kwargs): self._select_desc = select_desc self._default_path = path self._show_hidden = show_hidden self._select_desc = select_desc self._change_desc = change_desc self._path = path self._updir = Button(description='Up Directory') self._dircontent = Select(rows=8, layout=Layout(width='auto', grid_area='dircontent')) self._cancel = Button(description='Cancel', layout=Layout(width='auto', display='none')) self._select = Button(description=self._select_desc, layout=Layout(width='auto')) self._label = HTML(value=self._LBL_TEMPLATE.format( self._LBL_NOFILE, 'black'), placeholder='', description='') self._title = HTML(value=title) if title is '': self._title.layout.display = 'none' self._updir.on_click(self._on_updir_click) self._select.on_click(self._on_select_click) self._cancel.on_click(self._on_cancel_click) # Layout self._gb = GridBox(children=[self._updir, self._dircontent], layout=Layout(display='none', width='500px', grid_gap='0px 0px', grid_template_rows='auto auto', grid_template_columns='60% 40%', grid_template_areas=''' 'pathlist filename' 'dircontent dircontent' ''')) self._dircontent.observe(self._on_dircontent_select, names='value') buttonbar = HBox(children=[ self._select, self._cancel, self._label, ], layout=Layout(width='auto')) # Call setter to set initial form values self._set_form_values(self._path) # Call VBox super class __init__ super().__init__(children=[ self._gb, buttonbar, ], layout=Layout(width='auto'), **kwargs)
def init_gui(a): def create_widgets(): global title, material_1, material_2, view_3d, output_1, h1_slide, k1_slide, l1_slide global h2_slide, k2_slide, l2_slide, list_interfaces, output_2, SID1_slide, SID2_slide global gen_slabs, substrate_slide, gap_slide, merge_slabs, rep_x1, rep_y1, rep_z1, rep_x2 global rep_y2, rep_z2, rep_x3, rep_y3, rep_z3, rep_interface, rep_structures, down_interface global down_structures, file_format #Create all widgets here #Text as Buttons title = Button( description="Interface Generator", layout=Layout(height='auto', width='auto', grid_area="title"), ) #Input Texts material_1 = Text( value='mp-149', placeholder= 'Enter MPID (e.g: mp-2858) or Chemical Formula(e.g:ZrO2)', description='Material 1:', disabled=False, layout=Layout( height='auto', width='auto', grid_area="mat_1", #justify_items = "center" )) material_2 = Text( value='mp-352', placeholder= 'Enter MPID (e.g: mp-2858) or Chemical Formula(e.g:ZrO2)', description='Material 2:', disabled=False, layout=Layout(height='auto', width='auto', grid_area="mat_2" #justify_items = "center" )) #Buttons view_3d = Button(description="View 3D structure", layout=Layout(height='auto', width='auto', grid_area="view_3d"), tooltip='Click to view 3D structures') list_interfaces = Button(description="List Possible Slabs", disabled=True, layout=Layout(height='auto', width='auto', grid_area="list_interfaces"), tooltip='Click to list the possible slabs') gen_slabs = Button(description="Show Slabs", disabled=True, layout=Layout(height='auto', width='auto', grid_area="gen_slabs"), tooltip='Click to generate the desired slabs') merge_slabs = Button(description="Generate Interface", disabled=True, layout=Layout(height='auto', width='auto', grid_area="merge_slabs"), tooltip='Click to generate the desired interface') rep_structures = Button(description="Replicate Structures", disabled=True, layout=Layout(height='auto', width='auto', grid_area="rep_structures"), tooltip='Replicate the two structures') rep_interface = Button(description="Replicate Interface", disabled=True, layout=Layout(height='auto', width='auto', grid_area="rep_interface"), tooltip='Replicate the generated interface') down_structures = Button( description="Download Structures", disabled=True, layout=Layout(height='auto', width='auto', grid_area="down_structures"), tooltip='Download the two structures in desired formate') down_interface = Button( description="Download Interface", disabled=True, layout=Layout(height='auto', width='auto', grid_area="down_interface"), tooltip='Download the generated interface in desired format') #Sliders h1_slide = widgets.IntSlider(value=1, description='h_1', max=3, min=0, layout=Layout(height='auto', width='auto', grid_area="h1_slide")) k1_slide = widgets.IntSlider(value=1, description='k_1', max=3, min=0, layout=Layout(height='auto', width='auto', grid_area="k1_slide")) l1_slide = widgets.IntSlider(value=1, description='l_1', max=3, min=0, layout=Layout(height='auto', width='auto', grid_area="l1_slide")) h2_slide = widgets.IntSlider(value=1, description='h_2', max=3, min=0, layout=Layout(height='auto', width='auto', grid_area="h2_slide")) k2_slide = widgets.IntSlider(value=1, description='k_2', max=3, min=0, layout=Layout(height='auto', width='auto', grid_area="k2_slide")) l2_slide = widgets.IntSlider(value=1, description='l_2', max=3, min=0, layout=Layout(height='auto', width='auto', grid_area="l2_slide")) SID1_slide = widgets.IntSlider(value=0, description='SID_1', max=0, min=0, layout=Layout(height='auto', width='auto', grid_area="SID1_slide")) SID2_slide = widgets.IntSlider(value=0, description='SID_2', max=0, min=0, layout=Layout(height='auto', width='auto', grid_area="SID2_slide")) substrate_slide = widgets.IntSlider( value=1, description='Substrate (1 for material 1, 2 for material 2)', max=2, min=1, layout=Layout(height='auto', width='auto', grid_area="substrate_slide")) gap_slide = widgets.FloatSlider( value=0.1, description='Gap between 2 interfaces desired in Angstrom', min=0.1, max=5, step=0.1, layout=Layout(height='auto', width='auto', grid_area="gap_slide")) #Int Text rep_x1 = widgets.BoundedIntText(value=1, description='x1', max=10, min=1, layout=Layout(height='auto', width='auto', grid_area="rep_x1")) rep_y1 = widgets.BoundedIntText(value=1, description='y1', max=10, min=1, layout=Layout(height='auto', width='auto', grid_area="rep_y1")) rep_z1 = widgets.BoundedIntText(value=1, description='z1', max=10, min=1, layout=Layout(height='auto', width='auto', grid_area="rep_z1")) rep_x2 = widgets.BoundedIntText(value=1, description='x2', max=10, min=1, layout=Layout(height='auto', width='auto', grid_area="rep_x2")) rep_y2 = widgets.BoundedIntText(value=1, description='y2', max=10, min=1, layout=Layout(height='auto', width='auto', grid_area="rep_y2")) rep_z2 = widgets.BoundedIntText(value=1, description='z2', max=10, min=1, layout=Layout( height='auto', width='auto', grid_area="rep_z2", )) rep_x3 = widgets.BoundedIntText(value=1, description='x', max=10, min=1, layout=Layout(height='auto', width='auto', grid_area="rep_x3")) rep_y3 = widgets.BoundedIntText(value=1, description='y', max=10, min=1, layout=Layout(height='auto', width='auto', grid_area="rep_y3")) rep_z3 = widgets.BoundedIntText(value=1, description='z', max=10, min=1, layout=Layout(height='auto', width='auto', grid_area="rep_z3")) #Dropdowns file_format = widgets.Dropdown(options=[ ".cif", "POSCAR (VASP)", "Quantum Espresso input", ".xyz" ], layout=Layout(height='auto', width='auto', grid_area="file_format")) #Outputs output_1 = widgets.Output( layout=Layout(height='auto', width='auto', grid_area="output_1")) output_2 = widgets.Output( layout=Layout(height='auto', width='auto', grid_area="output_2")) #Functionality of Widgets here #Utilities to convert pymatgen structures to ase structures for modification def build_ase_struc_3d(pymatgen_struc): s = Atoms(pymatgen_struc.formula.replace(" ", ""), positions=pymatgen_struc.cart_coords, cell=pymatgen_struc.lattice.get_cartesian_coords(1), pbc=[1, 1, 1]) return s def build_ase_struc_2d(pymatgen_struc): s = Atoms(pymatgen_struc.formula.replace(" ", ""), positions=pymatgen_struc.cart_coords, cell=pymatgen_struc.lattice.get_cartesian_coords(1), pbc=[1, 1, 0]) return s #Fetching materials data from MP database def get_3D_Structures(b): global view, view_2, struc1, struc2, s1, s2, pressed pressed = 0 struc1 = a.get_structure_by_material_id(material_1.value) struc1 = SpacegroupAnalyzer( struc1).get_conventional_standard_structure() s1 = build_ase_struc_3d(struc1) view = nglview.show_ase(s1) view.add_representation('unitcell') view.background = 'black' view.camera = "orthographic" struc2 = a.get_structure_by_material_id(material_2.value) struc2 = SpacegroupAnalyzer( struc2).get_conventional_standard_structure() s2 = build_ase_struc_3d(struc2) view_2 = nglview.show_ase(s2) view_2.add_representation('unitcell') view_2.background = 'black' view_2.camera = "orthographic" with output_1: output_1.clear_output() display(view) display(view_2) list_interfaces.disabled = False rep_structures.disabled = False down_structures.disabled = False #Generating list possible slab terminations using slab generator from pymatgen def list_possible_2D_Slabs(b): global view, view_2, struc1, struc2, s1, s2, slabgen1, slabgen2, pressed pressed = 0 slabgen1 = SlabGenerator( struc1, (int(h1_slide.value), int(k1_slide.value), int(l1_slide.value)), 10, 10, center_slab=True) slabgen2 = SlabGenerator( struc2, (int(h2_slide.value), int(k2_slide.value), int(l2_slide.value)), 10, 10, center_slab=True) with output_2: output_2.clear_output() print("For Material 1") print( "There are actually now %s terminations that can be generated" % (len(slabgen1.get_slabs()))) i = 0 print("S-ID \t Miller Indices Polar? Symmetric? ") for slab in slabgen1.get_slabs(): print(i, "\t", slab.miller_index, "\t", slab.is_polar(), "\t", slab.is_symmetric()) i = i + 1 i = 0 SID1_slide.max = len(slabgen1.get_slabs()) - 1 print("For Material 2") print( "There are actually now %s terminations that can be generated" % (len(slabgen2.get_slabs()))) print("S-ID \t Miller Indices Polar? Symmetric? ") for slab in slabgen2.get_slabs(): print(i, "\t", slab.miller_index, "\t", slab.is_polar(), "\t", slab.is_symmetric()) i = i + 1 SID2_slide.max = len(slabgen2.get_slabs()) - 1 gen_slabs.disabled = False #ASE functionality to merge two slabs of the material def merge_2D_slabs(b): global view, view_2, struc1, struc2, s1, s2, slabgen1, slabgen2, s3, view_3, pressed pressed = 1 a1_tmp = (s2.cell.lengths()[0] / (s1.cell.lengths()[0])) a2_tmp = (s2.cell.lengths()[1] / (s1.cell.lengths()[1])) a1 = 1 b1 = 1 a2 = 1 b2 = 1 if (a1_tmp >= 1): a1 = int(np.round(a1)) else: b1 = int(np.round(1 / a1)) if (a2_tmp >= 1): a2 = int(np.round(a1)) else: b2 = int(np.round(1 / a1)) s1 = s1.repeat((a1, a2, 1)) s2 = s2.repeat((b1, b2, 1)) if (substrate_slide.value == 1): cell_final = s1.cell.copy() fix_val = 0 else: cell_final = s2.cell.copy() fix_val = 1 vac = gap_slide.value / 2 s1.center(vacuum=vac, axis=2) s2.center(vacuum=vac, axis=2) s3, s1_strain, s2_strain = stack(s1, s2, axis=2, fix=0, cell=cell_final, maxstrain=None, distance=None, output_strained=True) strain1 = np.sqrt(((s1_strain.cell - s1.cell).sum(axis=0)**2).sum()) strain2 = np.sqrt(((s2_strain.cell - s2.cell).sum(axis=0)**2).sum()) view_3 = nglview.show_ase(s3) view_3.add_representation('unitcell') view_3.background = 'black' view_3.camera = "orthographic" with output_1: output_1.clear_output() print("Strain on cell of Material 1 is", strain1) print("Strain on cell of Material 2 is", strain2) display(view_3) #Generate desired 2D slabs from the list of slabs generated by pymatgen def generate_2D_Slabs(b): global view, view_2, struc1, struc2, s1, s2, slabgen1, slabgen2, pressed pressed = 0 struc1 = slabgen1.get_slabs()[SID1_slide.value].get_sorted_structure() s1 = build_ase_struc_2d(struc1) view = nglview.show_ase(s1) view.add_representation('unitcell') view.background = 'black' view.camera = "orthographic" struc2 = slabgen2.get_slabs()[SID2_slide.value].get_sorted_structure() s2 = build_ase_struc_2d(struc2) view_2 = nglview.show_ase(s2) view_2.add_representation('unitcell') view_2.background = 'black' view_2.camera = "orthographic" with output_1: output_1.clear_output() display(view) display(view_2) merge_slabs.disabled = False rep_interface.disabled = False down_interface.disabled = False #Function to replicate slabs/3D models in x,y,z def replicate_structures(b): global view, view_2, s1, s2 s1 = s1.repeat((rep_x1.value, rep_y1.value, rep_z1.value)) s2 = s2.repeat((rep_x2.value, rep_y2.value, rep_z2.value)) view = nglview.show_ase(s1) view.add_representation('unitcell') view.background = 'black' view.camera = "orthographic" view_2 = nglview.show_ase(s2) view_2.add_representation('unitcell') view_2.background = 'black' view_2.camera = "orthographic" with output_1: output_1.clear_output() display(view) display(view_2) #Function to replicate interface in x,y,z def replicate_interface(b): global view_3, s3 s3 = s3.repeat((rep_x3.value, rep_y3.value, rep_z3.value)) view_3 = nglview.show_ase(s3) view_3.add_representation('unitcell') view_3.background = 'black' view_3.camera = "orthographic" with output_1: output_1.clear_output() display(view_3) #Function to download structures def download_structures(b): global s1, s2 if (file_format.value == "POSCAR (VASP)"): write("struc1.POSCAR", s1, format="vasp") write("struc2.POSCAR", s2, format="vasp") elif (file_format.value == ".cif"): write("struc1.cif", s1, format="cif") write("struc2.cif", s2, format="cif") elif (file_format.value == ".xyz"): write("struc1.xyz", s1, format="xyz") write("struc2.xyz", s2, format="xyz") elif (file_format.value == "Quantum Espresso input"): write("struc1.qe.in", s1, format="espresso-in") write("struc2.qe.in", s2, format="espresso-in") #Function to download interface def download_interface(b): global s3 if (file_format.value == "POSCAR (VASP)"): write("struc3.POSCAR", s3, format="vasp") elif (file_format.value == ".cif"): write("struc3.cif", s1, format="cif") elif (file_format.value == ".xyz"): write("struc3.xyz", s3, format="xyz") elif (file_format.value == "Quantum Espresso input"): write("struc3.qe.in", s3, format="espresso-in") create_widgets() view_3d.on_click(get_3D_Structures) list_interfaces.on_click(list_possible_2D_Slabs) gen_slabs.on_click(generate_2D_Slabs) merge_slabs.on_click(merge_2D_slabs) rep_structures.on_click(replicate_structures) rep_interface.on_click(replicate_interface) down_structures.on_click(download_structures) down_interface.on_click(download_interface) grid = GridBox( children=[ title, material_1, material_2, view_3d, output_1, h1_slide, k1_slide, l1_slide, h2_slide, k2_slide, l2_slide, list_interfaces, output_2, SID1_slide, SID2_slide, gen_slabs, substrate_slide, gap_slide, merge_slabs, rep_x1, rep_y1, rep_z1, rep_x2, rep_y2, rep_z2, rep_x3, rep_y3, rep_z3, rep_interface, rep_structures, down_interface, down_structures, file_format ], layout=Layout( width='100%', grid_template_columns='10% 12.5% 12.5% 10% 28% 13.5% 13.5%', grid_template_rows= 'auto auto auto auto auto auto auto auto auto auto suto auto auto', #grid_gap='0px', grid_template_areas=''' "title title title title title title title" ". mat_1 mat_1 . output_1 . ." ". mat_2 mat_2 . output_1 rep_x1 rep_x2" ". view_3d view_3d . output_1 rep_y1 rep_y2" "h1_slide h1_slide h2_slide h2_slide output_1 rep_z1 rep_z2" "k1_slide k1_slide k2_slide k2_slide output_1 rep_structures rep_structures" "l1_slide l1_slide l2_slide l2_slide output_1 rep_x3 rep_x3" ". list_interfaces list_interfaces . output_1 rep_y3 rep_y3" ". . . . output_1 rep_z3 rep_z3" ". . . . output_1 rep_interface rep_interface" "output_2 output_2 output_2 output_2 output_1 . ." "SID1_slide SID1_slide SID2_slide SID2_slide output_1 file_format file_format" ". gen_slabs gen_slabs . output_1 down_structures down_structures" "substrate_slide substrate_slide gap_slide gap_slide output_1 down_interface down_interface" ". merge_slabs merge_slabs . output_1 . ." ''', #justify_items='center' )) display(grid)
def __init__(self, path=os.getcwd(), filename='', title='', select_desc='Select', change_desc='Change', show_hidden=False, include_files=True, include_folders=True, **kwargs): self._default_path = path # path.rstrip(os.path.sep) self._default_filename = filename self._selected_path = '' self._selected_filename = '' self._show_hidden = show_hidden self._select_desc = select_desc self._change_desc = change_desc self._include_files = include_files self._include_folders = include_folders if not include_folders and not include_files: raise ValueError("You can't exclude both files and folders") # Widgets self._pathlist = Dropdown(description="", layout=Layout(width='auto', grid_area='pathlist')) self._filename = Text( placeholder='output filename', layout=Layout( width='auto', grid_area='filename', visibility='visible' if self._include_files else 'hidden', ), ) self._dircontent = Select(rows=8, layout=Layout(width='auto', grid_area='dircontent')) self._cancel = Button(description='Cancel', layout=Layout(width='auto', display='none')) self._select = Button(description=self._select_desc, layout=Layout(width='auto')) self._title = HTML(value=title) if title is '': self._title.layout.display = 'none' # Widget observe handlers self._pathlist.observe(self._on_pathlist_select, names='value') self._dircontent.observe(self._on_dircontent_select, names='value') self._filename.observe(self._on_filename_change, names='value') self._select.on_click(self._on_select_click) self._cancel.on_click(self._on_cancel_click) # Selected file label self._label = HTML(value=self._LBL_TEMPLATE.format( self._LBL_NOFILE if self._include_files else self._LBL_NOFOLDER if self._include_folders else "", 'black'), placeholder='', description='') # Layout self._gb = GridBox( children=[self._pathlist, self._filename, self._dircontent], layout=Layout(display='none', width='500px', grid_gap='0px 0px', grid_template_rows='auto auto', grid_template_columns='60% 40%', grid_template_areas=''' 'pathlist filename' 'dircontent dircontent' ''')) buttonbar = HBox(children=[self._select, self._cancel, self._label], layout=Layout(width='auto')) # Call setter to set initial form values self._set_form_values(self._default_path, self._default_filename) # Call VBox super class __init__ kwargs.setdefault('layout', Layout(width='auto')) super().__init__(children=[ self._title, self._gb, buttonbar, ], **kwargs)
def init_widgets(self): # Primary checkboxes read_hit = ChildCheckbox(self.compute_all, READ_HIT, 1) write_hit = ChildCheckbox(self.compute_all, WRITE_HIT, 2) read_capmiss = ChildCheckbox(self.compute_all, READ_MISS, 4) write_capmiss = ChildCheckbox(self.compute_all, WRITE_MISS, 5) read_compmiss = ChildCheckbox(self.compute_all, COMP_R_MISS, 6) write_compmiss = ChildCheckbox(self.compute_all, COMP_W_MISS, 8) chks = [read_hit, write_hit, read_capmiss, write_capmiss, read_compmiss, write_compmiss] self.checkboxes = chks # Parent checkboxes self.all_check = ParentCheckbox(chks, self.compute_all, label = 'All', tooltip="Show All") self.read_check = ParentCheckbox([read_hit, read_capmiss, read_compmiss], self.compute_all, label='Reads', tooltip="Reads") self.write_check = ParentCheckbox([write_hit, write_capmiss, write_compmiss], self.compute_all, label='Writes', tooltip="Writes") self.hit_check = ParentCheckbox([read_hit, write_hit], self.compute_all, label='Hits', tooltip="Hits") self.capmiss_check = ParentCheckbox([read_capmiss, write_capmiss], self.compute_all, label='Capacity Misses', tooltip="Capacity Misses") self.compmiss_check = ParentCheckbox([read_compmiss, write_compmiss], self.compute_all, label='Compuls Misses', tooltip="Compulsory Misses") self.parentcheckboxes = [self.all_check, self.read_check, self.write_check, self.hit_check, self.capmiss_check, self.compmiss_check] def parentbox(check): return HBox([check.widget], layout=Layout(align_items="center", overflow="hidden", justify_content="center")) def clr_picker(clr, cache=False): if cache: clr_picker = ColorPicker(concise=True, value=to_hex(self.colormap[clr][0:3]), disabled=False, layout=Layout(width="30px")) else: clr_picker = ColorPicker(concise=True, value=to_hex(self.colormap[clr][0:3]), disabled=False, layout=Layout(width="25px", margin="0 0 0 8px")) clr_picker.observing = True def handle_color_picker(change): self.colormap[clr] = to_rgba(change.new, 1) self.model.plot.colormap = ListedColormap(self.colormap) self.model.plot.backend.plot._update_image() clr_picker.observe(handle_color_picker, names='value') self.colorpickers[clr] = clr_picker return clr_picker def primbox(check): return HBox([check.widget, clr_picker(check.clr)], layout=Layout(justify_content="center",align_items="center",overflow="hidden")) # Wrap parent boxes in ipywidget alls = parentbox(self.all_check) read = parentbox(self.read_check) write = parentbox(self.write_check) hits = parentbox(self.hit_check) capmisses = parentbox(self.capmiss_check) compmisses = parentbox(self.compmiss_check) # Add pseudo grid and wrap primary boxes in ipywidget gridbox = HBox([GridBox([alls, vdiv, read, vdiv, write, hdiv, hdiv, hdiv, hdiv, hdiv, hits, vdiv, primbox(read_hit), lvdiv, primbox(write_hit), hdiv, hdiv, lhdiv, lhdiv, lhdiv, capmisses, vdiv, primbox(read_capmiss), lvdiv, primbox(write_capmiss), hdiv, hdiv, lhdiv, lhdiv, lhdiv, compmisses, vdiv, primbox(read_compmiss), lvdiv, primbox(write_compmiss)], layout=Layout(grid_template_rows="50px 2px 50px 2px 50px 2px 50px", grid_template_columns="100px 5px 100px 5px 100px"))], layout=Layout(padding="0 0 0 14px")) cache_icon = v.Icon(children=['fa-database'], v_on='tooltip.on') cache_icon_tp = v.Tooltip(bottom=True, v_slots=[{'name': 'activator', 'variable': 'tooltip', 'children': cache_icon}], children=["Cache"]) cache_clrpkr = clr_picker(3, cache=True) reset_clrs = v.Btn(v_on='tooltip.on', icon=True, children=[v.Icon(children=['refresh'])]) reset_clrs.on_event('click', self.reset_colormap) reset_clrs_tp = v.Tooltip(bottom=True, v_slots=[{'name': 'activator', 'variable': 'tooltip', 'children': reset_clrs}], children=["Reset all colors"]) cache_row = HBox([cache_icon_tp, cache_clrpkr, reset_clrs_tp], layout=Layout(padding="0 20px 20px 20px", align_items="center", justify_content="space-between")) cache_row return VBox([gridbox, cache_row])
def plot(big_umap, known_umap, skip=10): big_umap = big_umap.iloc[::skip] known_umap = known_umap.iloc[::skip] # The GDB scatter plot skip = 10 big_scatter = go.Scatter( x=big_umap.loc[:, 0], y=big_umap.loc[:, 1], name='Possible Molecules', mode="markers", hoverinfo="text", opacity=0.5, marker={ "size": 5, "line": { "width": 0.5, "color": "white" }, "color": big_umap.loc[:, 'p'], "colorscale": 'magma', "colorbar": { 'thickness': 20, 'title': 'p(Odorous)' }, }, ) # The known odorants scatter plot known_scatter = go.Scattergl( x=known_umap.loc[:, 0], y=known_umap.loc[:, 1], name='Known Odorous', mode="markers", hoverinfo="text", opacity=1, marker={ "size": 5, "line": { "width": 0.5, "color": "white" }, "color": "blue", }, ) # The axes, etc. layout = go.Layout(xaxis={ "type": "linear", "title": "", "showline": False, "showticklabels": False }, yaxis={ "type": "linear", "title": "", "showline": False, "showticklabels": False }, margin={ "l": 40, "b": 40, "t": 10, "r": 10 }, legend={ "x": 0, "y": 1, 'font': { 'size': 15, 'color': 'white' } }, hovermode="closest", paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(10,10,10,1)", width=1000, height=1000, xaxis_showgrid=False, yaxis_showgrid=False, xaxis_zeroline=False, yaxis_zeroline=False) fig = go.FigureWidget(data=[big_scatter, known_scatter], layout=layout) fig.layout.hovermode = 'closest' # The 2D drawing of the molecule first_smiles = "CCCCO" image_widget = Image(value=smiles_to_image(first_smiles), layout=Layout(height="200px", width="200px", left='50px', top='-250px')) text_widget = Text(value=first_smiles, placeholder=first_smiles, description='SMILES:', disabled=False, layout=Layout(width='400px', left='25px', top='-285px')) def hover_fn(trace, points, state): #print(points) try: ind = points.point_inds[0] if trace.name == 'Possible Molecules': use = big_umap else: use = known_umap smiles = use.index[ind] image_widget.value = smiles_to_image(smiles, size=200) text_widget.value = smiles except IndexError: pass except Exception as e: print(e) def click_fn(trace, points, state): global hover_on if hover_on: fig.data[0].on_hover(None) hover_on = 0 else: fig.data[0].on_hover(hover_fn) hover_on = 1 fig.data[0].on_hover(hover_fn) fig.data[0].on_click(click_fn) canvas = GridBox([fig, image_widget, text_widget], layout={'gridgap': '0'}) return canvas
def get_form(): from ipywidgets import VBox, GridBox, Checkbox, Label, Layout, Dropdown, Text, HTML, Button, IntProgress from docx.shared import Pt from docx.enum.style import WD_STYLE_TYPE import operator from base64 import b64encode spells = pickle.load(open("spells.p", "rb")) gods = pickle.load(open("gods.p", "rb")) sphere_checkboxes = {'major': {}, 'minor': {}} def on_change(b): html.value = '' progress.value = 0 for sphere in spells.keys(): for t in ['major', 'minor']: sphere_checkboxes[t][sphere] = Checkbox(value=False, description=sphere, indent=False) sphere_checkboxes[t][sphere].observe(on_change, names='value') gods_per_race = Dropdown(options=list(gods.keys()), description='Gruppi di divinità:', value=None) gods_of_race = Dropdown( options=[], description='Divinità:', ) extra_spheres = { 'major': Text(value='', placeholder='Sfere non specificate appaiono qui', description='Sfere maggiori', disabled=True), 'minor': Text(value='', placeholder='Sfere non specificate appaiono qui', description='Sfere minori', disabled=True) } def on_change_per_race(change): html.value = '' progress.value = 0 v = change['new'] gods_of_race.value = None if v is None: gods_of_race.options = None else: gods_of_race.options = list(zip(gods[v].keys(), gods[v].values())) gods_per_race.observe(on_change_per_race, names='value') def on_change_per_god(change): html.value = '' progress.value = 0 for t in extra_spheres: extra_spheres[t].value = '' god = change['new'] if god is None: for t in ['major', 'minor']: for c in sphere_checkboxes[t]: sphere_checkboxes[t][c].value = False else: for t in sphere_checkboxes: if t in god: for c in sphere_checkboxes[t]: if c in god[t]: sphere_checkboxes[t][c].value = True else: sphere_checkboxes[t][c].value = False for s in god[t]: if s not in sphere_checkboxes[t]: if extra_spheres[t].value is None: extra_spheres[t].value = s else: extra_spheres[t].value += s else: for c in sphere_checkboxes[t]: sphere_checkboxes[t][c].value = False gods_of_race.observe(on_change_per_god, names='value') button = Button(description='Genera elenco', disabled=False) def add_content(document, content, space_after=0, font_name='Arial', font_size=16, line_spacing=0, space_before=0, keep_together=True, keep_with_next=False, page_break_before=False, widow_control=False, set_bold=False, set_italic=False, set_underline=False, set_all_caps=False, style_name=""): paragraph = document.add_paragraph(content) font = paragraph.style.font font.name = font_name font.size = Pt(font_size) font.bold = set_bold font.italic = set_italic font.all_caps = set_all_caps font.underline = set_underline paragraph_format = paragraph.paragraph_format paragraph_format.space_before = Pt(space_before) paragraph_format.space_after = Pt(space_after) paragraph_format.line_spacing = line_spacing paragraph_format.keep_together = keep_together paragraph_format.keep_with_next = keep_with_next paragraph_format.page_break_before = page_break_before paragraph_format.widow_control = widow_control def build_list(b): progress.max = 7 * len(sphere_checkboxes['major']) + 3 * len( sphere_checkboxes['minor']) document = Document() style = document.styles.add_style('Indent', WD_STYLE_TYPE.PARAGRAPH) paragraph_format = style.paragraph_format paragraph_format.space_before = Pt(3) paragraph_format.widow_control = True title = 'Lista Incantesimi' if gods_of_race.value is not None and 'name' in gods_of_race.value: title = gods_of_race.value['name'] document.add_heading(title, 0) for i in range(7): spells_level = [] for c in sphere_checkboxes['major']: progress.value += 1 if sphere_checkboxes['major'][c].value == True: lst = spells[c][i] for s in lst: s['Sfera'] = s['Sfera'].upper() spells_level.extend(lst) if i < 3: for c in sphere_checkboxes['minor']: progress.value += 1 if sphere_checkboxes['minor'][c].value == True: lst = spells[c][i] for s in lst: s['Sfera'] = s['Sfera'].lower() spells_level.extend(lst) # Sort by name spells_level.sort( key=operator.itemgetter('Incantesimo', 'Effetto')) if len(spells_level) > 0: document.add_heading('Incantesimi di livello ' + str(i + 1), 1) def key_value(cell, key, value, font_size=None): p = cell.paragraphs[0] if font_size is not None: p.style.font.size = font_size r = p.add_run() r.text = key r.font.bold = True r = p.add_run() r.text = ': ' + str(value) spells_level_len = len(spells_level) i = 0 while i < spells_level_len: # Separator paragraph = document.add_paragraph() paragraph.style.font.size = Pt(3) paragraph_format = paragraph.paragraph_format paragraph_format.space_before = Pt(0) paragraph_format.space_after = Pt(0) # Count and skip duplicates c = [spells_level[i]['Sfera']] while i+1 < spells_level_len and \ spells_level[i]['Incantesimo'] == spells_level[i+1]['Incantesimo'] and \ spells_level[i]['Effetto'] == spells_level[i+1]['Effetto']: c.append(spells_level[i + 1]['Sfera']) i += 1 s = spells_level[i] # Spell in table format table = document.add_table(4, 4) table.style = 'TableGrid' cells_0 = table.rows[0].cells key_value(cells_0[0], 'Incantesimo', s['Incantesimo'], Pt(11)) cells_0[0].merge(cells_0[1]) key_value(cells_0[2], '#', str(len(c))) cells_0[3].text = ', '.join(c) cells_1 = table.rows[1].cells key_value(cells_1[0], 'Livello', s['Livello']) key_value(cells_1[1], 'Raggio d’azione', s['Raggio d’azione']) key_value(cells_1[2], 'Componenti', s['Componenti']) key_value(cells_1[3], 'Durata', s['Durata']) cells_2 = table.rows[2].cells key_value(cells_2[0], 'Tempo lancio', s['Tempo lancio']) key_value(cells_2[1], 'Area d’effetto', s['Area d’effetto']) key_value(cells_2[2], 'Tiro salvezza', s['Tiro salvezza']) key_value(cells_2[3], 'Reversibile', s['Reversibile']) cells_3 = table.rows[3].cells key_value(cells_3[0], 'Effetto', s['Effetto']) cells_3[0].merge(cells_3[1]) cells_3[0].merge(cells_3[2]) cells_3[0].merge(cells_3[3]) i += 1 # Save and generate downlpoad link document.save('lista_incantesimi.docx') with open('lista_incantesimi.docx', 'rb') as fp: data = str(b64encode(fp.read())) html_ = "<a download='{filename}' href='data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8;base64,{payload}' target='_blank'>{title}</a>" html.value = html_.format(payload=data[2:], title="Scarica Lista Incantesimi", filename=title + '.docx') button.on_click(build_list) html = HTML(value="") progress = IntProgress( value=0, min=0, max=10, step=1, description='', bar_style='', # 'success', 'info', 'warning', 'danger' or '' orientation='horizontal', layout=Layout(width='95%')) form = VBox([ GridBox([gods_per_race, gods_of_race], layout=Layout(grid_template_columns="repeat(2, 450px)")), GridBox(list(extra_spheres.values()), layout=Layout(grid_template_columns="repeat(2, 450px)")), Label(value='Sfere maggiori:'), GridBox(list(sphere_checkboxes['major'].values()), layout=Layout(grid_template_columns="repeat(4, 200px)")), Label(value='Sfere minori:'), GridBox(list(sphere_checkboxes['minor'].values()), layout=Layout(grid_template_columns="repeat(4, 200px)")), button, progress, html ]) return form
def __init__(self, path: str = os.getcwd(), filename: str = '', title: str = '', select_desc: str = 'Select', change_desc: str = 'Change', show_hidden: bool = False, select_default: bool = False, dir_icon: Optional[str] = '\U0001F4C1 ', dir_icon_append: bool = False, show_only_dirs: bool = False, filter_pattern: Optional[Sequence[str]] = None, sandbox_path: Optional[str] = None, layout: Layout = Layout(width='500px'), **kwargs): """Initialize FileChooser object.""" # Check if path and sandbox_path align if sandbox_path and not has_parent_path(normalize_path(path), normalize_path(sandbox_path)): raise ParentPathError(path, sandbox_path) # Verify the filename is valid if not is_valid_filename(filename): raise InvalidFileNameError(filename) self._default_path = normalize_path(path) self._default_filename = filename self._selected_path: Optional[str] = None self._selected_filename: Optional[str] = None self._show_hidden = show_hidden self._select_desc = select_desc self._change_desc = change_desc self._select_default = select_default self._dir_icon = dir_icon self._dir_icon_append = dir_icon_append self._show_only_dirs = show_only_dirs self._filter_pattern = filter_pattern self._sandbox_path = normalize_path( sandbox_path) if sandbox_path is not None else None self._callback: Optional[Callable] = None # Widgets self._pathlist = Dropdown(description="", layout=Layout(width='auto', grid_area='pathlist')) self._filename = Text( placeholder='output filename', layout=Layout(width='auto', grid_area='filename', display=(None, "none")[self._show_only_dirs]), disabled=self._show_only_dirs) self._dircontent = Select(rows=8, layout=Layout(width='auto', grid_area='dircontent')) self._cancel = Button(description='Cancel', layout=Layout(min_width='6em', width='6em', display='none')) self._select = Button(description=self._select_desc, layout=Layout(min_width='6em', width='6em')) self._title = HTML(value=title) if title == '': self._title.layout.display = 'none' # Widget observe handlers self._pathlist.observe(self._on_pathlist_select, names='value') self._dircontent.observe(self._on_dircontent_select, names='value') self._filename.observe(self._on_filename_change, names='value') self._select.on_click(self._on_select_click) self._cancel.on_click(self._on_cancel_click) # Selected file label self._label = HTML(value=self._LBL_TEMPLATE.format( self._LBL_NOFILE, 'black'), placeholder='', description='', layout=Layout(margin='0 0 0 1em')) # Layout self._gb = GridBox( children=[self._pathlist, self._filename, self._dircontent], layout=Layout(display='none', width='auto', grid_gap='0px 0px', grid_template_rows='auto auto', grid_template_columns='60% 40%', grid_template_areas=''' 'pathlist {}' 'dircontent dircontent' '''.format( ('filename', 'pathlist')[self._show_only_dirs]))) buttonbar = HBox(children=[ self._select, self._cancel, Box([self._label], layout=Layout(overflow='auto')) ], layout=Layout(width='auto')) # Call setter to set initial form values self._set_form_values(self._default_path, self._default_filename) # Use the defaults as the selected values if self._select_default: self._apply_selection() # Call VBox super class __init__ super().__init__(children=[self._title, self._gb, buttonbar], layout=layout, **kwargs)
def display_actions(self): from IPython.display import HTML from IPython.display import display from ipywidgets import Button from ipywidgets import GridBox from ipywidgets import Layout from ipywidgets import Output options_output_area = Output() run_output_area = Output() run_btn = Button( description='Run on Dataflow', button_style='success', tooltip= ('Submit to Dataflow for execution with the configured options. The ' 'output PCollection\'s data will be written to the GCS bucket you ' 'configure.')) show_options_btn = Button( description='Show Options', button_style='info', tooltip='Show current pipeline options configured.') def _run_on_dataflow(btn): with run_output_area: run_output_area.clear_output() @progress_indicated def _inner(): options = self.to_options() # Caches the output_pcoll to a GCS bucket. try: execution_count = 0 if is_in_ipython(): from IPython import get_ipython execution_count = get_ipython().execution_count output_location = '{}/{}'.format( options.view_as( GoogleCloudOptions).staging_location, self.output_name) _ = self.output_pcoll | 'WriteOuput{}_{}ToGCS'.format( self.output_name, execution_count) >> WriteToText(output_location) _LOGGER.info( 'Data of output PCollection %s will be written to %s', self.output_name, output_location) except (KeyboardInterrupt, SystemExit): raise except: # pylint: disable=bare-except # The transform has been added before, noop. pass if self.verbose: _LOGGER.info( 'Running the pipeline on Dataflow with pipeline options %s.', pformat_dict(options.display_data())) result = create_runner('DataflowRunner').run_pipeline( self.p, options) cloud_options = options.view_as(GoogleCloudOptions) url = ( 'https://console.cloud.google.com/dataflow/jobs/%s/%s?project=%s' % (cloud_options.region, result.job_id(), cloud_options.project)) display( HTML( 'Click <a href="%s" target="_new">here</a> for the details ' 'of your Dataflow job.' % url)) result_name = 'result_{}'.format(self.output_name) create_var_in_main(result_name, result) if self.verbose: _LOGGER.info( 'The pipeline result of the run can be accessed from variable ' '%s. The current status is %s.', result_name, result) try: btn.disabled = True _inner() finally: btn.disabled = False run_btn.on_click(_run_on_dataflow) def _show_options(btn): with options_output_area: options_output_area.clear_output() options = self.to_options() options_name = 'options_{}'.format(self.output_name) create_var_in_main(options_name, options) _LOGGER.info('The pipeline options configured is: %s.', pformat_dict(options.display_data())) show_options_btn.on_click(_show_options) grid = GridBox([run_btn, show_options_btn], layout=Layout(grid_template_columns='repeat(2, 200px)')) display(grid) # Implicitly initializes the options variable before 1st time showing # options. options_name_inited, _ = create_var_in_main( 'options_{}'.format(self.output_name), self.to_options()) if not self.notice_shown: _LOGGER.info( 'The pipeline options can be configured through variable %s. You ' 'may also add additional options or sink transforms such as write ' 'to BigQuery in other notebook cells. Come back to click "Run on ' 'Dataflow" button once you complete additional configurations. ' 'Optionally, you can chain more beam_sql magics with DataflowRunner ' 'and click "Run on Dataflow" in their outputs.', options_name_inited) self.notice_shown = True display(options_output_area) display(run_output_area)
def toExploration(self, event=None): reload = self.showPanel("Exploration") if reload: self.ui["Exploration"]["grid"].children = [] main_dimensions = [] secondary_dimensions = [] for k in self.ui["Filters"]["grid"].get_changed_df().columns: if "input" in k: main_dimensions.append( Checkbox(value=True, description=k, layout=Layout(width="auto"))) else: main_dimensions.append( Checkbox(value=False, description=k, layout=Layout(width="auto"))) secondary_dimensions.append( Checkbox(value=True, description=k, layout=Layout(width="auto"))) self.ui["Exploration"]["main_dimensions"] = main_dimensions self.ui["Exploration"]["main_plot"] = Dropdown( description="Visualization", options=[ "sankey", "pca", "sankeytree", "sunburst", "parallelscat", "scattermatrix" ], value="sankey") self.ui["Exploration"][ "secondary_dimensions"] = secondary_dimensions self.ui["Exploration"]["secondary_plot1"] = Dropdown( description="Visualization", options=[ "table", "corrcoef", "sankey", "pca", "sankeytree", "sunburst", "parallelscat", "parallels", "scattermatrix" ], value="corrcoef") self.ui["Exploration"]["secondary_plot2"] = Dropdown( description="Visualization", options=[ "table", "corrcoef", "sankey", "pca", "sankeytree", "sunburst", "parallelscat", "parallels", "scattermatrix" ], value="table") vb1 = VBox(main_dimensions, layout=Layout(width="100%", padding="10px")) vb1 = GridBox(layout=Layout( width='auto', grid_template_columns='auto auto auto', grid_template_rows=" ".join([ 'auto' for i in self.ui["Exploration"]["main_dimensions"] ]), grid_gap='1px 1px')) children = [] for i, w in enumerate(self.ui["Exploration"]["main_dimensions"]): children.append(w) up = Button(icon="angle-up", layout=Layout(width="50px")) up.on_click( lambda b, this=self, pos=i, w=vb1, l="main_dimensions": this.moveOption(pos, True, w, l)) children.append(up) down = Button(icon="angle-down", layout=Layout(width="50px")) down.on_click( lambda b, this=self, pos=i, w=vb1, l="main_dimensions": this.moveOption(pos, False, w, l)) children.append(down) vb1.children = children vb2 = GridBox(layout=Layout(width='auto', grid_template_columns='auto auto auto', grid_template_rows=" ".join([ 'auto' for i in self.ui["Exploration"] ["secondary_dimensions"] ]), grid_gap='1px 1px')) children = [] for i, w in enumerate( self.ui["Exploration"]["secondary_dimensions"]): children.append(w) up = Button(icon="angle-up", layout=Layout(width="50px")) up.on_click( lambda b, this=self, pos=i, w=vb2, l= "secondary_dimensions": this.moveOption(pos, True, w, l)) children.append(up) down = Button(icon="angle-down", layout=Layout(width="50px")) down.on_click( lambda b, this=self, pos=i, w=vb2, l= "secondary_dimensions": this.moveOption(pos, False, w, l)) children.append(down) vb2.children = children self.ui["Exploration"]["grid"].children = [ VBox([ Button(description="Main Dimensions", layout=Layout(width='auto'), style=ButtonStyle(button_color='lightblue')), self.ui["Exploration"]["main_plot"], vb1, ], layout=Layout(width="50%")), VBox([ Button(description="Secondary Dimensions", layout=Layout(width='auto'), style=ButtonStyle(button_color='lightblue')), self.ui["Exploration"]["secondary_plot1"], self.ui["Exploration"]["secondary_plot2"], vb2, ], layout=Layout(width="50%")) ]
def __init__( self, path=os.getcwd(), filename='', show_hidden=False, use_dir_icons=False, filter_pattern=None, **kwargs): """Initialize FileChooser object.""" self._default_path = path.rstrip(os.path.sep) self._default_filename = filename self._show_hidden = show_hidden self._use_dir_icons = use_dir_icons self._filter_pattern = filter_pattern # Widgets self._pathlist = Dropdown( description="", layout=Layout( width='auto', grid_area='pathlist' ) ) self._dircontent = Select( rows=8, layout=Layout( width='auto', grid_area='dircontent' ) ) # Widget observe handlers self._pathlist.observe( self._on_pathlist_select, names='value' ) self._dircontent.observe( self._on_dircontent_select, names='value' ) # Layout self._gb = GridBox( children=[ self._pathlist, self._dircontent ], layout=Layout( width='500px', grid_gap='0px 0px', grid_template_rows='auto auto', grid_template_columns='60% 40%', grid_template_areas=''' 'pathlist pathlist' 'dircontent dircontent' ''' ) ) # Call setter to set initial form values self._set_form_values( self._default_path, self._default_filename ) self._initialize_form_values() # Call VBox super class __init__ super().__init__( children=[self._gb], layout=Layout(width='auto'), **kwargs )
hexDrop = Dropdown(options = ['viridis', 'plasma', 'inferno', 'magma', 'hot', 'winter', 'ocean', 'gray', 'binary'], value = 'viridis', description = 'Hess diagram colormap', style=style, disabled = False, grid_area = 'hexDrop' ) #Combine widgets into grid widgrid = GridBox(children = [RABox, RASlider, gridSlider, DECBox, DECSlider, hexDrop, radBox, radSlider], layout=Layout( width ='1300px', align_items = 'flex-start', grid_template_rows = 'auto auto auto', grid_template_columns = '25% 40% 35%', grid_template_areas = ''' "RABox RASlider gridSlider" "DECBox DECSlider hexDrop" "radBox radSlider ." ''') ) #Link boxes with sliders RALink = jslink((RABox, 'value'), (RASlider, 'value')) DECLink = jslink((DECBox, 'value'), (DECSlider, 'value')) radLink = jslink((radBox, 'value'), (radSlider, 'value')) def generate_plots(gsize, ra, dec, ang, style): """Generates plots from queried data""" r = res(ra, dec, ang)
def __init__(self, path=os.getcwd(), filename='', title='', select_desc='Select', change_desc='Change', show_hidden=False, select_default=False, use_dir_icons=False, **kwargs): """Initialize FileChooser object.""" self._default_path = path.rstrip(os.path.sep) self._default_filename = filename self._selected_path = None self._selected_filename = None self._show_hidden = show_hidden self._select_desc = select_desc self._change_desc = change_desc self._callback = None self._use_dir_icons = use_dir_icons # Widgets self._pathlist = Dropdown(description="", layout=Layout(width='auto', grid_area='pathlist')) self._filename = Text(placeholder='output filename', layout=Layout(width='auto', grid_area='filename')) self._dircontent = Select(rows=8, layout=Layout(width='auto', grid_area='dircontent')) self._cancel = Button(description='Cancel', layout=Layout(width='auto', display='none')) self._select = Button(description=self._select_desc, layout=Layout(width='auto')) self._title = HTML(value=title) if title == '': self._title.layout.display = 'none' # Widget observe handlers self._pathlist.observe(self._on_pathlist_select, names='value') self._dircontent.observe(self._on_dircontent_select, names='value') self._filename.observe(self._on_filename_change, names='value') self._select.on_click(self._on_select_click) self._cancel.on_click(self._on_cancel_click) # Selected file label self._label = HTML(value=self._LBL_TEMPLATE.format( self._LBL_NOFILE, 'black'), placeholder='', description='') # Layout self._gb = GridBox( children=[self._pathlist, self._filename, self._dircontent], layout=Layout(display='none', width='500px', grid_gap='0px 0px', grid_template_rows='auto auto', grid_template_columns='60% 40%', grid_template_areas=''' 'pathlist filename' 'dircontent dircontent' ''')) buttonbar = HBox(children=[self._select, self._cancel, self._label], layout=Layout(width='auto')) # Call setter to set initial form values self._set_form_values(self._default_path, self._default_filename) # Use the defaults as the selected values if select_default: self._apply_selection() # Call VBox super class __init__ super().__init__(children=[ self._title, self._gb, buttonbar, ], layout=Layout(width='auto'), **kwargs)
def _init_grid(self): # Set up scales for the spatial x, spatial y, spectral, and flux self.scale_x = bqplot.LinearScale(min=0, max=1) self.scale_y = bqplot.LinearScale(min=0, max=1) self.scale_spec = bqplot.LinearScale(min=0, max=1) self.scale_flux = bqplot.LinearScale(min=0, max=1) # Set up colorscale self.scale_cutout_image = ColorScale(colors=['black', 'white']) self.scale_spec2d_image = ColorScale(colors=['black', 'white']) # Set up axes self.axis_x = bqplot.Axis(scale=self.scale_x, grid_lines='solid', label='x') self.axis_y = bqplot.Axis(scale=self.scale_y, grid_lines='solid', label='y', orientation='vertical') self.axis_spec = bqplot.Axis(scale=self.scale_spec, grid_lines='solid', label='spec') self.axis_flux = bqplot.Axis(scale=self.scale_flux, grid_lines='solid', label='flux', orientation='vertical') # Set up bqplot viewers # ===================== # Cutout # ------ self.fig_cutout = bqplot.Figure(scales={ 'x': self.scale_x, 'y': self.scale_y }, axes=[self.axis_x, self.axis_y], layout={ 'width': '500px', 'height': '400px' }) self.fig_cutout.interaction = PanZoom(scales={ 'x': [self.scale_x], 'y': [self.scale_y] }) # Spec 2d # ------- self.fig_spec2d = bqplot.Figure(scales={ 'x': self.scale_spec, 'y': self.scale_y }, axes=[self.axis_spec, self.axis_y], layout={ 'width': '500px', 'height': '400px' }) self.fig_spec2d.interaction = PanZoom(scales={ 'x': [self.scale_spec], 'y': [self.scale_y] }) # Spec 1d # ------- self.fig_spec1d = bqplot.Figure(scales={ 'x': self.scale_spec, 'y': self.scale_flux }, axes=[self.axis_spec, self.axis_flux], layout={ 'width': '500px', 'height': '400px' }) self.fig_spec1d.interaction = PanZoom(scales={ 'x': [self.scale_spec], 'y': [self.scale_flux] }) # info box # -------- self.info_box = Textarea(value='Hello World') self.info_box.layout.height = '100%' self.info_box.layout.width = '100%' self.info_box.layout.align_self = 'flex-end' # Set up content of figures # ========================= self.cutout_mark = AstroImage(scales={ 'x': self.scale_x, 'y': self.scale_y, 'image': self.scale_cutout_image }) self.fig_cutout.marks = [self.cutout_mark] self.spec2d_mark = AstroImage( scales={ 'x': self.scale_spec, 'y': self.scale_y, 'image': self.scale_spec2d_image }) self.fig_spec2d.marks = [self.spec2d_mark] self.spec1d_mark = bqplot.Lines(scales={ 'x': self.scale_spec, 'y': self.scale_flux }, x=[], y=[]) self.fig_spec1d.marks = [self.spec1d_mark] GridBox.__init__(self, [ self.fig_cutout, HTML(), self.fig_spec2d, HTML(), HTML(), HTML(), self.info_box, HTML(), self.fig_spec1d ], layout=Layout(width='100%', grid_template_columns='35% 5% 35%', grid_template_rows='30% 5% 30%', grid_gap='30px 30px')) self.layout.justify_content = "center" self.layout.align_items = "center"