def select_good_nodes_by_sid(g, sid_list, counts, replace=False): """For each sid in `sid_list` select `count` random nodes with an underlying `section` from `g` - a neurongraph. Returns a list of selected nodes. @seealso: neurograp.select_random_nodes_by_sid """ good_nodes = [ n for n, data in g.nodes(data=True) if data['orig'] is not None ] type_node_map = ng.get_stype_node_map(g.subgraph(good_nodes)) synnodes = [] for branch_id, count in zip(sid_list, counts): size = len(type_node_map[branch_id]) if (count > size) and (replace == False): print( 'Changing number of nodes to maximum {} available in branch, since replace={}' .format(size, replace)) count = size synnodes += list( np.random.choice(type_node_map[branch_id], size=count, replace=replace)) return synnodes
if ii < len(args.rotate): rot = args.rotate[ii].split() for jj in range(0, len(rot), 2): rot[jj + 1] = float(rot[jj + 1]) cell_rot[fname] = zip(rot[0::2], rot[1::2]) else: cell_rot[fname] = [] if args.branches: lnodes, edges = zip(*ng.branch_points(cg)) label_nodes[fname] = list(lnodes) if args.leaves: label_nodes[fname] += [ node for node in cg.nodes() if cg.degree(node) == 1 ] if len(args.sid) > 0: sid_node_map = ng.get_stype_node_map(cg) for sid in args.sid: label_nodes[fname] += sid_node_map[sid] show_neurons(cell_graphs, lines=args.lines, label_nodes_dict=label_nodes, labels_dict={}, pos_dict=cell_pos, rot_dict=cell_rot, nodecolor=colormap, background=background, axes=args.scalebar, fullscreen=args.fullscreen, relative=args.relative) #
ordered_tree = h.SectionList() ordered_tree.wholetree() h.pop_section() for sec in ordered_tree: sec.push() for ii, seg in enumerate(sec): if seg.diam < dialim: seg.diam = seg.diam * diascale count += 1 h.pop_section() print('Scaled diameters of', count, 'sections whose diameters were <', dialim, 'by', diascale) g0 = nu.nrngraph(ggn) g, nmap = ng.renumber_nodes(g0, ggn.soma.name()) # This also gets the dummy nodes at the tips stype_node_map_all = ng.get_stype_node_map(g) stype_node_map = {} # Collect only nodes with sections associated. for stype, nodes in stype_node_map_all.items(): good = [node for node in nodes if g.node[node]['orig'] is not None] stype_node_map[stype] = good synnodes = nu.select_good_nodes_by_sid(g, inputs, [syncount] * len(inputs), replace=True) synsecs = [g.nodes[n]['orig'] for n in synnodes] synsegs = [sec(1.0) for sec in synsecs] # Create the exp2syn # ereversal = 0 for glutamatergic synapse synlist = nu.insert_exp2syn(synsegs, args.rise_t, args.decay_t, 0.0) print('Number of synapses', syncount, 'synlist', len(synlist)) # Create stimulation system
if ii > 0: maxnode = max(combined_cellgraph.nodes()) for node in cellgraph.nodes(): cellgraph.node[node]['p'] += maxnode mapping = {n: n + maxnode for n in cellgraph.nodes()} cellgraph = nx.relabel_nodes(cellgraph, mapping) combined_cellgraph = nx.union(combined_cellgraph, cellgraph) label_nodes = [] if args.branches: label_nodes, degrees = zip(*ng.branch_points(combined_cellgraph)) label_nodes = list(label_nodes) if args.leaves: label_nodes += [node for node in combined_cellgraph.nodes() if combined_cellgraph.degree(node) == 1] if len(args.sid) > 0: sid_node_map = ng.get_stype_node_map(combined_cellgraph) for sid in args.sid: label_nodes += sid_node_map[sid] if module == 'mplot3d': ax = mp.plot_3d_lines(combined_cellgraph) plt.show() elif module == 'vtk': neuron3d(combined_cellgraph, lines=lines, label_nodes=label_nodes, labels=label_nodes, nodecolor=colormap, background=background, axes=args.scalebar, fullscreen=args.fullscreen) elif module == 'vispy': neuron3d(combined_cellgraph) elif module == 'vpython': neuron3d(combined_cellgraph) else: