sid.visualize_simulation_results

Module Contents

Functions

visualize_simulation_results(data, outdir_path, infection_vars, background_vars, window_length=7)

Visualize the results one or more simulation results.

_create_folders(outdir_path, background_vars)

_create_rates_for_all_data(datasets, infection_vars, background_vars, window_length)

Create the statistics for each dataset and merge them into one dataset.

_load_data(df_or_path, keep_vars, i)

_create_statistics(df, infection_vars, background_vars, window_length)

Calculate the infection rates and reproduction numbers for each date.

_prepend_column_level(df, key, name)

_create_rate_plots(rates, colors, title)

Plot all rates for a single background variable

_plot_rates(rates, title, color, y_range)

Plot the rates over time.

_export_plots_and_layout(title, plots, outdir_path)

Save all plots as png and the layout as html.

_style(p)

_nice_str(s)

visualize_simulation_results(data, outdir_path, infection_vars, background_vars, window_length=7)[source]

Visualize the results one or more simulation results.

Parameters
  • data (str, pandas.DataFrame, Path, list) – list of paths to the pickled simulation results.

  • outdir_path (path) – path to the folder where to save the results. Careful, all contents are removed when the function is called.

  • infection_vars (list) – list of infection rates to plot

  • background_vars (list) – list of background variables by whose value to group the results. Have to be present in all simulation results.

  • window_length (int) – How many dates to use for the reproduction numbers.

_create_folders(outdir_path, background_vars)[source]
_create_rates_for_all_data(datasets, infection_vars, background_vars, window_length)[source]

Create the statistics for each dataset and merge them into one dataset.

Parameters
  • datasets (list) – list of str, Paths to pickled DataFrames or pd.DataFrames.

  • infection_vars (list) – list of infection rates to plot

  • background_vars (list) – list of background variables by whose value to group the results. Have to be present in all simulation results.

  • window_length (int) – How many dates to use for the reproduction numbers.

rates (pandas.DataFrame): DataFrame with the dates as index.

The columns are a MultiIndex with four levels: The outermost is the “bg_var” (“general” for the overall rate). The next is the “rate” (e.g. the infectious rate or r zero), then “bg_value”, the value of the background variable and last “data_id”.

_load_data(df_or_path, keep_vars, i)[source]
_create_statistics(df, infection_vars, background_vars, window_length)[source]

Calculate the infection rates and reproduction numbers for each date.

Parameters
  • df (pandas.DataFrame) – The simulation results.

  • infection_vars (list) – list of infection rates to plot

  • background_vars (list) – list of background variables by whose value to group the results. Have to be present in all simulation results.

  • window_length (int) – How many dates to use for the reproduction numbers.

Returns

DataFrame with the statistics of one simulation run.

The index are the dates. The columns are a MultiIndex with three levels: The outermost is the “bg_var” (“general” for the overall rate). The next is the “bg_value”, the last is the “rate” (e.g. the infectious rate or r zero).

Return type

rates (pandas.DataFrame)

_prepend_column_level(df, key, name)[source]
_create_rate_plots(rates, colors, title)[source]

Plot all rates for a single background variable

Parameters
  • rates (pandas.DataFrame) – DataFrame with the dates as index. The columns are a MultiIndex with three levels: The outermost is the variable name (e.g. infectious or r_zero). The next are the values the background variable can take, the last “data_id”.

  • colors (list) – list of colors to use.

  • title (str) – the plot title will be the name of the rate plus this string.

Returns

list of bokeh plots.

Return type

plots (list)

_plot_rates(rates, title, color, y_range)[source]

Plot the rates over time.

Parameters
  • rates (DataFrame) – the index are the x values, the values the y values. Every column is plotted as a separate line.

  • color (str) – color.

  • title (str) – plot title.

  • y_range (tuple or None) – range of the y axis.

Returns

p (bokeh figure)

_export_plots_and_layout(title, plots, outdir_path)[source]

Save all plots as png and the layout as html.

Parameters
  • title (bokeh.Div) – title element.

  • plots (list) – list of bokeh plots

  • outdir_path (pathlib.Path) – base path to which to append the plot name to build the path where to save each plot.

_style(p)[source]
_nice_str(s)[source]