.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/glif_cond_neuron.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_glif_cond_neuron.py: Conductance-based generalized leaky integrate and fire (GLIF) neuron example ---------------------------------------------------------------------------- .. only:: html ---- Run this example as a Jupyter notebook: .. card:: :width: 25% :margin: 2 :text-align: center :link: https://lab.ebrains.eu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fnest%2Fnest-simulator-examples&urlpath=lab%2Ftree%2Fnest-simulator-examples%2Fnotebooks%2Fnotebooks%2Fglif_cond_neuron.ipynb&branch=main :link-alt: JupyterHub service .. image:: https://nest-simulator.org/TryItOnEBRAINS.png .. grid:: 1 1 1 1 :padding: 0 0 2 0 .. grid-item:: :class: sd-text-muted :margin: 0 0 3 0 :padding: 0 0 3 0 :columns: 4 See :ref:`our guide ` for more information and troubleshooting. ---- Simple example of how to use the ``glif_cond`` neuron model for five different levels of GLIF neurons. Four stimulation paradigms are illustrated for the GLIF model with externally applied current and spikes impinging Voltage traces, injecting current traces, threshold traces, synaptic conductance traces and spikes are shown. .. GENERATED FROM PYTHON SOURCE LINES 38-40 First, we import all necessary modules to simulate, analyze and plot this example. .. GENERATED FROM PYTHON SOURCE LINES 40-45 .. code-block:: Python import matplotlib.gridspec as gridspec import matplotlib.pyplot as plt import nest .. GENERATED FROM PYTHON SOURCE LINES 46-47 We initialize NEST and set the simulation resolution. .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: Python nest.ResetKernel() resolution = 0.05 nest.resolution = resolution .. GENERATED FROM PYTHON SOURCE LINES 53-64 We create the five levels of GLIF model to be tested, i.e., ``lif``, ``lif_r``, ``lif_asc``, ``lif_r_asc``, ``lif_r_asc_a``. For each level of GLIF model, we create a ``glif_cond`` node. The node is created by setting relative model mechanism parameters. Other neuron parameters are set as default. The five ``glif_cond`` node handles are combined as a list. Note that the default number of synaptic ports is two for spike inputs. One port is excitation receptor with time constant being 0.2 ms and reversal potential being 0.0 mV. The other port is inhibition receptor with time constant being 2.0 ms and -85.0 mV. Note that users can set as many synaptic ports as needed for ``glif_cond`` by setting array parameters ``tau_syn`` and ``E_rev`` of the model. .. GENERATED FROM PYTHON SOURCE LINES 64-83 .. code-block:: Python n_lif = nest.Create( "glif_cond", params={"spike_dependent_threshold": False, "after_spike_currents": False, "adapting_threshold": False} ) n_lif_r = nest.Create( "glif_cond", params={"spike_dependent_threshold": True, "after_spike_currents": False, "adapting_threshold": False} ) n_lif_asc = nest.Create( "glif_cond", params={"spike_dependent_threshold": False, "after_spike_currents": True, "adapting_threshold": False} ) n_lif_r_asc = nest.Create( "glif_cond", params={"spike_dependent_threshold": True, "after_spike_currents": True, "adapting_threshold": False} ) n_lif_r_asc_a = nest.Create( "glif_cond", params={"spike_dependent_threshold": True, "after_spike_currents": True, "adapting_threshold": True} ) neurons = n_lif + n_lif_r + n_lif_asc + n_lif_r_asc + n_lif_r_asc_a .. GENERATED FROM PYTHON SOURCE LINES 84-94 For the stimulation input to the glif_cond neurons, we create one excitation spike generator and one inhibition spike generator, each of which generates three spikes; we also create one step current generator and a Poisson generator, a parrot neuron(to be paired with the Poisson generator). The three different injections are spread to three different time periods, i.e., 0 ms ~ 200 ms, 200 ms ~ 500 ms, 600 ms ~ 900 ms. Configuration of the current generator includes the definition of the start and stop times and the amplitude of the injected current. Configuration of the Poisson generator includes the definition of the start and stop times and the rate of the injected spike train. .. GENERATED FROM PYTHON SOURCE LINES 94-113 .. code-block:: Python espikes = nest.Create("spike_generator", params={"spike_times": [10.0, 100.0, 150.0], "spike_weights": [20.0] * 3}) ispikes = nest.Create("spike_generator", params={"spike_times": [15.0, 99.0, 150.0], "spike_weights": [-20.0] * 3}) cg = nest.Create( "step_current_generator", params={ "amplitude_values": [ 400.0, ], "amplitude_times": [ 200.0, ], "start": 200.0, "stop": 500.0, }, ) pg = nest.Create("poisson_generator", params={"rate": 15000.0, "start": 600.0, "stop": 900.0}) pn = nest.Create("parrot_neuron") .. GENERATED FROM PYTHON SOURCE LINES 114-121 The generators are then connected to the neurons. Specification of the ``receptor_type`` uniquely defines the target receptor. We connect current generator to receptor 0, the excitation spike generator and the Poisson generator (via parrot neuron) to receptor 1, and the inhibition spike generator to receptor 2 of the GLIF neurons. Note that Poisson generator is connected to parrot neuron to transit the spikes to the glif_cond neuron. .. GENERATED FROM PYTHON SOURCE LINES 121-128 .. code-block:: Python nest.Connect(cg, neurons, syn_spec={"delay": resolution}) nest.Connect(espikes, neurons, syn_spec={"delay": resolution, "receptor_type": 1}) nest.Connect(ispikes, neurons, syn_spec={"delay": resolution, "receptor_type": 2}) nest.Connect(pg, pn, syn_spec={"delay": resolution}) nest.Connect(pn, neurons, syn_spec={"delay": resolution, "receptor_type": 1}) .. GENERATED FROM PYTHON SOURCE LINES 129-132 A ``multimeter`` is created and connected to the neurons. The parameters specified for the multimeter include the list of quantities that should be recorded and the time interval at which quantities are measured. .. GENERATED FROM PYTHON SOURCE LINES 132-151 .. code-block:: Python mm = nest.Create( "multimeter", params={ "interval": resolution, "record_from": [ "V_m", "I", "g_1", "g_2", "threshold", "threshold_spike", "threshold_voltage", "ASCurrents_sum", ], }, ) nest.Connect(mm, neurons) .. GENERATED FROM PYTHON SOURCE LINES 152-154 A ``spike_recorder`` is created and connected to the neurons record the spikes generated by the glif_cond neurons. .. GENERATED FROM PYTHON SOURCE LINES 154-158 .. code-block:: Python sr = nest.Create("spike_recorder") nest.Connect(neurons, sr) .. GENERATED FROM PYTHON SOURCE LINES 159-161 Run the simulation for 1000 ms and retrieve recorded data from the multimeter and spike recorder. .. GENERATED FROM PYTHON SOURCE LINES 161-171 .. code-block:: Python nest.Simulate(1000.0) data = mm.events senders = data["senders"] spike_data = sr.events spike_senders = spike_data["senders"] spikes = spike_data["times"] .. GENERATED FROM PYTHON SOURCE LINES 172-180 We plot the time traces of the membrane potential (in blue) and the overall threshold (in green), and the spikes (as red dots) in one panel; the spike component of threshold (in yellow) and the voltage component of threshold (in black) in another panel; the injected currents (in strong blue), the sum of after spike currents (in cyan) in the third panel; and the synaptic conductances of the two receptors (in blue and orange) in responding to the spike inputs to the neurons in the fourth panel. We plot all these four panels for each level of GLIF model in a separated figure. .. GENERATED FROM PYTHON SOURCE LINES 180-222 .. code-block:: Python glif_models = ["lif", "lif_r", "lif_asc", "lif_r_asc", "lif_r_asc_a"] for i in range(len(glif_models)): glif_model = glif_models[i] node_id = neurons[i].global_id plt.figure(glif_model) gs = gridspec.GridSpec(4, 1, height_ratios=[2, 1, 1, 1]) t = data["times"][senders == 1] ax1 = plt.subplot(gs[0]) plt.plot(t, data["V_m"][senders == node_id], "b") plt.plot(t, data["threshold"][senders == node_id], "g--") plt.plot( spikes[spike_senders == node_id], [max(data["threshold"][senders == node_id]) * 0.95] * len(spikes[spike_senders == node_id]), "r.", ) plt.legend(["V_m", "threshold", "spike"]) plt.ylabel("V (mV)") plt.title("Simulation of glif_cond neuron of " + glif_model) ax2 = plt.subplot(gs[1]) plt.plot(t, data["threshold_spike"][senders == node_id], "y") plt.plot(t, data["threshold_voltage"][senders == node_id], "k--") plt.legend(["threshold_spike", "threshold_voltage"]) plt.ylabel("V (mV)") ax3 = plt.subplot(gs[2]) plt.plot(t, data["I"][senders == node_id], "--") plt.plot(t, data["ASCurrents_sum"][senders == node_id], "c-.") plt.legend(["I_e", "ASCurrents_sum", "I_syn"]) plt.ylabel("I (pA)") plt.xlabel("t (ms)") ax4 = plt.subplot(gs[3]) plt.plot(t, data["g_1"][senders == node_id], "-") plt.plot(t, data["g_2"][senders == node_id], "--") plt.legend(["G_1", "G_2"]) plt.ylabel("G (nS)") plt.xlabel("t (ms)") plt.show() .. _sphx_glr_download_auto_examples_glif_cond_neuron.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: glif_cond_neuron.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: glif_cond_neuron.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_