def build_phase_plot(sym1, sym2): import pylab f = pylab.figure() pylab.plot(res[sym1], res[sym2]) pylab.xlabel('Symbol: %s' % sym1) pylab.ylabel('Symbol: %s' % sym2) return mredoc.Figure(f)
def build_trace_plot(sym): import pylab f = pylab.figure() pylab.plot(res['t'], res[sym]) pylab.xlabel('Time (s)') pylab.ylabel('Symbol: %s') return mredoc.Figure(f)
def build_comp_section(param): fig = figures[param] trcs = sorted( trace_comp_res[param] ) comp_tbl_header, comp_tbl_data= zip( *[ ('%s.max_ptp' %c, trace_comp_res[param][c].max_ptp) for c in trcs]) return mrd.Section('Parameters: %s' % str(param), mrd.VerticalColTable(comp_tbl_header, [comp_tbl_data] ), mrd.Figure( mrd.Image(fig, auto_adjust=False), caption='Comparison'), )
def build_population_complete_dot(self): fig_count = 0 fig_out = '/tmp/dotimages/' import pydot graph = pydot.Dot('graphname', graph_type='digraph', size='7,7', ratio='compress', compound='true', splines='true', sep='0.3') size = '0.55' fontsize = '6' kwargs_general = { 'fontsize': fontsize, 'fixedsize': 'True', 'width': size, 'height': size, 'fontname': 'Helvetica' } cell_size = '0.15' kwargs_cell = { 'shape': 'circle', 'fillcolor': '#80b3ffff', 'color': '#0066ffff', 'style': 'filled', 'penwidth': '1', 'width': cell_size, 'height': cell_size } kwargs_cc = { 'shape': 'circle', 'style': 'filled', 'width': '0.05', } kwargs_pop = { 'style': 'filled', 'color': 'lightgrey', 'nodesep': '100' } kwargs_synpop = {'shape': 'none', 'fixedsize': 'false'} kwargs_synpop_img = { 'shape': 'square', 'labelloc': 'b', 'scale': 'false', 'fixedsize': 'true', } kwargs_synpop_edge = { 'penwidth': '3', 'color': 'green', 'minlen': '50' } # Map Simulation objects into dot objects: obj2nodedict = {} subgraphs = [] # Populations become subgraphs: for population in self.sim.neuron_populations: n = pydot.Cluster(population.pop_name, label=population.pop_name, **dict(kwargs_general.items() + kwargs_pop.items())) subgraphs.append(n) obj2nodedict[population] = n # Cells into Nodes for cell in self.sim.cells: n = pydot.Node( cell.name, label=cell.name if cell.population is None else '<%d>' % cell.index_in_pop, **dict(kwargs_general.items() + kwargs_cell.items())) obj2nodedict[cell] = n if cell.population: obj2nodedict[cell.population].add_node(n) else: graph.add_node(n) for sg in subgraphs: graph.add_subgraph(sg) del subgraphs # Synapse Populations are turned into a node, with edges from pre and # to the post synaptic population: for synpopindex, synpop in enumerate(self.sim.synapse_populations): synpopcluster = pydot.Cluster('SynpopCluster' + synpop.synapse_pop_name) # Create the connectivity graph: connectivity_graph_figure = build_connectivity_graph(synpop) fname = fig_out + '/synpop%d.png' % synpopindex pylab.savefig(fname, transparent=True, dpi=400, bb_inches='tight') n = pydot.Node(synpop.synapse_pop_name + 'im', label='', image=fname, **dict(kwargs_general.items() + kwargs_synpop_img.items())) synpopcluster.add_node(n) label = '' label += synpop.synapse_pop_name len_prepop = len(synpop.presynaptic_population ) if synpop.presynaptic_population else 1 pc_conn = 100. * len(synpop) / ( len_prepop * len(synpop.postsynaptic_population)) #print pc_conn #pc_conn=50. #label+= '\\nType: %s'% (synpop.type) label += '\\nSynapses: %d (%d%%)' % (len(synpop), pc_conn) #label= synpop.synapse_pop_name n = pydot.Node(synpop.synapse_pop_name + 'cap', label='"%s"' % label, **dict(kwargs_general.items() + kwargs_synpop.items())) synpopcluster.add_node(n) obj2nodedict[synpop] = synpopcluster graph.add_subgraph(synpopcluster) # Connect to pre- and post- synaptic pops: post_pop = synpop.postsynaptic_population e = pydot.Edge( synpopcluster.get_name(), obj2nodedict[post_pop].get_name(), **dict(kwargs_general.items() + kwargs_synpop_edge.items())) graph.add_edge(e) pre_pop = synpop.presynaptic_population if pre_pop is not None: e = pydot.Edge( obj2nodedict[pre_pop].get_name(), synpopcluster.get_name(), **dict(kwargs_general.items() + kwargs_synpop_edge.items())) graph.add_edge(e) else: print 'NONE' for (i, synapse) in enumerate(self.sim.synapses): if synapse.population: continue pre_cell = synapse.get_presynaptic_cell() post_cell = synapse.get_postsynaptic_cell() if not pre_cell: pre_n = pydot.Node(name='SpikeTimes%d' % i, shape='point', color='lightsalmon', style='filled', **kwargs_general) graph.add_node(pre_n) else: pre_n = obj2nodedict[pre_cell] post_n = obj2nodedict[post_cell] syn_name = '%s' % synapse.name e = pydot.Edge(pre_n, post_n, label=syn_name, color='red', **kwargs_general) graph.add_edge(e) stims = {} # Simulations: for cclamp in self.sim.current_clamps: label = '"IClamp: %s\\n %s"' % (cclamp.name, cclamp.location_summary_dot_str) n = pydot.Node(cclamp.name, label=label, **dict(kwargs_general.items() + kwargs_cc.items())) stims[cclamp] = n graph.add_node(n) # Make the edge: cell_node = obj2nodedict[cclamp.cell] e = pydot.Edge(n, cell_node, label='', color='red') # **kwargs) graph.add_edge(e) ## Records: #records = {} #for record in self.sim.recordables: # name = record.name # # label = '"Record: %s\\n %s"' % (name, record.location_summary_dot_str ) # label = '"Record: %s\\n"' % name # , record.location_summary_dot_str ) # n = pydot.Node( # name, # shape='circle', # style='filled', # width='0.05', # fixedsize='True', # label=label, # fontsize=fontsize, # ) # records[record] = n # graph.add_node(n) # # Make the edge: # if isinstance(record, NEURONRecordableOnLocation): # post_node = obj2nodedict[record.cell_location.cell] # e = pydot.Edge(n, post_node, label='', color='green') # graph.add_edge(e) # # cell_node = obj2nodedict[record.cell_location.cell] graph.write_raw('example_cluster2.dot') # Put the stimulations on: #fname = _DotSummaryUtils.save_dot(graph, prog='dot') fname = _DotSummaryUtils.save_dot(graph, format='pdf', prog='fdp') #fname = _DotSummaryUtils.save_dot(graph, prog='osage') #fname = _DotSummaryUtils.save_dot(graph, prog='neato') return mrd.Section('Diagram Overview', mrd.Figure(mrd.Image(fname)))