plotting_pairsplot_flu.py

 1"""
 2Created on 20 sep. 2011
 3
 4.. codeauthor:: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
 5"""
 6
 7import matplotlib.pyplot as plt
 8import numpy as np
 9
10from ema_workbench import load_results, ema_logging
11from ema_workbench.analysis.pairs_plotting import pairs_lines, pairs_scatter, pairs_density
12
13ema_logging.log_to_stderr(level=ema_logging.DEFAULT_LEVEL)
14
15# load the data
16fh = "./data/1000 flu cases no policy.tar.gz"
17experiments, outcomes = load_results(fh)
18
19# transform the results to the required format
20# that is, we want to know the max peak and the casualties at the end of the
21# run
22tr = {}
23
24# get time and remove it from the dict
25time = outcomes.pop("TIME")
26
27for key, value in outcomes.items():
28    if key == "deceased_population_region_1":
29        tr[key] = value[:, -1]  # we want the end value
30    else:
31        # we want the maximum value of the peak
32        max_peak = np.max(value, axis=1)
33        tr["max peak"] = max_peak
34
35        # we want the time at which the maximum occurred
36        # the code here is a bit obscure, I don't know why the transpose
37        # of value is needed. This however does produce the appropriate results
38        logical = value.T == np.max(value, axis=1)
39        tr["time of max"] = time[logical.T]
40
41pairs_scatter(experiments, tr, filter_scalar=False)
42pairs_lines(experiments, outcomes)
43pairs_density(experiments, tr, filter_scalar=False)
44plt.show()