def __add__(self, other): def wrap_none(depth, count): if depth == 1: nones = [None]*count elif depth == 2: nones = [[None]]*count return nones 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 dom_keys = self.__dict__.keys() sub_keys = other.__dict__.keys() all_keys = lfu.uniqfy(dom_keys + sub_keys) new_dict = {} for key in all_keys: depth = self._depth_lookup_[key] if depth == 0: try: new_item = self.__dict__[key] except KeyError: new_item = other.__dict__[key] elif depth == 1 or depth == 2: left = wrap_side(self, key, depth) right = wrap_side(other, key, depth) new_item = left + right else: print 'depth cant be >2'; pdb.set_trace() new_dict[key] = new_item new = interface_template_gui(**new_dict) return new
def decimate(fine, orders): def create_subrange(dex, num_values): lower = relev_mags[dex - 1] upper = relev_mags[dex] new = np.linspace(lower, upper, num_values) return [np.round(val, 20) for val in new] left = locate(fine.bounds[0], orders) right = locate(fine.bounds[1], orders) if left == right: rng = range(2) relev_mags = [fine.bounds[0], fine.bounds[1]] else: rng = range(orders.index(left), orders.index(right) + 1) #many_orders = len(rng) relev_mags = orders[rng[0]:rng[-1] + 1] total_values = 20 num_values = max([10, int(total_values/len(relev_mags))]) new_axis = [] for dex in range(1, len(relev_mags)): new_axis.extend([np.round(val, 20) for val in create_subrange(dex, num_values)]) new_axis = lfu.uniqfy(new_axis) #print 'NEW AXIS', new_axis if len(new_axis) == 0: pdb.set_trace() return new_axis
def __init__(self, data = [], axes = [], surfs = [], label = 'another surface vector'): self.tag = 'surface' self.label = label self.data_scalars = [data for data in data if not data is self] self.axis_labels = axes self.axis_values = [scalars(label = dat.label, scalars = lfu.uniqfy(dat.scalars)) for dat in self.data_scalars if dat.label in self.axis_labels] self.axis_defaults = [da.scalars[0] for da in self.axis_values] self.surf_targets = surfs self.reduced = None
def make_surface(self, x_ax = '', y_ax = '', surf_target = ''): data = self.data_scalars daters = [dater.label for dater in data] are_ax = [label in self.axis_labels for label in daters] axes = [copy(dater) for dater, is_ax in zip(data, are_ax) if is_ax] ax_labs = [ax.label for ax in axes] if not (x_ax in ax_labs and y_ax in ax_labs and not x_ax == y_ax and surf_target in self.surf_targets): print 'chosen axes do not correspond to surface' print 'axes:\n', ax_labs, '\nsurfaces:\n', self.surf_targets return False surf = lfu.grab_mobj_by_name(surf_target, data) x_ax_dex = ax_labs.index(x_ax) y_ax_dex = ax_labs.index(y_ax) ax_slices = copy(self.axis_defaults) ax_slices[x_ax_dex] = None ax_slices[y_ax_dex] = None reduced = (axes, surf) in_slices = [] for ax_dex, ax in enumerate(axes): if ax_slices[ax_dex] is None: in_slices.append([True for val in ax.scalars]) else: in_slices.append([(val == ax_slices[ax_dex]) for val in ax.scalars]) in_every_slice = [(False not in row) for row in zip(*in_slices)] sub_surf = scalars_from_labels([surf_target])[0] sub_surf.scalars = [sur for sur, in_ in zip(surf.scalars, in_every_slice) if in_] sub_axes = scalars_from_labels(self.axis_labels) for sub_ax, ax in zip(sub_axes, axes): sub_ax.scalars = lfu.uniqfy([val for val, in_ in zip(ax.scalars, in_every_slice) if in_]) self.reduced = (sub_axes, sub_surf) return True
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 show_plot_color(self, *args, **kwargs): self.resolve_x_domain() self.resolve_y_domain() self.resolve_surf_target() ax = self.add_plot() try: surf_vector_dex = [hasattr(dater, 'reduced') for dater in self._data_.data].index(True) except ValueError: print 'no surface_vector found!'; return surf_vect = self._data_.data[surf_vector_dex] made_surf = surf_vect.make_surface( x_ax = self.x_ax_title, y_ax = self.y_ax_title, surf_target = self.surf_target) if not made_surf: print 'surface was not resolved' return self.title = self.surf_target ax.set_title(self.title) x_ax = lfu.grab_mobj_by_name(self.x_ax_title, surf_vect.axis_values) y_ax = lfu.grab_mobj_by_name(self.y_ax_title, surf_vect.axis_values) x = np.array(x_ax.scalars, dtype = float) y = np.array(y_ax.scalars, dtype = float) try: surf = np.array(surf_vect.reduced[1].scalars, dtype = float).reshape(len(x), len(y)) except ValueError: print 'not organized properly to colorplot...' return surf = surf.transpose() x_min, x_max = x.min(), x.max() y_min, y_max = y.min(), y.max() z_min, z_max = surf.min(), surf.max() #plt.xscale('log') #plt.yscale('log') delx = [x[i+1] - x[i] for i in range(len(x) - 1)] dely = [y[i+1] - y[i] for i in range(len(y) - 1)] xdels = lfu.uniqfy(delx) ydels = lfu.uniqfy(dely) if len(xdels) == 1 and len(ydels) == 1: pc_mesh = ax.imshow(surf, interpolation = 'bicubic', cmap = plt.get_cmap('jet'), vmin = z_min, vmax = z_max, #cmap = 'autumn', vmin = z_min, vmax = z_max, origin = 'lower', extent = (x_min, x_max, y_min, y_max)) #Acceptable interpolations are 'none', 'nearest', 'bilinear', #'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', #'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', #'bessel', 'mitchell', 'sinc', 'lanczos' else: print 'axes values are not evenly spaced; plot will be boxy' pc_mesh = ax.pcolormesh(x, y, surf, cmap = plt.get_cmap('jet'), #pc_mesh = ax.pcolormesh(x, y, surf, cmap = 'autumn', shading = 'gouraud', vmin = z_min, vmax = z_max) ax.axis([x.min(), x.max(), y.min(), y.max()]) ax.grid(True) self.figure.colorbar(pc_mesh) self.canvas.draw()