amep.plot.create_video#

amep.plot.create_video(fig: Figure, update_frame_func: object, data: Iterable, output_filename: str, fps: int = 10, output_codec: str = 'h264', bitrate: int = -1, layout_engine: str = 'constrained') None#

Create a video from frames generated by a make_frame function.

Forwards the matlplotlib FuncAnimation for simpler use with AMEP. We strongly recommend to use animate_trajectory function instead of doing this here at low level. If you need a lower level animation use matplotlibs functions directly. This function is just meant for internal use.

Parameters:
  • fig (mpl.figure.Figure) – Figure object to update with the update_frame_func.

  • update_frame_func (Callable) – A function that generates frames for the video.

  • data (Iterable) – The data to be plotted at each frame.

  • fps (int, optional) – The frames per second of the video. The default is 10.

  • output_filename (str) – The filename of the output video file. The extension is used to determine the video format.

  • output_codec (str, optional) – The codec to use for the MP4 video. only applicable if output_format is “mp4”.

  • bitrate (int, optional) – The bitrate of the MP4 video. only applicable if output_format is “mp4”.

Return type:

None.

Examples

In this example, we first calculate the local packing fraction from a Voronoi tesselation for each frame and the then create a video of it.

>>> import amep
>>> traj = amep.load.traj("../examples/data/lammps.h5amep")
>>> ld = amep.evaluate.LDdist(
...     traj, nav=traj.nframes,
...     mode="packing", use_voronoi=True
... )
>>> fig, axs = amep.plot.new(layout="constrained")
>>> def update_frame(data):
...     axs.clear()
...     plot = axs.plot(data[1], data[0])
...     axs.set_xlabel(r'$\varphi$')
...     axs.set_ylabel(r'$p(\varphi)$')
...     axs.set_ylim(-0.05, 10)
...     axs.set_xlim(0, 1.2)
...     return [plot,]
>>> amep.plot.create_video(
...     fig, update_frame, ld.frames,
...     "./figures/plot/plot-create_video.gif", fps=5,
... )
>>>
../_images/plot-create_video.gif