def __init__(self, mh, mw): ''' Takes in the max height and width from the main screen element ''' self.cmap = ColorMap() init_win = initWindow(mh, mw, self.cmap) self.ds_win = init_win.create('dropshadow', 'black_card', mh, mw)
def __init__(self, y, x, suit, value, suit_color): self.suit = suit self.value = value self.suit_color = suit_color self.cmap = ColorMap() init_win = initWindow(7, 9, self.cmap, y, x) self.ce_win = init_win.create('card', 'white_card')
def __init__(self, parent=None): scene.SceneCanvas.__init__(self, parent=parent) self.parent = parent self.has_redrawn = True self.data = None self.program = gloo.Program(vert, frag) self.colormap = ColorMap('colormaps/transform/Seismic.ppm') self.program_cm = gloo.Program(cm_vert, cm_frag) #self. self.line_type = None self.line_coord = 0 self.line_positions = [(0, 0), (0, 0)] self.program_line = gloo.Program(basic_vert, basic_frag) self.program_line['a_position'] = self.line_positions gloo.set_clear_color((1, 1, 1, 1)) canvas_size = (1000, 800) graph_size = (900, 700) margin_x = (canvas_size[0]-graph_size[0]) / 2. margin_y = (canvas_size[1]-graph_size[1]) / 2. pos_xax = np.array([[margin_x, canvas_size[1]-margin_y], [canvas_size[0]-margin_x, canvas_size[1]-margin_y]]) self.axis_x = AxisVisual(pos_xax, (0, 100), (0., 1.)) self.tr_sys = visuals.transforms.TransformSystem(self)
def __init__(self, mh, mw, hand=None): self.selected_cards = [] self.cmap = ColorMap() self.max_h = 1 self.max_w = 40 init_win = initWindow(mh, mw, self.cmap) self.cs_win = init_win.create('cardselect', 'blue_card', mh, mw) self.hand = hand
def __init__(self, win): self.cmap = ColorMap() self.max_h, self.max_w = win.getmaxyx() self.max_h, self.max_w = 24, 79 init_win = initWindow(self.max_h, self.max_w, self.cmap) self.line1_win = init_win.create( 'titleline1', 'black_card', h=1, w=17) self.line2_win = init_win.create( 'titleline2', 'black_card', h=1, w=46)
def __init__(self): self.ud = UserData() self.sd = SystemData() self.username = dropfile.process_dropfile("door.sys", "DOORSYS") self.ud.add(self.username) self.stdscr = curses.initscr() curses.noecho() curses.cbreak() curses.start_color() self.max_height, self.max_width = self.stdscr.getmaxyx() self.cmap = ColorMap()
def __init__(self, suit=None, value=None): self.cmap = ColorMap() self.blank_space = u'\u2588' self.heart = u'\u2665' self.club = u'\u2663' self.spade = u'\u2660' self.diamond = u'\u2666' # self.bg_color = curses.A_BOLD self.bg_color = self.cmap.colors['white_card'] self.deck = Deck() self.deck.card_mapping() self.hand = None self.suit_color = None
def __init__(self, mh, mw): self.cmap = ColorMap() self.name_pos_map = { 'Nothing': 0, 'One pair': 1, 'Two pair': 2, 'Three-of-a-kind': 3, 'Straight': 4, 'Flush': 5, 'Full house': 6, 'Four-of-a-kind': 7, 'Straight flush': 8, 'Royal flush': 9 } init_win = initWindow(mh, mw, self.cmap) self.ch_win = init_win.create('currenthand', 'blue_card')
def __init__(self, mh, mw): self.cmap = ColorMap() init_win = initWindow(mh, mw, self.cmap) self.ip_win = init_win.create('infopanel', 'black_card', mh, mw) self.mapping = Mappings() self.user_data = UserData()
def Main(): options, _ = MakeOpts().parse_args(sys.argv) assert options.input_filename assert options.first_col and options.second_col print 'Reading species list from', options.input_filename # Read data r = csv.DictReader(open(options.input_filename)) first_col, second_col = options.first_col, options.second_col third_col = options.third_col second_col_key = options.second_col_key or second_col third_col_key = options.third_col_key or third_col filter_values = [] if options.filter_values: filter_values = set(map(str.strip, options.filter_values.split(','))) pairmap = {} all_a = set() all_b = set() all_vals = set() for row in r: a, b = row[first_col].strip(), row[second_col].strip() c = row[third_col].strip() if not a or not b or not c: continue all_a.add(a) all_b.add(b) value = MergeBinary(b, c, second_col_key, third_col_key) if filter_values and value in filter_values: continue all_vals.add(value) pairmap.setdefault(a, []).append(value) a_to_num = dict((v,i) for i,v in enumerate(all_a)) counts = {} for k, v in pairmap.iteritems(): counter = Counter(v) counts[k] = counter x_vals = [] count_array = [] for a_val in all_a: x_vals.append(a_to_num[a_val]) count_array.append(counts.get(a_val, {})) # Plot circle scatter. axes = pylab.axes() colormap = ColorMap(all_vals) y_loc, radius = 1.0, 0.45 PieArray(axes, x_vals, y_loc=y_loc, radius=radius, counts_array=count_array, colormap=colormap) title = options.title or '%s vs. %s' % (options.first_col, options.second_col) pylab.title(title) size_10 = FontProperties(size=10) a_labels = [a or "None given" for a in all_a] axes.yaxis.set_major_locator(pylab.NullLocator()) axes.xaxis.set_major_locator(pylab.NullLocator()) for x, label in enumerate(a_labels): axes.text(x, y_loc - radius - 0.1, str(label), ha='center', va='baseline') handles, labels = axes.get_legend_handles_labels() mapped_labels = dict(zip(labels, handles)) labels = sorted(mapped_labels.keys()) handles = [mapped_labels[k] for k in labels] pylab.legend(handles, labels) pylab.axis('scaled') pylab.axis([-1, len(all_a), 0.0, 2]) pylab.show()
def __init__(self, mh, mw): self.cmap = ColorMap() h = mh w = mw init_win = initWindow(mh, mw, self.cmap) self.hw_win = init_win.create('handdisplay', 'blue_card', h, w)
class Canvas(scene.SceneCanvas): """ Handles the fast drawing of data using OpenGL for real-time editing. A data point is drawn using two triangles to form a quad, it is colored by using the normalized data value and a colormap texture in the fragment shader. """ def __init__(self, parent=None): scene.SceneCanvas.__init__(self, parent=parent) self.parent = parent self.has_redrawn = True self.data = None self.program = gloo.Program(vert, frag) self.colormap = ColorMap('colormaps/transform/Seismic.ppm') self.program_cm = gloo.Program(cm_vert, cm_frag) #self. self.line_type = None self.line_coord = 0 self.line_positions = [(0, 0), (0, 0)] self.program_line = gloo.Program(basic_vert, basic_frag) self.program_line['a_position'] = self.line_positions gloo.set_clear_color((1, 1, 1, 1)) canvas_size = (1000, 800) graph_size = (900, 700) margin_x = (canvas_size[0]-graph_size[0]) / 2. margin_y = (canvas_size[1]-graph_size[1]) / 2. pos_xax = np.array([[margin_x, canvas_size[1]-margin_y], [canvas_size[0]-margin_x, canvas_size[1]-margin_y]]) self.axis_x = AxisVisual(pos_xax, (0, 100), (0., 1.)) self.tr_sys = visuals.transforms.TransformSystem(self) def set_data(self, data): self.data = data self.xmin, self.xmax = np.nanmin(data.x_coords), np.nanmax(data.x_coords) self.ymin, self.ymax = np.nanmin(data.y_coords), np.nanmax(data.y_coords) self.zmin, self.zmax = np.nanmin(data.values), np.nanmax(data.values) self.cm_dx = (self.xmax-self.xmin)*0.1 self.view = translate((0, 0, 0)) self.projection = ortho(self.xmin, self.xmax + self.cm_dx, self.ymin, self.ymax, -1, 1) self.program['u_view'] = self.view self.program['u_projection'] = self.projection self.program['u_colormap'] = gloo.Texture1D(self.colormap.get_colors(), interpolation='linear') self.program_cm['u_view'] = self.view self.program_cm['u_projection'] = self.projection self.program_line['u_view'] = self.view self.program_line['u_projection'] = self.projection t0 = time.clock() vertices = self.generate_vertices(data) #print 'generate_vertices: ', time.clock()-t0 self.vbo = gloo.VertexBuffer(vertices) self.program.bind(self.vbo) self.update() def generate_vertices(self, data): x, y, z = data.get_sorted() xq, yq = data.get_quadrilaterals(x, y) # Top left x1 = xq[0:-1, 0:-1].ravel() y1 = yq[0:-1, 0:-1].ravel() # Bottom left x2 = xq[1:, 0:-1].ravel() y2 = yq[1:, 0:-1].ravel() # Bottom right x3 = xq[1:, 1:].ravel() y3 = yq[1:, 1:].ravel() # Top right x4 = xq[0:-1, 1:].ravel() y4 = yq[0:-1, 1:].ravel() # Two triangles / six vertices per datapoint xy = np.concatenate((x1[:,np.newaxis], y1[:,np.newaxis], x2[:,np.newaxis], y2[:,np.newaxis], x4[:,np.newaxis], y4[:,np.newaxis], x2[:,np.newaxis], y2[:,np.newaxis], x4[:,np.newaxis], y4[:,np.newaxis], x3[:,np.newaxis], y3[:,np.newaxis]), axis=1) total_vertices = len(x1) * 6 vertices = xy.reshape((total_vertices, 2)) vertex_data = np.zeros(total_vertices, dtype=[('a_position', np.float32, 2), ('a_value', np.float32, 1)]) vertex_data['a_position'] = vertices # Repeat the values six times for every two datapoint triangles vertex_data['a_value'] = np.repeat(z.ravel(), 6, axis=0) return vertex_data def screen_to_data_coords(self, pos): sw, sh = self.size sx, sy = pos relx, rely = float(sx*1.1) / sw, float(sh - sy) / sh dx = self.xmin + (relx) * (self.xmax - self.xmin) dy = self.ymin + (rely) * (self.ymax - self.ymin) return dx, dy def draw_linecut(self, event, old_position=False): # We need to check wether the canvas has had time to redraw itself # because continuous mouse movement events surpress the redrawing. if self.data != None and self.has_redrawn: x_name, y_name, data_name, order_x, order_y = self.parent.get_axis_names() if not old_position: x, y = self.screen_to_data_coords((event.pos[0], event.pos[1])) if event.button == 1: self.line_type = 'horizontal' self.line_coord = self.data.get_closest_y(y) self.line_positions = [(self.xmin, self.line_coord), (self.xmax, self.line_coord)] x, y = self.data.get_row_at(y) self.parent.linecut.plot_linecut(x, y, self.parent.name, x_name, data_name) self.has_redrawn = False elif event.button == 3: self.line_type = 'vertical' self.line_coord = self.data.get_closest_x(x) self.line_positions = [(self.line_coord, self.ymin), (self.line_coord, self.ymax)] x, y = self.data.get_column_at(x) self.parent.linecut.plot_linecut(x, y, self.parent.name, y_name, data_name) self.has_redrawn = False else: #self.line_type = 'horizontal' #self.line_coord = self.data.get_closest_y(y) if self.line_type == 'horizontal': self.line_positions = [(self.xmin, self.line_coord), (self.xmax, self.line_coord)] x, y = self.data.get_row_at(self.line_coord) else: self.line_positions = [(self.line_coord, self.ymin), (self.line_coord, self.ymax)] x, y = self.data.get_column_at(self.line_coord) self.parent.linecut.plot_linecut(x, y, self.parent.name, x_name, data_name) self.has_redrawn = False self.program_line['a_position'] = self.line_positions self.update() else: self.update() def on_mouse_press(self, event): self.draw_linecut(event) def on_mouse_move(self, event): if self.data != None: sw, sh = self.size sx, sy = event.pos if 0 <= sx < sw and 0 <= sy < sh: x, y = self.screen_to_data_coords((event.pos[0], event.pos[1])) xstr, ystr = eng_format(x, 1), eng_format(y, 1) self.parent.status_bar.showMessage('X: %s\t\t\tY: %s' % (xstr, ystr)) self.draw_linecut(event) def on_resize(self, event): width, height = event.physical_size gloo.set_viewport(0, 0, width, height) def on_draw(self, event): gloo.clear() if self.data != None: self.program['u_colormap'] = gloo.Texture1D(self.colormap.get_colors()) self.program['z_min'] = self.colormap.min self.program['z_max'] = self.colormap.max self.program_cm['u_colormap'] = gloo.Texture1D(self.colormap.get_colors()) self.program_cm['a_position'] = [(self.xmax + self.cm_dx*.2, self.ymax), (self.xmax + self.cm_dx*.2, self.ymin), (self.xmax + self.cm_dx, self.ymax), (self.xmax + self.cm_dx, self.ymin)] self.program_cm['a_texcoord'] = [[1], [0], [1], [0]] self.program.draw('triangles') self.program_cm.draw('triangle_strip') self.program_line.draw('lines') #self.axis_x.draw(self.tr_sys) self.has_redrawn = True
def Main(): options, _ = MakeOpts().parse_args(sys.argv) assert options.species_filename assert options.first_col and options.second_col print 'Reading species list from', options.species_filename filter_cols, filter_vals = [], [] if options.filter_cols: assert options.filter_vals filter_cols = map(str.strip, options.filter_cols.split(',')) filter_vals = map(str.strip, options.filter_vals.split(',')) # Read and filter species data r = csv.DictReader(open(options.species_filename)) first_col, second_col = options.first_col, options.second_col pairmap = {} for row in r: apply_filter = lambda x, y: x in row and row[x] == y or_reduce = lambda x, y: x or y passed_filter = reduce(or_reduce, map(apply_filter, filter_cols, filter_vals), True) if not passed_filter: continue a, b = row[first_col].strip(), row[second_col].strip() if not a or not b: continue key = (a, b) pairmap.setdefault(key, []).append(row) #for key, row_list in pairmap.iteritems(): # if len(row_list) < 5: # print key, row_list # Find cross-product of column values (all pairs). all_a = list(set([x[0] for x in pairmap.keys()])) all_b = list(set([x[1] for x in pairmap.keys()])) a_to_num = dict((v, i) for i, v in enumerate(all_a)) b_to_num = dict((v, i) for i, v in enumerate(all_b)) all_possible_pairs = list(itertools.product(all_a, all_b)) third_col = options.third_col or 'fake key' get_col = lambda x: x.get(third_col, None) col_vals = dict((k, map(get_col, v)) for k, v in pairmap.iteritems()) counts = {} totals = [] all_vals = set() for k, v in col_vals.iteritems(): counter = Counter(v) all_vals.update(counter.keys()) counts[k] = counter totals.append(sum(counter.values())) x_vals = [] y_vals = [] count_array = [] z_vals = [] max_val = max(totals) for pair in all_possible_pairs: a, b = pair x_vals.append(a_to_num[a]) y_vals.append(b_to_num[b]) z_vals.append(sum(counts.get(pair, {}).values())) count_array.append(counts.get(pair, {})) # Plot circle scatter. axes = pylab.axes() axes.grid(color='g', linestyle='--', linewidth=1) if options.third_col: colormap = ColorMap(all_vals) PieScatter(axes, x_vals, y_vals, count_array, max_val, colormap) handles, labels = axes.get_legend_handles_labels() mapped_labels = dict(zip(labels, handles)) labels = sorted(mapped_labels.keys()) handles = [mapped_labels[k] for k in labels] pylab.legend(handles, labels) else: scaled_z_vals = pylab.array(map(float, z_vals)) max_z = max(scaled_z_vals) scaled_z_vals /= (4.0 * max_z) scaled_z_vals = pylab.sqrt(scaled_z_vals) CircleScatter(axes, x_vals, y_vals, scaled_z_vals) for x, y, z in zip(x_vals, y_vals, z_vals): pylab.text(x + 0.1, y + 0.1, str(z)) # Labels, titles and ticks. pylab.title('%s vs. %s' % (options.first_col, options.second_col)) pylab.xlabel(options.first_col) pylab.ylabel(options.second_col) pylab.figtext(0.70, 0.02, '%d examples total.' % sum(totals)) size_8 = FontProperties(size=8) a_labels = [a or "None given" for a in all_a] b_labels = [b or "None given" for b in all_b] pylab.xticks(range(0, len(a_labels)), a_labels, fontproperties=size_8) pylab.yticks(range(0, len(b_labels)), b_labels, fontproperties=size_8) # Scale and show. pylab.axis('scaled') pylab.axis([-1, len(all_a), -1, len(all_b)]) pylab.show()