def test_GetTargetNodes(self): """Interface check for finding targets.""" cdict = { 'rule': 'pairwise_bernoulli', 'p': 1., 'mask': { 'grid': { 'shape': [2, 2] } } } sdict = {'synapse_model': 'stdp_synapse'} nest.ResetKernel() nest.SetKernelStatus({ 'sort_connections_by_source': False, 'use_compressed_spikes': False }) layer = nest.Create('iaf_psc_alpha', positions=nest.spatial.grid(shape=[3, 3], extent=(2., 2.), edge_wrap=True)) # connect layer -> layer nest.Connect(layer, layer, cdict, sdict) t = nest.GetTargetNodes(layer[0], layer) self.assertEqual(len(t), 1) t = nest.GetTargetNodes(layer, layer) self.assertEqual(len(t), len(layer)) # 2x2 mask -> four targets self.assertTrue(all([len(g) == 4 for g in t])) t = nest.GetTargetNodes(layer, layer, syn_model='static_synapse') self.assertEqual(len(t), len(layer)) self.assertTrue(all([len(g) == 0 for g in t])) # no static syns t = nest.GetTargetNodes(layer, layer, syn_model='stdp_synapse') self.assertEqual(len(t), len(layer)) self.assertTrue(all([len(g) == 4 for g in t])) # 2x2 mask -> four targets t = nest.GetTargetNodes(layer[0], layer) self.assertEqual(len(t), 1) self.assertEqual(t[0], nest.NodeCollection([1, 2, 4, 5])) t = nest.GetTargetNodes(layer[4], layer) self.assertEqual(len(t), 1) self.assertEqual(t[0], nest.NodeCollection([5, 6, 8, 9])) t = nest.GetTargetNodes(layer[8], layer) self.assertEqual(len(t), 1) self.assertEqual(t[0], nest.NodeCollection([1, 3, 7, 9]))
# extract position information, transpose to list of x, y and z positions xpos, ypos, zpos = zip(*nest.GetPosition(l1)) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(xpos, ypos, zpos, s=15, facecolor='b') # Gaussian connections in full box volume [-0.75,0.75]**3 nest.Connect(l1, l1, {'rule': 'pairwise_bernoulli', 'p': nest.spatial_distributions.gaussian(nest.spatial.distance, std=0.25), 'allow_autapses': False, 'mask': {'box': {'lower_left': [-0.75, -0.75, -0.75], 'upper_right': [0.75, 0.75, 0.75]}}}) # show connections from center element # sender shown in red, targets in green ctr = nest.FindCenterElement(l1) xtgt, ytgt, ztgt = zip(*nest.GetTargetPositions(ctr, l1)[0]) xctr, yctr, zctr = nest.GetPosition(ctr) ax.scatter([xctr], [yctr], [zctr], s=40, facecolor='r') ax.scatter(xtgt, ytgt, ztgt, s=40, facecolor='g', edgecolor='g') tgts = nest.GetTargetNodes(ctr, l1)[0] distances = nest.Distance(ctr, l1) tgt_distances = [d for i, d in enumerate(distances) if i + 1 in tgts] plt.figure() plt.hist(tgt_distances, 25) plt.show()