Example #1
0
    def _target_positions(self):
        """Return positions of all connected target nodes."""

        return [
            tuple(pos)
            for pos in nest.GetTargetPositions(self._driver, self._lt)[0]
        ]
    def test_GetTargetPositions(self):
        """Test that GetTargetPosition works as expected"""

        cdict = {'rule': 'pairwise_bernoulli', 'p': 1.}
        sdict = {'synapse_model': 'stdp_synapse'}

        nest.SetKernelStatus({'sort_connections_by_source': False})

        l = nest.Create('iaf_psc_alpha',
                        positions=nest.spatial.grid(shape=[1, 1],
                                                    extent=(1., 1.),
                                                    edge_wrap=False))
        nest.Connect(l, l, cdict, sdict)

        # Simple test with one node ID in the layer, should be placed in the origin
        p = nest.GetTargetPositions(l, l)
        self.assertTrue(p, [[(0.0, 0.0)]])

        # Test positions on a grid, we can calculate what they should be
        nest.ResetKernel()
        nest.SetKernelStatus({'sort_connections_by_source': False})

        x_extent = 1.
        y_extent = 1.
        shape = [3, 3]

        l = nest.Create('iaf_psc_alpha',
                        positions=nest.spatial.grid(
                            shape=shape,
                            extent=[x_extent, y_extent],
                            edge_wrap=False))
        nest.Connect(l, l, cdict, sdict)

        p = nest.GetTargetPositions(l[:1], l)
        self.assertEqual(len(p), 1)
        self.assertTrue(all([len(pp) == 2 for pp in p[0]]))

        p = nest.GetTargetPositions(l, l)
        self.assertEqual(len(p), len(l))

        dx = x_extent / shape[0]
        dy = y_extent / shape[1]

        x = [-dx, -dx, -dx, 0.0, 0.0, 0.0, dx, dx, dx]
        y = [dy, 0.0, -dy, dy, 0.0, -dy, dy, 0.0, -dy]

        pos = [(x[i], y[i]) for i in range(len(x))]

        for indx in range(len(pos)):
            # 4 chosen randomly, they should all be the same, as all node IDs in
            # the layer are connected
            self.assertAlmostEqual(p[4][indx][0], pos[indx][0])
            self.assertAlmostEqual(p[4][indx][1], pos[indx][1])

        # Test that we get correct positions when we send in a positions array
        # when creating the layer
        nest.ResetKernel()
        nest.SetKernelStatus({'sort_connections_by_source': False})

        positions = [(np.random.uniform(-0.5,
                                        0.5), np.random.uniform(-0.5, 0.5))
                     for _ in range(50)]
        l = nest.Create('iaf_psc_alpha',
                        positions=nest.spatial.free(positions,
                                                    edge_wrap=False))
        nest.Connect(l, l, cdict, sdict)

        p = nest.GetTargetPositions(l[:1], l)

        for indx in range(len(p[0])):
            self.assertAlmostEqual(positions[indx][0], p[0][indx][0])
            self.assertAlmostEqual(positions[indx][1], p[0][indx][1])
Example #3
0
# 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()
Example #4
0
})

plt.clf()

######################################################
# plot targets of neurons in different grid locations
# obtain node id for center: pick first node of composite

ctr_index = 30 * 15 + 15
ctr_id = a_pyr[ctr_index:ctr_index + 1]

# get all projection targets of center neuron
conn = nest.GetConnections(ctr_id)
tgts = conn.get('target')

tpyr = nest.GetTargetPositions(ctr_id, b_pyr)[0]
tin = nest.GetTargetPositions(ctr_id, b_in)[0]

tpyr_x = np.array([x for x, y in tpyr])
tpyr_y = np.array([y for x, y in tpyr])
tin_x = np.array([x for x, y in tin])
tin_y = np.array([y for x, y in tin])

# scatter-plot
plt.scatter(tpyr_x - 0.02, tpyr_y - 0.02, 20, 'b', zorder=10)
plt.scatter(tin_x + 0.02, tin_y + 0.02, 20, 'r', zorder=10)

# mark locations with background grey circle
plt.plot(tpyr_x,
         tpyr_y,
         'o',
                         'lower_left': [-0.2, -0.5],
                         'upper_right': [0.2, 0.5]
                     }
                 }
             },
             syn_spec={'weight': nest.random.uniform(0.5, 2.)})
plt.clf()

############################################################################
# plot sources of neurons in different grid locations
for tgt_index in [30 * 15 + 15, 0]:
    # obtain node id for center
    tgt = a[tgt_index:tgt_index + 1]

    # obtain list of outgoing connections for ctr
    spos = nest.GetTargetPositions(tgt, b)[0]

    spos_x = np.array([x for x, y in spos])
    spos_y = np.array([y for x, y in spos])

    print(spos_x)
    print(spos_y)

    # scatter-plot
    plt.scatter(spos_x, spos_y, 20, zorder=10)

    # mark sender position with transparent red circle
    ctrpos = np.array(nest.GetPosition(tgt))
    plt.gca().add_patch(
        plt.Circle(ctrpos, radius=0.1, zorder=99, fc='r', alpha=0.4,
                   ec='none'))