.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/recording_demo.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_recording_demo.py: Recording examples ------------------ .. 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%2Frecording_demo.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 how to select different recording backends and read the result data back in. The simulated network itself is rather boring with only a single poisson generator stimulating a single neuron, so we get some data. .. GENERATED FROM PYTHON SOURCE LINES 32-74 .. code-block:: Python import nest import numpy as np def setup(record_to, time_in_steps): """Set up the network with the given parameters.""" nest.ResetKernel() nest.overwrite_files = True pg_params = {"rate": 1000000.0} sr_params = {"record_to": record_to, "time_in_steps": time_in_steps} n = nest.Create("iaf_psc_exp") pg = nest.Create("poisson_generator", 1, pg_params) sr = nest.Create("spike_recorder", 1, sr_params) nest.Connect(pg, n, syn_spec={"weight": 10.0}) nest.Connect(n, sr) return sr def get_data(sr): """Get recorded data from the spike_recorder.""" if sr.record_to == "ascii": return np.loadtxt(f"{sr.filenames[0]}", dtype=object) if sr.record_to == "memory": return sr.get("events") # Just loop through some recording backends and settings for time_in_steps in (True, False): for record_to in ("ascii", "memory"): sr = setup(record_to, time_in_steps) nest.Simulate(30.0) data = get_data(sr) print(f"simulation resolution in ms: {nest.resolution}") print(f"data recorded by recording backend {record_to} (time_in_steps={time_in_steps})") print(data) .. _sphx_glr_download_auto_examples_recording_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: recording_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: recording_demo.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_