E-Cell4 util.viz API

ecell4.util.viz: Visualizer of particles based on D3.js, THREE.js and Elegans.

ecell4.util.viz.generate_html(keywords, tmpl_path)

Generate static html file from JSON model and its own id.

Parameters:

model : dict

JSON model from which ecell4.viz generates a plot.

model_id : string

Unique id for the plot.

Returns:

html :

A HTML object

ecell4.util.viz.plot_dense_array(arr, length=256, ranges=None, colors=['#a6cee3', '#fb9a99'], grid=False, camera_position=(-22, 23, 32), camera_rotation=(-0.6, 0.5, 0.6))

Volume renderer

Parameters:

arr : list of numpy.array

i.e. [array([[1,2,3], [2,3,4]]), array([[1,2,3]])]

ranges : list of tuple

ranges for x, y, and z axis i.e. [(-100, 100), (-100, 100), (-100, 100)]

colors : list of string

colors for species

length : int

length of the texture 256 or 64

camera_position : tuple, default (-22, 23, 32)

camera_rotaiton : tuple, default (-0.6, 0.5, 0.6)

Initial position and rotation of camera.

ecell4.util.viz.plot_movie(*args, **kwargs)

Generate a movie from received instances of World and show them. See also plot_movie_with_elegans and plot_movie_with_matplotlib.

Parameters:

worlds : list of World

Worlds to render.

interactive : bool, default True

Choose a visualizer. If False, show the plot with matplotlib. If True (only available on IPython Notebook), show it with elegans.

ecell4.util.viz.plot_movie2d_with_matplotlib(worlds, plane='xy', marker_size=3, figsize=6, grid=True, wireframe=False, species_list=None, max_count=None, angle=None, noaxis=False, interval=0.16, repeat_delay=3000, stride=1, rotate=None, legend=True, scale=1, output=None, crf=10, bitrate='1M', **kwargs)

Generate a movie projected on the given plane from the received list of instances of World, and show it on IPython notebook. This function may require ffmpeg.

Parameters:

worlds : list or FixedIntervalHDF5Observer

A list of Worlds to render.

plane : str, default ‘xy’

‘xy’, ‘yz’, ‘zx’.

marker_size : float, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsize : float, default 6

Size of the plotting area. Given in inch.

species_list : array of string, default None

If set, plot_world will not search the list of species.

max_count : Integer, default None

The maximum number of particles to show for each species. None means no limitation.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

interval : Integer, default 0.16

Parameters for matplotlib.animation.ArtistAnimation.

stride : Integer, default 1

Stride per frame.

rotate : tuple, default None

A pair of rotation angles, elev and azim, for animation. None means no rotation, same as (0, 0).

legend : bool, default True

scale : float, default 1

A length-scaling factor

output : str, default None

An output filename. ‘.webm’ or ‘.mp4’ is only accepted. If None, display a movie on IPython Notebook.

crf : int, default 10

The CRF value can be from 4-63. Lower values mean better quality.

bitrate : str, default ‘1M’

Target bitrate

ecell4.util.viz.plot_movie_of_trajectory(obs, figsize=6, grid=True, wireframe=False, max_count=None, angle=None, noaxis=False, interval=0.16, repeat_delay=3000, stride=1, rotate=None, legend=True, output=None, crf=10, bitrate='1M', plot_range=None, **kwargs)

Generate a move from the received list of instances of World, and show it on IPython notebook. This function may require ffmpeg.

Parameters:

worlds : list or FixedIntervalHDF5Observer

A list of Worlds to render.

marker_size : float, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsize : float, default 6

Size of the plotting area. Given in inch.

max_count : Integer, default None

The maximum number of particles to show for each species. None means no limitation.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

interval : Integer, default 0.16

Parameters for matplotlib.animation.ArtistAnimation.

stride : Integer, default 1

Stride per frame.

rotate : tuple, default None

A pair of rotation angles, elev and azim, for animation. None means no rotation, same as (0, 0).

legend : bool, default True

output : str, default None

An output filename. ‘.webm’ or ‘.mp4’ is only accepted. If None, display a movie on IPython Notebook.

crf : int, default 10

The CRF value can be from 4-63. Lower values mean better quality.

bitrate : str, default ‘1M’

Target bitrate

plot_range : tuple, default None

Range for plotting. A triplet of pairs suggesting (rangex, rangey, rangez). If None, the minimum volume containing all the trajectories is used.

ecell4.util.viz.plot_movie_of_trajectory2d_with_matplotlib(obs, plane='xy', figsize=6, grid=True, wireframe=False, max_count=None, angle=None, noaxis=False, interval=0.16, repeat_delay=3000, stride=1, rotate=None, legend=True, output=None, crf=10, bitrate='1M', plot_range=None, **kwargs)

Generate a move from the received list of instances of World, and show it on IPython notebook. This function may require ffmpeg.

Parameters:

worlds : list or FixedIntervalHDF5Observer

A list of Worlds to render.

plane : str, default ‘xy’

‘xy’, ‘yz’, ‘zx’.

figsize : float, default 6

Size of the plotting area. Given in inch.

max_count : Integer, default None

The maximum number of particles to show for each species. None means no limitation.

interval : Integer, default 0.16

Parameters for matplotlib.animation.ArtistAnimation.

stride : Integer, default 1

Stride per frame.

legend : bool, default True

output : str, default None

An output filename. ‘.webm’ or ‘.mp4’ is only accepted. If None, display a movie on IPython Notebook.

crf : int, default 10

The CRF value can be from 4-63. Lower values mean better quality.

bitrate : str, default ‘1M’

Target bitrate

plot_range : tuple, default None

Range for plotting. A triplet of pairs suggesting (rangex, rangey, rangez). If None, the minimum volume containing all the trajectories is used.

ecell4.util.viz.plot_movie_of_trajectory_with_matplotlib(obs, figsize=6, grid=True, wireframe=False, max_count=None, angle=None, noaxis=False, interval=0.16, repeat_delay=3000, stride=1, rotate=None, legend=True, output=None, crf=10, bitrate='1M', plot_range=None, **kwargs)

Generate a move from the received list of instances of World, and show it on IPython notebook. This function may require ffmpeg.

Parameters:

worlds : list or FixedIntervalHDF5Observer

A list of Worlds to render.

marker_size : float, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsize : float, default 6

Size of the plotting area. Given in inch.

max_count : Integer, default None

The maximum number of particles to show for each species. None means no limitation.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

interval : Integer, default 0.16

Parameters for matplotlib.animation.ArtistAnimation.

stride : Integer, default 1

Stride per frame.

rotate : tuple, default None

A pair of rotation angles, elev and azim, for animation. None means no rotation, same as (0, 0).

legend : bool, default True

output : str, default None

An output filename. ‘.webm’ or ‘.mp4’ is only accepted. If None, display a movie on IPython Notebook.

crf : int, default 10

The CRF value can be from 4-63. Lower values mean better quality.

bitrate : str, default ‘1M’

Target bitrate

plot_range : tuple, default None

Range for plotting. A triplet of pairs suggesting (rangex, rangey, rangez). If None, the minimum volume containing all the trajectories is used.

ecell4.util.viz.plot_movie_with_attractive_mpl(worlds, marker_size=6, figsize=6, grid=True, wireframe=False, species_list=None, max_count=None, angle=None, noaxis=False, interval=0.16, repeat_delay=3000, stride=1, rotate=None, legend=True, whratio=1.33, scale=1, output=None, crf=10, bitrate='1M', **kwargs)

Generate a move from the received list of instances of World, and show it on IPython notebook. This function may require ffmpeg.

Parameters:

worlds : list or FixedIntervalHDF5Observer

A list of Worlds to render.

marker_size : float, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsize : float, default 6

Size of the plotting area. Given in inch.

species_list : array of string, default None

If set, plot_world will not search the list of species.

max_count : Integer, default None

The maximum number of particles to show for each species. None means no limitation.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

interval : Integer, default 0.16

Parameters for matplotlib.animation.ArtistAnimation.

stride : Integer, default 1

Stride per frame.

rotate : tuple, default None

A pair of rotation angles, elev and azim, for animation. None means no rotation, same as (0, 0).

legend : bool, default True

whratio : float, default 1.33

A ratio between figure width and height. Customize this to keep a legend within the figure.

scale : float, default 1

A length-scaling factor

crf : int, default 10

The CRF value can be from 4-63. Lower values mean better quality.

bitrate : str, default ‘1M’

Target bitrate

output : str, default None

An output filename. ‘.webm’ or ‘.mp4’ is only accepted. If None, display a movie on IPython Notebook.

ecell4.util.viz.plot_movie_with_elegans(worlds, radius=None, width=500, height=500, config={}, grid=False, species_list=None)

Generate a movie from received instances of World and show them on IPython notebook.

Parameters:

worlds : list of World

Worlds to render.

radius : float, default None

If this value is set, all particles in the world will be rendered as if their radius are the same.

width : float, default 500

Width of the plotting area.

height : float, default 500

Height of the plotting area.

config : dict, default {}

Dict for configure default colors. Its values are colors unique to each speices. The dictionary will be updated during this plot. Colors included in config dict will never be used for other speices.

species_list : array of string, default None

If set, plot_movie will not search the list of species

ecell4.util.viz.plot_movie_with_matplotlib(worlds, marker_size=3, figsize=6, grid=True, wireframe=False, species_list=None, max_count=None, angle=None, noaxis=False, interval=0.16, repeat_delay=3000, stride=1, rotate=None, legend=True, output=None, crf=10, bitrate='1M', **kwargs)

Generate a movie from the received list of instances of World, and show it on IPython notebook. This function may require ffmpeg.

Parameters:

worlds : list or FixedIntervalHDF5Observer

A list of Worlds to render.

marker_size : float, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsize : float, default 6

Size of the plotting area. Given in inch.

species_list : array of string, default None

If set, plot_world will not search the list of species.

max_count : Integer, default None

The maximum number of particles to show for each species. None means no limitation.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

interval : Integer, default 0.16

Parameters for matplotlib.animation.ArtistAnimation.

stride : Integer, default 1

Stride per frame.

rotate : tuple, default None

A pair of rotation angles, elev and azim, for animation. None means no rotation, same as (0, 0).

legend : bool, default True

output : str, default None

An output filename. ‘.webm’ or ‘.mp4’ is only accepted. If None, display a movie on IPython Notebook.

crf : int, default 10

The CRF value can be from 4-63. Lower values mean better quality.

bitrate : str, default ‘1M’

Target bitrate

ecell4.util.viz.plot_number_observer(*args, **kwargs)

Generate a plot from NumberObservers and show it. See plot_number_observer_with_matplotlib and _with_nya for details.

Parameters:

obs : NumberObserver (e.g. FixedIntervalNumberObserver)

interactive : bool, default False

Choose a visualizer. If False, show the plot with matplotlib. If True (only available on IPython Notebook), show it with nyaplot.

Examples

>>> plot_number_observer(obs1)
>>> plot_number_observer(obs1, interactive=True)
ecell4.util.viz.plot_number_observer_with_matplotlib(*args, **kwargs)

Generate a plot from NumberObservers and show it on IPython notebook with matplotlib.

Parameters:

obs : NumberObserver (e.g. FixedIntervalNumberObserver)

fmt : str, optional

opt : dict, optional

matplotlib plot options.

Examples

>>> plot_number_observer(obs1)
>>> plot_number_observer(obs1, 'o')
>>> plot_number_observer(obs1, obs2, obs3, {'linewidth': 2})
>>> plot_number_observer(obs1, 'k-', obs2, 'k--')
ecell4.util.viz.plot_number_observer_with_nya(obs, config={}, width=600, height=400, x=None, y=None, to_png=False)

Generate a plot from NumberObservers and show it on IPython notebook with nyaplot.

Parameters:

obs : NumberObserver (e.g. FixedIntervalNumberObserver)

config : dict, optional

A config data for coloring. The dictionary will be updated during this plot.

width : int, optional

height : int, optional

x : str, optional

A serial for x-axis. If None, x-axis corresponds time.

y : str or list of str

Serials for y axis.

ecell4.util.viz.plot_trajectory(*args, **kwargs)

Generate a plot from received instance of TrajectoryObserver and show it See also plot_trajectory_with_elegans and plot_trajectory_with_matplotlib.

Parameters:

obs : TrajectoryObserver

TrajectoryObserver to render.

interactive : bool, default True

Choose a visualizer. If False, show the plot with matplotlib. If True (only available on IPython Notebook), show it with elegans.

Examples

>>> plot_trajectory(obs)
>>> plot_trajectory(obs, interactive=False)
ecell4.util.viz.plot_trajectory2d_with_matplotlib(obs, plane='xy', max_count=10, figsize=6, legend=True, wireframe=False, grid=True, noaxis=False, plot_range=None, **kwargs)

Make a 2D plot from received instance of TrajectoryObserver and show it on IPython notebook.

Parameters:

obs : TrajectoryObserver

TrajectoryObserver to render.

plane : str, default ‘xy’

‘xy’, ‘yz’, ‘zx’.

max_count : Integer, default 10

The maximum number of particles to show. If None, show all.

figsize : float, default 6

Size of the plotting area. Given in inch.

legend : bool, default True

plot_range : tuple, default None

Range for plotting. A triplet of pairs suggesting (rangex, rangey, rangez). If None, the minimum volume containing all the trajectories is used.

ecell4.util.viz.plot_trajectory_with_elegans(obs, width=350, height=350, config={}, grid=True, wireframe=False, max_count=10, camera_position=(-22, 23, 32), camera_rotation=(-0.6, 0.5, 0.6), plot_range=None)

Generate a plot from received instance of TrajectoryObserver and show it on IPython notebook.

Parameters:

obs : TrajectoryObserver

TrajectoryObserver to render.

width : float, default 350

Width of the plotting area.

height : float, default 350

Height of the plotting area.

config : dict, default {}

Dict for configure default colors. Its values are colors unique to each particle. The dictionary will be updated during this plot. Colors included in config dict will never be used for other particles.

camera_position : tuple, default (-30, 31, 42)

camera_rotaiton : tuple, default (-0.6, 0.5, 0.6)

Initial position and rotation of camera.

plot_range : tuple, default None

Range for plotting. A triplet of pairs suggesting (rangex, rangey, rangez). If None, the minimum volume containing all the trajectories is used.

ecell4.util.viz.plot_trajectory_with_matplotlib(obs, max_count=10, figsize=6, legend=True, angle=None, wireframe=False, grid=True, noaxis=False, plot_range=None, **kwargs)

Generate a plot from received instance of TrajectoryObserver and show it on IPython notebook.

Parameters:

obs : TrajectoryObserver

TrajectoryObserver to render.

max_count : Integer, default 10

The maximum number of particles to show. If None, show all.

figsize : float, default 6

Size of the plotting area. Given in inch.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

legend : bool, default True

plot_range : tuple, default None

Range for plotting. A triplet of pairs suggesting (rangex, rangey, rangez). If None, the minimum volume containing all the trajectories is used.

ecell4.util.viz.plot_world(*args, **kwargs)

Generate a plot from received instance of World and show it. See also plot_world_with_elegans and plot_world_with_matplotlib.

Parameters:

world : World or str

World or a HDF5 filename to render.

interactive : bool, default True

Choose a visualizer. If False, show the plot with matplotlib. If True (only available on IPython Notebook), show it with elegans.

Examples

>>> plot_world(w)
>>> plot_world(w, interactive=False)
ecell4.util.viz.plot_world2d_with_matplotlib(world, plane='xy', marker_size=3, figsize=6, grid=True, wireframe=False, species_list=None, max_count=1000, angle=None, legend=True, noaxis=False, scale=1.0, **kwargs)

Make a 2D plot from received instance of World and show it on IPython notebook.

Parameters:

world : World or str

World to render. A HDF5 filename is also acceptable.

plane : str, default ‘xy’

‘xy’, ‘yz’, ‘zx’.

marker_size : float, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsize : float, default 6

Size of the plotting area. Given in inch.

species_list : array of string, default None

If set, plot_world will not search the list of species.

max_count : Integer, default 1000

The maximum number of particles to show for each species. None means no limitation.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

legend : bool, default True

scale : float, default 1

A length-scaling factor

ecell4.util.viz.plot_world_with_attractive_mpl(world, marker_size=6, figsize=6, grid=True, wireframe=False, species_list=None, max_count=1000, angle=None, legend=True, noaxis=False, whratio=1.33, scale=1.0, **kwargs)

Generate a plot from received instance of World and show it on IPython notebook.

Parameters:

world : World or str

World to render. A HDF5 filename is also acceptable.

marker_size : float, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsize : float, default 6

Size of the plotting area. Given in inch.

species_list : array of string, default None

If set, plot_world will not search the list of species.

max_count : Integer, default 1000

The maximum number of particles to show for each species. None means no limitation.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

legend : bool, default True

whratio : float, default 1.33

A ratio between figure width and height. Customize this to keep a legend within the figure.

scale : float, default 1

A length-scaling factor

ecell4.util.viz.plot_world_with_elegans(world, radius=None, width=350, height=350, config={}, grid=True, wireframe=False, species_list=None, debug=None, max_count=1000, camera_position=(-22, 23, 32), camera_rotation=(-0.6, 0.5, 0.6), return_id=False, predicator=None)

Generate a plot from received instance of World and show it on IPython notebook. This method returns the instance of dict that indicates color setting for each speices. You can use the dict as the parameter of plot_world, in order to use the same colors in another plot.

Parameters:

world : World or str

World or a HDF5 filename to render.

radius : float, default None

If this value is set, all particles in the world will be rendered as if their radius are the same.

width : float, default 350

Width of the plotting area.

height : float, default 350

Height of the plotting area.

config : dict, default {}

Dict for configure default colors. Its values are colors unique to each speices. The dictionary will be updated during this plot. Colors included in config dict will never be used for other speices.

species_list : array of string, default None

If set, plot_world will not search the list of species.

max_count : Integer, default 1000

The maximum number of particles to show for each species.

debug : array of dict, default []

* EXPERIMENTAL IMPRIMENTATION * Example: >> [{‘type’: ‘box’, ‘x’: 10, ‘y’: 10, ‘z’: 10, ‘options’: {‘width’: 1, ‘height’: 1}}] type: ‘box’, ‘plane’, ‘sphere’, and ‘cylinder’ x, y, z: float options:

box: width, height, depth plane: width, height sphere: radius cylinder: radius, height

camera_position : tuple, default (-22, 23, 32)

camera_rotaiton : tuple, default (-0.6, 0.5, 0.6)

Initial position and rotation of camera.

return_id : bool, default False

If True, return a model id, which is required for to_png function.

ecell4.util.viz.plot_world_with_matplotlib(world, marker_size=3, figsize=6, grid=True, wireframe=False, species_list=None, max_count=1000, angle=None, legend=True, noaxis=False, **kwargs)

Generate a plot from received instance of World and show it on IPython notebook.

Parameters:

world : World or str

World to render. A HDF5 filename is also acceptable.

marker_size : float, default 3

Marker size for all species. Size is passed to scatter function as argument, s=(2 ** marker_size).

figsize : float, default 6

Size of the plotting area. Given in inch.

species_list : array of string, default None

If set, plot_world will not search the list of species.

max_count : Integer, default 1000

The maximum number of particles to show for each species. None means no limitation.

angle : tuple, default None

A tuple of view angle which is given as (azim, elev, dist). If None, use default assumed to be (-60, 30, 10).

legend : bool, default True

ecell4.util.viz.plot_world_with_plotly(world, species_list=None, max_count=1000)

Plot a World on IPython Notebook