10.1.1. pyopencl_scripts.network_visualization¶
This module provides examples and functions for visualizing simulations of networks or particles using PyOpenCL or python.
10.1.1.1. Overview¶
10.1.1.2. Classes and Functions¶
-
ilpm.pyopencl_scripts.network_visualization.
get_points_per_unit
(ax=None)[source]¶ Use the size of the matplotlib axis to measure the number of points per unit
-
ilpm.pyopencl_scripts.network_visualization.
absolute_sizer
(ax=None)[source]¶ Use the size of the matplotlib axis to create a function for sizing objects
-
ilpm.pyopencl_scripts.network_visualization.
ensure_dir
(f)[source]¶ Check if directory exists, and make it if not.
Parameters: f : string
directory path to ensure
-
ilpm.pyopencl_scripts.network_visualization.
get_fname_and_index_size
(hostdir)[source]¶ Obtain the name of the first nontrivial file in a directory and the length of its numerical index. For example, if “hostdir/xyz00001.txt” exist, get_fname_and_index_size(hostdir) returns (‘xyz’, 5). This function is robust to having ‘.’s in the filename.
Parameters: hostdir : string
Directory in which the files you want to grab exist.
Returns: fname : string
First file name in that directory
index_size : int
Length of the index (how many numbers make up its index)
-
ilpm.pyopencl_scripts.network_visualization.
data2stills_2D
(datadir, params={}, framedir_name='stills', vsaved=True, init_skip=10, climv=0.1, numbering='adopt', rough=False, roughmov=True, exaggerate=1.0, rm_stills=False)[source]¶ Converts a list of data into a stack of png images of mass-spring lattice using movie_plot_2D for each timestep. If roughmov is True, make a movie of every init_skip frames before going back and making detailed movie
Parameters: datadir : string
The output directory for the data (contains subdirs for xyv, KL if KL is changing, also contains xy0.txt)
params : dict (optional)
the parameters for the simulation
framedir_name : string
Subdirectory of datadir in which to save movie images
init_skip : int
One out of every init_skip frames will be written first, then the intermittent frames will be written, to see briefly what happens
climv : float or tuple
Color limit for coloring bonds by bond strain
numbering : ‘natural’ or ‘adopt’ (default = ‘adopt’)
Use indexing ‘0’,‘1’,‘2’,‘3’,... or adopt the index of the input file.
rough : boolean
Plot every init_skip files ONLY
roughmov : bool
Make a movie of every init_skip files before plotting every frame
exaggerate : float (default 1.0 –> in which case it is ignored)
Exaggerate the displacements of each particle from its initial position by this factor. Ignored if == 1.0
-
ilpm.pyopencl_scripts.network_visualization.
stills2mov_util
(todo, datadir, NL, xy0, xyfiles, KLfiles, params, h, numbering, index_sz, framedir_name, name, update_KL_each_timestep, exaggerate, xlimv, ylimv, climv, framerate=10, mov_exten='')[source]¶ Make a sequence of images and save it as a movie. This funciton is a utility function called by data2stills_2D()
Parameters: todo : int array or list
The indices of the stills to plot and save in a movie
xyfiles : list of strings
paths of xy data to load
KLfiles : list of strings
paths of connectivity files to load, if connectivity changes during sequence
params : dict
parameters for the simulation
h : float
timestep
numbering : string specifier (‘natural’ or other)
Whether to place the index of the frame as the index of the output timestep or of the frame index
index_sz : int
How many digits in the index (with leading zeros)
framedir_name : str
path for the frames
name : str
non-index part of the frame names
update_KL_each_timestep : bool
Whether connectivity is changing during simulation
exaggerate : float
Exaggeration of the displacement
xlimv : tuple of floats
limits for x axis
ylimv : tuple of floats
limits for y axis
climv : tuple of floats
limits for color axis
mov_exten : str (optional, default is ‘’)
an extension to the movie name describing the movie
-
ilpm.pyopencl_scripts.network_visualization.
movie_plot_2D
(xy, BL, bs=None, fname='none', title='', NL=[], KL=[], BLNNN=[], NLNNN=[], KLNNN=[], PVx=[], PVy=[], PVxydict={}, ax=None, fig=None, axcb='auto', xlimv='auto', ylimv='auto', climv=0.1, colorz=True, ptcolor=None, figsize='auto', colorpoly=False, bondcolor=None, colormap='seismic', bgcolor='#E8E8E8', axis_off=False, axis_equal=True, text_topleft=None, lw=-1.0, ptsize=10, negative_NNN_arrows=False, show=False, arrow_alpha=1.0, fontsize=8)[source]¶ Plots (and saves if fname is not ‘none’) a 2D image of the lattice with colored bonds and particles colored by coordination (both optional).
Parameters: xy : array of dimension nx2
2D lattice of points (positions x,y)
BL : array of dimension #bonds x 2
Each row is a bond and contains indices of connected points
bs : array of dimension #bonds x 1
Strain in each bond
fname : string
Full path including name of the file (.png, etc), if None, will not save figure
title : string
The title of the frame
NL : NP x NN int array (optional, for speed)
Specify to speed up computation, if colorz or colorpoly or if periodic boundary conditions
KL : NP x NN int array (optional, for speed)
Specify to speed up computation, if colorz or colorpoly or if periodic boundary conditions
PVx : NP x NN float array (optional, for periodic lattices and speed)
ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i If PVx and PVy are specified, PVxydict need not be specified.
PVy : NP x NN float array (optional, for periodic lattices and speed)
ijth element of PVy is the y-component of the vector taking NL[i,j] to its image as seen by particle i If PVx and PVy are specified, PVxydict need not be specified.
PVxydict : dict (optional, for periodic lattices)
dictionary of periodic bonds (keys) to periodic vectors (values)
ax: matplotlib figure axis instance
Axis on which to draw the network
fig: matplotlib figure instance
Figure on which to draw the network
axcb: matplotlib colorbar instance
Colorbar to use for strains in bonds
xlimv: float or tuple of floats
ylimv: float or tuple of floats
climv : float or tuple
Color limit for coloring bonds by bs
colorz: bool
whether to color the particles by their coordination number
ptcolor: string color spec or tuple color spec or None
color specification for coloring the points, if colorz is False. Default is None (no coloring of points)
figsize : tuple
w,h tuple in inches
colorpoly : bool
Whether to color in polygons formed by bonds according to the number of sides
bondcolor : color specification (hexadecimal or RGB)
colormap : if bondcolor is None, uses bs array to color bonds
bgcolor : hex format string, rgb color spec, or None
If not None, sets the bgcolor. Often used is ‘#d9d9d9’
axis_off
axis_equal
text_topleft
lw: float
line width for plotting bonds. If lw == -1, then uses automatic line width to adjust for bond density..
ptsize: float
size of points passed to absolute_sizer
Returns: [ax,axcb] : stuff to clear after plotting