TransTree#
- class TransTree(sim, to_networkx=False, **kwargs)[source]#
Bases:
Analyzer
A class for holding a transmission tree. There are several different representations of the transmission tree: “infection_log” is copied from the people object and is the simplest representation. “detailed h” includes additional attributes about the source and target. If NetworkX is installed (required for most methods), “graph” includes an NX representation of the transmission tree.
- Parameters:
sim (Sim) – the sim object
to_networkx (bool) – whether to convert the graph to a NetworkX object
Example:
sim = cv.Sim().run() sim.run() tt = sim.make_transtree() tt.plot() tt.plot_histograms()
New in version 2.1.0:
tt.detailed
is a dataframe rather than a list of dictionaries; for the latter, usett.detailed.to_dict('records')
.Methods
- count_targets(start_day=None, end_day=None)[source]#
Count the number of targets each infected person has. If start and/or end days are given, it will only count the targets of people who got infected between those dates (it does not, however, filter on the date the target got infected).
- Parameters:
start_day (int/str) – the day on which to start counting people who got infected
end_day (int/str) – the day on which to stop counting people who got infected
- count_transmissions()[source]#
Iterable over edges corresponding to transmission events
This excludes edges corresponding to seeded infections without a source
- make_detailed(people, reset=False)[source]#
Construct a detailed transmission tree, with additional information for each person
- r0(recovered_only=False)[source]#
Return average number of transmissions per person
This doesn’t include seed transmissions. By default, it also doesn’t adjust for length of infection (e.g. people infected towards the end of the simulation will have fewer transmissions because their infection may extend past the end of the simulation, these people are not included). If ‘recovered_only=True’ then the downstream transmissions will only be included for people that recover before the end of the simulation, thus ensuring they all had the same amount of time to transmit.
- plot(fig_args=None, plot_args=None, do_show=None, fig=None)[source]#
Plot the transmission tree.
- Parameters:
fig_args (dict) – passed to pl.figure()
plot_args (dict) – passed to pl.plot()
do_show (bool) – whether to show the plot
fig (fig) – if supplied, use this figure
- animate(*args, **kwargs)[source]#
Animate the transmission tree.
- Parameters:
animate (bool) – whether to animate the plot (otherwise, show when finished)
verbose (bool) – print out progress of each frame
markersize (int) – size of the markers
sus_color (list) – color for susceptibles
fig_args (dict) – arguments passed to pl.figure()
axis_args (dict) – arguments passed to pl.subplots_adjust()
plot_args (dict) – arguments passed to pl.plot()
delay (float) – delay between frames in seconds
colors (list) – color of each person
cmap (str) – colormap for each person (if colors is not supplied)
fig (fig) – if supplied, use this figure
- Returns:
the figure object
- Return type:
fig
- plot_histograms(start_day=None, end_day=None, bins=None, width=0.8, fig_args=None, fig=None)[source]#
Plots a histogram of the number of transmissions.
- Parameters:
start_day (int/str) – the day on which to start counting people who got infected
end_day (int/str) – the day on which to stop counting people who got infected
bins (list) – bin edges to use for the histogram
width (float) – width of bars
fig_args (dict) – passed to pl.figure()
fig (fig) – if supplied, use this figure