.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/sinusoidal_poisson_generator.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_sinusoidal_poisson_generator.py: Sinusoidal poisson generator 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%2Fsinusoidal_poisson_generator.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 script demonstrates the use of the ``sinusoidal_poisson_generator`` and its different parameters and modes. The source code of the model can be found in ``models/sinusoidal_poisson_generator.h``. The script is structured into two parts and creates one common figure. In Part 1, two instances of the ``sinusoidal_poisson_generator`` are created with different parameters. Part 2 illustrates the effect of the ``individual_spike_trains`` switch. .. GENERATED FROM PYTHON SOURCE LINES 40-41 We import the modules required to simulate, analyze and plot this example. .. GENERATED FROM PYTHON SOURCE LINES 41-50 .. code-block:: Python import matplotlib.pyplot as plt import nest import numpy as np nest.ResetKernel() # in case we run the script multiple times from iPython .. GENERATED FROM PYTHON SOURCE LINES 51-55 We create two instances of the ``sinusoidal_poisson_generator`` with two different parameter sets using ``Create``. Moreover, we create devices to record firing rates (``multimeter``) and spikes (``spike_recorder``) and connect them to the generators using ``Connect``. .. GENERATED FROM PYTHON SOURCE LINES 55-75 .. code-block:: Python nest.resolution = 0.01 num_nodes = 2 g = nest.Create( "sinusoidal_poisson_generator", n=num_nodes, params={"rate": [10000.0, 0.0], "amplitude": [5000.0, 10000.0], "frequency": [10.0, 5.0], "phase": [0.0, 90.0]}, ) m = nest.Create("multimeter", num_nodes, {"interval": 0.1, "record_from": ["rate"]}) s = nest.Create("spike_recorder", num_nodes) nest.Connect(m, g, "one_to_one") nest.Connect(g, s, "one_to_one") print(m.get()) nest.Simulate(200) .. GENERATED FROM PYTHON SOURCE LINES 76-78 After simulating, the spikes are extracted from the ``spike_recorder`` and plots are created with panels for the PST and ISI histograms. .. GENERATED FROM PYTHON SOURCE LINES 78-100 .. code-block:: Python colors = ["b", "g"] for j in range(num_nodes): ev = m[j].events t = ev["times"] r = ev["rate"] spike_times = s[j].events["times"] plt.subplot(221) h, e = np.histogram(spike_times, bins=np.arange(0.0, 201.0, 5.0)) plt.plot(t, r, color=colors[j]) plt.step(e[:-1], h * 1000 / 5.0, color=colors[j], where="post") plt.title("PST histogram and firing rates") plt.ylabel("Spikes per second") plt.subplot(223) plt.hist(np.diff(spike_times), bins=np.arange(0.0, 1.005, 0.02), histtype="step", color=colors[j]) plt.title("ISI histogram") .. GENERATED FROM PYTHON SOURCE LINES 101-102 The kernel is reset and the number of threads set to 4. .. GENERATED FROM PYTHON SOURCE LINES 102-108 .. code-block:: Python nest.ResetKernel() nest.local_num_threads = 4 .. GENERATED FROM PYTHON SOURCE LINES 109-113 A ``sinusoidal_poisson_generator`` with ``individual_spike_trains`` set to `True` is created and connected to 20 parrot neurons whose spikes are recorded by a ``spike_recorder``. After simulating, a raster plot of the spikes is created. .. GENERATED FROM PYTHON SOURCE LINES 113-134 .. code-block:: Python g = nest.Create( "sinusoidal_poisson_generator", params={"rate": 100.0, "amplitude": 50.0, "frequency": 10.0, "phase": 0.0, "individual_spike_trains": True}, ) p = nest.Create("parrot_neuron", 20) s = nest.Create("spike_recorder") nest.Connect(g, p, "all_to_all") nest.Connect(p, s, "all_to_all") nest.Simulate(200) ev = s.events plt.subplot(222) plt.plot(ev["times"], ev["senders"] - min(ev["senders"]), "o") plt.ylim([-0.5, 19.5]) plt.yticks([]) plt.title("Individual spike trains for each target") .. GENERATED FROM PYTHON SOURCE LINES 135-139 The kernel is reset again and the whole procedure is repeated for a ``sinusoidal_poisson_generator`` with `individual_spike_trains` set to `False`. The plot shows that in this case, all neurons receive the same spike train from the ``sinusoidal_poisson_generator``. .. GENERATED FROM PYTHON SOURCE LINES 139-162 .. code-block:: Python nest.ResetKernel() nest.local_num_threads = 4 g = nest.Create( "sinusoidal_poisson_generator", params={"rate": 100.0, "amplitude": 50.0, "frequency": 10.0, "phase": 0.0, "individual_spike_trains": False}, ) p = nest.Create("parrot_neuron", 20) s = nest.Create("spike_recorder") nest.Connect(g, p, "all_to_all") nest.Connect(p, s, "all_to_all") nest.Simulate(200) ev = s.events plt.subplot(224) plt.plot(ev["times"], ev["senders"] - min(ev["senders"]), "o") plt.ylim([-0.5, 19.5]) plt.yticks([]) plt.title("One spike train for all targets") plt.show() .. _sphx_glr_download_auto_examples_sinusoidal_poisson_generator.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sinusoidal_poisson_generator.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sinusoidal_poisson_generator.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_