Analysis¶
This class stores a series of methods to make plots and output data generated with COMORBUSS, this class can load data from a community object or from an hdf5 file.
do_plot(self, t, dt, data, colors, seeds, filename=None, size=(5, 4), title=None, events=False, events_type=0, skip=[], start_day=None, end_day=None, bands=True, colorsmap=None, start=True, close=True, dates=True, xlim=None, ylim=None, xlabel=False, ylabel=False, log_y=False, show_legend=True, legend_args={}, show_bands_legend=True, bands_legend_args={}, plt_args={})
¶
Internal method used to plot one or more curve.
**plot_args:¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size to generate the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
events |
bool |
Overlay simulation events on the plot. Defaults to False. |
False |
events_type |
int |
Type of logs to overlay as events. Defaults to MSG_EVENTS. |
0 |
skip |
list |
List of curves to skip plotting. Use the same string used in the legend of the plot to skip curves. |
[] |
start_day |
float |
Plot only the interval from start_day. Defaults to 0. |
None |
end_day |
float |
Plot only the interval to end_day. Defaults to last day. |
None |
bands |
bool |
Plot standard deviation bands and 95% percentiles if data has multiple seeds. Defaults to True. |
True |
colorsmap |
arr[str] |
If provided, the list of string is used to initialize colormaps, used in the shading of bands |
None |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
dates |
bool |
Use dates instead of days in the x axis. Defaults to True. |
True |
xlabel |
str |
Label for the x axis. |
False |
ylabel |
str |
Label for the y axis. |
False |
log_y |
bool |
Sets the y scale to log. Defaults to False |
False |
show_legend |
bool |
Hides legends if False. Defaults to True. |
True |
legend_args |
dict |
Arguments to be passed to pyplot.legend when drawing the legend. |
{} |
show_bands_legend |
bool |
Hides bands legends if False. Defaults to True. |
True |
bands_legend_args |
dict |
Arguments to be passed to pyplot.legend when drawing the bands legend. |
{} |
plt_args |
dict |
Additional arguments to be passed to pyplot.plot when drawing the curves. |
{} |
Internal parameters:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
[type] |
[description] |
required |
dt |
[type] |
[description] |
required |
data |
[type] |
[description] |
required |
colors |
[type] |
[description] |
required |
seeds |
[type] |
[description] |
required |
from_comm(comm, **loader_args)
classmethod
¶
Initialize an Analysis object from a community object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
comm |
community |
Community to extract data. |
required |
Returns:
Type | Description |
---|---|
Analysis |
An Analysis object. |
from_hdf5(hdf5_file='', seed='', **loader_args)
classmethod
¶
Initialize an Analysis object from an hdf5 file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
if |
seed == "" |
seed = list(results["realizations"].keys())[0]file (str): Path to the hdf5 file, if not informed a prompt will be open for the user to select the file. |
required |
seed |
int |
An execution seed in the hdf5 file to be loaded, if not informed will load the first in the file. |
'' |
Returns:
Type | Description |
---|---|
Analysis |
An Analysis object. |
placement_statistics(self, placement, txtfile=None, filename=None, plot_hist=True, size=(5, 4), include_guests=False, seeds=None)
¶
Show placement visitation statistics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
placement |
int or str |
Placement id or placement name to show statistics. |
required |
txtfile |
str |
File name to save text output, if not informed will only show it. |
None |
plot_hist |
bool |
Plots a histogram of the number of visits. Defaults to True. |
True |
filename |
str |
File name to save the histogram, if not informed will only show the plot. |
None |
size |
tuple |
Size to generate the plot. Defaults to (5, 4). |
(5, 4) |
include_guests |
bool |
Includes guests as visitors. Defaults to False. |
False |
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
plot_age_group_histogram(self, data='infected', percentage=False, filename=None, size=(5, 4), title=None, seed=-1, close=True)
¶
Plots a specift count of particles per age group. Can only plot one seed.
Available counts:
infected
: number of infected particles.vaccinated
: number of vaccinated particles.deceased
: number of deceased particles.particles
: total number of particles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
str |
Type of count to plot. Defaults to "infected". |
'infected' |
percentage |
bool |
Y axis as a percentage. Defaults to False. |
False |
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size for the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_contact_matrix_age_group(self, filename=None, slice_rng=slice(1, None, None), size=(10, 4), title=None, seed=-1, close=True)
¶
Plot a contacts matrix per age group. Contacts are unique in a day, encounters are not (particle A can have multiple encounters with particle B in a single day, but only one contact).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
slice_rng |
slice |
Slice of days (steps?) to plot. Defaults to slice(1, None). |
slice(1, None, None) |
size |
tuple |
Size for the plot. Defaults to (10, 4). |
(10, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_diagnosed(self, seeds=None, cumulative=True, **plot_args)
¶
Plots the number of encounters.
Important
This plot uses the do_plot method, see plot_args to see all available arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
cumulative |
bool |
Plot the cumulative diagnostics curve as well. Defaults to True. |
True |
**plot_args |
kwargs |
Arguments for the do_plot method (see plot_args). |
{} |
plot_encounters(self, seeds=None, plot_per_day=True, **plot_args)
¶
Plots the number of encounters.
Important
This plot uses the do_plot method, see plot_args to see all available arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
plot_per_day |
bool |
Consolidate the data on a one day resolution. |
True |
**plot_args |
kwargs |
Arguments for the do_plot method (see plot_args). |
{} |
plot_encounters_age_group(self, filename=None, slice_rng=slice(1, None, None), size=(5, 4), title=None, seed=-1, close=True)
¶
Plots number of encounters per age group on a slice of time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
slice_rng |
slice |
Slice of (steps?) to plot. Defaults to slice(1, None). |
slice(1, None, None) |
size |
tuple |
Size for the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_encounters_matrix_age_group(self, filename=None, slice_rng=slice(1, None, None), size=(10, 4), title=None, seed=-1, close=True)
¶
Plot an encounters matrix per age group. Contacts are unique in a day, encounters are not (particle A can have multiple encounters with particle B in a single day, but only one contact).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
slice_rng |
slice |
Slice of days (steps?) to plot. Defaults to slice(1, None). |
slice(1, None, None) |
size |
tuple |
Size for the plot. Defaults to (10, 4). |
(10, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_homes_hist(self, data='Symptoms', bins=10, filename=None, size=(5, 4), title=None, seed=-1)
¶
Plots histograms of the percentage of particles on each category on all homes. Can only plot one seed.
Available data:
symptoms
: Plots percentages of mild symptomatic, severe symptomatic, asymptomatic and not infected;infections
: Plots percentages of Infected ans not infected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
str |
Data to be plotted, "Symptoms" or "Infections". Defaults to "Symptoms". |
'Symptoms' |
bins |
int |
Number of bins in the histogram. Defaults to 10. |
10 |
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size for the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
Exceptions:
Type | Description |
---|---|
RuntimeWarning |
Invalid data selected or data unavailible. |
plot_homes_infection_hist(self, filename=None, size=(5, 4), seed=-1, title=None, bins=10, close=True)
¶
Plots a histogram of the percentage of infection that occurred inside each home. Can only plot one seed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size to generate the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
bins |
int |
Number of bins in the histogram. Defaults to 100. |
10 |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_inf_probability(self, filename=None, seed=-1, bins=100, size=(5, 4), title=None, remove_zeros=False, close=True)
¶
Plot a histogram of the maximum infection probability of all particles. Can only plot one seed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
bins |
int |
Number of bins in the histogram. Defaults to 100. |
100 |
size |
tuple |
Size to generate the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
remove_zeros |
bool |
Ignore particles with infection probability equals to zero. Defaults to False. |
False |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_inf_source_symptoms(self, filename=None, seed=-1, hide_zeros=False, size=(5, 4), title=None, pie=True, close=True)
¶
Plot vector symptom data. Can only plot one seed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
hide_zeros |
bool |
Hide placements with no infections. Defaults to False. |
False |
size |
tuple |
Size to generate the plot. Defaults to (10, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_inf_tree(self, filename=None, size=(20, 20), seed=-1, color=None, title=None, close=True)
¶
Plots the infection tree. Can only plot one seed.
Available color markers:
* placement
: placement where the infection occurred.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size for the plot. Defaults to (20, 20). |
(20, 20) |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
color |
str |
A color marker. Defaults to None. |
None |
title |
str |
Title for the plot. Defaults to None. |
None |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_infection_placement(self, filename=None, seeds=None, size=(5, 4), skip=[], close=True, title=None)
¶
Plot infection placement data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size to generate the plot. Defaults to (10, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
skip |
list |
List of placements names to skip plotting. |
[] |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_isolation_percentage(self, filename=None, size=(5, 4), seeds=None, dates=True, start_day=None, end_day=None, title=None, events=False, events_type=0)
¶
Plot a isolation curve in time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size to generate the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
dates |
bool |
Use dates instead of days in the x axis. Defaults to True. |
True |
start_day |
float |
Plot only the interval from start_day. Defaults to 0. |
None |
end_day |
float |
Plot only the interval to end_day. Defaults to last day. |
None |
events |
bool |
Overlay simulation events on the plot. Defaults to False. |
False |
events_type |
int |
Type of logs to overlay as events. Defaults to MSG_EVENTS. |
0 |
plot_quarantine(self, seeds=None, **plot_args)
¶
Plots the number of encounters.
Important
This plot uses the do_plot method, see plot_args to see all available arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
**plot_args |
kwargs |
Arguments for the do_plot method (see plot_args). |
{} |
plot_R(self, seeds=None, **plot_args)
¶
plot_secondary_infections_hist(self, filename=None, size=(5, 4), title=None, seed=-1, close=True)
¶
Plot a secondary infections histogram. Can only plot one seed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size to generate the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_SEIR(self, seeds=None, **plot_args)
¶
Save a SEIR graph.
Important
This plot uses the do_plot method, see plot_args to see all available arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
**plot_args |
kwargs |
Arguments for the do_plot method (see plot_args). |
{} |
plot_SEIR_stack(self, filename=None, size=(5, 4), seed=-1, show_legend=True, dates=True, events_type=0, title=None)
¶
Save a stacked SEIR graph. Can only plot one seed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size to generate the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
dates |
bool |
Use dates instead of days in the x axis. Defaults to True. |
True |
show_legend |
bool |
Hides legends if False. Defaults to True. |
True |
plot_service_infections(self, filename=None, seeds=None, size=(10, 4), skip=[], close=True, title=None)
¶
Plots proportion of infections relating clients and workers inside each service
Returns:
Type | Description |
---|---|
|
Three graphs, the first telling the proportion of infection derived from workers and clients, the second from workers to workers and clients, and the third from clients to workers and clients |
PS: This code has been developed by Edmilson Roque - USP edmilson.roque.usp@gmail.com
plot_services_visitors(self, time_window='day', seeds=None, per_instance=False, **plot_args)
¶
Plots the mean number of visitors on services in an week, whole simulation or a day window of time.
Important
This plot uses the do_plot method, see plot_args to see all available arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_window |
str |
"week", "day" or "simulation". Defaults to "day". |
'day' |
per_instance |
bool |
If True will divide the number of visitors by the number of instances. Defaults to False. |
False |
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
plot_symptomatic_states(self, seeds=None, **plot_args)
¶
Plots the number of particles in each symptomatic state in time.
Important
This plot uses the do_plot method, see plot_args to see all available arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
**plot_args |
kwargs |
Arguments for the do_plot method (see plot_args). |
{} |
plot_symptoms(self, seeds=None, **plot_args)
¶
Plots the percentage of symptomatic and asymptomatic particles in time.
Important
This plot uses the do_plot method, see plot_args to see all available arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
**plot_args |
kwargs |
Arguments for the do_plot method (see plot_args). |
{} |
plot_time_between_hist(self, time_in=['time_infectious'], time_out=['time_recovered', 'time_dead'], bins=10, percentage=False, filename=None, size=(5, 4), title=None, seed=-1, close=True)
¶
Plot a histogram of the duration between two times saved in the infection tree for all particles. Can only plot one seed.
Available times:
time_exposed
time_infectious
time_activated
time_recovered
time_deceased
time_vaccinated
time_immune
time_quarantined
time_released_quarantine
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_in |
list |
A list of times to be accepted as a start time, if a particle has more than one the first in the list will be used. Defaults to ["time_infectious"]. |
['time_infectious'] |
time_out |
list |
A list of times to be accepted as a end time, if a particle has more than one the first in the list will be used. Defaults to ["time_recovered", "time_dead"]. |
['time_recovered', 'time_dead'] |
bins |
int |
Number of bins in the histogram. Defaults to 10. |
10 |
percentage |
bool |
Y axis as a percentage. Defaults to False. |
False |
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size for the plot. Defaults to (5, 4). |
(5, 4) |
title |
str |
Title to be printed on the plot. |
None |
seed |
str |
Seed to be plotted, if None will plot last loaded. |
-1 |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |
plot_total_infections_hist(self, filename=None, title=None, seeds=None, size=(5, 4), close=True)
¶
Plots a histogram of the total number of infections at the end of the simulation for all seeds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str |
File name to save the graph, if not informed will only show the plot. |
None |
size |
tuple |
Size for the plot. Defaults to (20, 20). |
(5, 4) |
seeds |
list |
List of seeds to plot, if None will plot all seeds available. |
None |
title |
str |
Title for the plot. Defaults to None. |
None |
close |
bool |
If False doesn't show, save or close the plot so that the user can add more information to plot using the plt attribute from the class. Defaults to False. |
True |