From 646eaa64a91566885c01a380bf43a2258daddfe8 Mon Sep 17 00:00:00 2001 From: Kyle Johnsen Date: Wed, 18 Sep 2024 12:52:58 -0400 Subject: [PATCH] polish video tutorial, exit if no ffmpeg --- docs/tutorials/video_visualization.ipynb | 33 ++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/tutorials/video_visualization.ipynb b/docs/tutorials/video_visualization.ipynb index aa9de0e..9fc4a21 100644 --- a/docs/tutorials/video_visualization.ipynb +++ b/docs/tutorials/video_visualization.ipynb @@ -260,7 +260,7 @@ "source": [ "## Inject VideoVisualizer\n", "\n", - "A `VideoVisualizer` is an `InterfaceDevice` like recorders and stimulators and needs to be injected in order to properly interact with the Brian network.\n", + "A {class}`~cleo.viz.VideoVisualizer` is an {class}`~cleo.InterfaceDevice` like recorders and stimulators and needs to be injected in order to properly interact with the Brian network.\n", "Keep in mind the following:\n", "\n", "- It must be injected *after* all other devices for the `devices='all'` argument to work as expected. \n", @@ -377,9 +377,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The `VideoVisualizer` stores the data it needs during the simulation, but hasn't yet produced any visual output. We first use the `generate_Animation()`, plugging in the arguments we used for the original plot.\n", + "The {class}`~cleo.viz.VideoVisualizer` stores the data it needs during the simulation, but hasn't yet produced any visual output.\n", + "We first use the {meth}`~cleo.viz.VideoVisualizer.generate_Animation` method, plugging in the arguments we used for the original plot.\n", "\n", - "Also, we set the `max_Irr0_mW_per_mm2_viz` attribute of the optogenetic intervention. This effectively scales how bright the light appears in the visualization. That is, a high maximum irradiance makes the stimulus values small in comparison and produces a faint light, while a low ceiling makes the values relatively large and produces a bright light in the resulting video." + "Also, we set the {attr}`~cleo.light.Light.max_value_viz` attribute of the light.\n", + "This effectively scales how bright the light appears in the visualization.\n", + "That is, a high maximum irradiance makes the stimulus values small in comparison and produces a faint light, while a low ceiling makes the values relatively large and produces a bright light in the resulting video." ] }, { @@ -407,13 +410,33 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The `generate_Animation()` function returns a matplotlib [`FuncAnimation` object](https://matplotlib.org/stable/api/_as_gen/matplotlib.animation.FuncAnimation.html), which you can then use however you want. You will probably want to [save a video](https://matplotlib.org/stable/api/_as_gen/matplotlib.animation.Animation.html#matplotlib.animation.Animation.save).\n", + "{meth}`~cleo.viz.VideoVisualizer.generate_Animation` returns a matplotlib [`FuncAnimation` object](https://matplotlib.org/stable/api/_as_gen/matplotlib.animation.FuncAnimation.html), which you can then use however you want. \n", + "You will probably want to [save a video](https://matplotlib.org/stable/api/_as_gen/matplotlib.animation.Animation.html#matplotlib.animation.Animation.save).\n", "\n", - "Note that at this point the video still hasn't been rendered; that happens when you try and save or visualize the animation. This step takes a while if your temporal resolution is high, so we suggest you do this only after your experiment is finalized and after you've experimented with low framerate videos to finalize video parameters.\n", + "Note that at this point the video still hasn't been rendered; that happens when you try and save or visualize the animation.\n", + "This step takes a while if your temporal resolution is high, so we suggest you do this only after your experiment is finalized and after you've experimented with low framerate videos to finalize video parameters.\n", "\n", "Here we embed the video using HTML so you can see the output:" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [ + "remove-cell" + ] + }, + "outputs": [], + "source": [ + "import sys\n", + "from matplotlib.animation import writers\n", + "\n", + "if \"ffmpeg\" not in writers.list():\n", + " print(\"ffmpeg is not available in MovieWriterRegistry. Exiting script.\")\n", + " sys.exit(0)" + ] + }, { "cell_type": "code", "execution_count": null,