utils

Various handy visualization utilities.

All images are expected to have values from 0 to 1.

utils.animate_frames(color_frames: numpy.ndarray, velocity_frames: Optional[numpy.ndarray] = None, interval: int = 30) → matplotlib.animation.FuncAnimation

Draw a stack of frames into a matplotlib animation.

Parameters
  • color – A stack of color field frames. Shape: [timesteps, y, x, 3].

  • velocity – A stack of velocity field frames. If provided, draws a quiver plot on each frame. Shape: [timesteps, y, x, 2].

  • interval – Milliseconds between consecutive frames of the animation.

utils.draw_frame(color: numpy.ndarray, velocity: Optional[numpy.ndarray] = None, axes=None)

Draw a single frame of simulation.

Parameters
  • color – A color field. Shape: [y, x, 3].

  • velocity – A velocity field. If provided, draws and returns a quiver plot; otherwise, just draws and returns an image. Shape: [y, x, 2].

  • axes – If provided, uses these pyplot axes to draw the plots. Otherwise, create a new figure.

utils.write_video(filepath: str, images: numpy.ndarray, **kwargs) → None

Write a stack of color frames into a video.

Parameters
  • filepath – The filepath to save the video to.

  • images – A stack of color frames. Shape: [timesteps, y, x, 3].

  • kwargs – See deltaflow.utils._VideoWriter for all optional arguments.