.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/spatial/conncon_sources.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_spatial_conncon_sources.py: Spatial networks: Convergent projection and rectangular mask, from target perspective ------------------------------------------------------------------------------------- .. only:: html ---- Run this example as a Jupyter notebook: .. card:: :width: 25% :margin: 2 :text-align: center :link: https://lab.ebrains.eu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fnest%2Fnest-simulator-examples&urlpath=lab%2Ftree%2Fnest-simulator-examples%2Fnotebooks%2Fnotebooks%2Fspatial%2Fconncon_sources.ipynb&branch=main :link-alt: JupyterHub service .. image:: https://nest-simulator.org/TryItOnEBRAINS.png .. grid:: 1 1 1 1 :padding: 0 0 2 0 .. grid-item:: :class: sd-text-muted :margin: 0 0 3 0 :padding: 0 0 3 0 :columns: 4 See :ref:`our guide ` for more information and troubleshooting. ---- Create two populations of iaf_psc_alpha neurons on a 30x30 grid Connect the two populations with convergent projection and rectangular mask and visualize connection from target perspective. BCCN Tutorial @ CNS*09 Hans Ekkehard Plesser, UMB .. GENERATED FROM PYTHON SOURCE LINES 34-44 .. code-block:: Python import matplotlib.pyplot as plt import nest import numpy as np nest.ResetKernel() nest.set_verbosity("M_WARNING") pos = nest.spatial.grid(shape=[30, 30], extent=[3.0, 3.0], edge_wrap=True) .. GENERATED FROM PYTHON SOURCE LINES 45-46 create and connect two populations .. GENERATED FROM PYTHON SOURCE LINES 46-62 .. code-block:: Python a = nest.Create("iaf_psc_alpha", positions=pos) b = nest.Create("iaf_psc_alpha", positions=pos) nest.Connect( a, b, conn_spec={ "rule": "pairwise_bernoulli", "p": 0.5, "use_on_source": True, "mask": {"rectangular": {"lower_left": [-0.2, -0.5], "upper_right": [0.2, 0.5]}}, }, syn_spec={"weight": nest.random.uniform(0.5, 2.0)}, ) plt.clf() .. GENERATED FROM PYTHON SOURCE LINES 63-64 plot sources of neurons in different grid locations .. GENERATED FROM PYTHON SOURCE LINES 64-98 .. code-block:: Python 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")) # mark mask position with open red rectangle plt.gca().add_patch(plt.Rectangle(ctrpos - (0.2, 0.5), 0.4, 1.0, zorder=1, fc="none", ec="r", lw=3)) # mark layer edge plt.gca().add_patch(plt.Rectangle((-1.5, -1.5), 3.0, 3.0, zorder=1, fc="none", ec="k", lw=3)) # beautify plt.axes().set_xticks(np.arange(-1.5, 1.55, 0.5)) plt.axes().set_yticks(np.arange(-1.5, 1.55, 0.5)) plt.grid(True) plt.axis([-2.0, 2.0, -2.0, 2.0]) plt.axes().set_aspect("equal", "box") plt.title("Connection sources") plt.show() .. _sphx_glr_download_auto_examples_spatial_conncon_sources.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: conncon_sources.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: conncon_sources.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_