episimmer.utils
ArgParse API
Module Handling API
- module_from_file(module_name, file_path)[source]
Returns the module from the file passed
- Parameters
module_name (str) – Name of module
file_path (str) – Path to file used to create module
- Returns
Module of file
- Return type
module
Time API
- class Time[source]
Class that handles the time step and world of simulation.
- current_world: Optional[int] = None
- current_time_step: Optional[int] = None
- static get_current_world()[source]
Returns the current world of simulation.
- Returns
Index of current world
- Return type
int
- static get_current_time_step()[source]
Returns the current time step of simulation.
- Returns
Index of current time step
- Return type
int
- static reset()[source]
Resets the world and time step at the beginning of a new simulation.
- Return type
None
Statistics API
Class to handle variable statistics in Episimmer |
|
This function is a recursive function which expands the current object's variables to a given number of levels. |
|
Expands the object by expanding the members of the object such as dictionaries and iterables. |
|
This function is a recursive function which selects the variables of the dictionary to be saved. |
|
Processes the expanded object as a dictionary by choosing to save only required properties. |
|
Returns the dictionary as a string in pretty print format |
|
Saves the dictionary into a pickle file |
|
Saves the string to a text file. |
|
Decorator to save statistics (object members) into a dictionary |
|
Decorator to write statistics (object members) into a file |
- class Stats[source]
Class to handle variable statistics in Episimmer
- stats_dict = {}
- expand_levels_recursion(obj, levels, cur_level)[source]
This function is a recursive function which expands the current object’s variables to a given number of levels. If the object is a dictionary or an iterable,only then will the object be expanded. Other objects are returned as is.
- Parameters
obj (object) – Object to be expanded
levels (int) – Number of levels to expand the object
cur_level (int) – Current level expanded
- Returns
An expanded object
- Return type
Union[Dict[str, Dict], object]
- expand_levels(obj, levels)[source]
Expands the object by expanding the members of the object such as dictionaries and iterables. Calls the expand_levels_recursion method for expansion of object.
- Parameters
obj (object) – Object to be expanded
levels (int) – Number of levels to expand the object
- Returns
An expanded object
- Return type
Union[Dict[str, Dict], object]
- process_dict_recursion(stats_dict, final_level_properties, levels, cur_level)[source]
This function is a recursive function which selects the variables of the dictionary to be saved.
- Parameters
stats_dict (Dict[str, Dict]) – Dictionary containing an object’s expanded members
final_level_properties (Union[str, List[str]]) – Properties required to be saved
levels (int) – NNumber of levels the object was expanded
cur_level (int) – Current level of dictionary
- Returns
Processed dictionary
- Return type
Dict[str, Dict]
- process_dict(stats_dict, final_level_properties, levels)[source]
Processes the expanded object as a dictionary by choosing to save only required properties. Calls the process_dict_recursion method.
- Parameters
stats_dict (Dict[str, Dict]) – Dictionary containing an object’s expanded members
final_level_properties (Union[str, List[str]]) – Properties required to be saved
levels (int) – NNumber of levels the object was expanded
- Returns
Processed dictionary
- Return type
Dict[str, Dict]
- get_pretty_print_str(stats_dict)[source]
Returns the dictionary as a string in pretty print format
- Parameters
stats_dict (Dict[str, Dict]) – Dictionary to be converted to pretty print string
- Returns
String representing dictionary in pretty print format
- Return type
str
- save_pickle(example_path, pickle_file, final_dict)[source]
Saves the dictionary into a pickle file
- Parameters
example_path (str) – Path to directory containing simulation files.
pickle_file (str) – Name of pickle file
final_dict (Dict[str, Dict]) – Dictionary to be saved
- Return type
None
- save_to_text_file(example_path, string, text_filename)[source]
Saves the string to a text file.
- Parameters
example_path (str) – Path to directory containing simulation files.
string (str) – String to be saved
text_filename (str) – Name of text file
- Return type
None
- save_stats(obj_lev_tuples, key, final_level_properties='All')[source]
Decorator to save statistics (object members) into a dictionary
- Parameters
obj_lev_tuples (List[Tuple[str, int]]) – List of tuples containing the object to be saved (as a string) and the number of levels
key (str) – Key to use while saving the content in the statistics dictionary
final_level_properties (Union[str, List[str]]) – Properties to save. Can be a list of properties/members of the object or ‘All’
- Returns
Callable function
- Return type
Callable
Visualization API
Plots the epidemic trajectory |
|
Builds the epidemic trajectory graph for current frame i |
|
Saves the animation of epidemic trajectory to a gif file |
|
Generates the interaction graph from the simulation object |
|
Decorator to save the interactions graph to the |
|
Sets the title and legend of the Axes for the interaction graph |
|
Sets the node positions and edges according to the spring layout and returns them. |
|
Sets up the figure to plot the current time step interaction network |
|
Decorator to store the evolving interactions graph as a gif. |
- plot_results(example_path, model, avg_dict, stddev_dict, max_dict, min_dict, plot)[source]
Plots the epidemic trajectory
- Parameters
example_path (str) – Path to directory containing simulation files
model (BaseModel) – Disease model used
avg_dict (Dict[str, List[float]]) – Average of epidemic trajectory
stddev_dict (Dict[str, List[float]]) – Standard deviation of epidemic trajectory
max_dict (Dict[str, List[int]]) – Maximum values of epidemic trajectory across worlds
min_dict (Dict[str, List[int]]) – Minimum values of epidemic trajectory across worlds
plot (bool) – Boolean used to plot the epidemic trajectory
- Return type
None
- buildgraph(i, model, avg_dict)[source]
Builds the epidemic trajectory graph for current frame i
- Parameters
i (int) – Current frame
model (BaseModel) – Disease model used
avg_dict (Dict[str, List[float]]) – Average of epidemic trajectory
- Return type
None
- store_animated_time_plot(example_path, model, avg_dict)[source]
Saves the animation of epidemic trajectory to a gif file
- Parameters
example_path (str) – Path to directory containing simulation files
model (BaseModel) – Disease model used
avg_dict (Dict[str, List[float]]) – Average of epidemic trajectory
- Return type
None
- get_interaction_graph_from_object(obj)[source]
Generates the interaction graph from the simulation object
- Parameters
obj (Simulate) – Simulation object
- Returns
Interaction graph
- Return type
networkx.classes.graph.Graph
- save_env_graph()[source]
Decorator to save the interactions graph to the
Simulateobject- Returns
Callable function
- Return type
Callable
- set_ax_params(ax, model, time_step)[source]
Sets the title and legend of the Axes for the interaction graph
- Parameters
ax (matplotlib.axes._axes.Axes) – Axes
model (BaseModel) – Disease model used
time_step (int) – Current time step
- Returns
Axes
- Return type
matplotlib.axes._axes.Axes
- draw_graph(g, ax, seed)[source]
Sets the node positions and edges according to the spring layout and returns them.
- Parameters
g (networkx.classes.graph.Graph) – Current interaction graph
ax (matplotlib.axes._axes.Axes) – Axes
seed (Union[str, int]) – Seed for consistent graph
- Returns
Nodes and Edges
- Return type
Tuple[matplotlib.collections.PatchCollection, matplotlib.collections.LineCollection]
- animate_graph(time_step, fig, model, g_list, seed)[source]
Sets up the figure to plot the current time step interaction network
- Parameters
time_step (int) – Current time step
fig (matplotlib.figure.Figure) – Figure used to plot
model (BaseModel) – Disease model used
g_list (List[networkx.classes.graph.Graph]) – List of interaction graphs for every time step
seed (Union[str, int]) – Seed for consistent graph
- Returns
Nodes and edges for current time step
- Return type
Tuple[matplotlib.collections.PatchCollection, matplotlib.collections.LineCollection]
Math API
This function returns the average of the values in the epidemic trajectory |
|
This function returns the standard deviation of the values in the epidemic trajectory. |
- deep_copy_average(tdict, number)[source]
This function returns the average of the values in the epidemic trajectory
- Parameters
tdict (Dict[str, List[int]]) – Time series dictionary.
number (int) – Number of worlds
- Returns
Average of epidemic trajectory
- Return type
Dict[str, List[float]]
- deep_copy_stddev(tdict, t2_dict, number)[source]
This function returns the standard deviation of the values in the epidemic trajectory.
- Parameters
tdict (Dict[str, List[int]]) – Time series dictionary.
t2_dict (Dict[str, List[int]]) – Squared time series dictionary.
number (int) – Number of worlds
- Returns
Standard Deviation of epidemic trajectory
- Return type
Dict[str, List[float]]