.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/csa_spatial_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_csa_spatial_example.py: Using CSA with spatial populations ---------------------------------- This example shows a brute-force way of specifying connections between NEST populations with spatial data using Connection Set Algebra instead of the built-in connection routines. Using the CSA requires NEST to be compiled with support for libneurosim. For details, see [1]_. See Also ~~~~~~~~ :doc:`csa_example` References ~~~~~~~~~~ .. [1] Djurfeldt M, Davison AP and Eppler JM (2014). Efficient generation of connectivity in neuronal networks from simulator-independent descriptions. Front. Neuroinform. https://doi.org/10.3389/fninf.2014.00043 .. GENERATED FROM PYTHON SOURCE LINES 49-50 First, we import all necessary modules. .. GENERATED FROM PYTHON SOURCE LINES 50-54 .. code-block:: default import nest import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 55-57 Next, we check for the availability of the CSA Python module. If it does not import, we exit with an error message. .. GENERATED FROM PYTHON SOURCE LINES 57-69 .. code-block:: default try: import csa haveCSA = True except ImportError: print("This example requires CSA to be installed in order to run.\n" + "Please make sure you compiled NEST using\n" + " -Dwith-libneurosim=[OFF|ON|]\n" + "and CSA and libneurosim are available.") import sys sys.exit(1) .. GENERATED FROM PYTHON SOURCE LINES 70-76 We define a factory that returns a CSA-style geometry function for the given layer. The function returned will return for each CSA-index the position in space of the given neuron as a 2- or 3-element list. This function stores a copy of the neuron positions internally, entailing memory overhead. .. GENERATED FROM PYTHON SOURCE LINES 76-88 .. code-block:: default def geometryFunction(population): positions = nest.GetPosition(population) def geometry_function(idx): return positions[idx] return geometry_function .. GENERATED FROM PYTHON SOURCE LINES 89-91 We create two spatial populations that have 20x20 neurons of type ``iaf_psc_alpha``. .. GENERATED FROM PYTHON SOURCE LINES 91-95 .. code-block:: default pop1 = nest.Create('iaf_psc_alpha', positions=nest.spatial.grid([20, 20])) pop2 = nest.Create('iaf_psc_alpha', positions=nest.spatial.grid([20, 20])) .. GENERATED FROM PYTHON SOURCE LINES 96-98 For each population, we create a CSA-style geometry function and a CSA metric based on them. .. GENERATED FROM PYTHON SOURCE LINES 98-103 .. code-block:: default g1 = geometryFunction(pop1) g2 = geometryFunction(pop2) d = csa.euclidMetric2d(g1, g2) .. GENERATED FROM PYTHON SOURCE LINES 104-107 The connection set `cg` 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. .. GENERATED FROM PYTHON SOURCE LINES 107-110 .. code-block:: default cg = csa.cset(csa.random * (csa.gaussian(0.2, 0.5) * d), 10000.0, 1.0) .. GENERATED FROM PYTHON SOURCE LINES 111-116 We can now connect the populations using the ``Connect`` function with the ``conngen`` rule. It takes the IDs of pre- and postsynaptic neurons (``pop1`` and ``pop2``), the connection set (``cg``) and a dictionary that map the parameters weight and delay to positions in the value set associated with the connection set (``params_map``). .. GENERATED FROM PYTHON SOURCE LINES 116-121 .. code-block:: default params_map = {"weight": 0, "delay": 1} connspec = {"rule": "conngen", "cg": cg, "params_map": params_map} nest.Connect(pop1, pop2, connspec) .. GENERATED FROM PYTHON SOURCE LINES 122-124 Finally, we use the ``PlotTargets`` function to show all targets in `pop2` starting at the center neuron of `pop1`. .. GENERATED FROM PYTHON SOURCE LINES 124-128 .. code-block:: default cntr = nest.FindCenterElement(pop1) nest.PlotTargets(cntr, pop2) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_csa_spatial_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: csa_spatial_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: csa_spatial_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_