def createHistoryPanel(self): self.activeui = widgets.SelectMultiple( options=[], value=[], rows=4, disabled=False ) self.activeui.layout = widgets.Layout(width='99%') self.historyui = widgets.SelectMultiple( options=[], value=[], rows=4, disabled=False ) self.historyui.layout = widgets.Layout(width='99%') bt = widgets.Button( description = 'Recreate plot', disabled=False, button_style='', # 'success', 'info', 'warning', 'danger' or '' tooltip='re creates plot', ) bt.on_click(lambda e : GlueManagerWidget.restorePlot(self)) hb4 = widgets.HBox([self.historyui, bt]) vb4 = widgets.VBox([self.activeui, hb4]) return vb4
def latex_tab(db, output): b_table = widgets.Button(description="Display Latex Table") # d_avg_across_columns = widgets.Text( # value=str(db.vars.get('avg_across', 'None')), # description='avg_across:', # disabled=False # ) hparam_txt = widgets.Label(value="Select Rows:", layout=widgets.Layout(width='300px'),) try: db.latex_rows_widget = widgets.SelectMultiple(options=db.rm.exp_params, value=list(db.vars.get('latex_rows'))) except: db.latex_rows_widget = widgets.SelectMultiple(options=db.rm.exp_params, value=[db.rm.exp_params[0]]) metrics_txt = widgets.Label(value="Select Columns:", layout=db.layout_label,) try: db.latex_cols_widget = widgets.SelectMultiple(value=list(db.vars.get('latex_columns')), options=db.rm_original.score_keys) except: db.latex_cols_widget = widgets.SelectMultiple(value=[db.rm_original.score_keys[0]], options=db.rm_original.score_keys) button = widgets.VBox([ widgets.HBox([hparam_txt, metrics_txt]), widgets.HBox([db.latex_rows_widget, db.latex_cols_widget]), widgets.HBox([b_table]), ]) output_plot = widgets.Output() with output: display(button) display(output_plot) def on_clicked(b): output_plot.clear_output() with output_plot: db.update_rm() db.vars['latex_rows'] = list(db.latex_rows_widget.value) db.vars['latex_columns'] = list(db.latex_cols_widget.value) # print('cols', db.hparam_dict) # stop score_table = db.rm.get_latex_table(columns=db.vars.get('latex_columns'), rows=db.vars.get('latex_rows'), caption='Results') print(score_table) b_table.on_click(on_clicked)
def select_labels(self): set_all_columns = set([ col.name for col in self._all_columns]) set_features = set([ col.name for col in self._list_structfield_features]) set_labels = set([ col.name for col in self._list_structfield_label]) set_ids = set([ col.name for col in self._list_structfield_id]) list_avail_columns = list( set_all_columns - set_features - set_labels - set_ids) widget_select_labels = widgets.SelectMultiple( value= [], options= list_avail_columns, description= "Select Features" ) def obs_feature(change): if change.new != change.old: self._list_structfield_label = [ i for i in self._all_columns if i.name in widget_select_labels.value ] widget_select_labels.observe(obs_feature, names= 'value') display.display(widget_select_labels)
def make_trial_event_controller(trials, layout=None, multiple=False): """Controller for which reference to use (e.g. start_time) when making time-aligned averages""" trial_events = ["start_time"] if not np.all(np.isnan(trials["stop_time"].data)): trial_events.append("stop_time") trial_events += [ x.name for x in trials.columns if (("_time" in x.name) and (x.name not in ("start_time", "stop_time"))) ] kwargs = {} if layout is not None: kwargs.update(layout=layout) if multiple: trial_event_controller = widgets.SelectMultiple( options=trial_events, value=["start_time"], description='align to:', disabled=False, **kwargs) else: trial_event_controller = widgets.Dropdown(options=trial_events, value="start_time", description="align to: ", **kwargs) return trial_event_controller
def display_metadata_list(self): self.list_images = self.get_list_of_images() list_images = self.list_images self.record_file_extension(filename=list_images[0]) image0 = list_images[0] o_image0 = Image.open(image0) info = collections.OrderedDict(sorted(o_image0.tag_v2.items())) display_format = [] list_default_value_selected = [] dict_of_metadata = {} for tag, value in info.items(): formatted_string = "{} -> {}".format(tag, value) dict_of_metadata[formatted_string] = tag display_format.append(formatted_string) if tag in self.default_metadata_to_select: list_default_value_selected.append(formatted_string) self.box1 = widgets.HBox([widgets.Label("Select Metadata:", layout=widgets.Layout(width='10%')), widgets.SelectMultiple(options=display_format, value=list_default_value_selected, layout=widgets.Layout(width='50%', height='300px'))]) display(self.box1) self.dict_of_metadata = dict_of_metadata
def __init__(self, heading, options, value, db_vars, var): h = widgets.Label( value="Select Rows:", layout=widgets.Layout(width=WIDTH), ) sm = widgets.SelectMultiple(options=db.rm.exp_params, value=list(db.vars.get('latex_rows'))) return
def createSubsetsPanel(self): self.subsetsui = widgets.SelectMultiple( options=[sset.label for sset in self.gluemanager.data.subsets], value=[], rows=4, disabled=False ) self.subsetsui.layout = widgets.Layout(width='99%') bt = widgets.Button( description='Create new Subset.', disabled=False, button_style='', # 'success', 'info', 'warning', 'danger' or '' tooltip='createa new subset from current selection', ) bt.layout = widgets.Layout(width='99%') tx = widgets.Text( value='', placeholder='new subset name', disabled=False ) tx.layout = widgets.Layout(width='99%') bt.on_click(lambda e : GlueManagerWidget.createSubsetFromSelection(self, tx)) dl = widgets.Button( description='remove selected Subsets', disabled=False, button_style='danger', tooltip='Removes active subsets from the data workspace', ) dl.layout = widgets.Layout(width='99%') dl.on_click(lambda e : GlueManagerWidget.deleteSubsetFromSelection(self)) sl = widgets.Button( description='Hide selected subsets', disabled=False, button_style='warning', tooltip='', ) sl.layout = widgets.Layout(width='99%') vb = widgets.VBox([dl, sl]) vb2 = widgets.VBox([tx, bt]) hb1 = widgets.HBox([vb2,self.subsetsui,vb]) vb3 = widgets.VBox([hb1]) return vb3
def _create_widgets(self): self.sel_file = widgets.SelectMultiple( description='Product', options=self.filenames, value=[self.filenames[0]], layout=Layout(width="100%"), ) self.button = widgets.Button(description="Submit") self.button.on_click(self._on_button_clicked)
def createMenuItem(self): self.menuglobal = widgets.SelectMultiple(options=self.getalltickers()) # button, output, function and linkage self.butt = widgets.Button(description='Select Tickers!') self.outt = widgets.Output() self.textbox = widgets.Text( value='last', placeholder='Enter Simulation start date!', description='Enter Date to start Simulation!:', disabled=False)
def __init__(self, dynamic_table: DynamicTable, group_by=None, window=None, start_discard_rows=None): """ Parameters ---------- dynamic_table group_by window: None or bool, """ super().__init__(dynamic_table) groups = self.get_groups() self.discard_rows = start_discard_rows self.limit_bit = widgets.BoundedIntText(value=50, min=0, max=99999, disabled=True, layout=Layout(max_width='70px')) self.limit_bit.observe(self.limit_bit_observer) self.limit_cb = widgets.Checkbox(description='limit', style={'description_width': 'initial'}, disabled=True, indent=False, layout=Layout(max_width='70px')) self.limit_cb.observe(self.limit_cb_observer) self.order_dd = widgets.Dropdown(options=[None] + list(groups), description='order by', layout=Layout(max_width='120px'), style={'description_width': 'initial'}) self.order_dd.observe(self.order_dd_observer) self.ascending_dd = widgets.Dropdown(options=['ASC', 'DESC'], disabled=True, layout=Layout(max_width='70px')) self.ascending_dd.observe(self.ascending_dd_observer) range_controller_max = min(30, self.nitems) if window is None: self.range_controller = RangeController(0, self.nitems, start_value=(0, range_controller_max), dtype='int', description='units', orientation='vertical') self.range_controller.observe(self.range_controller_observer) self.window = self.range_controller.value elif window is False: self.window = (0, self.nitems) self.range_controller = widgets.HTML('') self.group_sm = widgets.SelectMultiple(layout=Layout(max_width='100px'), disabled=True, rows=1) self.group_sm.observe(self.group_sm_observer) if group_by is None: self.group_dd = widgets.Dropdown(options=[None] + list(groups), description='group by', style={'description_width': 'initial'}, layout=Layout(width='90%')) self.group_dd.observe(self.group_dd_observer) else: self.group_dd = None self.set_group_by(group_by) self.children = self.get_children() self.layout = Layout(width='280px') self.update_value()
def select_metadata_to_extrapolate(self): list_metadata = self.get_column_names(self.merged_dataframe) display(HTML('<span style="font-size: 15px; color:blue">CTRL + Click to select multiple rows!</span>')) box = widgets.HBox([widgets.Label("Select Metadata to Extrapolate:", layout=widgets.Layout(width='30%')), widgets.SelectMultiple(options=list_metadata, layout=widgets.Layout(width='70%', height='70%')) ], layout=widgets.Layout(height='250px')) self.metadata_to_extrapolate_widget = box.children[1] display(box)
def interact(): from ipywidgets import interactive, fixed, widgets, interact_manual from IPython.display import display from ipywidgets import AppLayout, Button, Layout target_values_options = list(df["{}"].unique()) features_options = list(df.columns.values) features_options.remove("{}") w1 = widgets.SelectMultiple( options=target_values_options, value=target_values_options, rows=len(target_values_options), description="Target Values (column: {})", style={{ "description_width": "initial" }}, disabled=False, ) w2 = widgets.SelectMultiple( options=features_options, value=features_options[0:min(len(features_options), 2)], rows=len(features_options), description="Features", disabled=False, ) ui = widgets.HBox([w1, w2]) out = widgets.interactive_output( pairwise_scatter_plots, {{ "df": fixed(df), "target_values": w1, "features": w2 }}, ) display(ui, out)
def SelectMultiple(question, options=['1', '2', '3', '4', '5']): start_time = time.time() widget = widgets.SelectMultiple(options=options, value=['1'], description='Answers', disabled=False) display(widget) def on_value_change(change): # Appends to the dictionary answer Answer_Dict[question].append(change["new"]) widget.observe(on_value_change, names='value') button(question, start_time)
def __init__(self, header, options, db_vars, var): org_value = db_vars.get(var) if org_value is None: value = [options[0]] else: value = [v for v in org_value if v in options] self.header = widgets.Label( value=header, layout=widgets.Layout(width=WIDTH), ) self.select_multiple = widgets.SelectMultiple( options=options, value=value, layout=widgets.Layout(width=WIDTH)) self.db_vars = db_vars self.var = var
def __init__(self, Notebook): super(Plot_Pareto_Fronts, self).__init__(Notebook) self.notebook.dependencies_dict["seed"].append(self) self.widget_selectGenerations = widgets.SelectMultiple( options=[None], value=[None], description='Generation', disabled=True) self.widget_selectText = widgets.Text( value="", placeholder="List of generations separated with commas.", disabled=True) self.widget_plot = widgets.Button(description="Plot Pareto Fronts", disabled=True) self._widget_with_indexes = widgets.Checkbox( value=False, description='Display indexes', disabled=False)
def compare(files=widgets.SelectMultiple(options=result_analyse. resultloader.get_runs_summary( dataset), description='Files', layout=Layout( width='100%', height='180px')), metric=metrics, titles="title1,title2"): run_info = {} dataset = {} evalres = {} res = {} titles = titles.split(',') if (len(titles) != len(files)): print('Titles are not correct. use files names instead') titles = files print(files) for i, file in enumerate(files): print(i, file) t = titles[i] run_info[t], dataset[t], evalres[t] = utils.loadState(file) # print(evalres[t]) # for i in evalres[t]: # evalres[t][i]['test'].Sdata=None dataset[t].sensor_events = None res[t] = an.mergeEvals(dataset[t], evalres[t], metric) res = {t: res[t] for t in sorted(res.keys())} import pandas as pd from IPython.display import display, HTML actres = {} for k in dataset[t].activities_map: if (k == 0): continue actres[k] = {(m, e): res[m][k]['avg'][e] for m in res for e in res[m][k]['avg']} print('act=', k, '==============================') # print(actres[k]) if (len(actres[k]) == 0): print('No Eval') else: df2 = pd.DataFrame(actres[k]).round(2) display(HTML(df2.to_html())) vs.plotJoinMetric(res, [k for k in res[t]], dataset[t].activities_map)
def _create_sim_dropdown(self, options): """ Provide the widget for selection of simulations. Can be overridden in derived classes if some of those widgets are not necessary. Note: Make sure that no value of the widget is selected initially since otherwise initial plotting after creation of the widget might not work (since the constructor sets the value to the first available which leads to the visualization callback being triggered.) Returns ------- a jupyter widget that allows selection of value(s) """ sim_drop = widgets.SelectMultiple(description="Sims", options=options, value=()) return sim_drop
def __init__(self, on_interact=None, output=None, overwrite_previous_output=True, feedback=False, run=True, action_kws={}, *args, **kwargs): super().__init__(on_interact=on_interact, output=output, overwrite_previous_output=overwrite_previous_output, feedback=feedback, action_kws=action_kws) self.widget = widgets.SelectMultiple(*args, **kwargs) if run: self.run()
def select_data_to_keep(self, default_selection=[-1]): # names of the columns in the data part list_columns = self.get_data_column_names() # what to select by default when showing the widget default_value = [list_columns[_index] for _index in default_selection] self.box = widgets.HBox([ widgets.Label( "Select Metadata(s) to Keep:", layout=widgets.Layout(width='30%'), ), widgets.SelectMultiple(options=list_columns, value=default_value, rows=10, layout=widgets.Layout(width='30%')), ]) display(self.box)
def multi_select(self, callback_method, _analyser, options, rows=6, description="", variable="", width='100%'): _analyser.data[variable] = [] multi_select = widgets.SelectMultiple(options=options, rows=rows, description=description, disabled=False, layout=widgets.Layout( width=width, grid_area=variable)) multi_select.observe(callback_method, ['value']) return multi_select
def select_metadata(self, system=None, list_of_files=[]): if not list_of_files: display( HTML( '<span style="font-size: 20px; color:red">You need to select at least one file!</span>' )) return if not system: display( HTML( '<span style="font-size: 20px; color:red">No input folder selected!</span>' )) return self.instrument = system.System.get_instrument_selected() self.facility = system.System.get_facility_selected() self.list_of_files = list_of_files self.first_file = list_of_files[0] self.list_metadata_with_examples = self.retrieve_list_metadata_with_examples( ) display( HTML( '<span style="font-size: 20px; color:blue">CTRL + Click to select multiple rows!</span>' )) box1 = widgets.HBox([ widgets.Label("Select Metadata To Retrieve", layout=widgets.Layout(width='20%')), widgets.SelectMultiple(options=self.list_metadata_with_examples, layout=widgets.Layout(width='80%', height='100%')) ], layout=widgets.Layout(height='500px')) self.select_box = box1.children[1] display(box1)
def display_metadata(self, list_nexus): self.o_file.shortcut_buttons.close() self.list_nexus = list_nexus self.list_keys = self.retrieve_left_widget_list_keys() self.list_values = self.retrieve_right_widget_list_keys( left_widget_key_selected=list(self.list_keys)[0]) # search box search_box = widgets.HBox([ widgets.Label("Search:"), widgets.Text("", layout=widgets.Layout(width="30%")) ]) # search_text_widget = search_box.children[1] # search_text_widget.observe(self.search_text_changed, names='value') # list of keys hori_box = widgets.HBox([ widgets.Select(options=self.list_keys, layout=widgets.Layout(width="400px", height=self.widget_height)), widgets.SelectMultiple(options=self.list_values, layout=widgets.Layout( width="400px", height=self.widget_height)) ], ) display(hori_box) [self.left_widget_ui, self.right_widget_ui] = hori_box.children self.left_widget_ui.observe(self.left_widget_changed, names='value') self.right_widget_ui.observe(self.right_widget_changed, names='value') display( widgets.Label( "Command + Click: to select more than 1 element in the right widget" ))
def __init__(self, header, options, db_vars, var, select_all=False): org_value = db_vars.get(var) if org_value is None: if len(options) > 0: if select_all: value = options else: value = [options[0]] else: value = [] else: value = [v for v in org_value if v in options] if len(value) == 0 and len(options) > 0: value = [options[0]] self.header = widgets.Label( value=header, layout=widgets.Layout(width=WIDTH), ) self.select_multiple = widgets.SelectMultiple( options=options, value=value, layout=widgets.Layout(width=WIDTH)) self.db_vars = db_vars self.var = var
def tables_tab(db, output): d_columns_txt = widgets.Label( value="Select Hyperparam column", layout=db.layout_label, ) d_columns = widgets.Dropdown( options=['None'] + db.rm.exp_params, value='None', layout=db.layout_dropdown, disabled=False, ) d_score_columns_txt = widgets.Label( value="Select Score column", layout=db.layout_label, ) d_score_columns = widgets.Dropdown( options=db.rm_original.score_keys, value='None', layout=db.layout_dropdown, disabled=False, ) bstatus = widgets.Button(description="Jobs Status") blogs = widgets.Button(description="Jobs Logs") bfailed = widgets.Button(description="Jobs Failed") b_table = widgets.Button(description="Display Table") b_meta = widgets.Button(description="Display Meta Table") b_diff = widgets.Button(description="Display Filtered Table") # d_avg_across_columns = widgets.Text( # value=str(db.vars.get('avg_across', 'None')), # description='avg_across:', # disabled=False # ) d_avg_across_txt = widgets.Label(value="avg_across:", ) d_avg_across_columns = widgets.Dropdown( options=['None'] + db.rm.exp_params, value='None', layout=db.layout_dropdown, disabled=False, ) hparam_txt = widgets.Label( value="Hyperparamters:", layout=widgets.Layout(width='300px'), ) db.hparam_widget = widgets.SelectMultiple(options=db.rm.exp_params) metrics_txt = widgets.Label( value="Metrics:", layout=db.layout_label, ) db.metrics_widget = widgets.SelectMultiple( options=[k for k in db.rm_original.score_keys if k is not 'None']) button = widgets.VBox([ widgets.HBox([hparam_txt, metrics_txt]), widgets.HBox([db.hparam_widget, db.metrics_widget]), widgets.HBox([ b_table, bstatus, blogs, bfailed, d_avg_across_txt, d_avg_across_columns ]), # widgets.HBox([d_columns_txt, d_score_columns_txt]), # widgets.HBox([d_columns, d_score_columns ]), ]) output_plot = widgets.Output() with output: display(button) display(output_plot) def on_table_clicked(b): output_plot.clear_output() with output_plot: db.update_rm() db.vars['avg_across'] = d_avg_across_columns.value avg_across_value = db.vars.get('avg_across', 'None') if avg_across_value == "None": avg_across_value = None db.vars['columns'] = list(db.hparam_widget.value) db.vars['score_columns'] = list(db.metrics_widget.value) # print('cols', db.hparam_dict) # stop score_table = db.rm.get_score_table( columns=db.vars.get('columns'), score_columns=db.vars.get('score_columns'), avg_across=avg_across_value) display(score_table) def on_job_status_clicked(b): output_plot.clear_output() with output_plot: db.update_rm() summary_list = db.rm.get_job_summary(verbose=db.rm.verbose, add_prefix=True) summary_dict = hu.group_list(summary_list, key='job_state', return_count=True) display(summary_dict) summary_dict = hu.group_list(summary_list, key='job_state', return_count=False) for state in summary_dict: n_jobs = len(summary_dict[state]) if n_jobs: display('Experiments %s: %d' % (state, n_jobs)) df = pd.DataFrame(summary_dict[state]) display(df.head()) def on_logs_clicked(b): output_plot.clear_output() with output_plot: summary_list = db.rm.get_job_summary(verbose=db.rm.verbose, add_prefix=True) n_logs = len(summary_list) for i, logs in enumerate(summary_list): print('\nLogs %d/%d' % (i + 1, n_logs), '=' * 50) print('exp_id:', logs['exp_id']) print('job_id:', logs['job_id']) print('job_state:', logs['job_state']) print( 'savedir:', os.path.join(db.rm_original.savedir_base, logs['exp_id'])) print('\nexp_dict') print('-' * 50) pprint.pprint(logs['exp_dict']) print('\nLogs') print('-' * 50) pprint.pprint(logs.get('logs')) def on_failed_clicked(b): output_plot.clear_output() with output_plot: db.update_rm() summary_list = db.rm.get_job_summary(verbose=db.rm.verbose, add_prefix=True) summary_dict = hu.group_list(summary_list, key='job_state', return_count=False) if 'FAILED' not in summary_dict: display('NO FAILED JOBS') return n_failed = len(summary_dict['FAILED']) if n_failed == 0: display('no failed experiments') else: for i, failed in enumerate(summary_dict['FAILED']): print('\nFailed %d/%d' % (i + 1, n_failed), '=' * 50) print('exp_id:', failed['exp_id']) print('job_id:', failed['job_id']) print('job_state:', 'FAILED') print( 'savedir:', os.path.join(db.rm_original.savedir_base, failed['exp_id'])) print('\nexp_dict') print('-' * 50) pprint.pprint(failed['exp_dict']) print('\nLogs') print('-' * 50) pprint.pprint(failed.get('logs')) # Add call listeners b_table.on_click(on_table_clicked) bstatus.on_click(on_job_status_clicked) blogs.on_click(on_logs_clicked) bfailed.on_click(on_failed_clicked) d_columns.observe(on_table_clicked) d_score_columns.observe(on_table_clicked) # meta stuff and column filtration def on_bmeta_clicked(b): db.vars['show_meta'] = 1 - db.vars.get('show_meta', 0) on_table_clicked(None) def on_hparam_diff_clicked(b): db.vars['hparam_diff'] = 2 - db.vars.get('hparam_diff', 0) on_table_clicked(None) b_meta.on_click(on_bmeta_clicked) b_diff.on_click(on_hparam_diff_clicked)
def create_cell_selection(self): def downloadNIP(_): with out: clear_output() os.chdir("transfer") for f in os.listdir("."): if f.startswith("exp"): os.remove(f) w3 = [] for k in range(len(w.value)): w4 = w.value[k] w4p = w4[w4.find('mice'):len(w4)] w3.append('exp' + w4p[w4p.find('(') + 1:w4p.find(')')] + '.txt') for k in range(len(cell_list.listurldownload)): data_nrrd_url = cell_list.listurldownload[k] filename = data_nrrd_url[data_nrrd_url. find('exp'):len(data_nrrd_url)] if filename in w3: my_data = requests.get(data_nrrd_url) with open(filename, 'wb') as fd: for chunk in my_data.iter_content(): fd.write(chunk) os.chdir("../..") plots.PlotsSEF(self.RB, w, out) os.chdir("GUI") TB.layout.display = '' self.RB.layout.display = '' self.RB1.disabled = False self.RBHPC.disabled = False self.RBM.disabled = False w = widgets.SelectMultiple(description='', options=cell_list.listnames, layout=widgets.Layout(width="100%", border='solid')) text = widgets.Text() text.value = 'Select experimental data to download from CSCS storage' text.disabled = True text.layout.width = '80%' display(text) TB = widgets.Text() TB.value = 'Select experimental data:' TB.disabled = True self.RB.layout = {'width': 'max-content'} BB = widgets.VBox(children=[TB, self.RB]) TB.layout.display = 'none' self.RB.layout.display = 'none' NIPD = widgets.Button() NIPD.background_color = 'gainsboro' NIPD.border_color = 'black' NIPD.layout.width = '20%' NIPD.description = 'Download data' NIPD.on_click(downloadNIP) out = widgets.Output() display(w) display(NIPD) display(BB) display(out)
def build_layout(self, dset_id: str): """ :param dset_id: :return: """ all_fields = list(self.get_data(dset_id=dset_id).keys()) try: field_reference = self.skd[dset_id].attrs('target') except: field_reference = all_fields[0] fields_comparison = [all_fields[1]] # chart type widget self.register_widget( chart_type=widgets.RadioButtons( options=['individual', 'grouped'], value='individual', description='Chart Type:' ) ) # bins widget self.register_widget( bins=IntSlider( description='Bins:', min=2, max=10, value=2, continuous_update=False ) ) # fields comparison widget self.register_widget( xs=widgets.SelectMultiple( description='Xs:', options=[f for f in all_fields if not f == field_reference], value=fields_comparison ) ) # field reference widget self.register_widget( y=widgets.Dropdown( description='Y:', options=all_fields, value=field_reference ) ) # used to internal flow control y_changed = [False] self.register_widget( box_filter_panel=widgets.VBox([ self._('y'), self._('xs'), self._('bins') ]) ) # layout widgets self.register_widget( table=widgets.HTML(), chart=widgets.HTML() ) self.register_widget(vbox_chart=widgets.VBox([ self._('chart_type'), self._('chart') ])) self.register_widget( tab=widgets.Tab( children=[ self._('box_filter_panel'), self._('table'), self._('vbox_chart') ] ) ) self.register_widget(dashboard=widgets.HBox([self._('tab')])) # observe hooks def w_y_change(change: dict): """ When y field was changed xs field should be updated and data table and chart should be displayed/updated. :param change: :return: """ # remove reference field from the comparison field list _xs = [ f for f in all_fields if not f == change['new'] ] y_changed[0] = True # flow control variable _xs_value = list(self._('xs').value) if change['new'] in self._('xs').value: _xs_value.pop(_xs_value.index(change['new'])) if not _xs_value: _xs_value = [_xs[0]] self._('xs').options = _xs self._('xs').value = _xs_value self._display_result(y=change['new'], dset_id=dset_id) y_changed[0] = False # flow control variable # widgets registration # change tab settings self._('tab').set_title(0, 'Filter') self._('tab').set_title(1, 'Data') self._('tab').set_title(2, 'Chart') # data panel self._('table').value = '...' # chart panel self._('chart').value = '...' # create observe callbacks self._('bins').observe( lambda change: ( self._display_result(bins=change['new'], dset_id=dset_id) ), 'value' ) self._('y').observe(w_y_change, 'value') # execute display result if 'y' was not changing. self._('xs').observe( lambda change: ( self._display_result(xs=change['new'], dset_id=dset_id) if not y_changed[0] else None ), 'value' ) self._('chart_type').observe( lambda change: ( self._display_result(chart_type=change['new'], dset_id=dset_id) ), 'value' )
def plot_gamma(data): """Plot all the interactions.""" groups = data.columns[1:].map(standardize_interaction).unique() fig = go.FigureWidget( layout=go.Layout( width=1000, xaxis=go.layout.XAxis( title="Inverse Temperature", type="log", exponentformat="power", ), yaxis=go.layout.YAxis( title="Interaction Rate", type="log", exponentformat="power", # range=[-20, 20], ), ) ) fig.add_shape( type="rect", x0=data["beta"].min(), x1=data["beta"].max(), y0=1e-1, y1=1e1, fillcolor="Grey", line_color="Grey", opacity=0.2, ) selected_groups = widgets.SelectMultiple( description="Group", options=groups, value=[], ) particles = widgets.SelectMultiple( description="Particle", options=sorted( set( [ p.split(".")[0] for group in groups for p in interaction_particle(group) ] ) ), value=[], ) def update_plot(_): with fig.batch_update(): fig.data = [] for column in data.columns[1:]: if standardize_interaction(column) not in selected_groups.value: continue if ( not data[column].isnull().all() and data[column].map(lambda x: x > 0).any() ): fig.add_trace( go.Scatter( name=column, showlegend=True, x=data["beta"], y=data[column] ) ) def update_groups(_): if len(particles.value) == 0: selected_groups.options = groups return new_groups = [] for group in groups: for p in particles.value: if p not in group: break else: new_groups.append(group) selected_groups.options = new_groups particles.observe(update_groups, names="value") selected_groups.observe(update_plot, names="value") return widgets.VBox( [ particles, selected_groups, fig, ] )
def __init__(self, table: DynamicTable): super().__init__() self.dynamic_table = table self.col_names, self.categorical_cols = infer_columns_to_plot( self.dynamic_table) num_entries = len(self.dynamic_table) num_columns = len(self.dynamic_table.colnames) num_columns_to_plot = len(self.col_names) num_categorical = len(self.categorical_cols) self.name_text = widgets.Label( f"Table name: {self.dynamic_table.name}\n", layout=field_lay) self.entries_text = widgets.Label( f"Number of entries: {num_entries}\n", layout=field_lay) self.col_text = widgets.Label( f"Number of columns: {num_columns} - real (r): {num_columns - num_categorical}, " f"categorical (c): {num_categorical}", layout=field_lay) self.col_plot_text = widgets.Label( f"Number of inspectable columns: {num_columns_to_plot}") self.summary_text = widgets.VBox([ self.name_text, self.entries_text, self.col_text, self.col_plot_text ]) self.col_names_display = {} for col in self.col_names: if col in self.categorical_cols: self.col_names_display[f"(c) {col}"] = col else: self.col_names_display[f"(r) {col}"] = col self.column_dropdown = widgets.SelectMultiple( options=list(self.col_names_display), description="Inspect columns", layout=Layout(max_width="400px"), style={"description_width": "initial"}, disabled=False, tooltip= "Select columns to inspect. You can select at most 1 categorical and 3 real columns." ) self.column_dropdown.observe(self.max_selection) self.nbins = widgets.IntText(10, min=0, description="# bins", layout=Layout(max_width="400px")) self.nbins.layout.visibility = "hidden" self.show_labels = widgets.Checkbox(value=True, description="show labels") self.plot_controls = widgets.HBox( [self.column_dropdown, self.nbins, self.show_labels]) self.controls = dict(col_names_display=self.column_dropdown, nbins=self.nbins, show_labels=self.show_labels) out_fig = interactive_output(self.plot_hist_bar, self.controls) bottom_panel = widgets.VBox([self.plot_controls, out_fig]) self.children = [self.summary_text, bottom_panel]
def automator_gui(filename): """ :parameter project_filename: The name of a puckle file containing an OQtProject """ global w_model, w_sources, w_nb_name, w_nb_type, w_repo, w_progress global project_filename, model global project_dir wdg_list = [] margin = 5 project_filename = filename oqmbtp = OQtProject.load_from_file(project_filename) models = oqmbtp.models.keys() project_dir = oqmbtp.directory w_title = widgets.HTML(value="<h3>Automator<h3>") tmp_str = "Name : %s <br>" % (oqmbtp.name) tmp_str += "Stored in: %s <br><br>" % (project_dir) w_text = widgets.HTML(value=tmp_str) wdg_list.append(w_title) wdg_list.append(w_text) tmp_str = "Warning: the model does not contain sources" w_warn = widgets.HTML(value=tmp_str, visible=False) if len(models): model_id = models[0] model = oqmbtp.models[model_id] w_model = widgets.Dropdown(options=models, description='Model', value=model_id, width=400, margin=margin) if len(model.sources.keys()): # Sources drop down menu tmp_list = sorted(model.sources.keys()) tmp_list.insert(0, 'All') tmp_str = 'Sources' w_sources = widgets.SelectMultiple(options=tmp_list, description=tmp_str, width=200, margin=margin) else: w_sources = widgets.Dropdown(options=[], description='Source') wdg_list.append(w_model) wdg_list.append(w_sources) else: w_warn.visible = True # Notebook type w_nb_type = widgets.Dropdown(options=NB_TYPES, description='Notebook type', width=400, margin=margin) wdg_list.append(w_nb_type) # Notebook name w_nb_name = widgets.Dropdown(options=[], description='Notebook name', width=400, margin=margin) wdg_list.append(w_nb_name) # Report checkbox w_repo = widgets.Checkbox(description='Generate report', value=False) wdg_list.append(w_repo) # Warning wdg_list.append(w_warn) # Button w_butt = widgets.Button(description='Run', width=100, border_color='red') wdg_list.append(w_butt) # Progress bar w_progress = widgets.FloatProgress(value=0.0, min=0.0, step=1, visible=False, description='Processing:') wdg_list.append(w_progress) w_model.on_trait_change(handle_change_model) w_nb_type.on_trait_change(handle_change_nb_type, 'value') w_butt.on_click(handle_run) # Clean variables del oqmbtp return widgets.VBox(children=wdg_list)
def __init__(self, path): self._css = """ <style> /*.container{ width: 98%; }*/ .output{ height:100%; } .output_scroll{ height: 100%; } .widget-label{ height: 100px; white-space: wrap; font-weight: bold; font-size: 16px; text-align: left; } .widget-checkbox { width: 90%; } .space{ text-align: left; font-size: 13px; } .space-checkBox{ text-align: left; font-size: 13px; margin-left: 3%; } .vazio{ color: red; font-size: 12px; text-align: left; } .center{ text-align: center; font-size: 17px; } .blue{ color: blue; font-size: 11.5px; } .vertical-line{ border-right: 1px groove black; } .horizontal-line{ border-bottom: 1px groove black; } .top-line{ border-top: 1px groove black; } .border{ border: 1px groove black; border-radius: 5px; } </style>""" ###### Boxes Creation ###### self._static = widgets.HBox() self._multiple_box = widgets.VBox() self._uniquePlusCollapse = widgets.HBox() self._selectMultiple = widgets.SelectMultiple() self._select = widgets.VBox() ###### Buttons Creation ###### self._collapse = widgets.Button(description="", tooltip="Collapse", icon="fa-angle-double-up") self._filter_btn = widgets.Button(description="Aplicar Filtros", icon="fa-paper-plane", button_style="primary") self._applyChooses = widgets.Button(description="Aplicar", button_style="primary", icon="fa-check-circle") ###### Variables Creation ###### self._path = path self._unicos = list() self._multiplas = list() self.finded = list() self._filtro = dict() self._arquivo = dict() self._arquivos = dict() self._refined = dict() self._fullFiles = dict() self._file_Path = dict() ###### Variable that receive external methods return - Creation ###### self._emExibicao = widgets.Label(value="", align_self="center") self._buildJson = FindFiles(self._path) self._mj = self._buildJson.montaJson() self._refineJson = RefineJson(self._mj) self._json = self._refineJson.build() self._leftBox()