.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto/plot_hnn_animation.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_howto_plot_hnn_animation.py: ================================ 06. Animating HNN simulations ================================ This example demonstrates how to animate HNN simulations .. GENERATED FROM PYTHON SOURCE LINES 8-12 .. code-block:: Python # Author: Nick Tolley .. GENERATED FROM PYTHON SOURCE LINES 13-15 First, we'll import the necessary modules for instantiating a network and running a simulation that we would like to animate. .. GENERATED FROM PYTHON SOURCE LINES 15-21 .. code-block:: Python import os.path as op import hnn_core from hnn_core import jones_2009_model, simulate_dipole, read_params from hnn_core.network_models import add_erp_drives_to_jones_model .. GENERATED FROM PYTHON SOURCE LINES 22-24 We begin by instantiating the network. For this example, we will reduce the number of cells in the network to speed up the simulations. .. GENERATED FROM PYTHON SOURCE LINES 24-30 .. code-block:: Python net = jones_2009_model(mesh_shape=(3, 3)) # Note that we move the cells further apart to allow better visualization of # the network (default inplane_distance=1.0 µm). net.set_cell_positions(inplane_distance=300) .. GENERATED FROM PYTHON SOURCE LINES 31-33 The :class:`hnn_core.viz.NetworkPlotter` class can be used to visualize the 3D structure of the network. .. GENERATED FROM PYTHON SOURCE LINES 33-38 .. code-block:: Python from hnn_core.viz import NetworkPlotter net_plot = NetworkPlotter(net) net_plot.fig .. image-sg:: /auto_examples/howto/images/sphx_glr_plot_hnn_animation_001.png :alt: plot hnn animation :srcset: /auto_examples/howto/images/sphx_glr_plot_hnn_animation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 39-41 We can also visualize the network from another angle by adjusting the azimuth and elevation parameters. .. GENERATED FROM PYTHON SOURCE LINES 41-45 .. code-block:: Python net_plot.azim = 45 net_plot.elev = 40 net_plot.fig .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 46-53 Next we add event related potential (ERP) producing drives to the network and run the simulation (see :ref:`evoked example ` for more details). To visualize the membrane potential of cells in the network, we need use `simulate_dipole(..., record_vsec='all')` which turns on the recording of voltages in all sections of all cells in the network. .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: Python add_erp_drives_to_jones_model(net) dpl = simulate_dipole(net, tstop=170, record_vsec='all') net_plot = NetworkPlotter(net) # Reinitialize plotter with simulated network .. image-sg:: /auto_examples/howto/images/sphx_glr_plot_hnn_animation_002.png :alt: plot hnn animation :srcset: /auto_examples/howto/images/sphx_glr_plot_hnn_animation_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Joblib will run 1 trial(s) in parallel by distributing trials over 1 jobs. Building the NEURON model [Done] Trial 1: 0.03 ms... Trial 1: 10.0 ms... Trial 1: 20.0 ms... Trial 1: 30.0 ms... Trial 1: 40.0 ms... Trial 1: 50.0 ms... Trial 1: 60.0 ms... Trial 1: 70.0 ms... Trial 1: 80.0 ms... Trial 1: 90.0 ms... Trial 1: 100.0 ms... Trial 1: 110.0 ms... Trial 1: 120.0 ms... Trial 1: 130.0 ms... Trial 1: 140.0 ms... Trial 1: 150.0 ms... Trial 1: 160.0 ms... .. GENERATED FROM PYTHON SOURCE LINES 58-60 Finally, we can animate the simulation using the `export_movie()` method. We can adjust the xyz limits of the plot to better visualize the network. .. GENERATED FROM PYTHON SOURCE LINES 60-65 .. code-block:: Python net_plot.xlim = (400, 1600) net_plot.ylim = (400, 1600) net_plot.zlim = (-500, 1600) net_plot.azim = 225 net_plot.export_movie('animation_demo.gif', dpi=100, fps=30, interval=100) .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 39.034 seconds) .. _sphx_glr_download_auto_examples_howto_plot_hnn_animation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/jonescompneurolab/hnn-core/gh-pages?filepath=v0.4/notebooks/auto_examples/howto/plot_hnn_animation.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_hnn_animation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hnn_animation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_hnn_animation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_