forked from paulvangentcom/python_corona_simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
115 lines (95 loc) · 4.14 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
'''
file that contains all configuration of the actual model run
'''
class Configuration():
__slots__ = [
#simulation variables
'verbose',#whether to print infections, recoveries and fatalities to the terminal
'simulation_steps',#total simulation steps performed
'tstep',#current simulation timestep
'save_data',#whether to dump data at end of simulation
'save_pop', #whether to save population matrix every 'save_pop_freq' timesteps
'save_pop_freq', #population data will be saved every 'n' timesteps. Default: 10
'save_pop_folder',#folder to write population timestep data to
'endif_no_infections' ,#whether to stop simulation if no infections remain
#world variables, defines where population can and cannot roam
'xbounds',
'ybounds' ,
#visualisation variables
'visualise' , #whether to visualise the simulation
'plot_mode' , #default or sir
#size of the simulated world in coordinates
'x_plot' ,
'y_plot',
'save_plot',
'plot_path' ,#folder where plots are saved to
'plot_style' ,#can be default, dark, ...
'colorblind_mode',
#if colorblind is enabled, set type of colorblindness
#available: deuteranopia, protanopia, tritanopia. defauld=deuteranopia
'colorblind_type',
'frame']
def __init__(self,
verbose = True,
simulation_steps = 10000,
tstep = 0,
save_data = False,
save_pop = False,
save_pop_freq = 10,
save_pop_folder = 'pop_data/' ,
endif_no_infections = True,
xbounds = [0.02, 0.498],
ybounds = [0.02, 0.498],
visualise = True ,
plot_mode = 'sir',
x_plot = [0.02, .498] ,
y_plot = [0.02, .498],
save_plot = False,
plot_path = 'render/' ,
plot_style = 'default' ,
colorblind_mode = False,
colorblind_type = 'deuteranopia',
frame = 0):
#simulation variables
self.verbose = verbose
self.simulation_steps = simulation_steps
self.tstep = tstep
self.save_data = save_data
self.save_pop = save_pop
self.save_pop_freq = save_pop_freq
self.save_pop_folder = save_pop_folder
self.endif_no_infections =endif_no_infections
self.xbounds = xbounds
self.ybounds = ybounds
self.visualise = visualise
self.plot_mode = plot_mode
self.x_plot = x_plot
self.y_plot =y_plot
self.save_plot = save_plot
self.plot_path = plot_path
self.plot_style = plot_style
self.colorblind_mode = colorblind_mode
self.colorblind_type = colorblind_type
self.frame = frame
def get_palette(self):
'''returns appropriate color palette
Uses config.plot_style to determine which palette to pick,
and changes palette to colorblind mode (config.colorblind_mode)
and colorblind type (config.colorblind_type) if required.
Palette colors are based on
https://venngage.com/blog/color-blind-friendly-palette/
'''
#palette colors are: [healthy, infected, immune, dead]
palettes = {'regular': {'default': ['gray', 'red', 'green', 'black'],
'dark': ['#404040', '#ff0000', '#00ff00', '#000000']},
'deuteranopia': {'default': ['gray', '#a50f15', '#08519c', 'black'],
'dark': ['#404040', '#fcae91', '#6baed6', '#000000']},
'protanopia': {'default': ['gray', '#a50f15', '08519c', 'black'],
'dark': ['#404040', '#fcae91', '#6baed6', '#000000']},
'tritanopia': {'default': ['gray', '#a50f15', '08519c', 'black'],
'dark': ['#404040', '#fcae91', '#6baed6', '#000000']}
}
if self.colorblind_mode:
return palettes[self.colorblind_type.lower()][self.plot_style]
else:
return palettes['regular'][self.plot_style]