.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/intrinsic_currents_spiking.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_intrinsic_currents_spiking.py: Intrinsic currents spiking -------------------------- .. 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%2Fintrinsic_currents_spiking.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. ---- This example illustrates a neuron receiving spiking input through several different receptors (AMPA, NMDA, GABA_A, GABA_B), provoking spike output. The model, ``ht_neuron``, also has intrinsic currents (``I_NaP``, ``I_KNa``, ``I_T``, and ``I_h``). It is a slightly simplified implementation of neuron model proposed in [1]_. The neuron is bombarded with spike trains from four Poisson generators, which are connected to the AMPA, NMDA, GABA_A, and GABA_B receptors, respectively. References ~~~~~~~~~~ .. [1] Hill and Tononi (2005) Modeling sleep and wakefulness in the thalamocortical system. J Neurophysiol 93:1671 https://doi.org/10.1152/jn.00915.2004 See Also ~~~~~~~~ :doc:`intrinsic_currents_subthreshold` .. GENERATED FROM PYTHON SOURCE LINES 52-53 We imported all necessary modules for simulation, analysis and plotting. .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python import matplotlib.pyplot as plt import nest .. GENERATED FROM PYTHON SOURCE LINES 58-60 Additionally, we set the verbosity using ``set_verbosity`` to suppress info messages. We also reset the kernel to be sure to start with a clean NEST. .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python nest.set_verbosity("M_WARNING") nest.ResetKernel() .. GENERATED FROM PYTHON SOURCE LINES 65-72 We define the simulation parameters: - The rate of the input spike trains - The weights of the different receptors (names must match receptor types) - The time to simulate Note that all parameter values should be doubles, since NEST expects doubles. .. GENERATED FROM PYTHON SOURCE LINES 72-79 .. code-block:: Python rate_in = 100.0 w_recep = {"AMPA": 30.0, "NMDA": 30.0, "GABA_A": 5.0, "GABA_B": 10.0} t_sim = 250.0 num_recep = len(w_recep) .. GENERATED FROM PYTHON SOURCE LINES 80-85 We create - one neuron instance - one Poisson generator instance for each synapse type - one multimeter to record from the neuron: .. GENERATED FROM PYTHON SOURCE LINES 85-104 .. code-block:: Python # - membrane potential # - threshold potential # - synaptic conductances # - intrinsic currents # # See :doc:`intrinsic_currents_subthreshold` for more details on ``multimeter`` # configuration. nrn = nest.Create("ht_neuron") p_gens = nest.Create("poisson_generator", 4, params={"rate": rate_in}) mm = nest.Create( "multimeter", params={ "interval": 0.1, "record_from": ["V_m", "theta", "g_AMPA", "g_NMDA", "g_GABA_A", "g_GABA_B", "I_NaP", "I_KNa", "I_T", "I_h"], }, ) .. GENERATED FROM PYTHON SOURCE LINES 105-118 We now connect each Poisson generator with the neuron through a different receptor type. First, we need to obtain the numerical codes for the receptor types from the model. The ``receptor_types`` entry of the default dictionary for the ``ht_neuron`` model is a dictionary mapping receptor names to codes. In the loop, we use Python's tuple unpacking mechanism to unpack dictionary entries from our `w_recep` dictionary. Note that we need to pack the `pg` variable into a list before passing it to ``Connect``, because iterating over the `p_gens` list makes `pg` a "naked" node ID. .. GENERATED FROM PYTHON SOURCE LINES 118-123 .. code-block:: Python receptors = nest.GetDefaults("ht_neuron")["receptor_types"] for index, (rec_name, rec_wgt) in enumerate(w_recep.items()): nest.Connect(p_gens[index], nrn, syn_spec={"receptor_type": receptors[rec_name], "weight": rec_wgt}) .. GENERATED FROM PYTHON SOURCE LINES 124-126 We then connect the ``multimeter``. Note that the multimeter is connected to the neuron, not the other way around. .. GENERATED FROM PYTHON SOURCE LINES 126-129 .. code-block:: Python nest.Connect(mm, nrn) .. GENERATED FROM PYTHON SOURCE LINES 130-131 We are now ready to simulate. .. GENERATED FROM PYTHON SOURCE LINES 131-134 .. code-block:: Python nest.Simulate(t_sim) .. GENERATED FROM PYTHON SOURCE LINES 135-140 We now fetch the data recorded by the multimeter. The data are returned as a dictionary with entry ``times`` containing timestamps for all recorded data, plus one entry per recorded quantity. All data is contained in the ``events`` entry of the status dictionary returned by the multimeter. .. GENERATED FROM PYTHON SOURCE LINES 140-144 .. code-block:: Python data = mm.events t = data["times"] .. GENERATED FROM PYTHON SOURCE LINES 145-147 The following function turns a name such as ``I_NaP`` into proper TeX code :math:`I_{\mathrm{NaP}}` for a pretty label. .. GENERATED FROM PYTHON SOURCE LINES 147-153 .. code-block:: Python def texify_name(name): return r"${}_{{\mathrm{{{}}}}}$".format(*name.split("_")) .. GENERATED FROM PYTHON SOURCE LINES 154-157 The next step is to plot the results. We create a new figure, and add one subplot each for membrane and threshold potential, synaptic conductances, and intrinsic currents. .. GENERATED FROM PYTHON SOURCE LINES 157-192 .. code-block:: Python fig = plt.figure() Vax = fig.add_subplot(311) Vax.plot(t, data["V_m"], "b", lw=2, label=r"$V_m$") Vax.plot(t, data["theta"], "g", lw=2, label=r"$\Theta$") Vax.set_ylabel("Potential [mV]") try: Vax.legend(fontsize="small") except TypeError: Vax.legend() # work-around for older Matplotlib versions Vax.set_title("ht_neuron driven by Poisson processes") Gax = fig.add_subplot(312) for gname in ("g_AMPA", "g_NMDA", "g_GABA_A", "g_GABA_B"): Gax.plot(t, data[gname], lw=2, label=texify_name(gname)) try: Gax.legend(fontsize="small") except TypeError: Gax.legend() # work-around for older Matplotlib versions Gax.set_ylabel("Conductance [nS]") Iax = fig.add_subplot(313) for iname, color in (("I_h", "maroon"), ("I_T", "orange"), ("I_NaP", "crimson"), ("I_KNa", "aqua")): Iax.plot(t, data[iname], color=color, lw=2, label=texify_name(iname)) try: Iax.legend(fontsize="small") except TypeError: Iax.legend() # work-around for older Matplotlib versions Iax.set_ylabel("Current [pA]") Iax.set_xlabel("Time [ms]") .. _sphx_glr_download_auto_examples_intrinsic_currents_spiking.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: intrinsic_currents_spiking.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: intrinsic_currents_spiking.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_