Skip to content

Commit

Permalink
polish video tutorial, exit if no ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohnsen committed Sep 18, 2024
1 parent 2852b72 commit 646eaa6
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions docs/tutorials/video_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."
]
},
{
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 646eaa6

Please sign in to comment.