def hide_quiet_widgets(self, widgs, template): try: verbosities = template.verbosities if verbosities is None: verbosities = [[1]*len(widg_list) for widg_list in widgs] elif len(verbosities) < len(widgs): missing = len(widgs) - len(verbosities) verbosities.extend([1]*missing) except AttributeError: verbosities = [[1]*len(widg_list) for widg_list in widgs] for dex in range(len(verbosities)): widg_list = widgs[dex] if not type(verbosities[dex]) is types.ListType: verbosities[dex] = [verbosities[dex]]*len(widg_list) if len(verbosities[dex]) < len(widg_list): missing = len(widg_list) - len(verbosities[dex]) verbosities[dex].extend([1]*missing) try: threshold = self.lset.get_setting('interface_verbosity') if not threshold: threshold = 1 except: threshold = 1 for widg, volume in zip(lfu.flatten(widgs), lfu.flatten(verbosities)): if not volume <= threshold: widg.hide()
def set_up_widg_templates(self, *args, **kwargs): if type(self.content) is types.ListType: #obliges if mobj needs widgets recalculated #uses the mobjs' widgets for the current widget set [content.set_settables(*self.settables_infos) for content in self.content if content.rewidget( infos = self.settables_infos)] self.widg_templates = lfu.flatten([content.widg_templates for content in self.content]) self.menu_templates = lfu.flatten([content.menu_templates for content in self.content]) self.tool_templates = lfu.flatten([content.tool_templates for content in self.content]) else: print 'window content unrecognized; window will be empty' self.content = []
def wrap_side(inst, key, depth): try: side = inst.__dict__[key] except KeyError: count = len(inst.widgets) if key == 'widg_spans': try: count = len(lfu.flatten(inst.labels)) except: pdb.set_trace() side = wrap_none(depth, count) return side
def set_up_widg_templates(self, *args, **kwargs): if type(self.content) is types.ListType: #obliges if mobj needs widgets recalculated #uses the mobjs' widgets for the current widget set [ content.set_settables(*self.settables_infos) for content in self.content if content.rewidget(infos=self.settables_infos) ] self.widg_templates = lfu.flatten( [content.widg_templates for content in self.content]) self.menu_templates = lfu.flatten( [content.menu_templates for content in self.content]) self.tool_templates = lfu.flatten( [content.tool_templates for content in self.content]) else: print 'window content unrecognized; window will be empty' self.content = []
def show_plot_lines(self, *args, **kwargs): #interpolate y so that it covers domain x def fill_via_interpolation(x, y): print 'interpolation for incorrectly '+\ 'structured data is not supported' def plot_(x, y, label, col): if not x.size == y.size: x, y = fill_via_interpolation(x, y) try: line = matplotlib.lines.Line2D( #x, y, color = self.colors.pop()) x, y, color = self.colors[col]) except IndexError: print 'too many lines!'; return except: pdb.set_trace() line.set_label(label) ax.add_line(line) self.resolve_x_domain() ax = self.add_plot() ax.grid(True) if type(self._data_.data[0]) is types.ListType: self._data_.data = lfu.flatten(self._data_.data) x_ax = lfu.grab_mobj_by_name(self.x_ax_title, self._data_.data) y_axes = [dater for dater in self._data_.data if dater.label in self._plot_targets_ and not dater.label is x_ax.label] #in self._plot_targets_] if not y_axes: print 'incorrect plot targets...reconciling...' y_axes = [dater for dater in self._data_.data] self.colors = [self.colormap(i) for i in np.linspace( 0, 0.9, min([self.max_line_count, len(y_axes)]))] x = np.array(x_ax.scalars) ys = [np.array(y_ax.scalars) for y_ax in y_axes if hasattr(y_ax, 'scalars')] [plot_(x, y, label, col_dex) for x, y, label, col_dex in zip([x]*len(ys), ys, [dater.label for dater in y_axes], range(len(ys)))] ax.axis([x.min(), x.max(), min([y.min() for y in ys]), max([y.max() for y in ys])]) ax.legend() #pylab.gca().set_xscale('log',basex=2) #ax.set_yscale('log') if self.x_log: ax.set_xscale('log') if self.y_log: ax.set_yscale('log') self.canvas.draw()
def apply_reduction(self, unred): read = self.parent.parent.read['layout'].read flat = lfu.flatten(read['table']) well_cnt = len(flat) reduced = unred[:len(unred)-well_cnt] #list of replicate averaged scalers con_offset = len(reduced) uniq = lfu.uniqfy(flat) layout = OrderedDict() for dex, key in enumerate(flat): if key in layout.keys(): layout[key].append(dex + con_offset) else: layout[key] = [dex + con_offset] new = lgeo.scalars_from_labels(layout.keys()) for ndex, key in enumerate(layout.keys()): rel_dexes = layout[key] rel_dater = [unred[d] for d in rel_dexes] zi = zip(*[r.scalars for r in rel_dater]) new[ndex].scalars = np.array([np.mean(z) for z in zi]) reduced.extend(new) red = lfu.data_container(data = reduced) return red
def interpret_template(self, template): widgs = [] if not hasattr(template, 'widgets'): pdb.set_trace() for widg_dex, widget_type in enumerate(template.widgets): if widget_type == 'button_set': widg_list = self.interpret_template_button_set( template, widg_dex) elif widget_type == 'check_set': widg_list = self.interpret_template_check_set( template, widg_dex) elif widget_type == 'text': widg_list = self.interpret_template_text_box( template, widg_dex) elif widget_type == 'selector': widg_list = self.interpret_template_combo_box( template, widg_dex) elif widget_type == 'image': widg_list = self.interpret_template_image( template, widg_dex) elif widget_type == 'spin': widg_list = self.interpret_template_spin( template, widg_dex) elif widget_type == 'slider': widg_list = self.interpret_template_slider( template, widg_dex) elif widget_type == 'slider_advanced': widg_list = self.interpret_template_slider_advanced( template, widg_dex) elif widget_type == 'radio': widg_list = self.interpret_template_radio( template, widg_dex) elif widget_type == 'splitter': widg_list = self.interpret_template_splitter( template, widg_dex) elif widget_type == 'panel': widg_list = self.interpret_template_panel( template, widg_dex) elif widget_type == 'file_name_box': widg_list = self.interpret_template_file_name_box( template, widg_dex) elif widget_type == 'directory_name_box': widg_list = self.interpret_template_directory_name_box( template, widg_dex) elif widget_type == 'full_path_box': widg_list = self.interpret_template_full_path_box( template, widg_dex) elif widget_type == 'check_spin_list': widg_list = self.interpret_template_check_spin_list( template, widg_dex) elif widget_type == 'mobj_inspector': widg_list = self.interpret_template_inspector( template, widg_dex) elif widget_type == 'mobj_catalog': widg_list = self.interpret_template_catalog( template, widg_dex) elif widget_type == 'tab_book': widg_list = self.interpret_template_tab_book( template, widg_dex) elif widget_type == 'tree_book': widg_list = self.interpret_template_tree_book( template, widg_dex) elif widget_type == 'list_controller': widg_list = self.interpret_template_list_controller( template, widg_dex) elif widget_type == 'console_listener': widg_list = self.interpret_template_console_listener( template, widg_dex) elif widget_type == 'opengl_view': widg_list = self.interpret_template_opengl_view( template, widg_dex) elif widget_type == 'plot': widg_list = self.interpret_template_plot( template, widg_dex) else: print 'no interpretation of widget type: ' + widget_type return None try: if template.handles[widg_dex]: handle = template.handles[widg_dex] inst = handle[0] key = handle[1] inst.__dict__[key] = widg_list if not handle in inst._handles_: inst._handles_.append(handle) except AttributeError: pass widgs.append(widg_list) self.hide_quiet_widgets(widgs, template) try: lgb.set_tooltips(widgs, template.tooltips) except AttributeError: pass try: lgb.set_sizes_limits(widgs, template.minimum_sizes) except AttributeError: pass try: lgb.set_sizes_limits(widgs, template.maximum_sizes, 'max') except AttributeError: pass try: layout = template.layout except AttributeError: layout = 'vertical' try: subspacers = template.subspacers[widg_dex] except AttributeError: subspacers = None if layout == 'vertical': box = lgb.create_vert_box elif layout == 'horizontal': box = lgb.create_horz_box elif layout == 'grid': box = lgb.create_grid_box try: positions = template.widg_positions except AttributeError: positions = [] try: spans = template.widg_spans except AttributeError: spans = [] try: g_spacing = template.grid_spacing except AttributeError: g_spacing = 5 try: widg_layout = box(widgs, positions, spans, g_spacing, template.layouts) except AttributeError: widg_layout = box(lfu.flatten(widgs), positions, spans, g_spacing) return widg_layout else: print 'widget layout "', layout,\ '" unrecognized; returning empty' return lgb.create_vert_box([]) try: widg_layout = box(widgs, template.layouts, subspacers) except AttributeError: widg_layout = box(lfu.flatten(widgs)) return widg_layout
def parse_p_space(p_sub, ensem): def validate(rng): valid = [] for val in rng.split(','): try: valid.append(float(val)) except: pass return valid def turn_on_mobjs_first_p_space_axis(mobj): dex = axes.index(mobj.label) mobj_attr = variants[dex] mobj.set_settables(0, ensem) for p_temp in mobj.parameter_space_templates: if mobj_attr == p_temp.key: p_temp.contribute_to_p_sp = True p_temp.p_sp_bounds = rng_bounds[dex] p_temp.p_sp_perma_bounds = rng_bounds[dex] p_temp.p_sp_increment = increments[dex] def read_increment(rng): if rng.count(';') > 0: read = float(rng[rng.rfind(';')+1:]) else: read = 10 return read if p_sub[0][0].count('<product_space>'): comp_meth = 'Product Space' elif p_sub[0][0].count('<zip_space>'): comp_meth = '1 - 1 Zip' elif p_sub[0][0].count('<fitting_space>'): comp_meth = 'Fitting' if comp_meth == 'Product Space' or comp_meth == '1 - 1 Zip': ax_lines = p_sub[1:] elif comp_meth == 'Fitting': ax_lines = [] con_lines = [] for li in p_sub[1:]: if li[0].startswith('#'): continue elif li[0].count('<axes>'): sub_parser = 'axes' elif li[0].count('<constraints>'): sub_parser = 'constraints' else: if sub_parser == 'axes': ax_lines.append(li) elif sub_parser == 'constraints': con_lines.append(li) def parse_axes(lines): axes = [ax[0] for ax in lines] variants = [ax[1] for ax in lines] ax_rngs = [ax[2] for ax in lines] return axes, variants, ax_rngs def parse_constraint(li, subspaces): ops = ['<', '>', '<=', '>='] op_in = [li.count(op) for op in ops] try: op = ops[op_in.index(True)] spl = li.split(op) which = subspaces[int(spl[0])] target = subspaces[int(spl[-1])] con = axis_constraint( op = op, inst = which.inst, key = which.key, inst_ruler = target.inst, key_ruler = target.key) which.constraints.append(con) except: traceback.print_exc(file=sys.stdout) print 'unable to parse constraint', li axes, variants, ax_rngs = parse_axes(ax_lines) increments = [read_increment(rng) for rng in ax_rngs] ranges = [lm.make_range(rng)[0] for rng in ax_rngs] rng_bounds = [[validate(rng)[0], validate(rng)[-1]] for rng in ranges] poss_contribs = ['species', 'variables', 'reactions'] p_mobjs = ensem.cartographer_plan.parameter_space_mobjs for key in p_mobjs.keys(): if key in poss_contribs: if type(p_mobjs[key]) is types.DictionaryType: for sub_key in p_mobjs[key].keys(): mobj = p_mobjs[key][sub_key] if mobj.label in axes: turn_on_mobjs_first_p_space_axis(mobj) if type(p_mobjs[key]) is types.ListType: for mobj in p_mobjs[key]: if mobj.label in axes: turn_on_mobjs_first_p_space_axis(mobj) ensem.cartographer_plan.generate_parameter_space() selected = [ensem.cartographer_plan.\ parameter_space.get_start_position()] if comp_meth == 'Product Space' or comp_meth == '1 - 1 Zip': traj_dlg = lgd.trajectory_dialog(parent = None, base_object = selected, composition_method = comp_meth, p_space = ensem.cartographer_plan.parameter_space) for ax, vari, rng in zip(axes, variants, ranges): trj_dlg_dex = traj_dlg.axis_labels.index( ' : '.join([ax, vari])) traj_dlg.variations[trj_dlg_dex] = validate(rng) traj_dlg.on_make() if traj_dlg.made: ensem.cartographer_plan.trajectory_string =\ traj_dlg.result_string ensem.cartographer_plan.on_delete_selected_pts( preselected = None) ensem.cartographer_plan.on_reset_trajectory_parameterization() ensem.cartographer_plan.on_append_trajectory(traj_dlg.result) ensem.cartographer_plan.traj_count = p_sub[0][1] ensem.cartographer_plan.on_assert_trajectory_count(all_ = True) elif comp_meth == 'Fitting': subspaces = ensem.cartographer_plan.parameter_space.subspaces for li in lfu.flatten(con_lines): parse_constraint(li, subspaces)