{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Create two populations on a 30x30 grid and connect them using a Gaussian probabilistic kernel\n\nBCCN Tutorial @ CNS*09\nHans Ekkehard Plesser, UMB\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\nimport nest\n\nnest.ResetKernel()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "create two test layers\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "pos = 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': nest.spatial_distributions.gaussian(nest.spatial.distance,\n                                                  std=0.5),\n         'mask': {'circular': {'radius': 3.0}}}\n\nnest.Connect(a, b, cdict)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "plot targets of neurons in different grid locations\n\nplot targets of two source neurons into same figure, with mask\nuse different colors\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "for src_index, color, cmap in [(30 * 15 + 15, 'blue', 'Blues'), (0, 'green', 'Greens')]:\n    # obtain node id for center\n    src = a[src_index:src_index + 1]\n    fig = plt.figure()\n    nest.PlotTargets(src, b, mask=cdict['mask'], probability_parameter=cdict['p'],\n                     src_color=color, tgt_color=color, mask_color=color,\n                     probability_cmap=cmap, src_size=100,\n                     fig=fig)\n\n    # beautify\n    plt.axes().set_xticks(np.arange(-1.5, 1.55, 0.5))\n    plt.axes().set_yticks(np.arange(-1.5, 1.55, 0.5))\n    plt.grid(True)\n    plt.axis([-2.0, 2.0, -2.0, 2.0])\n    plt.axes().set_aspect('equal', 'box')\n    plt.title('Connection targets, Gaussian kernel')\n\nplt.show()\n\n# plt.savefig('gaussex.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
}