Visualization
Visualizations of simulations with pyglet.
- class epipack.vis.App(width, height, simulation_status, *args, **kwargs)[source]
Bases:
BaseWindowA pyglet Window class that makes zooming and panning convenient and tracks user input.
Adapted from Peter Varo's solution at https://stackoverflow.com/a/19453006/4177832
- Parameters
width (float) -- Width of the app window
height (float) -- Height of the app window
simulation_status (SimulationStatus) -- An object that tracks the simulation. Here, it's used to pause or increase the simulation speed.
- add_batch(batch, prefunc=None)[source]
Add a batch that needs to be drawn. Optionally, also pass a function that's triggered before this batch is drawn.
- class epipack.vis.Curve(x, y, color, scale, batch)[source]
Bases:
objectA class that draws an OpenGL curve to a pyglet Batch instance with easy methods to update data.
- Parameters
- batch
The batch instance in which this curve is drawn
- Type
pyglet.graphics.Batch
- scale
An instance of a Scale that maps the data dimensions to an area in a pyglet Window
- Type
- vertex_list
Contains the vertex list in window coordinates. format strings are
v2fandc3B.- Type
pyglet.graphics.VertexList
- append_list(x, y)[source]
Append a list of data points to this curve. Note that if the bounds change with this update, the connect Scale-instance will be updated automatically.
- class epipack.vis.Scale(bound_increase_factor=1.0)[source]
Bases:
objectA scale that maps all its connected graphics objects to world (window) dimensions.
- Parameters
bound_increase_factor (float, default = 1.0) -- By how much the respective bound should increase once it's reached.
- bound_increase_factor
By how much the respective bound should increase once it's reached.
- Type
- scaling_objects
A list of objects that need to be rescaled once the data or world dimensions change. Each entry of this list is assumed to be an object that has a method called
rescale().- Type
- class epipack.vis.SimulationStatus(N, sampling_dt)[source]
Bases:
objectSaves information about the current simulation.
- Parameters
- old_node_status
An array containing node statuses of the previous update
- Type
numpy.ndarray
- sampling_dt
The amount of simulation time that's supposed to pass during a single update
- Type
- epipack.vis.get_network_batch(stylized_network, yoffset, draw_links=True, draw_nodes=True, draw_nodes_as_rectangles=False, n_circle_segments=16)[source]
Create a batch for a network visualization.
- Parameters
stylized_network (dict) -- The network properties which are returned from the interactive visualization.
draw_links (bool, default : True) -- Whether the links should be drawn
draw_nodes (bool, default : True) -- Whether the nodes should be drawn
n_circle_segments (bool, default = 16) -- Number of segments a circle will be constructed of.
- Returns
network_objects -- A dictionary containing all the necessary objects to draw and update the network. - lines : a list of pyglet-line objects (one entry per link)
disks : a list of pyglet-circle objects (one entry per node)
circles : a list of pyglet-circle objects (one entry per node)
nodes_to_lines : a dictionary mapping a node to a list of pairs. Each pair's first entry is the focal node's neighbor and the second entry is the index of the line-object that connects the two
batch : the pyglet Batch instance that contains all of the objects
- Return type
- epipack.vis.visualize(model, network, sampling_dt, ignore_plot_compartments=[], quarantine_compartments=[], config=None)[source]
Start a visualization of a stochastic simulation.
- Parameters
model (epipack.stochastic_epi_models.StochasticEpiModel) -- An initialized StochasticEpiModel.
network (dict) --
A stylized network in the netwulf-format (see https://netwulf.readthedocs.io/en/latest/python_api/post_back.html) where instead of 'x' and 'y', node positions are saved in 'x_canvas' and 'y_canvas'. Example:
stylized_network = { "xlim": [0, 833], "ylim": [0, 833], "linkAlpha": 0.5, "nodeStrokeWidth": 0.75, "links": [ {"source": 0, "target": 1, "width": 3.0 } ], "nodes": [ {"id": 0, "x_canvas": 436.0933431058901, "y_canvas": 431.72418500564186, "radius": 20 }, {"id": 1, "x_canvas": 404.62184898400426, "y_canvas": 394.8158724310507, "radius": 20 } ] }
sampling_dt (float) -- The amount of simulation time that's supposed to pass with a single update.
ignore_plot_compartments (list, default = []) -- List of compartment objects that are supposed to be ignored when plotted.
quarantine_compartments (list, default = []) -- List of compartment objects that are supposed to be resemble quarantine (i.e. temporarily losing all connections)
config (dict, default = None) --
A dictionary containing all possible configuration options. Entries in this dictionary will overwrite the default config which is
_default_config = { 'plot_sampled_curve': True, 'draw_links':True, 'draw_nodes':True, 'n_circle_segments':16, 'plot_height':120, 'bgcolor':'#253237', 'curve_stroke_width':4.0, 'node_stroke_width':1.0, 'link_color': '#4b5a62', 'node_stroke_color':'#000000', 'node_color':'#264653', 'bound_increase_factor':1.0, 'update_dt':0.04, 'show_curves':True, 'draw_nodes_as_rectangles':False, 'show_legend': True, 'legend_font_color':'#fafaef', 'legend_font_size':10, 'padding':10, 'compartment_colors':_colors }
- epipack.vis.visualize_reaction_diffusion(model, network, sampling_dt, node_compartments, value_extent=[0.0, 1.0], integrator='euler', n_integrator_midpoints=0, config=None)[source]
Start a visualization of a reaction-diffusion simulation.
- Parameters
model (:class:`epipack.numeric_matrix_epi_models.MatrixEpiModel) -- An initialized
MatrixEpiModel.network (dict) --
A stylized network in the netwulf-format (see https://netwulf.readthedocs.io/en/latest/python_api/post_back.html) where instead of 'x' and 'y', node positions are saved in 'x_canvas' and 'y_canvas'. Example:
stylized_network = { "xlim": [0, 833], "ylim": [0, 833], "linkAlpha": 0.5, "nodeStrokeWidth": 0.75, "links": [ {"source": 0, "target": 1, "width": 3.0 } ], "nodes": [ {"id": 0, "x_canvas": 436.0933431058901, "y_canvas": 431.72418500564186, "radius": 20 }, {"id": 1, "x_canvas": 404.62184898400426, "y_canvas": 394.8158724310507, "radius": 20 } ] }
sampling_dt (float) -- The amount of simulation time that's supposed to pass with a single update.
quarantine_compartments (list) -- List of compartment objects that are supposed to be resemble quarantine (i.e. temporarily losing all connections)
node_compartments (list) -- The compartments for which to display the concentrations. Each entry m in this list is expected to be a compartment associated with node m. this list should therefore be as long as the number of nodes.
config (dict, default = None) --
A dictionary containing all possible configuration options. Entries in this dictionary will overwrite the default config which is
_default_config = { 'plot_sampled_curve': True, 'draw_links':True, 'draw_nodes':True, 'n_circle_segments':16, 'plot_height':120, 'bgcolor':'#253237', 'curve_stroke_width':4.0, 'node_stroke_width':1.0, 'link_color': '#4b5a62', 'node_stroke_color':'#000000', 'node_color':'#264653', 'bound_increase_factor':1.0, 'update_dt':0.04, 'show_curves':True, 'draw_nodes_as_rectangles':False, 'show_legend': True, 'legend_font_color':'#fafaef', 'legend_font_size':10, 'padding':10, 'compartment_colors':_colors }