.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/repeated_stimulation.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_repeated_stimulation.py: Repeated Stimulation -------------------- .. 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%2Frepeated_stimulation.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 for how to repeat a stimulation protocol using the ``origin`` property of devices. In this example, a ``poisson_generator`` generates a spike train that is recorded directly by a ``spike_recorder``, using the following paradigm: 1. A single trial last for 1000 ms. 2. Within each trial, the ``poisson_generator`` is active from 100 ms to 500 ms. We achieve this by defining the `start` and `stop` properties of the generator to 100 ms and 500 ms, respectively, and setting the ``origin`` to the simulation time at the beginning of each trial. Start and stop are interpreted relative to the ``origin``. .. GENERATED FROM PYTHON SOURCE LINES 44-45 First, the modules needed for simulation and analysis are imported. .. GENERATED FROM PYTHON SOURCE LINES 45-51 .. code-block:: Python import matplotlib.pyplot as plt import nest import nest.raster_plot .. GENERATED FROM PYTHON SOURCE LINES 52-54 Second, we set the parameters so the ``poisson_generator`` generates 1000 spikes per second and is active from 100 to 500 ms .. GENERATED FROM PYTHON SOURCE LINES 54-61 .. code-block:: Python rate = 1000.0 # generator rate in spikes/s start = 100.0 # start of simulation relative to trial start, in ms stop = 500.0 # end of simulation relative to trial start, in ms .. GENERATED FROM PYTHON SOURCE LINES 62-63 The simulation is supposed to take 1s (1000 ms) and is repeated 5 times .. GENERATED FROM PYTHON SOURCE LINES 63-69 .. code-block:: Python trial_duration = 1000.0 # trial duration, in ms num_trials = 5 # number of trials to perform .. GENERATED FROM PYTHON SOURCE LINES 70-75 Third, the network is set up. We reset the kernel and create a ``poisson_generator``, in which the handle is stored in `pg`. The parameters for rate and start and stop of activity are given as optional parameters in the form of a dictionary. .. GENERATED FROM PYTHON SOURCE LINES 75-82 .. code-block:: Python nest.ResetKernel() pg_params = {"rate": rate, "start": start, "stop": stop} pg = nest.Create("poisson_generator", params=pg_params) .. GENERATED FROM PYTHON SOURCE LINES 83-84 The ``spike_recorder`` is created and the handle stored in `sr`. .. GENERATED FROM PYTHON SOURCE LINES 84-89 .. code-block:: Python sr = nest.Create("spike_recorder") .. GENERATED FROM PYTHON SOURCE LINES 90-92 The ``Connect`` function connects the nodes so spikes from pg are collected by the ``spike_recorder`` `sr` .. GENERATED FROM PYTHON SOURCE LINES 92-97 .. code-block:: Python nest.Connect(pg, sr) .. GENERATED FROM PYTHON SOURCE LINES 98-102 Before each trial, we set the ``origin`` of the ``poisson_generator`` to the current simulation time. This automatically sets the start and stop time of the ``poisson_generator`` to the specified times with respect to the origin. The simulation is then carried out for the specified time in trial_duration. .. GENERATED FROM PYTHON SOURCE LINES 102-109 .. code-block:: Python for n in range(num_trials): pg.origin = nest.biological_time nest.Simulate(trial_duration) .. GENERATED FROM PYTHON SOURCE LINES 110-114 Now we plot the result, including a histogram using the ``nest.raster_plot`` function. Note: The histogram will show spikes seemingly located before 100 ms into each trial. This is due to sub-optimal automatic placement of histogram bin borders. .. GENERATED FROM PYTHON SOURCE LINES 114-117 .. code-block:: Python nest.raster_plot.from_device(sr, hist=True, hist_binwidth=100.0, title="Repeated stimulation by Poisson generator") plt.show() .. _sphx_glr_download_auto_examples_repeated_stimulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: repeated_stimulation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: repeated_stimulation.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_