def _scan2recarray(self): # unwrapping/assembling table from stats stats = self.scanstats xkeys = sorted( stats.keys() ) ids = sorted( stats[xkeys[0]].keys() ) fieldnames = sorted( stats[xkeys[0]][ids[0]].keys() ) self.scanarrays = {} for id in ids: a = {} for y in fieldnames: a[y] = [stats[x][id][y] for x in xkeys] self.scanarrays[id] = numpy.rec.fromarrays( [a[y] for y in fieldnames],names=fieldnames)
def show(self): print "Statistics S" print "------------" pp.pprint(self.S) print "Data in D" print "---------" pp.pprint(sorted(self.D.keys()))
def __init__(self,hoppinggraphs,normalization="maxabs",verbosity=1,prune='default'): """Create a 'heatmap' for the Hopgraph statistics from a dictionary of CombinedGraphs. >>> hm = HeatmapAnalysis(hg,normalize="maxabs") :Arguments: HoppingGraphs Dictionary of HoppingGraph instances. The key is used to label the simulation in the heat map and thus should be expressive. normalization Method to normalize the data across observables. Can be None (not recommended), 'maxabs', or 'zscore'. See the normalize() method for documentation. NOTE that the normalization strongly influences the clustering in the heat map. verbosity Chattiness; use at least 1 in order to be notified if you should install additional packages. Otherwise a less powerful alternative is chosen silently, prune dict with keys that are removed from the heat map; see prune_default class attribute. :Methods: plot plot the heat map normalize normalize using the 'normalize' method labels dictionary of row, column names (and the normalization constants as strings) annotation 'enumerate' dictionaries of labels but not stringified """ # TODO: input a dict of HopGraph or CombinedGraph instances # and a dict with metadata # Currently assumes CombinedGraph as input set_verbosity(verbosity) hg = hoppinggraphs self._filename = None # holds default filename if prune is 'default': prune = self.prune_default elif prune is None: prune = [] else: try: 'foo' in prune except: raise TypeError("prune must support 'in' lookup") self.columns = hg.keys() # labels for sim: 'R13_1_plm', 'R13_1_apo', ... self.names = [] self.heatmap = None self.normalization_method = normalization # boring data reorganization table = {} for sim,hopgraph in hg.items(): for k,v in hopgraph.stats().items(): try: table[k].append(v) except: table[k] = [v] self.names = [k for k in sorted(table.keys()) if k not in prune] self.data = numpy.array([table[k] for k in self.names]) # reference values, tagged with row name # colum offsets are the indices in self.columns self.taggeddata = numpy.rec.fromarrays(self.data,names=self.names) self.heatmap = self.data.copy() self.normalizations = numpy.zeros(len(self.heatmap)) self.normalize(method=normalization) # modifies heatmap and normalizations # set up annotation self.annotation()