landlab.plot.video_out¶
Create mp4 animation of Landlab output.
This component allows creation of mp4 animations of output from Landlab. It does so by stitching together output from the conventional Landlab static plotting routines from plot/imshow.py.
It is compatible with all Landlab grids, though cannot handle an evolving grid as yet.
Initialize the video object vid at the start of your code, then simply call vid.add_frame(grid, data) each time you want to add a frame. At the end of the model run, call vid.produce_video().
CAUTION: This component may prove very memory-intensive. It is recommended that the total number of frames included in the output multiplied by the number of pixels (nodes) in the image not exceed XXXXXXXXX.
Due to some issues with codecs in matplotlib, at the moment on .gif output movies are recommended. If this irritates you, you can modify your own PYTHONPATH to allow .mp4 compilation (try a google search for the warning raised by this method for some hints). These (known) issues are apparently likely to resolve themselves in a future release of matplotlib.
- class VideoPlotter[source]¶
Bases:
object
Create animations of landlab output.
Create Landlab movies.
- Parameters:
grid (RasterModelGrid) – A RasterModelGrid.
data_centering ({'node', 'cell'}, optional) – Where data are centered.
start (float, optional) – Model time at which filming starts.
stop (float, optional) – Model time at which filming stops.
step (float, optional) – Model time frequency at which frames are made.
Create Landlab movies.
- Parameters:
grid (RasterModelGrid) – A RasterModelGrid.
data_centering ({'node', 'cell'}, optional) – Where data are centered.
start (float, optional) – Model time at which filming starts.
stop (float, optional) – Model time at which filming stops.
step (float, optional) – Model time frequency at which frames are made.
- __init__(grid, data_centering='node', start=None, stop=None, step=None)[source]¶
Create Landlab movies.
- Parameters:
grid (RasterModelGrid) – A RasterModelGrid.
data_centering ({'node', 'cell'}, optional) – Where data are centered.
start (float, optional) – Model time at which filming starts.
stop (float, optional) – Model time at which filming stops.
step (float, optional) – Model time frequency at which frames are made.
- __new__(**kwargs)¶
- add_frame(grid, data, elapsed_t, **kwds)[source]¶
Add a frame to the video.
data can be either the data to plot (nnodes, or appropriately lengthed numpy array), or a string for grid field access.
kwds can be any of the usual plotting keywords, e.g., cmap.
- clear_module()[source]¶
Clear internally held data.
Wipe all internally held data that would cause trouble if module were to be rerun without being reinstantiated.
- initialize(grid, data_centering, start, stop, step)[source]¶
Set up the plotter.
A copy of the grid is required.
data_centering controls the type of data the video will be plotting.
It can be set to: “node” (default) or “cell”.
start, stop, and step control when a frame is added. They are absolute times in the model run. All are optional.
- Parameters:
grid (RasterModelGrid) – A RasterModelGrid.
data_centering ({'node', 'cell'}, optional) – Where data are centered.
start (float) – Model time at which filming starts.
stop (float) – Model time at which filming stops.
step (float) – Model time frequency at which frames are made.
- produce_video(interval=200, repeat_delay=2000, filename='video_output.gif', override_min_max=None)[source]¶
Finalize and save the video of the data.
- Parameters:
interval (int, optional) – Interval between frames in milliseconds.
repeat_delay (int, optional) – Repeat delay before restart in milliseconds.
filename (str, optional) – Name of the file to save in the present working directory. At present, only .gifs will implement reliably without tweaking Python’s PATHs.
override_min_max (tuple of float) – Minimum and maximum for the scale on the plot as (min, max).