-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotparsers.py
More file actions
208 lines (172 loc) · 8.86 KB
/
Copy pathplotparsers.py
File metadata and controls
208 lines (172 loc) · 8.86 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
## some parsing functions to take the outputs from our sweeps
## needs to be a dictionary of levels
import numpy as np
def pldata(runs,lvl,steps=50):
decomp_means = []
decomp_stds = []
endo_means = []
endo_stds = []
trees_means = []
inf_trees_means = []
inf_trees_stds = []
despo_means = []
despo_stds = []
espo_means = []
espo_stds = []
for j in range(steps): ## for all 50 time steps
datime = [] ## decomposer abundances for a particular timestep, all 100 runs
eatime = [] ## endophyte abundances for a particular timestep, all 100 runs
inf_trees = [] ## num of infected trees for a particular timestep, all 100 runs
trees = [] ## num of trees for a particular timestep, all 100 runs
despo = [] ## num of infected trees for a particular timestep, all 100 runs
espo = [] ## num of infected trees for a particular timestep, all 100 runs
for i in runs[lvl]: ## for all the 100 sims from disp=j
datime.append(i.Decomp_subs[j]) ## add this simulation's decomps total to the list
eatime.append(i.Endo_subs[j]) ## add this simulation's endophyte total to the list
if 'Trees' in i.columns:
trees.append(i.Trees[j]) ## add this simulation's endophyte total to the list
else: trees.append([0])
inf_trees.append(i.Infected_trees[j]) ## add this simulation's endophyte total to the list
despo.append(i.decompspor_count[j]) ## add this simulation's endophyte total to the list
espo.append(i.endospor_count[j]) ## add this simulation's endophyte total to the list
## create the time series of means and stdevs:
decomp_means.append(np.mean(datime))
decomp_stds.append(np.std(datime))
endo_means.append(np.mean(eatime))
endo_stds.append(np.std(eatime))
trees_means.append(np.mean(trees))
inf_trees_means.append(np.mean(inf_trees))
inf_trees_stds.append(np.std(inf_trees))
despo_means.append(np.mean(despo))
despo_stds.append(np.std(despo))
espo_means.append(np.mean(espo))
espo_stds.append(np.std(espo))
## decomp error zone:
decomp_updev = np.array(decomp_means) + np.array(decomp_stds) ## add error
decomp_updev[decomp_updev < 0] = 0 ## get rid of negatives
decomp_downdev = np.array(decomp_means) - np.array(decomp_stds) ## sub error
decomp_downdev[decomp_downdev < 0] = 0 ## get rid of negatives
## endo error zone:
endo_updev = np.array(endo_means) + np.array(endo_stds) ## add error
endo_updev[endo_updev < 0] = 0 ## get rid of negatives
endo_downdev = np.array(endo_means) - np.array(endo_stds) ## sub error
endo_downdev[endo_downdev < 0] = 0 ## get rid of negatives
## inf_trees error zone:
inf_trees_updev = np.array(inf_trees_means) + np.array(inf_trees_stds) ## add error
inf_trees_updev[inf_trees_updev < 0] = 0 ## get rid of negatives
inf_trees_downdev = np.array(inf_trees_means) - np.array(inf_trees_stds) ## sub error
inf_trees_downdev[inf_trees_downdev < 0] = 0 ## get rid of negatives
## despo error zone:
despo_updev = np.array(despo_means) + np.array(despo_stds) ## add error
despo_updev[despo_updev < 0] = 0 ## get rid of negatives
despo_downdev = np.array(despo_means) - np.array(despo_stds) ## sub error
despo_downdev[despo_downdev < 0] = 0 ## get rid of negatives
## espo error zone:
espo_updev = np.array(espo_means) + np.array(espo_stds) ## add error
espo_updev[espo_updev < 0] = 0 ## get rid of negatives
espo_downdev = np.array(espo_means) - np.array(espo_stds) ## sub error
espo_downdev[espo_downdev < 0] = 0 ## get rid of negatives
## store it in a dictionary:
pltdata = {'decomp_means':decomp_means,
'decomp_updev':decomp_updev,
'decomp_downdev':decomp_downdev,
'endo_means':endo_means,
'endo_updev':endo_updev,
'endo_downdev':endo_downdev,
'trees_means':trees_means,
'inf_trees_means':inf_trees_means,
'inf_trees_updev':inf_trees_updev,
'inf_trees_downdev':inf_trees_downdev,
'despo_means':despo_means,
'despo_updev':despo_updev,
'despo_downdev':despo_downdev,
'espo_means':espo_means,
'espo_updev':espo_updev,
'espo_downdev':espo_downdev,
}
return(pltdata)
## can we do the above, with a single level list of simulation dataframes?
def pldata_single(runs,steps=50):
decomp_means = []
decomp_stds = []
endo_means = []
endo_stds = []
trees_means = []
inf_trees_means = []
inf_trees_stds = []
despo_means = []
despo_stds = []
espo_means = []
espo_stds = []
for j in range(steps): ## for all 50 time steps
datime = [] ## decomposer abundances for a particular timestep, all 100 runs
eatime = [] ## endophyte abundances for a particular timestep, all 100 runs
trees = [] ## num of trees for a particular timestep, all 100 runs
inf_trees = [] ## num of infected trees for a particular timestep, all 100 runs
despo = [] ## num of infected trees for a particular timestep, all 100 runs
espo = [] ## num of infected trees for a particular timestep, all 100 runs
for i in runs: ## for all the 100 sims from disp=j
datime.append(i.Decomp_subs[j]) ## add this simulation's decomps total to the list
eatime.append(i.Endo_subs[j]) ## add this simulation's endophyte total to the list
if 'Trees' in i.columns:
trees.append(i.Trees[j]) ## add this simulation's endophyte total to the list
else: trees.append(0)
inf_trees.append(i.Infected_trees[j]) ## add this simulation's endophyte total to the list
despo.append(i.decompspor_count[j]) ## add this simulation's endophyte total to the list
espo.append(i.endospor_count[j]) ## add this simulation's endophyte total to the list
## create the time series of means and stdevs:
decomp_means.append(np.mean(datime))
decomp_stds.append(np.std(datime))
endo_means.append(np.mean(eatime))
endo_stds.append(np.std(eatime))
trees_means.append(np.mean(trees))
inf_trees_means.append(np.mean(inf_trees))
inf_trees_stds.append(np.std(inf_trees))
despo_means.append(np.mean(despo))
despo_stds.append(np.std(despo))
espo_means.append(np.mean(espo))
espo_stds.append(np.std(espo))
## decomp error zone:
decomp_updev = np.array(decomp_means) + np.array(decomp_stds) ## add error
decomp_updev[decomp_updev < 0] = 0 ## get rid of negatives
decomp_downdev = np.array(decomp_means) - np.array(decomp_stds) ## sub error
decomp_downdev[decomp_downdev < 0] = 0 ## get rid of negatives
## endo error zone:
endo_updev = np.array(endo_means) + np.array(endo_stds) ## add error
endo_updev[endo_updev < 0] = 0 ## get rid of negatives
endo_downdev = np.array(endo_means) - np.array(endo_stds) ## sub error
endo_downdev[endo_downdev < 0] = 0 ## get rid of negatives
## inf_trees error zone:
inf_trees_updev = np.array(inf_trees_means) + np.array(inf_trees_stds) ## add error
inf_trees_updev[inf_trees_updev < 0] = 0 ## get rid of negatives
inf_trees_downdev = np.array(inf_trees_means) - np.array(inf_trees_stds) ## sub error
inf_trees_downdev[inf_trees_downdev < 0] = 0 ## get rid of negatives
## despo error zone:
despo_updev = np.array(despo_means) + np.array(despo_stds) ## add error
despo_updev[despo_updev < 0] = 0 ## get rid of negatives
despo_downdev = np.array(despo_means) - np.array(despo_stds) ## sub error
despo_downdev[despo_downdev < 0] = 0 ## get rid of negatives
## espo error zone:
espo_updev = np.array(espo_means) + np.array(espo_stds) ## add error
espo_updev[espo_updev < 0] = 0 ## get rid of negatives
espo_downdev = np.array(espo_means) - np.array(espo_stds) ## sub error
espo_downdev[espo_downdev < 0] = 0 ## get rid of negatives
## store it in a dictionary:
pltdata = {'decomp_means':decomp_means,
'decomp_updev':decomp_updev,
'decomp_downdev':decomp_downdev,
'endo_means':endo_means,
'endo_updev':endo_updev,
'endo_downdev':endo_downdev,
'trees_means':trees_means,
'inf_trees_means':inf_trees_means,
'inf_trees_updev':inf_trees_updev,
'inf_trees_downdev':inf_trees_downdev,
'despo_means':despo_means,
'despo_updev':despo_updev,
'despo_downdev':despo_downdev,
'espo_means':espo_means,
'espo_updev':espo_updev,
'espo_downdev':espo_downdev,
}
return(pltdata)