def wd_fig(fig, loc, ldict, cdict, what, rpos=None, xlim=[-1, 51], ylim=[0, 1], xticks=range(0, 51, 5), yticks=np.arange(0., 1.1, 0.2), clr='blue', label=''): nest.ResetKernel() l = tp.CreateLayer(ldict) tp.ConnectLayers(l, l, cdict) ax = fig.add_subplot(loc) if rpos is None: rn = nest.GetLeaves(l)[0][:1] # first node else: rn = tp.FindNearestElement(l, rpos) conns = nest.GetConnections(rn) cstat = nest.GetStatus(conns) vals = np.array([sd[what] for sd in cstat]) tgts = [sd['target'] for sd in cstat] locs = np.array(tp.GetPosition(tgts)) ax.plot(locs[:, 0], vals, 'o', mec='none', mfc=clr, label=label) ax.set_xlim(xlim) ax.set_ylim(ylim) ax.set_xticks(xticks) ax.set_yticks(yticks)
def recordElectrodeEnviromentLazy(network, folder): neurons_x_position_distance = 0.5/(network.parameters['Columns']/2.) neurons_x_position = [(i, 0.) for i in np.arange(0., 0.5, neurons_x_position_distance*2.)] #Add y-Positions neurons_x_position += ([(0., i) for i in np.arange(0., 0.5, neurons_x_position_distance*2.)]) #Add diagonal neurons_x_position += ([(i, i) for i in np.arange(0., 0.5, neurons_x_position_distance*2.)]) neurons_x_position = tp.FindNearestElement(network.l, neurons_x_position) neurons_position = tp.GetPosition(neurons_x_position) for position in neurons_position: plt.close() magic.recordElectrodeEnviroment(network.df_ex, position[0], position[1], 0.05, 0.05) plt.savefig(folder + '/excitatory_neurons/electrode_enviroment' + str(round(position[0], 4)) + ', ' + str(round(position[1], 4)) + '.png', dpi=300) plt.close() magic.recordElectrodeEnviroment(network.df_in, position[0], position[1], 0.05, 0.05) plt.savefig(folder + '/inhibitory_neurons/electrode_enviroment' + str(round(position[0], 4)) + ', ' + str(round(position[1], 4)) + '.png', dpi=300)
def plot_connections(ax, src, tgt, pops_list, red_conn_dens): # z-positions z0 = pops_list.index(src) z1 = z0 + (pops_list.index(tgt) - z0) # x,y-positions if src == 'STIM': xyloc = [0., 0.] elif src == tgt: xyloc = [0.8, 0.8] elif src == 'EX': xyloc = [0.8, -0.8] elif src == 'IN': xyloc = [-0.8, -0.8] srcid = tp.FindNearestElement(pops[src]['layer'], xyloc, False) srcloc = tp.GetPosition(srcid)[0] tgtsloc = np.array(tp.GetTargetPositions(srcid, pops[tgt]['layer'])[0]) # targets do not get picked in the same order; # they are sorted here for reproducibility tgtsloc = tgtsloc[np.argsort(tgtsloc[:, 0])] tgtsloc_show = tgtsloc[0:len(tgtsloc):red_conn_dens] for tgtloc in tgtsloc_show: ax.plot([srcloc[0], tgtloc[0]], [srcloc[1], tgtloc[1]], [z0, z1], c=pops[src]['conn_color_light'], linewidth=1.) # highlight target ax.plot(xs=[tgtloc[0]], ys=[tgtloc[1]], zs=[z1], marker='o', markeredgecolor='none', markersize=2, color=pops[src]['conn_color_dark'], alpha=1.) # to be printed on top dots = [tgtsloc_show, z1, pops[src]['conn_color_dark'], 'none', 2] srcdot = [srcloc, z0, 'white', 'black', 3] return dots, srcdot
def test_FindElements(self): """Interface and result check for finding nearest element. This function is Py only, so we also need to check results.""" # nodes at [-1,0,1]x[-1,0,1], column-wise ldict = { 'elements': 'iaf_neuron', 'rows': 3, 'columns': 3, 'extent': (3., 3.) } nest.ResetKernel() l = topo.CreateLayer(ldict) # single location at center n = topo.FindNearestElement(l, (0., 0.)) self.assertEqual(n, (6, )) # single location, two layers n = topo.FindNearestElement(l * 2, (0., 0.)) self.assertEqual(n, (6, 6)) # two locations, one layer n = topo.FindNearestElement(l, ((0., 0.), (1., 1.))) self.assertEqual(n, (6, 8)) # two locations, two layers n = topo.FindNearestElement(l * 2, ((0., 0.), (1., 1.))) self.assertEqual(n, ((6, 8), ) * 2) # several closest locations, not all n = topo.FindNearestElement(l, (0.5, 0.5)) self.assertEqual(len(n), 1) self.assertEqual(1, sum(n[0] == k for k in (5, 6, 8, 9))) # several closest locations, all n = topo.FindNearestElement(l, (0.5, 0.5), find_all=True) self.assertEqual(len(n), 1) self.assertEqual(n, ((5, 6, 8, 9), )) # complex case n = topo.FindNearestElement(l * 2, ((0., 0.), (0.5, 0.5)), find_all=True) self.assertEqual(n, (((6, ), (5, 6, 8, 9)), ) * 2)
def test_FindElements(self): """Interface and result check for finding nearest element. This function is Py only, so we also need to check results.""" # nodes at [-1,0,1]x[-1,0,1], column-wise ldict = { 'elements': 'iaf_neuron', 'rows': 3, 'columns': 3, 'extent': [3., 3.] } nest.ResetKernel() l = topo.CreateLayer(ldict) # single location at center n = topo.FindNearestElement(l, [0., 0.]) self.assertEqual(n, [6]) # single location, two layers n = topo.FindNearestElement(l * 2, [0., 0.]) self.assertEqual(n, [6, 6]) # two locations, one layer n = topo.FindNearestElement(l, [[0., 0.], [1., 1.]]) self.assertEqual(n, [6, 8]) # two locations, two layers n = topo.FindNearestElement(l * 2, [[0., 0.], [1., 1.]]) self.assertEqual(n, [[6, 8]] * 2) # several closest locations, not all n = topo.FindNearestElement(l, [0.5, 0.5]) self.assertEqual(len(n), 1) self.assertEqual(1, sum([n[0] == k for k in [5, 6, 8, 9]])) # several closest locations, all n = topo.FindNearestElement(l, [0.5, 0.5], find_all=True) self.assertEqual(len(n), 1) self.assertEqual(n, [[5, 6, 8, 9]]) # complex case n = topo.FindNearestElement(l * 2, [[0., 0.], [0.5, 0.5]], find_all=True) self.assertEqual(n, [[[6], [5, 6, 8, 9]]] * 2)
'rectangular': { 'lower_left': [-2., -1.], 'upper_right': [2., 1.] } } } tp.ConnectLayers(l, l, conndict) # { end #} fig = plt.figure() fig.add_subplot(121) conn_figure(fig, l, conndict, targets=((tp.FindCenterElement(l), 'red'), (tp.FindNearestElement(l, [4., 5.]), 'yellow'))) # same another time, with periodic bcs lpbc = tp.CreateLayer({ 'rows': 11, 'columns': 11, 'extent': [11., 11.], 'elements': 'iaf_neuron', 'edge_wrap': True }) tp.ConnectLayers(lpbc, lpbc, conndict) fig.add_subplot(122) conn_figure(fig, lpbc, conndict, showmask=False,
def plot_connections(ax, pop, pops_list, red_conn_dens, dots): # note that xyloc of connection is set here manually # connections from pop to tagt for tgt in pops[pop]['tgts']: z0 = pops_list.index(pop) z1 = z0 + (pops_list.index(tgt) - z0) if pop == tgt or z0 <= z1: if pop == tgt: xyloc = [0.8, 0.8] else: xyloc = [-0.8, -0.8] srcid = tp.FindNearestElement(pops[pop]['layer'], xyloc, False) srcloc = tp.GetPosition(srcid)[0] tgtsloc = np.array( tp.GetTargetPositions(srcid, pops[tgt]['layer'])[0]) # targets do not get picked in the same order; # they are sorted here for reproducibility tgtsloc = tgtsloc[np.argsort(tgtsloc[:, 0])] tgtsloc_show = tgtsloc[0:len(tgtsloc):red_conn_dens] for tgtloc in tgtsloc_show: plt.plot([srcloc[0], tgtloc[0]], [srcloc[1], tgtloc[1]], [z0, z1], c=pops[pop]['conn_color'], linewidth=1, alpha=0.1) # highlight target plt.plot(tgtloc[0], tgtloc[1], zs=[z1], marker='o', markeredgecolor='none', markersize=2, color=pops[pop]['conn_color'], alpha=1.) dots.append([srcloc, z0, 'white', 'black', 3]) if pop == 'IN' and tgt == 'EX': # final dots.append( [tgtsloc_show, z1, pops[pop]['conn_color'], 'none', 2]) # draw connections from src to pop for src in pops_list: z0 = pops_list.index(src) z1 = z0 + (pops_list.index(pop) - z0) if src != pop and (pop in pops[src]['tgts']) and z0 > z1: if src == 'STIM': xyloc = [0., 0.] else: xyloc = [0.8, -0.8] srcid = tp.FindNearestElement(pops[src]['layer'], xyloc, False) srcloc = tp.GetPosition(srcid)[0] tgtsloc = np.array( tp.GetTargetPositions(srcid, pops[pop]['layer'])[0]) tgtsloc = tgtsloc[np.argsort(tgtsloc[:, 0])] tgtsloc_show = tgtsloc[0:len(tgtsloc):red_conn_dens] for tgtloc in tgtsloc_show: plt.plot([srcloc[0], tgtloc[0]], [srcloc[1], tgtloc[1]], [z0, z1], c=pops[src]['conn_color'], linewidth=1, alpha=0.1) plt.plot(tgtloc[0], tgtloc[1], zs=[z1], marker='o', markeredgecolor='none', markersize=2, color=pops[src]['conn_color'], alpha=1.) dots.append([srcloc, z0, 'white', 'black', 3]) if src == 'STIM': # final dots.append( [tgtsloc_show, z1, pops[src]['conn_color'], 'none', 2]) return dots