Modeling networks of spiking neurons using NEST
Python Module of the Week, 03.05.2019
This notebook guides through your first steps using NEST. It shows
Essentially, this is a reproduction of the 'Hello World!' notebook with added explanations.
For more details see part 1 of the official PyNEST tutorial.
In [ ]:
# populate namespace with pylab functions and stuff
%pylab inline
In [ ]:
import nest # import NEST module
In [ ]:
# information about functions with Python's help() ...
help(nest.Models)
In [ ]:
# ... or IPython's question mark
nest.Models?
In [ ]:
# list neuron models
nest.Models()
In [ ]:
# choose LIF neuron with exponential synaptic currents: 'iaf_psc_exp'
# look in documentation for model description
# or (if not compiled with MPI)
nest.help('iaf_psc_exp')
In [ ]:
# before creating a new network,
# reset the simulation kernel / remove all nodes
nest.ResetKernel()
In [ ]:
# create the neuron
neuron = nest.Create('iaf_psc_exp')
In [ ]:
# investigate the neuron
# Create() just returns a list (tuple) with handles to the new nodes
# (handles = integer numbers called ids)
neuron
In [ ]:
# current dynamical state/parameters of the neuron
# note that the membrane voltage is at -70 mV
nest.GetStatus(neuron)
In [ ]:
# create a spike generator
spikegenerator = nest.Create('spike_generator')
In [ ]:
# check out 'spike_times' in its parameters
nest.GetStatus(spikegenerator)
In [ ]:
# set the spike times at 10 and 50 ms
nest.SetStatus(spikegenerator, {'spike_times': [10., 50.]})
In [ ]:
# create a voltmeter for recording
voltmeter = nest.Create('voltmeter')
In [ ]:
# investigate the voltmeter
voltmeter
In [ ]:
# see that it records membrane voltage, senders, times
nest.GetStatus(voltmeter)
In [ ]:
# investigate Connect() function
nest.Connect?
In [ ]:
# connect spike generator and voltmeter to the neuron
nest.Connect(spikegenerator, neuron, syn_spec={'weight': 1e3})
In [ ]:
nest.Connect(voltmeter, neuron)
In [ ]:
# run simulation for 100 ms
nest.Simulate(100.)
In [ ]:
# look at nest's KernelStatus:
# network_size (root node, neuron, spike generator, voltmeter)
# num_connections
# time (simulation duration)
nest.GetKernelStatus()
In [ ]:
# note that voltmeter has recorded 99 events
nest.GetStatus(voltmeter)
In [ ]:
# read out recording time and voltage from voltmeter
times = nest.GetStatus(voltmeter)[0]['events']['times']
voltages = nest.GetStatus(voltmeter)[0]['events']['V_m']
In [ ]:
# plot results
# units can be found in documentation
pylab.plot(times, voltages, label='Neuron 1')
pylab.xlabel('Time (ms)')
pylab.ylabel('Membrane potential (mV)')
pylab.title('Membrane potential')
pylab.legend()
In [ ]:
# create the same plot with NEST's build-in plotting function
import nest.voltage_trace
In [ ]:
nest.voltage_trace.from_device(voltmeter)
0_hello_world.ipynb
)