4.2.1. Extracting information from densities and hop graphs — hop.analysis

A collection of functions and classes to extract statistics and plot histograms. Use this as examples how to write your own.

4.2.1.1. Classes and functions

class hop.analysis.DensityScanner(densityAnalysis, with_densities=True)
load(fn, merge=True)

Reinstantiate class from a pickled file (produced with save()).

plot(fn=None, idens=0, functions='all', properties=None, fignumber=1)

Plot density statistics against rho_cut for reference (black) and density 0 (red).

plot(filename,properties=<dict of dicts>)

Plot various functions of the density cut-off rho_cut. Current functions are ‘sites’, ‘volume’, ‘occupancy’, or ‘all’.

Plots can be customized by using the properties dict. To change the ylim and add an title to the sites graph, use

properties = {‘sites’: {ylim’:(0,220),’title’:’number of sites’}}
Arguments:

fn file name for the file; default is scan.pdf. Suffix determines file type. idens number of density plot; the first one is 0 in self.scanarrays[]. functions list of function names or ‘all’ properties dict1 of dicts; keys1: sites, volume, occupancy;

keys2: any matplotlib settable property, values2: appropriate values

fignumber pylab figure number

class hop.analysis.HeatmapAnalysis(hoppinggraphs, normalization='maxabs', verbosity=1, prune='default')

Combine Hopgraph statistics for a number of simulations into a grid, normalize each observable, and color. Clustering is performed if the R package is installed in the system. The idea is to quickly compare a number simulations based on a combination of observables.

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

filename(filename=None, ext=None, set_default=False, use_my_ext=False)

Supply a file name for the object.

fn = filename() —> <default_filename> fn = filename(‘name.ext’) —> ‘name’ fn = filename(ext=’pickle’) —> <default_filename>’.pickle’ fn = filename(‘name.inp’,’pdf’) –> ‘name.pdf’ fn = filename(‘foo.pdf’,ext=’png’,use_my_ext=True) –> ‘foo.pdf’

The returned filename is stripped of the extension (use_my_ext=False) and if provided, another extension is appended. Chooses a default if no filename is given. Raises a ValueError exception if no default file name is known.

If set_default=True then the default filename is also set.

use_my_ext=True lets the suffix of a provided filename take priority over a default ext(tension).

labels(precision=2)

labels of the columns (simulations) and rows (observables)

normalize(method=None)

Normalize the data by row.

normalize(method=None|’zscore’|’maxabs’)

method can be None Return the unchanged data array. ‘maxabs’ Take the largest absolute value in each row/column and

divide each entry in the row/column by it. This results in values between -1 and +1.

‘zscore’ (X-<X>)/sd(X)

Sets self.heatmap, self.normalizations, self.normalization_method

normalizations only makes sense for ‘maxabs’; in all other cases it only contains zeroes.

plot(filename=None, format='pdf', **kwargs)

Plot the heatmap and save to an image file.

plot() # display using windowing system plot(‘hm’) # –> hm.pdf plot(‘hm.png’) # –> hm.png plot(‘hm’,’png’) # –> hm.png

By default a clustered heat map is constructed using R’s heatmap.2 function. If R cannot be found, an unclustered heat map is plotted. **kwargs can be used to customize the output.

Arguments:
filename name of the image file; may contain extension
If empty use the windowing system.

format eps,pdf,png… whatever matplotlib understands

**kwargs for R: scale Determines the coloring. Choose between ‘none’ (the

actual values in the heat map (possibly already normalized)), ‘row’ or ‘column’ (z-score across the dimension)

N_colors Number of color levels; default is 32.

**kwargs for matplotlib:
The kwargs are applied to the matplotlib.text() method and are typically used to set font properties. See the pylab/matplotlib documentation.
class hop.analysis.HopgraphAnalysis(hopgraph, dir='.', verbosity=3)

Comprehensive analysis of an annotated hop graph.

Analyse hopgraph.

a = HopgraphAnalysis(hopgraph)

The show() method prints statistics on the HoppingGraph and histograms() produces a number of plots as pdf files in the current directory.

Arguments:
hopgraph can be the name of a pickled file or a HoppingGraph
instance

dir save figures in this directory verbosity=3 chattiness

Attributes:

S statistics dictionary (see keys for explanation) D raw data dictionary

Methods:

all() show() and histograms() show() print stats histograms() produce histograms

class hop.analysis.LegendContainer

For each bar plot, record first lines instance and the label with >>> Legend = LegendContainer() >>> lines = pylab.bar(…) >>> Legend.append(lines[0],’plotlabel’) Once all legends have been collected, build the legend with >>> pylab.legend(*Legend.args())

args()

Use as pylab.legend(**Legend.args()).

hop.analysis.kill_R()

Manual last resort to kill the R quartz() window.