.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/spatial/conncomp.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_conncomp.py: Spatial networks: Pyramidal cells and interneurons -------------------------------------------------- .. 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%2Fconncomp.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 pyramidal cells and two populations of interneurons on a 30x30 grid. Connect with two projections, one pyr->pyr, one pyr->in, and visualize. BCCN Tutorial @ CNS*09 Hans Ekkehard Plesser, UMB .. GENERATED FROM PYTHON SOURCE LINES 33-44 .. code-block:: Python import matplotlib.pyplot as plt import nest import numpy as np nest.ResetKernel() nest.set_verbosity("M_WARNING") nest.CopyModel("iaf_psc_alpha", "pyr") nest.CopyModel("iaf_psc_alpha", "in") .. GENERATED FROM PYTHON SOURCE LINES 45-46 same positions for all populations .. GENERATED FROM PYTHON SOURCE LINES 46-60 .. code-block:: Python pos = nest.spatial.grid(shape=[30, 30], extent=[3.0, 3.0]) a_pyr = nest.Create("pyr", positions=pos) a_in = nest.Create("in", positions=pos) b_pyr = nest.Create("pyr", positions=pos) b_in = nest.Create("in", positions=pos) nest.Connect(a_pyr, b_pyr, {"rule": "pairwise_bernoulli", "p": 0.5, "mask": {"circular": {"radius": 0.5}}}) nest.Connect(a_pyr, b_in, {"rule": "pairwise_bernoulli", "p": 0.2, "mask": {"circular": {"radius": 1.0}}}) plt.clf() .. GENERATED FROM PYTHON SOURCE LINES 61-63 plot targets of neurons in different grid locations obtain node id for center: pick first node of composite .. GENERATED FROM PYTHON SOURCE LINES 63-109 .. code-block:: Python 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", markerfacecolor=(0.7, 0.7, 0.7), markersize=10, markeredgewidth=0, zorder=1, label="_nolegend_" ) plt.plot( tin_x, tin_y, "o", markerfacecolor=(0.7, 0.7, 0.7), markersize=10, markeredgewidth=0, zorder=1, label="_nolegend_" ) # mark sender position with transparent red circle ctrpos = nest.GetPosition(ctr_id) plt.gca().add_patch(plt.Circle(ctrpos, radius=0.15, zorder=99, fc="r", alpha=0.4, ec="none")) # mark mask positions with open red/blue circles plt.gca().add_patch(plt.Circle(ctrpos, radius=0.5, zorder=2, fc="none", ec="b", lw=3)) plt.gca().add_patch(plt.Circle(ctrpos, radius=1.0, zorder=2, 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([-1.6, 1.6, -1.6, 1.6]) plt.axes().set_aspect("equal", "box") plt.show() .. _sphx_glr_download_auto_examples_spatial_conncomp.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: conncomp.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: conncomp.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_