4.8.1. pde.visualization.movies module

Functions for creating movies of simulation results

Movie

Class for creating movies from matplotlib figures using ffmpeg

movie_scalar

produce a movie for a simulation of a scalar field

movie_multiple

produce a movie for a simulation with n components

movie

produce a movie by simply plotting each frame

class Movie(filename: str, framerate: float = 30, dpi: float = None, **kwargs)[source]

Bases: object

Class for creating movies from matplotlib figures using ffmpeg

Note

Internally, this class uses matplotlib.animation.FFMpegWriter. Note that the ffmpeg program needs to be installed in a system path, so that matplotlib can find it.

Warning

The movie is only fully written after the save() method has been called. To aid with this, it is best practice to use a contextmanager:

with Movie("output.mp4") as movie:
    movie.add_figure()
Parameters
  • filename (str) – The filename where the movie is stored. The suffix of this path also determines the default movie codec.

  • framerate (float) – The number of frames per second, which determines how fast the movie will appear to run.

  • dpi (float) – The resolution of the resulting movie

  • **kwargs – Additional parameters are used to initialize matplotlib.animation.FFMpegWriter. Here, we can for instance set the bit rate of the resulting video using the bitrate parameter.

add_figure(fig=None)[source]

adds the figure fig as a frame to the current movie

Parameters

fig (Figure) – The plot figure that is added to the movie

classmethod is_available() bool[source]

check whether the movie infrastructure is available

Returns

True if movies can be created

Return type

bool

save()[source]

convert the recorded images to a movie using ffmpeg

movie(storage: StorageBase, filename: str, *, progress: bool = True, dpi: float = 150, show_time: bool = True, plot_args: dict = None, movie_args: dict = None) None[source]

produce a movie by simply plotting each frame

Parameters
  • storage (StorageBase) – The storage instance that contains all the data for the movie

  • filename (str) – The filename to which the movie is written. The extension determines the format used.

  • progress (bool) – Flag determining whether the progress of making the movie is shown.

  • dpi (float) – Resolution of the movie

  • show_time (bool) – Whether to show the simulation time in the movie

  • plot_args (dict) – Additional arguments for the function plotting the state

  • movie_args (dict) – Additional arguments for Movie. For example, this can be used to set the resolution (dpi), the framerate (framerate), and the bitrate (bitrate).

movie_multiple(storage: StorageBase, filename: str, quantities=None, scale: Union[str, float, Tuple[float, float]] = 'automatic', progress: bool = True) None[source]

produce a movie for a simulation with n components

Parameters
  • storage (StorageBase) – The storage instance that contains all the data for the movie

  • filename (str) – The filename to which the movie is written. The extension determines the format used.

  • quantities – A 2d list of quantities that are shown in a rectangular arrangement. If quantities is a simple list, the panels will be rendered as a single row. Each panel is defined by a dictionary, where the mandatory item ‘source’ defines what is being shown. Here, an integer specifies the component that is extracted from the field while a function is evaluate with the full state as an input and the result is shown. Additional items in the dictionary can be ‘title’ (setting the title of the panel), ‘scale’ (defining the color range shown; these are typically two numbers defining the lower and upper bound, but if only one is given the range [0, scale] is assumed), and ‘cmap’ (defining the colormap being used).

  • scale (str, float, tuple of float) – Flag determining how the range of the color scale is determined. In the simplest case a tuple of numbers marks the lower and upper end of the scalar values that will be shown. If only a single number is supplied, the range starts at zero and ends at the given number. Additionally, the special value ‘automatic’ determines the range from the range of scalar values.

  • progress (bool) – Flag determining whether the progress of making the movie is shown.

movie_scalar(storage: StorageBase, filename: str, scale: Union[str, float, Tuple[float, float]] = 'automatic', extras: dict = None, progress: bool = True, tight: bool = False, show: bool = True) None[source]

produce a movie for a simulation of a scalar field

Parameters
  • storage (StorageBase) – The storage instance that contains all the data for the movie

  • filename (str) – The filename to which the movie is written. The extension determines the format used.

  • scale (str, float, tuple of float) – Flag determining how the range of the color scale is determined. In the simplest case a tuple of numbers marks the lower and upper end of the scalar values that will be shown. If only a single number is supplied, the range starts at zero and ends at the given number. Additionally, the special value ‘automatic’ determines the range from the range of scalar values.

  • extras (dict, optional) – Additional functions that are evaluated and shown for each time step. The key of the dictionary is used as a panel title.

  • progress (bool) – Flag determining whether the progress of making the movie is shown.

  • tight (bool) – Whether to call matplotlib.pyplot.tight_layout(). This affects the layout of all plot elements.

  • show (bool) – Flag determining whether images are shown during making the movie