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, framerate=30, dpi=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. The default value is controlled by matplotlib and is usally set to 100.

  • **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()[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, filename, *, progress=True, show_time=True, plot_args=None, movie_args=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.

  • 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).

Return type:

None

movie_multiple(storage, filename, quantities=None, scale='automatic', progress=True)[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.

Return type:

None

movie_scalar(storage, filename, scale='automatic', extras=None, progress=True, tight=False, show=True)[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

Return type:

None