fluidsim.base.output.movies

Movies output (fluidsim.base.output.movies)

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

Provides:

class fluidsim.base.output.movies.MoviesBase(output)[source]

Bases: object

Base class defining most generic functions for movies.

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

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

_init_ani_times(self, tmin, tmax, dt_equations)[source]

Initialization of the variable ani_times for one animation.

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

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

_set_font(self, 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.

get_field_to_plot(self, 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(self, xlabel=None, ylabel=None)[source]

Initialize the labels.

_get_axis_data(self)[source]

Replace this function to load axis data.

_set_key_field(self, key_field)[source]

Defines key_field default.

animate(self, key_field=None, dt_frame_in_sec=0.3, dt_equations=None, tmin=None, tmax=None, repeat=True, save_file=False, numfig=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

fargsdict

Dictionary of arguments for update_animation. Matplotlib requirement.

fig_kwdict

Dictionary of arguments 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

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', tmax=25, clim=(-5,5), save_file='True')
>>> animate('rot', clim=(-5,5), save_file='~/fluidsim.gif', codec='imagemagick')
interact(self, key_field=None, dt_frame_in_sec=0.3, dt_equations=None, tmin=None, tmax=None, fig_kw={}, **kwargs)[source]

Launches an interactive plot.

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.

fig_kwdict

Dictionary of arguments 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

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(self, path_file, dt_frame_in_sec, codec='ffmpeg', **kwargs)[source]

Saves the animation using matplotlib.animation.writers.

class fluidsim.base.output.movies.MoviesBase1D(output)[source]

Bases: fluidsim.base.output.movies.MoviesBase

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

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

Initializes animated figure.

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

Loads contour data and updates figure.

_get_axis_data(self)[source]

Get axis data.

Returns
xarray

x-axis data.

class fluidsim.base.output.movies.MoviesBase2D(output)[source]

Bases: fluidsim.base.output.movies.MoviesBase

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

_get_axis_data(self)[source]

Get axis data.

Returns
xarray

x-axis data.

yarray

y-axis data.

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.