InfectionLog#

class InfectionLog(incoming_graph_data=None, multigraph_input=None, **attr)[source]#

Bases: MultiDiGraph

Record infections

The infection log records transmission events and optionally other data associated with each transmission. Basic functionality is to track transmission with

>>> Disease.log.append(source, target, t)

Seed infections can be recorded with a source of None, although all infections should have a target and a time. Other data can be captured in the log, either at the time of creation, or later on. For example

>>> Disease.log.append(source, target, t, network='msm')

could be used by a module to track the network in which transmission took place. Modules can optionally add per-infection outcomes later as well, for example

>>> Disease.log.add_data(source, t_dead=2024.25)

This would be equivalent to having specified the data at the original time the log entry was created - however, it is more useful for tracking events that may or may not occur after the infection and could be modified by interventions (e.g., tracking diagnosis, treatment, notification etc.)

A table of outcomes can be returned using InfectionLog.line_list()

Attributes

adj

Graph adjacency object holding the neighbors of each node.

degree

A DegreeView for the Graph as G.degree or G.degree().

edges

An OutMultiEdgeView of the Graph as G.edges or G.edges().

in_degree

A DegreeView for (node, in_degree) or in_degree for single node.

in_edges

A view of the in edges of the graph as G.in_edges or G.in_edges().

name

String identifier of the graph.

nodes

A NodeView of the Graph as G.nodes or G.nodes().

out_degree

Returns an iterator for (node, out-degree) or out-degree for single node.

out_edges

An OutMultiEdgeView of the Graph as G.edges or G.edges().

pred

Graph adjacency object holding the predecessors of each node.

succ

Graph adjacency object holding the successors of each node.

Methods

add_data(uids, **kwargs)[source]#

Record extra infection data

This method can be used to add data to an existing transmission event. The most recent transmission event will be used

Parameters:
  • uid – The UID of the target node (the agent that was infected)

  • kwargs – Remaining arguments are stored as edge data

line_list()[source]#

Return a tabular representation of the log

This function returns a dataframe containing columns for all quantities recorded in the log. Note that the log will contain NaN for quantities that are defined for some edges and not others (and which are missing for a particular entry)