def _build(self): """Create populations.""" if self._open_bc: x = rnd.uniform(-self._L / 2., self._L / 2., self._N) y = rnd.uniform(-self._L / 2., self._L / 2., self._N) pos = list(zip(x, y)) self._ls = nest.Create('iaf_psc_alpha', positions=nest.spatial.free( [[self._x_d, self._y_d]], edge_wrap=False)) self._lt = nest.Create('iaf_psc_alpha', positions=nest.spatial.free( pos, edge_wrap=False)) self._driver = self._ls else: x = rnd.uniform(-self._L / 2., self._L / 2., self._N) y = rnd.uniform(-self._L / 2., self._L / 2., self._N) if self._dimensions == 3: z = rnd.uniform(-self._L / 2., self._L / 2., self._N) pos = list(zip(x, y, z)) else: pos = list(zip(x, y)) self._ls = nest.Create( 'iaf_psc_alpha', positions=nest.spatial.free([[0.] * self._dimensions], [self._L] * self._dimensions, edge_wrap=True)) self._lt = nest.Create('iaf_psc_alpha', positions=nest.spatial.free( pos, [self._L] * self._dimensions, edge_wrap=True)) self._driver = nest.FindCenterElement(self._ls)
def conn_figure_3d(fig, layer, connd, targets=None, showmask=True, xticks=range(-5, 6), yticks=range(-5, 6), xlim=[-5.5, 5.5], ylim=[-5.5, 5.5]): if targets is None: targets = ((nest.FindCenterElement(layer), 'red'), ) nest.PlotLayer(layer, fig=fig, nodesize=20, nodecolor=(.5, .5, 1.)) for src, clr in targets: if showmask: mask = connd['mask'] else: mask = None nest.PlotTargets(src, layer, fig=fig, mask=mask, probability_parameter=None, src_size=250, tgt_color=clr, tgt_size=60, probability_cmap='Greens') ax = fig.gca() # ax.set_aspect('equal', 'box') plt.draw()
def test_GetCenterElement(self): """Interface and result check for finding center element. This function is Py only, so we also need to check results.""" # nodes at [-1,0,1]x[-1,0,1], column-wise nest.ResetKernel() l = nest.Create('iaf_psc_alpha', positions=nest.spatial.grid(shape=[3, 3], extent=(2., 2.))) # single layer n = nest.FindCenterElement(l) self.assertEqual(n, l[4:5]) # new layer l2 = nest.Create('iaf_psc_alpha', positions=nest.spatial.grid(shape=[3, 3], extent=(2., 2.))) n = nest.FindCenterElement(l2) self.assertEqual(n, l2[4:5])
def conn_figure(fig, layer, connd, targets=None, showmask=True, kern=None, xticks=range(-5, 6), yticks=range(-5, 6), xlim=[-5.5, 5.5], ylim=[-5.5, 5.5]): if targets is None: targets = ((nest.FindCenterElement(layer), 'red'), ) nest.PlotLayer(layer, fig=fig, nodesize=60) for src, clr in targets: if showmask: mask = connd['mask'] else: mask = None nest.PlotTargets(src, layer, fig=fig, mask=mask, probability_parameter=kern, src_size=250, tgt_color=clr, tgt_size=20, mask_color='red', probability_cmap='Greens') beautify_layer(layer, fig, xlim=xlim, ylim=ylim, xticks=xticks, yticks=yticks, xlabel='', ylabel='') fig.gca().grid(False)
def test_PlotTargets(self): """Test plotting targets.""" delta = 0.05 mask = { 'rectangular': { 'lower_left': [-delta, -2 / 3 - delta], 'upper_right': [2 / 3 + delta, delta] } } cdict = {'rule': 'pairwise_bernoulli', 'p': 1., 'mask': mask} sdict = {'synapse_model': 'stdp_synapse'} nest.ResetKernel() 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) ctr = nest.FindCenterElement(layer) fig = nest.PlotTargets(ctr, layer) fig.gca().set_title('Plain call') plotted_datapoints = plt.gca().collections[0].get_offsets().data eps = 0.01 pos = np.array(nest.GetPosition(layer)) pos_xmask = pos[np.where(pos[:, 0] > -eps)] reference_datapoints = pos_xmask[np.where(pos_xmask[:, 1] < eps)][::-1] self.assertTrue( np.array_equal(np.sort(plotted_datapoints, axis=0), np.sort(reference_datapoints, axis=0))) fig = nest.PlotTargets(ctr, layer, mask=mask) ax = fig.gca() ax.set_title('Call with mask') self.assertGreaterEqual(len(ax.patches), 1)
retThal_syn_spec = {"weight": 10.0, "delay": 1.0, "synapse_model": "AMPA"} print("Connecting: retino-thalamic") nest.Connect(retina, TpRelay, retThal_conn_spec, retThal_syn_spec) nest.Connect(retina, TpInter, retThal_conn_spec, retThal_syn_spec) ############################################################################## # Checks on connections # --------------------- # # As a very simple check on the connections created, we inspect # the connections from the central node of various layers. # Connections from Retina to TpRelay retina_ctr_node_id = nest.FindCenterElement(retina) retina_ctr_index = retina.index(retina_ctr_node_id.global_id) conns = nest.GetConnections(retina[retina_ctr_index], TpRelay) nest.PlotTargets(retina[retina_ctr_index], TpRelay, 'AMPA') plt.title('Connections Retina -> TpRelay') # Connections from TpRelay to L4pyr in Vp (horizontally tuned) TpRelay_ctr_node_id = nest.FindCenterElement(TpRelay) TpRelay_ctr_index = TpRelay.index(TpRelay_ctr_node_id.global_id) nest.PlotTargets(TpRelay[TpRelay_ctr_index], Vp_h_layers['L4pyr_0'], 'AMPA') plt.title('Connections TpRelay -> Vp(h) L4pyr') # Connections from TpRelay to L4pyr in Vp (vertically tuned) nest.PlotTargets(TpRelay[TpRelay_ctr_index], Vp_v_layers['L4pyr_0'], 'AMPA') plt.title('Connections TpRelay -> Vp(v) L4pyr')
#{ vislayer #} l = nest.Create('iaf_psc_alpha', positions=nest.spatial.grid(shape=[21, 21])) probability_param = nest.spatial_distributions.gaussian(nest.spatial.distance, std=0.15) conndict = { 'rule': 'pairwise_bernoulli', 'p': probability_param, 'mask': { 'circular': { 'radius': 0.4 } } } nest.Connect(l, l, conndict) fig = nest.PlotLayer(l, nodesize=80) ctr = nest.FindCenterElement(l) nest.PlotTargets(ctr, l, fig=fig, mask=conndict['mask'], probability_parameter=probability_param, src_size=250, tgt_color='red', tgt_size=20, mask_color='red', probability_cmap='Greens') #{ end #} plt.savefig('../user_manual_figures/vislayer.png', bbox_inches='tight')
exec('{} = nest.Create(layer[1], positions=nest.spatial.grid(layer[2], extent=layer[3]))'.format(layer[0])) # ! Create connections, need to insert variable names for conn in s_conn: eval('nest.Connect({}, {}, conn[2], conn[3])'.format(conn[0], conn[1])) nest.Simulate(10) # ! **Ooops:*** Nothing happened? Well, it did, but pyreport cannot capture the # ! output directly generated by NEST. The absence of an error message in this # ! place shows that network construction and simulation went through. # ! Inspecting the connections actually created # ! ::::::::::::::::::::::::::::::::::::::::::: # ! The following block of messy and makeshift code plots the targets of the # ! center neuron of the B/E population in the B/E and the B/I populations. E_ctr = nest.FindCenterElement(RG_E) # get all targets, split into excitatory and inhibitory Econns = nest.GetConnections(E_ctr, RG_E, synapse_model='static_synapse') Etgts = Econns.get('target') Iconns = nest.GetConnections(E_ctr, RG_I, synapse_model='static_synapse') Itgts = Iconns.get('target') # obtain positions of targets Etpos = np.array([nest.GetPosition(RG_E[RG_E.index(tnode_id)]) for tnode_id in Etgts]) Itpos = np.array([nest.GetPosition(RG_I[RG_I.index(tnode_id)]) for tnode_id in Itgts]) # plot excitatory plt.clf() plt.subplot(121) plt.scatter(Etpos[:, 0], Etpos[:, 1])
'mask': { 'rectangular': { 'lower_left': [-2., -1.], 'upper_right': [2., 1.] } } } nest.Connect(l, l, conndict) #{ end #} fig = plt.figure() fig.add_subplot(121) conn_figure(fig, l, conndict, targets=((nest.FindCenterElement(l), 'red'), (nest.FindNearestElement(l, [4., 5.])[0], 'yellow'))) # same another time, with periodic bcs lpbc = nest.Create('iaf_psc_alpha', positions=nest.spatial.grid(shape=[11, 11], extent=[11., 11.], edge_wrap=True)) nest.Connect(lpbc, lpbc, conndict) fig.add_subplot(122) conn_figure(fig, lpbc, conndict, showmask=False, targets=((nest.FindCenterElement(lpbc), 'red'), (nest.FindNearestElement(lpbc, [4., 5.])[0], 'yellow')))
# For each population, we create a CSA-style geometry function and a CSA metric # based on them. g1 = geometryFunction(pop1) g2 = geometryFunction(pop2) d = csa.euclidMetric2d(g1, g2) ############################################################################### # The connection set `cs` describes a Gaussian connectivity profile with # ``sigma = 0.2`` and cutoff at 0.5, and two values (10000.0 and 1.0) used as # ``weight`` and ``delay``, respectively. cs = csa.cset(csa.random * (csa.gaussian(0.2, 0.5) * d), 10000.0, 1.0) ############################################################################### # We can now connect the populations using the ``CGConnect`` function. It # takes the IDs of pre- and postsynaptic neurons (`pop` and `pop2`), # the connection set (`cs`) and a dictionary that map the parameters # weight and delay to positions in the value set associated with the # connection set. nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1}) ############################################################################### # Finally, we use the ``PlotTargets`` function to show all targets in `pop2` # starting at the center neuron of `pop1`. cntr = nest.FindCenterElement(pop1) nest.PlotTargets(cntr, pop2) plt.show()
'mask': { 'rectangular': { 'lower_left': [-2., -1.], 'upper_right': [2., 1.] } } } nest.Connect(spatial_nodes, spatial_nodes, conndict) #{ end #} fig = plt.figure() fig.add_subplot(121) conn_figure(fig, spatial_nodes, conndict, targets=((nest.FindCenterElement(spatial_nodes), 'red'), (nest.FindNearestElement(spatial_nodes, [4., 5.])[0], 'yellow'))) # same another time, with periodic bcs lpbc = nest.Create('iaf_psc_alpha', positions=nest.spatial.grid(shape=[11, 11], extent=[11., 11.], edge_wrap=True)) nest.Connect(lpbc, lpbc, conndict) fig.add_subplot(122) conn_figure(fig, lpbc, conndict, showmask=False, targets=((nest.FindCenterElement(lpbc), 'red'),