fluidsim_core.output.movies

Movies output

Contains base classes which acts as a framework to implement the method animate to make movies.

Provides:

class fluidsim_core.output.movies.MoviesBase(output)[source]

Bases: object

Base class defining most generic functions for movies.

_set_font(family='serif', size=12)[source]

Use to set font attribute. May be either an alias (generic name is CSS parlance), such as serif, sans-serif, cursive, fantasy, or monospace, a real font name or a list of real font names.

init_animation(key_field, numfig, dt_equations, tmin, tmax, fig_kw, **kwargs)[source]

Initializes animated fig. and list of times of save files to load.

resume()[source]
pause(event=None)[source]
_forward(event=None)[source]
_backward(event=None)[source]
_one_forward(event=None)[source]
_one_backward(event=None)[source]
_get_default_tmax()[source]
_init_ani_times(tmin, tmax, dt_equations)[source]

Initialization of the variable ani_times for one animation.

abstract update_animation(frame, **fargs)[source]

Replace this function to load data for next frame and update the figure.

get_field_to_plot(time=None, key=None, equation=None)[source]

Once a saved file is loaded, this selects the field and mpi-gathers.

Returns:
fieldnd array or string
_init_labels(xlabel=None, ylabel=None)[source]

Initialize the labels.

_get_axis_data()[source]

Replace this function to load axis data.

_set_key_field(key_field=None)[source]

Defines key_field default.

animate(key_field=None, dt_frame_in_sec=0.3, dt_equations=None, tmin=None, tmax=None, repeat=True, save_file=False, numfig=None, interactive=None, fargs={}, fig_kw={}, **kwargs)[source]

Load the key field from multiple save files and display as an animated plot or save as a movie file.

Parameters:
key_fieldstr

Specifies which field to animate

dt_frame_in_secfloat

Interval between animated frames in seconds

dt_equationsfloat

Approx. interval between saved files to load in simulation time units

tmaxfloat

Animate till time tmax.

repeatbool

Loop the animation

save_filestr or bool

Path to save the movie. When True saves into a file instead of plotting it on screen (default: ~/fluidsim_movie.mp4). Specify a string to save to another file location. Format is autodetected from the filename extension.

numfigint

Figure number on the window

interactivebool

Add player buttons (pause, step by step and forward/backward)

fargsdict

Dictionary of arguments for update_animation. Matplotlib requirement.

fig_kwdict

Dictionary for arguments for the figure.

Other Parameters:
All `kwargs` are passed on to `init_animation` and `_ani_save`
xmaxfloat

Set x-axis limit for 1D animated plots

ymaxfloat

Set y-axis limit for 1D animated plots

climtuple

Set colorbar limits for 2D animated plots

stepint

Set step value to get a coarse 2D field

QUIVERbool

Set quiver on or off on top of 2D pcolor plots

normalize_vectorsbool (default True)

Normalize the vectors at each time by the instantaneous maximum

quiver_kw: dict

Dictionary for arguments for the quiver call.

pcolor_kw: dict

Dictionary for arguments for the pcolormesh call.

codecstr

Codec used to save into a movie file (default: ffmpeg)

Notes

This method is kept as generic as possible. Any arguments specific to 1D, 2D or 3D animations or specific to a type of output are be passed via keyword arguments (kwargs) into its respective init_animation or update_animation methods.

Examples

>>> import fluidsim as fls
>>> sim = fls.load_sim_for_plot()
>>> animate = sim.output.spectra.animate
>>> animate('E')
>>> animate('rot')
>>> animate('rot', dt_equations=0.1, dt_frame_in_sec=50, clim=(-5, 5))
>>> animate('rot', clim=(-300, 300), fig_kw={"figsize": (14, 4)})
>>> animate('rot', tmax=25, clim=(-5, 5), save_file='True')
>>> animate('rot', clim=(-5, 5), save_file='~/fluidsim.gif', codec='imagemagick')
_frames_iterative()[source]
onestep()[source]
_toggle_pause(event)[source]
interact(key_field=None, dt_equations=None, tmin=None, tmax=None, fig_kw={}, **kwargs)[source]

Launches an interactive plot.

Parameters:
key_fieldstr

Specifies which field to animate

dt_equationsfloat

Approx. interval between saved files to load in simulation time units

tmaxfloat

Animate till time tmax.

fig_kwdict

Dictionary for arguments for the figure.

Other Parameters:
All `kwargs` are passed on to `init_animation` and `_ani_save`
xmaxfloat

Set x-axis limit for 1D animated plots

ymaxfloat

Set y-axis limit for 1D animated plots

climtuple

Set colorbar limits for 2D animated plots

stepint

Set step value to get a coarse 2D field

QUIVERbool

Set quiver on or off on top of 2D pcolor plots

quiver_kw: dict

Dictionary for arguments for the quiver call.

Notes

Installation instructions for notebook:

pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension

Restart the notebook and call the function using:

>>> %matplotlib notebook

For JupyterLab:

pip install ipywidgets ipympl
jupyter labextension install @jupyter-widgets/jupyterlab-manager

Restart JupyterLab and call the function using:

>>> %matplotlib widget
_ani_save(path_file, dt_frame_in_sec, codec='ffmpeg', **kwargs)[source]

Saves the animation using matplotlib.animation.writers.

class fluidsim_core.output.movies.MoviesBase1D(output)[source]

Bases: MoviesBase

Base class defining most generic functions for movies for 1D data.

_init_labels(xlabel=None, ylabel=None)[source]

Initialize the labels.

init_animation(key_field, numfig, dt_equations, tmin, tmax, fig_kw, **kwargs)[source]

Initializes animated figure.

get_field_to_plot(time, key)[source]

Once a saved file is loaded, this selects the field and mpi-gathers.

Returns:
fieldnd array or string
update_animation(frame, **fargs)[source]

Loads contour data and updates figure.

_get_axis_data()[source]

Get axis data.

Returns:
xarray

x-axis data.

class fluidsim_core.output.movies.MoviesBase2D(output)[source]

Bases: MoviesBase

Base class defining most generic functions for movies for 2D data.

_get_axis_data()[source]

Get axis data.

Returns:
xarray

x-axis data.

yarray

y-axis data.

class fluidsim_core.output.movies.MoviesBasePhysFields(output, phys_fields)[source]

Bases: MoviesBase2D

init_animation(key_field, numfig, dt_equations, tmin, tmax, fig_kw, **kwargs)[source]

Initialize list of files and times, pcolor plot, quiver and colorbar.

_init_fig(field, time, vec_xaxis=None, vec_yaxis=None, **kwargs)[source]

Initialize only the figure and related matplotlib objects. This method is shared by both animate and online_plot functionalities.

update_animation(frame, **fargs)[source]

Loads data and updates figure.

_set_clim()[source]

Maintains a constant colorbar throughout the animation.

class fluidsim_core.output.movies.MoviesBasePhysFieldsHexa(output, phys_fields)[source]

Bases: MoviesBasePhysFields

_init_fig(field, time, vec_xaxis=None, vec_yaxis=None, **kwargs)[source]

Initialize only the figure and related matplotlib objects. This method is shared by both animate and online_plot functionalities.

update_animation(frame, **fargs)[source]

Loads data and updates figure.

_set_clim()[source]

Maintains a constant colorbar throughout the animation.

_init_labels(xlabel=None, ylabel=None)[source]

Initialize the labels.

Classes

MoviesBase(output)

Base class defining most generic functions for movies.

MoviesBase1D(output)

Base class defining most generic functions for movies for 1D data.

MoviesBase2D(output)

Base class defining most generic functions for movies for 2D data.

MoviesBasePhysFields(output, phys_fields)

MoviesBasePhysFieldsHexa(output, phys_fields)