{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# One neuron with noise\n\nThis script simulates a neuron with input from the ``poisson_generator``, and\nrecords the neuron's membrane potential.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "First, we import all necessary modules needed to simulate, analyze and\nplot our example. Additionally, we set the verbosity to only show warnings\nand reset the kernel.\nResetting the kernel removes any nodes we may have created previously and\nresets the internal clock to zero. This allows us to execute the script\nseveral times in a Python shell without interference from previous NEST\nsimulations.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import nest\nimport nest.voltage_trace\nimport matplotlib.pyplot as plt\n\nnest.set_verbosity(\"M_WARNING\")\nnest.ResetKernel()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Second, the nodes (the neuron, poisson generator (two of them), and the\nvoltmeter) are created using  the ``Create`` function.\nWe store the returned handles in variables for later reference.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "neuron = nest.Create(\"iaf_psc_alpha\")\nnoise = nest.Create(\"poisson_generator\", 2)\nvoltmeter = nest.Create(\"voltmeter\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Third, the Poisson generator is configured using ``SetStatus``, which expects\na list of node handles and a list of parameter dictionaries. We set the\nPoisson generators to 8,000 Hz and 15,000 Hz, respectively. Note that we do\nnot need to set parameters for the neuron and the voltmeter, since they have\nsatisfactory defaults.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "noise[0].rate = 80000.0\nnoise[1].rate = 15000.0"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Fourth, the neuron is connected to the ``poisson_generator`` and to the\n``voltmeter``. We also specify the synaptic weight and delay in this step.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "nest.Connect(noise, neuron, syn_spec={'weight': [[1.2, -1.0]], 'delay': 1.0})\nnest.Connect(voltmeter, neuron)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Now we simulate the network using ``Simulate``, which takes the\ndesired simulation time in milliseconds.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "nest.Simulate(1000.0)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Finally, we plot the neuron's membrane potential as a function of\ntime.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "nest.voltage_trace.from_device(voltmeter)\nplt.show()"
      ]
    }
  ],
  "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
}