{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Connect with circular mask, flat probability using 2 populations of iaf_psc_alpha neurons\n\nCreate two populations on a 30x30 grid of iaf_psc_alpha neurons,\nconnect with circular mask, flat probability,\nvisualize.\n\nBCCN Tutorial @ CNS*09\nHans Ekkehard Plesser, UMB\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import nest\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nnest.ResetKernel()\n\npos = nest.spatial.grid(shape=[30, 30], extent=[3., 3.])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "create and connect two populations\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "a = nest.Create('iaf_psc_alpha', positions=pos)\nb = nest.Create('iaf_psc_alpha', positions=pos)\n\ncdict = {'rule': 'pairwise_bernoulli',\n         'p': 0.5,\n         'mask': {'circular': {'radius': 0.5}}}\n\nnest.Connect(a, b,\n             conn_spec=cdict,\n             syn_spec={'weight': nest.random.uniform(0.5, 2.)})"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "plot targets of neurons in different grid locations\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# first, clear existing figure, get current figure\nplt.clf()\nfig = plt.gcf()\n\n# plot targets of two source neurons into same figure, with mask\nfor src_index in [30 * 15 + 15, 0]:\n    # obtain node id for center\n    src = a[src_index:src_index + 1]\n    nest.PlotTargets(src, b, mask=cdict['mask'], fig=fig)\n\n# beautify\nplt.axes().set_xticks(np.arange(-1.5, 1.55, 0.5))\nplt.axes().set_yticks(np.arange(-1.5, 1.55, 0.5))\nplt.grid(True)\nplt.axis([-2.0, 2.0, -2.0, 2.0])\nplt.axes().set_aspect('equal', 'box')\nplt.title('Connection targets')\n\nplt.show()\n\n# plt.savefig('connex.pdf')"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.6"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}