Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add description for "Two neuron example" #1825

Merged
merged 11 commits into from
Nov 5, 2020
17 changes: 7 additions & 10 deletions pynest/examples/one_neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

"""

#######################################################################
###############################################################################
# First, we import all necessary modules for simulation, analysis and
# plotting. Additionally, we set the verbosity to suppress info
# messages and reset the kernel.
Expand All @@ -50,7 +50,7 @@
nest.set_verbosity("M_WARNING")
nest.ResetKernel()

#######################################################################
###############################################################################
# Second, the nodes (neurons and devices) are created using ``Create``.
# We store the returned handles in variables for later reference.
# The ``Create`` function also allow you to create multiple nodes
Expand All @@ -64,15 +64,12 @@
neuron = nest.Create("iaf_psc_alpha")
voltmeter = nest.Create("voltmeter")

#######################################################################
# Third, the neuron is configured using `SetStatus()`, which expects
# a list of node handles and a list of parameter dictionaries.
# In this example we use `SetStatus()` to configure the constant
# current input to the neuron.
###############################################################################
# Third, we set the external current of the neuron.

neuron.I_e = 376.0

#######################################################################
###############################################################################
# Fourth, the neuron is connected to the voltmeter. The command
# ``Connect`` has different variants. Plain ``Connect`` just takes the
# handles of pre- and post-synaptic nodes and uses the default values
Expand All @@ -85,13 +82,13 @@

nest.Connect(voltmeter, neuron)

#######################################################################
###############################################################################
# Now we simulate the network using ``Simulate``, which takes the
# desired simulation time in milliseconds.

nest.Simulate(1000.0)

#######################################################################
###############################################################################
# Finally, we plot the neuron's membrane potential as a function of
# time and display the plot using pyplot.

Expand Down
49 changes: 40 additions & 9 deletions pynest/examples/twoneurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,63 @@
"""Two neuron example
----------------------------

This script simulates two connected pre- and postsynaptic neurons.
The presynaptic neuron receives a constant external current,
and the membrane potential of both neurons are recorded.

See Also
~~~~~~~~~~
~~~~~~~~

:doc:`one_neuron`

"""

###############################################################################
# First, we import all necessary modules for simulation, analysis and plotting.
# Additionally, we set the verbosity to suppress info messages and reset
YounesBouhadjar marked this conversation as resolved.
Show resolved Hide resolved
# the kernel.

import nest
import nest.voltage_trace
import matplotlib.pyplot as plt

nest.set_verbosity("M_WARNING")
nest.ResetKernel()
hakonsbm marked this conversation as resolved.
Show resolved Hide resolved

###############################################################################
# Second, we create the two neurons and the recording device.

neuron_1 = nest.Create("iaf_psc_alpha")
neuron_2 = nest.Create("iaf_psc_alpha")
voltmeter = nest.Create("voltmeter")

###############################################################################
# Third, we set the external current of neuron 1.

neuron_1.I_e = 376.0

###############################################################################
# Fourth, we connect neuron 1 to neuron 2.
# Then, we connect a voltmeter to the two neurons.
# To learn more about the previous steps, please check out the
# :doc:`one neuron example <one_neuron>`.

weight = 20.0
delay = 1.0
stim = 1000.0

neuron1 = nest.Create("iaf_psc_alpha")
neuron2 = nest.Create("iaf_psc_alpha")
voltmeter = nest.Create("voltmeter")
nest.Connect(neuron_1, neuron_2, syn_spec={"weight": weight, "delay": delay})
nest.Connect(voltmeter, neuron_1)
nest.Connect(voltmeter, neuron_2)

###############################################################################
# Now we simulate the network using ``Simulate``, which takes the
# desired simulation time in milliseconds.

neuron1.I_e = stim
nest.Connect(neuron1, neuron2, syn_spec={'weight': weight, 'delay': delay})
nest.Connect(voltmeter, neuron2)
nest.Simulate(1000.0)

nest.Simulate(100.0)
###############################################################################
# Finally, we plot the neurons' membrane potential as a function of
# time.

nest.voltage_trace.from_device(voltmeter)
plt.show()