5
|
1 #!/usr/bin/env Rscript
|
|
2
|
|
3 suppressPackageStartupMessages(library("optparse"))
|
|
4
|
|
5 option_list <- list(
|
6
|
6 make_option(c("--adult_mortality"), action="store", dest="adult_mortality", type="integer", help="Adjustment rate for adult mortality"),
|
|
7 make_option(c("--adult_accumulation"), action="store", dest="adult_accumulation", type="integer", help="Adjustment of degree-days accumulation (old nymph->adult)"),
|
|
8 make_option(c("--egg_mortality"), action="store", dest="egg_mortality", type="integer", help="Adjustment rate for egg mortality"),
|
|
9 make_option(c("--input"), action="store", dest="input", help="Temperature data for selected location"),
|
|
10 make_option(c("--insect"), action="store", dest="insect", help="Insect name"),
|
|
11 make_option(c("--insects_per_replication"), action="store", dest="insects_per_replication", type="integer", help="Number of insects with which to start each replication"),
|
10
|
12 make_option(c("--life_stages"), action="store", dest="life_stages", help="Selected life stages for plotting"),
|
|
13 make_option(c("--life_stages_adult"), action="store", dest="life_stages_adult", default=NULL, help="Adult life stages for plotting"),
|
16
|
14 make_option(c("--life_stages_nymph"), action="store", dest="life_stages_nymph", default=NULL, help="Nymph life stages for plotting"),
|
6
|
15 make_option(c("--location"), action="store", dest="location", help="Selected location"),
|
|
16 make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"),
|
|
17 make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"),
|
27
|
18 make_option(c("--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"),
|
6
|
19 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"),
|
|
20 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"),
|
|
21 make_option(c("--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"),
|
|
22 make_option(c("--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"),
|
10
|
23 make_option(c("--plot_generations_separately"), action="store", dest="plot_generations_separately", help="Plot Plot P, F1 and F2 as separate lines or pool across them"),
|
|
24 make_option(c("--plot_std_error"), action="store", dest="plot_std_error", help="Plot Standard error"),
|
27
|
25 make_option(c("--replications"), action="store", dest="replications", type="integer", help="Number of replications"),
|
6
|
26 make_option(c("--young_nymph_accumulation"), action="store", dest="young_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (egg->young nymph)")
|
5
|
27 )
|
|
28
|
8
|
29 parser <- OptionParser(usage="%prog [options] file", option_list=option_list);
|
|
30 args <- parse_args(parser, positional_arguments=TRUE);
|
|
31 opt <- args$options;
|
5
|
32
|
27
|
33 add_daylight_length = function(temperature_data_frame, num_rows) {
|
5
|
34 # Return a vector of daylight length (photoperido profile) for
|
|
35 # the number of days specified in the input temperature data
|
|
36 # (from Forsythe 1995).
|
8
|
37 p = 0.8333;
|
|
38 latitude = temperature_data_frame$LATITUDE[1];
|
|
39 daylight_length_vector = NULL;
|
5
|
40 for (i in 1:num_rows) {
|
|
41 # Get the day of the year from the current row
|
|
42 # of the temperature data for computation.
|
8
|
43 doy = temperature_data_frame$DOY[i];
|
|
44 theta = 0.2163108 + 2 * atan(0.9671396 * tan(0.00860 * (doy - 186)));
|
|
45 phi = asin(0.39795 * cos(theta));
|
5
|
46 # Compute the length of daylight for the day of the year.
|
8
|
47 darkness_length = 24 / pi * acos((sin(p * pi / 180) + sin(latitude * pi / 180) * sin(phi)) / (cos(latitude * pi / 180) * cos(phi)));
|
|
48 daylight_length_vector[i] = 24 - darkness_length;
|
5
|
49 }
|
|
50 # Append daylight_length_vector as a new column to temperature_data_frame.
|
27
|
51 temperature_data_frame = append_vector(temperature_data_frame, daylight_length_vector, "DAYLEN");
|
8
|
52 return(temperature_data_frame);
|
5
|
53 }
|
|
54
|
27
|
55 append_vector = function(data_frame, vec, new_column_name) {
|
|
56 num_columns = dim(data_frame)[2];
|
|
57 current_column_names = colnames(data_frame);
|
|
58 # Append vector vec as a new column to data_frame.
|
|
59 data_frame[,num_columns+1] = vec;
|
|
60 # Reset the column names with the additional column for later access.
|
|
61 colnames(data_frame) = append(current_column_names, new_column_name);
|
|
62 return(data_frame);
|
|
63 }
|
|
64
|
19
|
65 get_file_path = function(life_stage, base_name, life_stage_nymph=NULL, life_stage_adult=NULL) {
|
|
66 if (!is.null(life_stage_nymph)) {
|
|
67 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph);
|
|
68 file_name = paste(lsi, tolower(life_stage_nymph), base_name, sep="_");
|
|
69 } else if (!is.null(life_stage_adult)) {
|
|
70 lsi = get_life_stage_index(life_stage, life_stage_adult=life_stage_adult);
|
|
71 file_name = paste(lsi, tolower(life_stage_adult), base_name, sep="_");
|
|
72 } else {
|
|
73 lsi = get_life_stage_index(life_stage);
|
|
74 file_name = paste(lsi, base_name, sep="_");
|
|
75 }
|
34
|
76 file_path = paste("output_plots_dir", file_name, sep="/");
|
19
|
77 return(file_path);
|
|
78 }
|
|
79
|
18
|
80 get_life_stage_index = function(life_stage, life_stage_nymph=NULL, life_stage_adult=NULL) {
|
|
81 # Name collection elements so that they
|
|
82 # are displayed in logical order.
|
|
83 if (life_stage=="Egg") {
|
|
84 lsi = "01";
|
|
85 } else if (life_stage=="Nymph") {
|
|
86 if (life_stage_nymph=="Young") {
|
|
87 lsi = "02";
|
|
88 } else if (life_stage_nymph=="Old") {
|
|
89 lsi = "03";
|
|
90 } else if (life_stage_nymph=="Total") {
|
|
91 lsi="04";
|
|
92 }
|
|
93 } else if (life_stage=="Adult") {
|
|
94 if (life_stage_adult=="Pre-vittelogenic") {
|
|
95 lsi = "05";
|
|
96 } else if (life_stage_adult=="Vittelogenic") {
|
|
97 lsi = "06";
|
|
98 } else if (life_stage_adult=="Diapausing") {
|
|
99 lsi = "07";
|
|
100 } else if (life_stage_adult=="Total") {
|
|
101 lsi = "08";
|
|
102 }
|
|
103 } else if (life_stage=="Total") {
|
|
104 lsi = "09";
|
|
105 }
|
|
106 return(lsi);
|
|
107 }
|
|
108
|
20
|
109 get_mean_and_std_error = function(p_replications, f1_replications, f2_replications) {
|
|
110 # P mean.
|
|
111 p_m = apply(p_replications, 1, mean);
|
|
112 # P standard error.
|
|
113 p_se = apply(p_replications, 1, sd) / sqrt(opt$replications);
|
|
114 # F1 mean.
|
|
115 f1_m = apply(f1_replications, 1, mean);
|
|
116 # F1 standard error.
|
|
117 f1_se = apply(f1_replications, 1, sd) / sqrt(opt$replications);
|
|
118 # F2 mean.
|
|
119 f2_m = apply(f2_replications, 1, mean);
|
|
120 # F2 standard error.
|
|
121 f2_se = apply(f2_replications, 1, sd) / sqrt(opt$replications);
|
|
122 return(list(p_m, p_se, f1_m, f1_se, f2_m, f2_se))
|
|
123 }
|
|
124
|
5
|
125 get_temperature_at_hour = function(latitude, temperature_data_frame, row, num_days) {
|
8
|
126 # Base development threshold for Brown Marmorated Stink Bug
|
5
|
127 # insect phenology model.
|
8
|
128 threshold = 14.17;
|
5
|
129 # Minimum temperature for current row.
|
8
|
130 curr_min_temp = temperature_data_frame$TMIN[row];
|
5
|
131 # Maximum temperature for current row.
|
8
|
132 curr_max_temp = temperature_data_frame$TMAX[row];
|
5
|
133 # Mean temperature for current row.
|
8
|
134 curr_mean_temp = 0.5 * (curr_min_temp + curr_max_temp);
|
5
|
135 # Initialize degree day accumulation
|
8
|
136 averages = 0;
|
6
|
137 if (curr_max_temp < threshold) {
|
8
|
138 averages = 0;
|
5
|
139 }
|
|
140 else {
|
|
141 # Initialize hourly temperature.
|
8
|
142 T = NULL;
|
5
|
143 # Initialize degree hour vector.
|
8
|
144 dh = NULL;
|
5
|
145 # Daylight length for current row.
|
8
|
146 y = temperature_data_frame$DAYLEN[row];
|
5
|
147 # Darkness length.
|
8
|
148 z = 24 - y;
|
5
|
149 # Lag coefficient.
|
8
|
150 a = 1.86;
|
5
|
151 # Darkness coefficient.
|
8
|
152 b = 2.20;
|
5
|
153 # Sunrise time.
|
8
|
154 risetime = 12 - y / 2;
|
5
|
155 # Sunset time.
|
8
|
156 settime = 12 + y / 2;
|
|
157 ts = (curr_max_temp - curr_min_temp) * sin(pi * (settime - 5) / (y + 2 * a)) + curr_min_temp;
|
5
|
158 for (i in 1:24) {
|
|
159 if (i > risetime && i < settime) {
|
|
160 # Number of hours after Tmin until sunset.
|
8
|
161 m = i - 5;
|
|
162 T[i] = (curr_max_temp - curr_min_temp) * sin(pi * m / (y + 2 * a)) + curr_min_temp;
|
5
|
163 if (T[i] < 8.4) {
|
8
|
164 dh[i] = 0;
|
5
|
165 }
|
|
166 else {
|
8
|
167 dh[i] = T[i] - 8.4;
|
5
|
168 }
|
|
169 }
|
6
|
170 else if (i > settime) {
|
8
|
171 n = i - settime;
|
|
172 T[i] = curr_min_temp + (ts - curr_min_temp) * exp( - b * n / z);
|
5
|
173 if (T[i] < 8.4) {
|
8
|
174 dh[i] = 0;
|
5
|
175 }
|
|
176 else {
|
8
|
177 dh[i] = T[i] - 8.4;
|
5
|
178 }
|
|
179 }
|
|
180 else {
|
8
|
181 n = i + 24 - settime;
|
|
182 T[i] = curr_min_temp + (ts - curr_min_temp) * exp( - b * n / z);
|
5
|
183 if (T[i] < 8.4) {
|
8
|
184 dh[i] = 0;
|
5
|
185 }
|
|
186 else {
|
8
|
187 dh[i] = T[i] - 8.4;
|
5
|
188 }
|
|
189 }
|
|
190 }
|
8
|
191 averages = sum(dh) / 24;
|
5
|
192 }
|
6
|
193 return(c(curr_mean_temp, averages))
|
5
|
194 }
|
|
195
|
35
|
196 get_tick_index = function(index, last_tick, ticks, month_labels) {
|
|
197 # The R code tries hard not to draw overlapping tick labels, and so
|
|
198 # will omit labels where they would abut or overlap previously drawn
|
|
199 # labels. This can result in, for example, every other tick being
|
|
200 # labelled. We'll keep track of the last tick to make sure all of
|
|
201 # the month labels are displayed, and missing ticks are restricted
|
|
202 # to Sundays which have no labels anyway.
|
|
203 if (last_tick==0) {
|
|
204 return(length(ticks)+1);
|
|
205 }
|
|
206 last_saved_tick = ticks[[length(ticks)]];
|
|
207 if (index-last_saved_tick<6) {
|
|
208 last_saved_month = month_labels[[length(month_labels)]];
|
|
209 if (last_saved_month=="") {
|
|
210 # We're safe overwriting a tick
|
|
211 # with no label (i.e., a Sunday tick).
|
|
212 return(length(ticks));
|
|
213 } else {
|
|
214 # Don't eliminate a Month label.
|
|
215 return(NULL);
|
|
216 }
|
|
217 }
|
|
218 return(length(ticks)+1);
|
|
219 }
|
|
220
|
|
221 get_x_axis_ticks_and_labels = function(temperature_data_frame, num_rows) {
|
|
222 # Keep track of the years to see if spanning years.
|
|
223 month_labels = list();
|
|
224 ticks = list();
|
|
225 current_month_label = NULL;
|
|
226 last_tick = 0;
|
|
227 for (i in 1:num_rows) {
|
|
228 # Get the year and month from the date which
|
|
229 # has the format YYYY-MM-DD.
|
|
230 date = format(temperature_data_frame$DATE[i]);
|
|
231 # Get the month label.
|
|
232 items = strsplit(date, "-")[[1]];
|
|
233 month = items[2];
|
|
234 month_label = month.abb[as.integer(month)];
|
|
235 tick_index = get_tick_index(i, last_tick, ticks, month_labels)
|
|
236 if (!is.null(tick_index)) {
|
|
237 if (!identical(current_month_label, month_label)) {
|
|
238 # Add an x-axis tick for the month.
|
|
239 ticks[tick_index] = i;
|
|
240 month_labels[tick_index] = month_label;
|
|
241 current_month_label = month_label;
|
|
242 last_tick = i;
|
|
243 }
|
|
244 # Get the day.
|
|
245 day = weekdays(as.Date(date));
|
|
246 if (day=="Sunday") {
|
|
247 # Add an x-axis tick if we're on a Sunday.
|
|
248 ticks[tick_index] = i;
|
|
249 # Add a blank month label so it is not displayed.
|
|
250 month_labels[tick_index] = "";
|
|
251 last_tick = i;
|
|
252 }
|
|
253 }
|
|
254 }
|
|
255 return(list(ticks, month_labels));
|
|
256 }
|
|
257
|
6
|
258 mortality.adult = function(temperature) {
|
|
259 if (temperature < 12.7) {
|
8
|
260 mortality.probability = 0.002;
|
6
|
261 }
|
|
262 else {
|
8
|
263 mortality.probability = temperature * 0.0005 + 0.02;
|
6
|
264 }
|
|
265 return(mortality.probability)
|
5
|
266 }
|
|
267
|
|
268 mortality.egg = function(temperature) {
|
|
269 if (temperature < 12.7) {
|
8
|
270 mortality.probability = 0.8;
|
5
|
271 }
|
|
272 else {
|
8
|
273 mortality.probability = 0.8 - temperature / 40.0;
|
6
|
274 if (mortality.probability < 0) {
|
8
|
275 mortality.probability = 0.01;
|
5
|
276 }
|
|
277 }
|
6
|
278 return(mortality.probability)
|
5
|
279 }
|
|
280
|
|
281 mortality.nymph = function(temperature) {
|
|
282 if (temperature < 12.7) {
|
8
|
283 mortality.probability = 0.03;
|
5
|
284 }
|
|
285 else {
|
8
|
286 mortality.probability = temperature * 0.0008 + 0.03;
|
5
|
287 }
|
8
|
288 return(mortality.probability);
|
6
|
289 }
|
|
290
|
|
291 parse_input_data = function(input_file, num_rows) {
|
|
292 # Read in the input temperature datafile into a data frame.
|
8
|
293 temperature_data_frame = read.csv(file=input_file, header=T, strip.white=TRUE, sep=",");
|
|
294 num_columns = dim(temperature_data_frame)[2];
|
6
|
295 if (num_columns == 6) {
|
|
296 # The input data has the following 6 columns:
|
|
297 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX
|
|
298 # Set the column names for access when adding daylight length..
|
8
|
299 colnames(temperature_data_frame) = c("LATITUDE","LONGITUDE", "DATE", "DOY", "TMIN", "TMAX");
|
27
|
300 current_column_names = colnames(temperature_data_frame);
|
6
|
301 # Add a column containing the daylight length for each day.
|
27
|
302 temperature_data_frame = add_daylight_length(temperature_data_frame, num_rows);
|
6
|
303 }
|
8
|
304 return(temperature_data_frame);
|
5
|
305 }
|
|
306
|
34
|
307 render_chart = function(ticks, date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval,
|
20
|
308 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL,
|
|
309 life_stages_adult=NULL, life_stages_nymph=NULL) {
|
10
|
310 if (chart_type=="pop_size_by_life_stage") {
|
|
311 if (life_stage=="Total") {
|
|
312 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
313 legend_text = c("Egg", "Nymph", "Adult");
|
|
314 columns = c(4, 2, 1);
|
35
|
315 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=FALSE, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
10
|
316 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3);
|
|
317 lines(days, group2, lwd=2, lty=1, col=2);
|
|
318 lines(days, group3, lwd=2, lty=1, col=4);
|
35
|
319 axis(side=1, at=ticks, labels=date_labels, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
320 axis(side=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
10
|
321 if (plot_std_error=="yes") {
|
|
322 # Standard error for group.
|
|
323 lines(days, group+group_std_error, lty=2);
|
|
324 lines(days, group-group_std_error, lty=2);
|
|
325 # Standard error for group2.
|
|
326 lines(days, group2+group2_std_error, col=2, lty=2);
|
|
327 lines(days, group2-group2_std_error, col=2, lty=2);
|
|
328 # Standard error for group3.
|
|
329 lines(days, group3+group3_std_error, col=4, lty=2);
|
|
330 lines(days, group3-group3_std_error, col=4, lty=2);
|
|
331 }
|
|
332 } else {
|
|
333 if (life_stage=="Egg") {
|
|
334 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
335 legend_text = c(life_stage);
|
15
|
336 columns = c(4);
|
10
|
337 } else if (life_stage=="Nymph") {
|
16
|
338 stage = paste(life_stages_nymph, "Nymph Pop :", sep=" ");
|
10
|
339 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
16
|
340 legend_text = c(paste(life_stages_nymph, life_stage, sep=" "));
|
10
|
341 columns = c(2);
|
|
342 } else if (life_stage=="Adult") {
|
|
343 stage = paste(life_stages_adult, "Adult Pop", sep=" ");
|
|
344 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
345 legend_text = c(paste(life_stages_adult, life_stage, sep=" "));
|
|
346 columns = c(1);
|
|
347 }
|
35
|
348 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=FALSE, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
10
|
349 legend("topleft", legend_text, lty=c(1), col="black", cex=3);
|
35
|
350 axis(side=1, at=ticks, labels=date_labels, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
351 axis(side=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
10
|
352 if (plot_std_error=="yes") {
|
|
353 # Standard error for group.
|
|
354 lines(days, group+group_std_error, lty=2);
|
|
355 lines(days, group-group_std_error, lty=2);
|
|
356 }
|
|
357 }
|
|
358 } else if (chart_type=="pop_size_by_generation") {
|
|
359 if (life_stage=="Total") {
|
|
360 title_str = ": Total Pop by Gen :";
|
|
361 } else if (life_stage=="Egg") {
|
|
362 title_str = ": Egg Pop by Gen :";
|
|
363 } else if (life_stage=="Nymph") {
|
16
|
364 title_str = paste(":", life_stages_nymph, "Nymph Pop by Gen", ":", sep=" ");
|
10
|
365 } else if (life_stage=="Adult") {
|
|
366 title_str = paste(":", life_stages_adult, "Adult Pop by Gen", ":", sep=" ");
|
|
367 }
|
|
368 title = paste(insect, ": Reps", replications, title_str, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
8
|
369 legend_text = c("P", "F1", "F2");
|
|
370 columns = c(1, 2, 4);
|
36
|
371 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=FALSE, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
10
|
372 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3);
|
|
373 lines(days, group2, lwd=2, lty=1, col=2);
|
|
374 lines(days, group3, lwd=2, lty=1, col=4);
|
35
|
375 axis(side=1, at=ticks, labels=date_labels, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
376 axis(side=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
10
|
377 if (plot_std_error=="yes") {
|
|
378 # Standard error for group.
|
|
379 lines(days, group+group_std_error, lty=2);
|
|
380 lines(days, group-group_std_error, lty=2);
|
|
381 # Standard error for group2.
|
|
382 lines(days, group2+group2_std_error, col=2, lty=2);
|
|
383 lines(days, group2-group2_std_error, col=2, lty=2);
|
|
384 # Standard error for group3.
|
|
385 lines(days, group3+group3_std_error, col=4, lty=2);
|
|
386 lines(days, group3-group3_std_error, col=4, lty=2);
|
|
387 }
|
5
|
388 }
|
|
389 }
|
|
390
|
10
|
391 # Determine if we're plotting generations separately.
|
|
392 if (opt$plot_generations_separately=="yes") {
|
|
393 plot_generations_separately = TRUE;
|
|
394 } else {
|
|
395 plot_generations_separately = FALSE;
|
|
396 }
|
|
397 # Read the temperature data into a data frame.
|
8
|
398 temperature_data_frame = parse_input_data(opt$input, opt$num_days);
|
31
|
399 # Create copies of the temperature data for generations P, F1 and F2 if we're plotting generations separately.
|
|
400 if (plot_generations_separately) {
|
|
401 temperature_data_frame_P = data.frame(temperature_data_frame);
|
|
402 temperature_data_frame_F1 = data.frame(temperature_data_frame);
|
|
403 temperature_data_frame_F2 = data.frame(temperature_data_frame);
|
|
404 }
|
10
|
405 # Get the date labels for plots.
|
34
|
406 ticks_and_labels = get_x_axis_ticks_and_labels(temperature_data_frame, opt$num_days);
|
|
407 ticks = c(unlist(ticks_and_labels[1]));
|
|
408 date_labels = c(unlist(ticks_and_labels[2]));
|
10
|
409 # All latitude values are the same, so get the value for plots from the first row.
|
8
|
410 latitude = temperature_data_frame$LATITUDE[1];
|
20
|
411 # Determine the specified life stages for processing.
|
10
|
412 # Split life_stages into a list of strings for plots.
|
|
413 life_stages_str = as.character(opt$life_stages);
|
|
414 life_stages = strsplit(life_stages_str, ",")[[1]];
|
|
415 # Determine the data we need to generate for plotting.
|
|
416 process_eggs = FALSE;
|
|
417 process_nymphs = FALSE;
|
20
|
418 process_young_nymphs = FALSE;
|
|
419 process_old_nymphs = FALSE;
|
|
420 process_total_nymphs = FALSE;
|
10
|
421 process_adults = FALSE;
|
23
|
422 process_previttelogenic_adults = FALSE;
|
|
423 process_vittelogenic_adults = FALSE;
|
20
|
424 process_diapausing_adults = FALSE;
|
|
425 process_total_adults = FALSE;
|
10
|
426 for (life_stage in life_stages) {
|
|
427 if (life_stage=="Total") {
|
|
428 process_eggs = TRUE;
|
|
429 process_nymphs = TRUE;
|
|
430 process_adults = TRUE;
|
|
431 } else if (life_stage=="Egg") {
|
|
432 process_eggs = TRUE;
|
|
433 } else if (life_stage=="Nymph") {
|
|
434 process_nymphs = TRUE;
|
|
435 } else if (life_stage=="Adult") {
|
|
436 process_adults = TRUE;
|
|
437 }
|
|
438 }
|
20
|
439 if (process_nymphs) {
|
|
440 # Split life_stages_nymph into a list of strings for plots.
|
|
441 life_stages_nymph_str = as.character(opt$life_stages_nymph);
|
|
442 life_stages_nymph = strsplit(life_stages_nymph_str, ",")[[1]];
|
23
|
443 for (life_stage_nymph in life_stages_nymph) {
|
20
|
444 if (life_stage_nymph=="Young") {
|
|
445 process_young_nymphs = TRUE;
|
|
446 } else if (life_stage_nymph=="Old") {
|
|
447 process_old_nymphs = TRUE;
|
|
448 } else if (life_stage_nymph=="Total") {
|
|
449 process_total_nymphs = TRUE;
|
|
450 }
|
|
451 }
|
|
452 }
|
16
|
453 if (process_adults) {
|
|
454 # Split life_stages_adult into a list of strings for plots.
|
|
455 life_stages_adult_str = as.character(opt$life_stages_adult);
|
|
456 life_stages_adult = strsplit(life_stages_adult_str, ",")[[1]];
|
23
|
457 for (life_stage_adult in life_stages_adult) {
|
|
458 if (life_stage_adult=="Pre-vittelogenic") {
|
|
459 process_previttelogenic_adults = TRUE;
|
24
|
460 } else if (life_stage_adult=="Vittelogenic") {
|
23
|
461 process_vittelogenic_adults = TRUE;
|
20
|
462 } else if (life_stage_adult=="Diapausing") {
|
|
463 process_diapausing_adults = TRUE;
|
|
464 } else if (life_stage_adult=="Total") {
|
|
465 process_total_adults = TRUE;
|
|
466 }
|
|
467 }
|
16
|
468 }
|
6
|
469 # Initialize matrices.
|
10
|
470 if (process_eggs) {
|
|
471 Eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
472 }
|
23
|
473 if (process_young_nymphs | process_total_nymphs) {
|
10
|
474 YoungNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
20
|
475 }
|
23
|
476 if (process_old_nymphs | process_total_nymphs) {
|
10
|
477 OldNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
478 }
|
23
|
479 if (process_previttelogenic_adults | process_total_adults) {
|
|
480 Previttelogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
481 }
|
|
482 if (process_vittelogenic_adults | process_total_adults) {
|
24
|
483 Vittelogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
23
|
484 }
|
|
485 if (process_diapausing_adults | process_total_adults) {
|
10
|
486 Diapausing.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
487 }
|
8
|
488 newborn.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
489 adult.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
490 death.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
10
|
491 if (plot_generations_separately) {
|
|
492 # P is Parental, or overwintered adults.
|
|
493 P.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
494 # F1 is the first field-produced generation.
|
|
495 F1.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
496 # F2 is the second field-produced generation.
|
|
497 F2.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
498 if (process_eggs) {
|
|
499 P_eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
500 F1_eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
501 F2_eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
502 }
|
20
|
503 if (process_young_nymphs) {
|
|
504 P_young_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
505 F1_young_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
506 F2_young_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
507 }
|
|
508 if (process_old_nymphs) {
|
|
509 P_old_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
510 F1_old_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
511 F2_old_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
512 }
|
|
513 if (process_total_nymphs) {
|
|
514 P_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
515 F1_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
516 F2_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
10
|
517 }
|
23
|
518 if (process_previttelogenic_adults) {
|
|
519 P_previttelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
520 F1_previttelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
521 F2_previttelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
522 }
|
|
523 if (process_vittelogenic_adults) {
|
|
524 P_vittelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
25
|
525 F1_vittelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
23
|
526 F2_vittelogenic_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
527 }
|
|
528 if (process_diapausing_adults) {
|
|
529 P_diapausing_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
530 F1_diapausing_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
531 F2_diapausing_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
532 }
|
|
533 if (process_total_adults) {
|
|
534 P_total_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
535 F1_total_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
536 F2_total_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
10
|
537 }
|
|
538 }
|
|
539 # Total population.
|
8
|
540 population.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
5
|
541
|
6
|
542 # Process replications.
|
18
|
543 for (current_replication in 1:opt$replications) {
|
6
|
544 # Start with the user-defined number of insects per replication.
|
8
|
545 num_insects = opt$insects_per_replication;
|
6
|
546 # Generation, Stage, degree-days, T, Diapause.
|
8
|
547 vector.ini = c(0, 3, 0, 0, 0);
|
10
|
548 # Replicate to create a matrix where the columns are
|
|
549 # Generation, Stage, degree-days, T, Diapause and the
|
|
550 # rows are the initial number of insects per replication.
|
8
|
551 vector.matrix = rep(vector.ini, num_insects);
|
10
|
552 # Complete transposed matrix for the population, so now
|
|
553 # the rows are Generation, Stage, degree-days, T, Diapause
|
8
|
554 vector.matrix = base::t(matrix(vector.matrix, nrow=5));
|
5
|
555 # Time series of population size.
|
10
|
556 if (process_eggs) {
|
|
557 Eggs = rep(0, opt$num_days);
|
|
558 }
|
23
|
559 if (process_young_nymphs | process_total_nymphs) {
|
10
|
560 YoungNymphs = rep(0, opt$num_days);
|
23
|
561 }
|
|
562 if (process_old_nymphs | process_total_nymphs) {
|
10
|
563 OldNymphs = rep(0, opt$num_days);
|
|
564 }
|
23
|
565 if (process_previttelogenic_adults | process_total_adults) {
|
|
566 Previttelogenic = rep(0, opt$num_days);
|
|
567 }
|
|
568 if (process_vittelogenic_adults | process_total_adults) {
|
24
|
569 Vittelogenic = rep(0, opt$num_days);
|
23
|
570 }
|
|
571 if (process_diapausing_adults | process_total_adults) {
|
10
|
572 Diapausing = rep(0, opt$num_days);
|
|
573 }
|
8
|
574 N.newborn = rep(0, opt$num_days);
|
|
575 N.adult = rep(0, opt$num_days);
|
|
576 N.death = rep(0, opt$num_days);
|
|
577 overwintering_adult.population = rep(0, opt$num_days);
|
|
578 first_generation.population = rep(0, opt$num_days);
|
|
579 second_generation.population = rep(0, opt$num_days);
|
10
|
580 if (plot_generations_separately) {
|
|
581 # P is Parental, or overwintered adults.
|
|
582 # F1 is the first field-produced generation.
|
|
583 # F2 is the second field-produced generation.
|
|
584 if (process_eggs) {
|
|
585 P.egg = rep(0, opt$num_days);
|
|
586 F1.egg = rep(0, opt$num_days);
|
|
587 F2.egg = rep(0, opt$num_days);
|
|
588 }
|
20
|
589 if (process_young_nymphs) {
|
|
590 P.young_nymph = rep(0, opt$num_days);
|
|
591 F1.young_nymph = rep(0, opt$num_days);
|
|
592 F2.young_nymph = rep(0, opt$num_days);
|
|
593 }
|
|
594 if (process_old_nymphs) {
|
|
595 P.old_nymph = rep(0, opt$num_days);
|
|
596 F1.old_nymph = rep(0, opt$num_days);
|
|
597 F2.old_nymph = rep(0, opt$num_days);
|
|
598 }
|
|
599 if (process_total_nymphs) {
|
|
600 P.total_nymph = rep(0, opt$num_days);
|
|
601 F1.total_nymph = rep(0, opt$num_days);
|
|
602 F2.total_nymph = rep(0, opt$num_days);
|
10
|
603 }
|
23
|
604 if (process_previttelogenic_adults) {
|
|
605 P.previttelogenic_adult = rep(0, opt$num_days);
|
|
606 F1.previttelogenic_adult = rep(0, opt$num_days);
|
|
607 F2.previttelogenic_adult = rep(0, opt$num_days);
|
|
608 }
|
|
609 if (process_vittelogenic_adults) {
|
|
610 P.vittelogenic_adult = rep(0, opt$num_days);
|
|
611 F1.vittelogenic_adult = rep(0, opt$num_days);
|
|
612 F2.vittelogenic_adult = rep(0, opt$num_days);
|
|
613 }
|
|
614 if (process_diapausing_adults) {
|
|
615 P.diapausing_adult = rep(0, opt$num_days);
|
|
616 F1.diapausing_adult = rep(0, opt$num_days);
|
|
617 F2.diapausing_adult = rep(0, opt$num_days);
|
|
618 }
|
|
619 if (process_total_adults) {
|
|
620 P.total_adult = rep(0, opt$num_days);
|
|
621 F1.total_adult = rep(0, opt$num_days);
|
|
622 F2.total_adult = rep(0, opt$num_days);
|
10
|
623 }
|
|
624 }
|
8
|
625 total.population = NULL;
|
|
626 averages.day = rep(0, opt$num_days);
|
5
|
627 # All the days included in the input temperature dataset.
|
|
628 for (row in 1:opt$num_days) {
|
|
629 # Get the integer day of the year for the current row.
|
8
|
630 doy = temperature_data_frame$DOY[row];
|
5
|
631 # Photoperiod in the day.
|
8
|
632 photoperiod = temperature_data_frame$DAYLEN[row];
|
|
633 temp.profile = get_temperature_at_hour(latitude, temperature_data_frame, row, opt$num_days);
|
|
634 mean.temp = temp.profile[1];
|
|
635 averages.temp = temp.profile[2];
|
|
636 averages.day[row] = averages.temp;
|
5
|
637 # Trash bin for death.
|
8
|
638 death.vector = NULL;
|
5
|
639 # Newborn.
|
8
|
640 birth.vector = NULL;
|
5
|
641 # All individuals.
|
6
|
642 for (i in 1:num_insects) {
|
|
643 # Individual record.
|
8
|
644 vector.individual = vector.matrix[i,];
|
6
|
645 # Adjustment for late season mortality rate (still alive?).
|
5
|
646 if (latitude < 40.0) {
|
8
|
647 post.mortality = 1;
|
|
648 day.kill = 300;
|
5
|
649 }
|
|
650 else {
|
8
|
651 post.mortality = 2;
|
|
652 day.kill = 250;
|
5
|
653 }
|
6
|
654 if (vector.individual[2] == 0) {
|
5
|
655 # Egg.
|
8
|
656 death.probability = opt$egg_mortality * mortality.egg(mean.temp);
|
5
|
657 }
|
6
|
658 else if (vector.individual[2] == 1 | vector.individual[2] == 2) {
|
18
|
659 # Nymph.
|
8
|
660 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp);
|
5
|
661 }
|
6
|
662 else if (vector.individual[2] == 3 | vector.individual[2] == 4 | vector.individual[2] == 5) {
|
|
663 # Adult.
|
5
|
664 if (doy < day.kill) {
|
8
|
665 death.probability = opt$adult_mortality * mortality.adult(mean.temp);
|
5
|
666 }
|
|
667 else {
|
|
668 # Increase adult mortality after fall equinox.
|
8
|
669 death.probability = opt$adult_mortality * post.mortality * mortality.adult(mean.temp);
|
5
|
670 }
|
|
671 }
|
6
|
672 # Dependent on temperature and life stage?
|
8
|
673 u.d = runif(1);
|
6
|
674 if (u.d < death.probability) {
|
8
|
675 death.vector = c(death.vector, i);
|
6
|
676 }
|
5
|
677 else {
|
6
|
678 # End of diapause.
|
|
679 if (vector.individual[1] == 0 && vector.individual[2] == 3) {
|
27
|
680 # Overwintering adult (pre-vittelogenic).
|
6
|
681 if (photoperiod > opt$photoperiod && vector.individual[3] > 68 && doy < 180) {
|
5
|
682 # Add 68C to become fully reproductively matured.
|
|
683 # Transfer to vittelogenic.
|
8
|
684 vector.individual = c(0, 4, 0, 0, 0);
|
|
685 vector.matrix[i,] = vector.individual;
|
5
|
686 }
|
|
687 else {
|
27
|
688 # Add average temperature for current day.
|
8
|
689 vector.individual[3] = vector.individual[3] + averages.temp;
|
5
|
690 # Add 1 day in current stage.
|
8
|
691 vector.individual[4] = vector.individual[4] + 1;
|
|
692 vector.matrix[i,] = vector.individual;
|
5
|
693 }
|
|
694 }
|
6
|
695 if (vector.individual[1] != 0 && vector.individual[2] == 3) {
|
27
|
696 # Not overwintering adult (pre-vittelogenic).
|
8
|
697 current.gen = vector.individual[1];
|
6
|
698 if (vector.individual[3] > 68) {
|
5
|
699 # Add 68C to become fully reproductively matured.
|
|
700 # Transfer to vittelogenic.
|
8
|
701 vector.individual = c(current.gen, 4, 0, 0, 0);
|
|
702 vector.matrix[i,] = vector.individual;
|
5
|
703 }
|
|
704 else {
|
6
|
705 # Add average temperature for current day.
|
8
|
706 vector.individual[3] = vector.individual[3] + averages.temp;
|
5
|
707 # Add 1 day in current stage.
|
8
|
708 vector.individual[4] = vector.individual[4] + 1;
|
|
709 vector.matrix[i,] = vector.individual;
|
5
|
710 }
|
|
711 }
|
6
|
712 # Oviposition -- where population dynamics comes from.
|
|
713 if (vector.individual[2] == 4 && vector.individual[1] == 0 && mean.temp > 10) {
|
5
|
714 # Vittelogenic stage, overwintering generation.
|
6
|
715 if (vector.individual[4] == 0) {
|
5
|
716 # Just turned in vittelogenic stage.
|
8
|
717 num_insects.birth = round(runif(1, 2 + opt$min_clutch_size, 8 + opt$max_clutch_size));
|
5
|
718 }
|
|
719 else {
|
|
720 # Daily probability of birth.
|
8
|
721 p.birth = opt$oviposition * 0.01;
|
|
722 u1 = runif(1);
|
5
|
723 if (u1 < p.birth) {
|
8
|
724 num_insects.birth = round(runif(1, 2, 8));
|
5
|
725 }
|
|
726 }
|
6
|
727 # Add average temperature for current day.
|
8
|
728 vector.individual[3] = vector.individual[3] + averages.temp;
|
5
|
729 # Add 1 day in current stage.
|
8
|
730 vector.individual[4] = vector.individual[4] + 1;
|
|
731 vector.matrix[i,] = vector.individual;
|
6
|
732 if (num_insects.birth > 0) {
|
5
|
733 # Add new birth -- might be in different generations.
|
8
|
734 new.gen = vector.individual[1] + 1;
|
5
|
735 # Egg profile.
|
8
|
736 new.individual = c(new.gen, 0, 0, 0, 0);
|
|
737 new.vector = rep(new.individual, num_insects.birth);
|
5
|
738 # Update batch of egg profile.
|
8
|
739 new.vector = t(matrix(new.vector, nrow=5));
|
5
|
740 # Group with total eggs laid in that day.
|
8
|
741 birth.vector = rbind(birth.vector, new.vector);
|
5
|
742 }
|
|
743 }
|
6
|
744 # Oviposition -- for generation 1.
|
|
745 if (vector.individual[2] == 4 && vector.individual[1] == 1 && mean.temp > 12.5 && doy < 222) {
|
5
|
746 # Vittelogenic stage, 1st generation
|
6
|
747 if (vector.individual[4] == 0) {
|
5
|
748 # Just turned in vittelogenic stage.
|
8
|
749 num_insects.birth = round(runif(1, 2+opt$min_clutch_size, 8+opt$max_clutch_size));
|
5
|
750 }
|
|
751 else {
|
|
752 # Daily probability of birth.
|
8
|
753 p.birth = opt$oviposition * 0.01;
|
|
754 u1 = runif(1);
|
5
|
755 if (u1 < p.birth) {
|
8
|
756 num_insects.birth = round(runif(1, 2, 8));
|
5
|
757 }
|
|
758 }
|
6
|
759 # Add average temperature for current day.
|
8
|
760 vector.individual[3] = vector.individual[3] + averages.temp;
|
5
|
761 # Add 1 day in current stage.
|
8
|
762 vector.individual[4] = vector.individual[4] + 1;
|
|
763 vector.matrix[i,] = vector.individual;
|
6
|
764 if (num_insects.birth > 0) {
|
5
|
765 # Add new birth -- might be in different generations.
|
8
|
766 new.gen = vector.individual[1] + 1;
|
5
|
767 # Egg profile.
|
8
|
768 new.individual = c(new.gen, 0, 0, 0, 0);
|
|
769 new.vector = rep(new.individual, num_insects.birth);
|
5
|
770 # Update batch of egg profile.
|
8
|
771 new.vector = t(matrix(new.vector, nrow=5));
|
5
|
772 # Group with total eggs laid in that day.
|
8
|
773 birth.vector = rbind(birth.vector, new.vector);
|
5
|
774 }
|
|
775 }
|
6
|
776 # Egg to young nymph.
|
|
777 if (vector.individual[2] == 0) {
|
|
778 # Add average temperature for current day.
|
8
|
779 vector.individual[3] = vector.individual[3] + averages.temp;
|
6
|
780 if (vector.individual[3] >= (68+opt$young_nymph_accumulation)) {
|
|
781 # From egg to young nymph, degree-days requirement met.
|
8
|
782 current.gen = vector.individual[1];
|
5
|
783 # Transfer to young nymph stage.
|
8
|
784 vector.individual = c(current.gen, 1, 0, 0, 0);
|
5
|
785 }
|
|
786 else {
|
|
787 # Add 1 day in current stage.
|
8
|
788 vector.individual[4] = vector.individual[4] + 1;
|
5
|
789 }
|
8
|
790 vector.matrix[i,] = vector.individual;
|
5
|
791 }
|
6
|
792 # Young nymph to old nymph.
|
|
793 if (vector.individual[2] == 1) {
|
|
794 # Add average temperature for current day.
|
8
|
795 vector.individual[3] = vector.individual[3] + averages.temp;
|
6
|
796 if (vector.individual[3] >= (250+opt$old_nymph_accumulation)) {
|
|
797 # From young to old nymph, degree_days requirement met.
|
8
|
798 current.gen = vector.individual[1];
|
5
|
799 # Transfer to old nym stage.
|
8
|
800 vector.individual = c(current.gen, 2, 0, 0, 0);
|
5
|
801 if (photoperiod < opt$photoperiod && doy > 180) {
|
8
|
802 vector.individual[5] = 1;
|
5
|
803 } # Prepare for diapausing.
|
|
804 }
|
|
805 else {
|
|
806 # Add 1 day in current stage.
|
8
|
807 vector.individual[4] = vector.individual[4] + 1;
|
5
|
808 }
|
8
|
809 vector.matrix[i,] = vector.individual;
|
6
|
810 }
|
27
|
811 # Old nymph to adult: pre-vittelogenic or diapausing?
|
6
|
812 if (vector.individual[2] == 2) {
|
|
813 # Add average temperature for current day.
|
8
|
814 vector.individual[3] = vector.individual[3] + averages.temp;
|
6
|
815 if (vector.individual[3] >= (200+opt$adult_accumulation)) {
|
|
816 # From old to adult, degree_days requirement met.
|
8
|
817 current.gen = vector.individual[1];
|
6
|
818 if (vector.individual[5] == 0) {
|
|
819 # Previttelogenic.
|
8
|
820 vector.individual = c(current.gen, 3, 0, 0, 0);
|
5
|
821 }
|
|
822 else {
|
|
823 # Diapausing.
|
8
|
824 vector.individual = c(current.gen, 5, 0, 0, 1);
|
5
|
825 }
|
|
826 }
|
|
827 else {
|
|
828 # Add 1 day in current stage.
|
8
|
829 vector.individual[4] = vector.individual[4] + 1;
|
5
|
830 }
|
8
|
831 vector.matrix[i,] = vector.individual;
|
5
|
832 }
|
6
|
833 # Growing of diapausing adult (unimportant, but still necessary).
|
|
834 if (vector.individual[2] == 5) {
|
8
|
835 vector.individual[3] = vector.individual[3] + averages.temp;
|
|
836 vector.individual[4] = vector.individual[4] + 1;
|
|
837 vector.matrix[i,] = vector.individual;
|
5
|
838 }
|
|
839 } # Else if it is still alive.
|
|
840 } # End of the individual bug loop.
|
6
|
841
|
|
842 # Number of deaths.
|
8
|
843 num_insects.death = length(death.vector);
|
6
|
844 if (num_insects.death > 0) {
|
|
845 # Remove record of dead.
|
8
|
846 vector.matrix = vector.matrix[-death.vector,];
|
5
|
847 }
|
6
|
848 # Number of births.
|
8
|
849 num_insects.newborn = length(birth.vector[,1]);
|
|
850 vector.matrix = rbind(vector.matrix, birth.vector);
|
5
|
851 # Update population size for the next day.
|
8
|
852 num_insects = num_insects - num_insects.death + num_insects.newborn;
|
5
|
853
|
10
|
854 # Aggregate results by day. Due to multiple transpose calls
|
|
855 # on vector.matrix above, the columns of vector.matrix
|
|
856 # are now Generation, Stage, degree-days, T, Diapause,
|
|
857 if (process_eggs) {
|
|
858 # For egg population size, column 2 (Stage), must be 0.
|
|
859 Eggs[row] = sum(vector.matrix[,2]==0);
|
|
860 }
|
23
|
861 if (process_young_nymphs | process_total_nymphs) {
|
10
|
862 # For young nymph population size, column 2 (Stage) must be 1.
|
|
863 YoungNymphs[row] = sum(vector.matrix[,2]==1);
|
20
|
864 }
|
23
|
865 if (process_old_nymphs | process_total_nymphs) {
|
10
|
866 # For old nymph population size, column 2 (Stage) must be 2.
|
|
867 OldNymphs[row] = sum(vector.matrix[,2]==2);
|
|
868 }
|
23
|
869 if (process_previttelogenic_adults | process_total_adults) {
|
|
870 # For pre-vittelogenic population size, column 2 (Stage) must be 3.
|
|
871 Previttelogenic[row] = sum(vector.matrix[,2]==3);
|
|
872 }
|
|
873 if (process_vittelogenic_adults | process_total_adults) {
|
|
874 # For vittelogenic population size, column 2 (Stage) must be 4.
|
24
|
875 Vittelogenic[row] = sum(vector.matrix[,2]==4);
|
23
|
876 }
|
|
877 if (process_diapausing_adults | process_total_adults) {
|
10
|
878 # For diapausing population size, column 2 (Stage) must be 5.
|
|
879 Diapausing[row] = sum(vector.matrix[,2]==5);
|
|
880 }
|
5
|
881
|
6
|
882 # Newborn population size.
|
8
|
883 N.newborn[row] = num_insects.newborn;
|
6
|
884 # Adult population size.
|
8
|
885 N.adult[row] = sum(vector.matrix[,2]==3) + sum(vector.matrix[,2]==4) + sum(vector.matrix[,2]==5);
|
6
|
886 # Dead population size.
|
8
|
887 N.death[row] = num_insects.death;
|
6
|
888
|
8
|
889 total.population = c(total.population, num_insects);
|
6
|
890
|
10
|
891 # For overwintering adult (P) population
|
|
892 # size, column 1 (Generation) must be 0.
|
8
|
893 overwintering_adult.population[row] = sum(vector.matrix[,1]==0);
|
10
|
894 # For first field generation (F1) population
|
|
895 # size, column 1 (Generation) must be 1.
|
8
|
896 first_generation.population[row] = sum(vector.matrix[,1]==1);
|
10
|
897 # For second field generation (F2) population
|
|
898 # size, column 1 (Generation) must be 2.
|
8
|
899 second_generation.population[row] = sum(vector.matrix[,1]==2);
|
5
|
900
|
10
|
901 if (plot_generations_separately) {
|
|
902 if (process_eggs) {
|
18
|
903 # For egg life stage of generation P population size,
|
10
|
904 # column 1 (generation) is 0 and column 2 (Stage) is 0.
|
|
905 P.egg[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==0);
|
|
906 # For egg life stage of generation F1 population size,
|
|
907 # column 1 (generation) is 1 and column 2 (Stage) is 0.
|
|
908 F1.egg[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==0);
|
|
909 # For egg life stage of generation F2 population size,
|
|
910 # column 1 (generation) is 2 and column 2 (Stage) is 0.
|
|
911 F2.egg[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==0);
|
|
912 }
|
20
|
913 if (process_young_nymphs) {
|
|
914 # For young nymph life stage of generation P population
|
|
915 # size, the following combination is required:
|
|
916 # - column 1 (Generation) is 0 and column 2 (Stage) is 1 (Young nymph)
|
|
917 P.young_nymph[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==1);
|
|
918 # For young nymph life stage of generation F1 population
|
|
919 # size, the following combination is required:
|
|
920 # - column 1 (Generation) is 1 and column 2 (Stage) is 1 (Young nymph)
|
|
921 F1.young_nymph[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==1);
|
|
922 # For young nymph life stage of generation F2 population
|
|
923 # size, the following combination is required:
|
|
924 # - column 1 (Generation) is 2 and column 2 (Stage) is 1 (Young nymph)
|
|
925 F2.young_nymph[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==1);
|
|
926 }
|
|
927 if (process_old_nymphs) {
|
|
928 # For old nymph life stage of generation P population
|
|
929 # size, the following combination is required:
|
|
930 # - column 1 (Generation) is 0 and column 2 (Stage) is 2 (Old nymph)
|
|
931 P.old_nymph[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==2);
|
|
932 # For old nymph life stage of generation F1 population
|
|
933 # size, the following combination is required:
|
|
934 # - column 1 (Generation) is 1 and column 2 (Stage) is 2 (Old nymph)
|
|
935 F1.old_nymph[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==2);
|
|
936 # For old nymph life stage of generation F2 population
|
|
937 # size, the following combination is required:
|
|
938 # - column 1 (Generation) is 2 and column 2 (Stage) is 2 (Old nymph)
|
|
939 F2.old_nymph[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==2);
|
|
940 }
|
|
941 if (process_total_nymphs) {
|
|
942 # For total nymph life stage of generation P population
|
10
|
943 # size, one of the following combinations is required:
|
|
944 # - column 1 (Generation) is 0 and column 2 (Stage) is 1 (Young nymph)
|
|
945 # - column 1 (Generation) is 0 and column 2 (Stage) is 2 (Old nymph)
|
20
|
946 P.total_nymph[row] = sum((vector.matrix[,1]==0 & vector.matrix[,2]==1) | (vector.matrix[,1]==0 & vector.matrix[,2]==2));
|
|
947 # For total nymph life stage of generation F1 population
|
10
|
948 # size, one of the following combinations is required:
|
|
949 # - column 1 (Generation) is 1 and column 2 (Stage) is 1 (Young nymph)
|
|
950 # - column 1 (Generation) is 1 and column 2 (Stage) is 2 (Old nymph)
|
20
|
951 F1.total_nymph[row] = sum((vector.matrix[,1]==1 & vector.matrix[,2]==1) | (vector.matrix[,1]==1 & vector.matrix[,2]==2));
|
|
952 # For total nymph life stage of generation F2 population
|
10
|
953 # size, one of the following combinations is required:
|
|
954 # - column 1 (Generation) is 2 and column 2 (Stage) is 1 (Young nymph)
|
|
955 # - column 1 (Generation) is 2 and column 2 (Stage) is 2 (Old nymph)
|
20
|
956 F2.total_nymph[row] = sum((vector.matrix[,1]==2 & vector.matrix[,2]==1) | (vector.matrix[,1]==2 & vector.matrix[,2]==2));
|
10
|
957 }
|
23
|
958 if (process_previttelogenic_adults) {
|
|
959 # For previttelogenic adult life stage of generation P population
|
|
960 # size, the following combination is required:
|
|
961 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
962 P.previttelogenic_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==3);
|
|
963 # For previttelogenic adult life stage of generation F1 population
|
|
964 # size, the following combination is required:
|
|
965 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
966 F1.previttelogenic_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==3);
|
|
967 # For previttelogenic adult life stage of generation F2 population
|
|
968 # size, the following combination is required:
|
|
969 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
970 F2.previttelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==3);
|
|
971 }
|
|
972 if (process_vittelogenic_adults) {
|
|
973 # For vittelogenic adult life stage of generation P population
|
|
974 # size, the following combination is required:
|
24
|
975 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vittelogenic)
|
23
|
976 P.vittelogenic_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==4);
|
|
977 # For vittelogenic adult life stage of generation F1 population
|
|
978 # size, the following combination is required:
|
24
|
979 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vittelogenic)
|
23
|
980 F1.vittelogenic_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==4);
|
|
981 # For vittelogenic adult life stage of generation F2 population
|
|
982 # size, the following combination is required:
|
24
|
983 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vittelogenic)
|
23
|
984 F2.vittelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==4);
|
|
985 }
|
|
986 if (process_diapausing_adults) {
|
|
987 # For diapausing adult life stage of generation P population
|
|
988 # size, the following combination is required:
|
10
|
989 # - column 1 (Generation) is 0 and column 2 (Stage) is 5 (Diapausing)
|
23
|
990 P.diapausing_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==5);
|
|
991 # For diapausing adult life stage of generation F1 population
|
|
992 # size, the following combination is required:
|
|
993 # - column 1 (Generation) is 1 and column 2 (Stage) is 5 (Diapausing)
|
|
994 F1.diapausing_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==5);
|
|
995 # For diapausing adult life stage of generation F2 population
|
|
996 # size, the following combination is required:
|
|
997 # - column 1 (Generation) is 2 and column 2 (Stage) is 5 (Diapausing)
|
|
998 F2.diapausing_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==5);
|
|
999 }
|
|
1000 if (process_total_adults) {
|
|
1001 # For total adult life stage of generation P population
|
10
|
1002 # size, one of the following combinations is required:
|
23
|
1003 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
24
|
1004 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vittelogenic)
|
23
|
1005 # - column 1 (Generation) is 0 and column 2 (Stage) is 5 (Diapausing)
|
|
1006 P.total_adult[row] = sum((vector.matrix[,1]==0 & vector.matrix[,2]==3) | (vector.matrix[,1]==0 & vector.matrix[,2]==4) | (vector.matrix[,1]==0 & vector.matrix[,2]==5));
|
|
1007 # For total adult life stage of generation F1 population
|
|
1008 # size, one of the following combinations is required:
|
|
1009 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
24
|
1010 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vittelogenic)
|
10
|
1011 # - column 1 (Generation) is 1 and column 2 (Stage) is 5 (Diapausing)
|
23
|
1012 F1.total_adult[row] = sum((vector.matrix[,1]==1 & vector.matrix[,2]==3) | (vector.matrix[,1]==1 & vector.matrix[,2]==4) | (vector.matrix[,1]==1 & vector.matrix[,2]==5));
|
|
1013 # For total adult life stage of generation F2 population
|
10
|
1014 # size, one of the following combinations is required:
|
23
|
1015 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
24
|
1016 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vittelogenic)
|
10
|
1017 # - column 1 (Generation) is 2 and column 2 (Stage) is 5 (Diapausing)
|
23
|
1018 F2.total_adult[row] = sum((vector.matrix[,1]==2 & vector.matrix[,2]==3) | (vector.matrix[,1]==2 & vector.matrix[,2]==4) | (vector.matrix[,1]==2 & vector.matrix[,2]==5));
|
10
|
1019 }
|
|
1020 }
|
6
|
1021 } # End of days specified in the input temperature data.
|
5
|
1022
|
8
|
1023 averages.cum = cumsum(averages.day);
|
5
|
1024
|
6
|
1025 # Define the output values.
|
10
|
1026 if (process_eggs) {
|
18
|
1027 Eggs.replications[,current_replication] = Eggs;
|
10
|
1028 }
|
23
|
1029 if (process_young_nymphs | process_total_nymphs) {
|
18
|
1030 YoungNymphs.replications[,current_replication] = YoungNymphs;
|
20
|
1031 }
|
23
|
1032 if (process_old_nymphs | process_total_nymphs) {
|
18
|
1033 OldNymphs.replications[,current_replication] = OldNymphs;
|
10
|
1034 }
|
23
|
1035 if (process_previttelogenic_adults | process_total_adults) {
|
|
1036 Previttelogenic.replications[,current_replication] = Previttelogenic;
|
|
1037 }
|
|
1038 if (process_vittelogenic_adults | process_total_adults) {
|
24
|
1039 Vittelogenic.replications[,current_replication] = Vittelogenic;
|
23
|
1040 }
|
|
1041 if (process_diapausing_adults | process_total_adults) {
|
18
|
1042 Diapausing.replications[,current_replication] = Diapausing;
|
10
|
1043 }
|
18
|
1044 newborn.replications[,current_replication] = N.newborn;
|
|
1045 adult.replications[,current_replication] = N.adult;
|
|
1046 death.replications[,current_replication] = N.death;
|
10
|
1047 if (plot_generations_separately) {
|
|
1048 # P is Parental, or overwintered adults.
|
18
|
1049 P.replications[,current_replication] = overwintering_adult.population;
|
10
|
1050 # F1 is the first field-produced generation.
|
18
|
1051 F1.replications[,current_replication] = first_generation.population;
|
10
|
1052 # F2 is the second field-produced generation.
|
18
|
1053 F2.replications[,current_replication] = second_generation.population;
|
10
|
1054 if (process_eggs) {
|
18
|
1055 P_eggs.replications[,current_replication] = P.egg;
|
|
1056 F1_eggs.replications[,current_replication] = F1.egg;
|
|
1057 F2_eggs.replications[,current_replication] = F2.egg;
|
10
|
1058 }
|
20
|
1059 if (process_young_nymphs) {
|
|
1060 P_young_nymphs.replications[,current_replication] = P.young_nymph;
|
|
1061 F1_young_nymphs.replications[,current_replication] = F1.young_nymph;
|
|
1062 F2_young_nymphs.replications[,current_replication] = F2.young_nymph;
|
|
1063 }
|
|
1064 if (process_old_nymphs) {
|
|
1065 P_old_nymphs.replications[,current_replication] = P.old_nymph;
|
|
1066 F1_old_nymphs.replications[,current_replication] = F1.old_nymph;
|
|
1067 F2_old_nymphs.replications[,current_replication] = F2.old_nymph;
|
|
1068 }
|
|
1069 if (process_total_nymphs) {
|
|
1070 P_total_nymphs.replications[,current_replication] = P.total_nymph;
|
|
1071 F1_total_nymphs.replications[,current_replication] = F1.total_nymph;
|
|
1072 F2_total_nymphs.replications[,current_replication] = F2.total_nymph;
|
10
|
1073 }
|
23
|
1074 if (process_previttelogenic_adults) {
|
|
1075 P_previttelogenic_adults.replications[,current_replication] = P.previttelogenic_adult;
|
|
1076 F1_previttelogenic_adults.replications[,current_replication] = F1.previttelogenic_adult;
|
|
1077 F2_previttelogenic_adults.replications[,current_replication] = F2.previttelogenic_adult;
|
|
1078 }
|
|
1079 if (process_vittelogenic_adults) {
|
|
1080 P_vittelogenic_adults.replications[,current_replication] = P.vittelogenic_adult;
|
|
1081 F1_vittelogenic_adults.replications[,current_replication] = F1.vittelogenic_adult;
|
|
1082 F2_vittelogenic_adults.replications[,current_replication] = F2.vittelogenic_adult;
|
|
1083 }
|
|
1084 if (process_diapausing_adults) {
|
|
1085 P_diapausing_adults.replications[,current_replication] = P.diapausing_adult;
|
|
1086 F1_diapausing_adults.replications[,current_replication] = F1.diapausing_adult;
|
|
1087 F2_diapausing_adults.replications[,current_replication] = F2.diapausing_adult;
|
|
1088 }
|
|
1089 if (process_total_adults) {
|
|
1090 P_total_adults.replications[,current_replication] = P.total_adult;
|
|
1091 F1_total_adults.replications[,current_replication] = F1.total_adult;
|
|
1092 F2_total_adults.replications[,current_replication] = F2.total_adult;
|
10
|
1093 }
|
|
1094 }
|
18
|
1095 population.replications[,current_replication] = total.population;
|
|
1096 # End processing replications.
|
5
|
1097 }
|
|
1098
|
10
|
1099 if (process_eggs) {
|
|
1100 # Mean value for eggs.
|
|
1101 eggs = apply(Eggs.replications, 1, mean);
|
27
|
1102 temperature_data_frame = append_vector(temperature_data_frame, eggs, "EGG");
|
10
|
1103 # Standard error for eggs.
|
|
1104 eggs.std_error = apply(Eggs.replications, 1, sd) / sqrt(opt$replications);
|
27
|
1105 temperature_data_frame = append_vector(temperature_data_frame, eggs.std_error, "EGGSE");
|
10
|
1106 }
|
|
1107 if (process_nymphs) {
|
|
1108 # Calculate nymph populations for selected life stage.
|
16
|
1109 for (life_stage_nymph in life_stages_nymph) {
|
28
|
1110 if (life_stage_nymph=="Young") {
|
16
|
1111 # Mean value for young nymphs.
|
|
1112 young_nymphs = apply(YoungNymphs.replications, 1, mean);
|
27
|
1113 temperature_data_frame = append_vector(temperature_data_frame, young_nymphs, "YOUNGNYMPH");
|
16
|
1114 # Standard error for young nymphs.
|
|
1115 young_nymphs.std_error = apply(YoungNymphs.replications / sqrt(opt$replications), 1, sd);
|
27
|
1116 temperature_data_frame = append_vector(temperature_data_frame, young_nymphs.std_error, "YOUNGNYMPHSE");
|
18
|
1117 } else if (life_stage_nymph=="Old") {
|
16
|
1118 # Mean value for old nymphs.
|
|
1119 old_nymphs = apply(OldNymphs.replications, 1, mean);
|
27
|
1120 temperature_data_frame = append_vector(temperature_data_frame, old_nymphs, "OLDNYMPH");
|
16
|
1121 # Standard error for old nymphs.
|
|
1122 old_nymphs.std_error = apply(OldNymphs.replications / sqrt(opt$replications), 1, sd);
|
27
|
1123 temperature_data_frame = append_vector(temperature_data_frame, old_nymphs.std_error, "OLDNYMPHSE");
|
28
|
1124 } else if (life_stage_nymph=="Total") {
|
|
1125 # Mean value for all nymphs.
|
|
1126 total_nymphs = apply((YoungNymphs.replications+OldNymphs.replications), 1, mean);
|
|
1127 temperature_data_frame = append_vector(temperature_data_frame, total_nymphs, "TOTALNYMPH");
|
|
1128 # Standard error for all nymphs.
|
|
1129 total_nymphs.std_error = apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd);
|
|
1130 temperature_data_frame = append_vector(temperature_data_frame, total_nymphs.std_error, "TOTALNYMPHSE");
|
16
|
1131 }
|
10
|
1132 }
|
|
1133 }
|
|
1134 if (process_adults) {
|
|
1135 # Calculate adult populations for selected life stage.
|
16
|
1136 for (life_stage_adult in life_stages_adult) {
|
28
|
1137 if (life_stage_adult == "Pre-vittelogenic") {
|
23
|
1138 # Mean value for previttelogenic adults.
|
|
1139 previttelogenic_adults = apply(Previttelogenic.replications, 1, mean);
|
27
|
1140 temperature_data_frame = append_vector(temperature_data_frame, previttelogenic_adults, "PRE-VITADULT");
|
23
|
1141 # Standard error for previttelogenic adults.
|
|
1142 previttelogenic_adults.std_error = apply(Previttelogenic.replications, 1, sd) / sqrt(opt$replications);
|
27
|
1143 temperature_data_frame = append_vector(temperature_data_frame, previttelogenic_adults.std_error, "PRE-VITADULTSE");
|
18
|
1144 } else if (life_stage_adult == "Vittelogenic") {
|
23
|
1145 # Mean value for vittelogenic adults.
|
24
|
1146 vittelogenic_adults = apply(Vittelogenic.replications, 1, mean);
|
27
|
1147 temperature_data_frame = append_vector(temperature_data_frame, vittelogenic_adults, "VITADULT");
|
23
|
1148 # Standard error for vittelogenic adults.
|
24
|
1149 vittelogenic_adults.std_error = apply(Vittelogenic.replications, 1, sd) / sqrt(opt$replications);
|
27
|
1150 temperature_data_frame = append_vector(temperature_data_frame, vittelogenic_adults.std_error, "VITADULTSE");
|
18
|
1151 } else if (life_stage_adult == "Diapausing") {
|
23
|
1152 # Mean value for vittelogenic adults.
|
16
|
1153 diapausing_adults = apply(Diapausing.replications, 1, mean);
|
27
|
1154 temperature_data_frame = append_vector(temperature_data_frame, diapausing_adults, "DIAPAUSINGADULT");
|
23
|
1155 # Standard error for vittelogenic adults.
|
16
|
1156 diapausing_adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications);
|
27
|
1157 temperature_data_frame = append_vector(temperature_data_frame, diapausing_adults.std_error, "DIAPAUSINGADULTSE");
|
28
|
1158 } else if (life_stage_adult=="Total") {
|
|
1159 # Mean value for all adults.
|
|
1160 total_adults = apply((Previttelogenic.replications+Vittelogenic.replications+Diapausing.replications), 1, mean);
|
|
1161 temperature_data_frame = append_vector(temperature_data_frame, total_adults, "TOTALADULT");
|
|
1162 # Standard error for all adults.
|
|
1163 total_adults.std_error = apply((Previttelogenic.replications+Vittelogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications);
|
|
1164 temperature_data_frame = append_vector(temperature_data_frame, total_adults.std_error, "TOTALADULTSE");
|
16
|
1165 }
|
10
|
1166 }
|
|
1167 }
|
5
|
1168
|
10
|
1169 if (plot_generations_separately) {
|
20
|
1170 m_se = get_mean_and_std_error(P.replications, F1.replications, F2.replications);
|
|
1171 P = m_se[[1]];
|
|
1172 P.std_error = m_se[[2]];
|
|
1173 F1 = m_se[[3]];
|
|
1174 F1.std_error = m_se[[4]];
|
|
1175 F2 = m_se[[5]];
|
|
1176 F2.std_error = m_se[[6]];
|
10
|
1177 if (process_eggs) {
|
20
|
1178 m_se = get_mean_and_std_error(P_eggs.replications, F1_eggs.replications, F2_eggs.replications);
|
|
1179 P_eggs = m_se[[1]];
|
|
1180 P_eggs.std_error = m_se[[2]];
|
31
|
1181 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_eggs, "EGG-P");
|
|
1182 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_eggs.std_error, "EGG-P-SE");
|
20
|
1183 F1_eggs = m_se[[3]];
|
|
1184 F1_eggs.std_error = m_se[[4]];
|
31
|
1185 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_eggs, "EGG-F1");
|
|
1186 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_eggs.std_error, "EGG-F1-SE");
|
20
|
1187 F2_eggs = m_se[[5]];
|
|
1188 F2_eggs.std_error = m_se[[6]];
|
31
|
1189 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_eggs, "EGG-F2");
|
|
1190 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_eggs.std_error, "EGG-F2-SE");
|
20
|
1191 }
|
|
1192 if (process_young_nymphs) {
|
|
1193 m_se = get_mean_and_std_error(P_young_nymphs.replications, F1_young_nymphs.replications, F2_young_nymphs.replications);
|
|
1194 P_young_nymphs = m_se[[1]];
|
|
1195 P_young_nymphs.std_error = m_se[[2]];
|
31
|
1196 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_young_nymphs, "YOUNGNYMPH-P");
|
|
1197 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_young_nymphs.std_error, "YOUNGNYMPH-P-SE");
|
20
|
1198 F1_young_nymphs = m_se[[3]];
|
|
1199 F1_young_nymphs.std_error = m_se[[4]];
|
31
|
1200 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_young_nymphs, "YOUNGNYMPH-F1");
|
|
1201 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_young_nymphs.std_error, "YOUNGNYMPH-F1-SE");
|
20
|
1202 F2_young_nymphs = m_se[[5]];
|
|
1203 F2_young_nymphs.std_error = m_se[[6]];
|
31
|
1204 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_young_nymphs, "YOUNGNYMPH-F2");
|
|
1205 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_young_nymphs.std_error, "YOUNGNYMPH-F2-SE");
|
10
|
1206 }
|
20
|
1207 if (process_old_nymphs) {
|
|
1208 m_se = get_mean_and_std_error(P_old_nymphs.replications, F1_old_nymphs.replications, F2_old_nymphs.replications);
|
|
1209 P_old_nymphs = m_se[[1]];
|
|
1210 P_old_nymphs.std_error = m_se[[2]];
|
31
|
1211 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_old_nymphs, "OLDNYMPH-P");
|
|
1212 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_old_nymphs.std_error, "OLDNYMPH-P-SE");
|
20
|
1213 F1_old_nymphs = m_se[[3]];
|
|
1214 F1_old_nymphs.std_error = m_se[[4]];
|
31
|
1215 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_old_nymphs, "OLDNYMPH-F1");
|
|
1216 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_old_nymphs.std_error, "OLDNYMPH-F1-SE");
|
20
|
1217 F2_old_nymphs = m_se[[5]];
|
|
1218 F2_old_nymphs.std_error = m_se[[6]];
|
31
|
1219 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_old_nymphs, "OLDNYMPH-F2");
|
|
1220 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_old_nymphs.std_error, "OLDNYMPH-F2-SE");
|
20
|
1221 }
|
|
1222 if (process_total_nymphs) {
|
|
1223 m_se = get_mean_and_std_error(P_total_nymphs.replications, F1_total_nymphs.replications, F2_total_nymphs.replications);
|
|
1224 P_total_nymphs = m_se[[1]];
|
|
1225 P_total_nymphs.std_error = m_se[[2]];
|
31
|
1226 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_nymphs, "TOTALNYMPH-P");
|
|
1227 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_nymphs.std_error, "TOTALNYMPH-P-SE");
|
20
|
1228 F1_total_nymphs = m_se[[3]];
|
|
1229 F1_total_nymphs.std_error = m_se[[4]];
|
31
|
1230 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_nymphs, "TOTALNYMPH-F1");
|
|
1231 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_nymphs.std_error, "TOTALNYMPH-F1-SE");
|
20
|
1232 F2_total_nymphs = m_se[[5]];
|
|
1233 F2_total_nymphs.std_error = m_se[[6]];
|
31
|
1234 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_nymphs, "TOTALNYMPH-F2");
|
|
1235 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_nymphs.std_error, "TOTALNYMPH-F2-SE");
|
10
|
1236 }
|
23
|
1237 if (process_previttelogenic_adults) {
|
|
1238 m_se = get_mean_and_std_error(P_previttelogenic_adults.replications, F1_previttelogenic_adults.replications, F2_previttelogenic_adults.replications);
|
|
1239 P_previttelogenic_adults = m_se[[1]];
|
|
1240 P_previttelogenic_adults.std_error = m_se[[2]];
|
31
|
1241 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_previttelogenic_adults, "PRE-VITADULT-P");
|
|
1242 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_previttelogenic_adults.std_error, "PRE-VITADULT-P-SE");
|
23
|
1243 F1_previttelogenic_adults = m_se[[3]];
|
|
1244 F1_previttelogenic_adults.std_error = m_se[[4]];
|
31
|
1245 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_previttelogenic_adults, "PRE-VITADULT-F1");
|
|
1246 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_previttelogenic_adults.std_error, "PRE-VITADULT-F1-SE");
|
23
|
1247 F2_previttelogenic_adults = m_se[[5]];
|
|
1248 F2_previttelogenic_adults.std_error = m_se[[6]];
|
31
|
1249 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_previttelogenic_adults, "PRE-VITADULT-F2");
|
|
1250 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_previttelogenic_adults.std_error, "PRE-VITADULT-F2-SE");
|
23
|
1251 }
|
|
1252 if (process_vittelogenic_adults) {
|
|
1253 m_se = get_mean_and_std_error(P_vittelogenic_adults.replications, F1_vittelogenic_adults.replications, F2_vittelogenic_adults.replications);
|
|
1254 P_vittelogenic_adults = m_se[[1]];
|
|
1255 P_vittelogenic_adults.std_error = m_se[[2]];
|
31
|
1256 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_vittelogenic_adults, "VITADULT-P");
|
|
1257 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_vittelogenic_adults.std_error, "VITADULT-P-SE");
|
23
|
1258 F1_vittelogenic_adults = m_se[[3]];
|
|
1259 F1_vittelogenic_adults.std_error = m_se[[4]];
|
31
|
1260 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_vittelogenic_adults, "VITADULT-F1");
|
|
1261 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_vittelogenic_adults.std_error, "VITADULT-F1-SE");
|
23
|
1262 F2_vittelogenic_adults = m_se[[5]];
|
|
1263 F2_vittelogenic_adults.std_error = m_se[[6]];
|
31
|
1264 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_vittelogenic_adults, "VITADULT-F2");
|
|
1265 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_vittelogenic_adults.std_error, "VITADULT-F2-SE");
|
23
|
1266 }
|
|
1267 if (process_diapausing_adults) {
|
|
1268 m_se = get_mean_and_std_error(P_diapausing_adults.replications, F1_diapausing_adults.replications, F2_diapausing_adults.replications);
|
|
1269 P_diapausing_adults = m_se[[1]];
|
|
1270 P_diapausing_adults.std_error = m_se[[2]];
|
31
|
1271 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_diapausing_adults, "DIAPAUSINGADULT-P");
|
|
1272 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_diapausing_adults.std_error, "DIAPAUSINGADULT-P-SE");
|
23
|
1273 F1_diapausing_adults = m_se[[3]];
|
|
1274 F1_diapausing_adults.std_error = m_se[[4]];
|
31
|
1275 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_diapausing_adults, "DIAPAUSINGADULT-F1");
|
|
1276 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_diapausing_adults.std_error, "DIAPAUSINGADULT-F1-SE");
|
23
|
1277 F2_diapausing_adults = m_se[[5]];
|
|
1278 F2_diapausing_adults.std_error = m_se[[6]];
|
31
|
1279 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_diapausing_adults, "DIAPAUSINGADULT-F2");
|
|
1280 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_diapausing_adults.std_error, "DIAPAUSINGADULT-F2-SE");
|
23
|
1281 }
|
|
1282 if (process_total_adults) {
|
|
1283 m_se = get_mean_and_std_error(P_total_adults.replications, F1_total_adults.replications, F2_total_adults.replications);
|
|
1284 P_total_adults = m_se[[1]];
|
|
1285 P_total_adults.std_error = m_se[[2]];
|
31
|
1286 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_adults, "TOTALADULT-P");
|
|
1287 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_adults.std_error, "TOTALADULT-P-SE");
|
23
|
1288 F1_total_adults = m_se[[3]];
|
|
1289 F1_total_adults.std_error = m_se[[4]];
|
31
|
1290 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_adults, "TOTALADULT-F1");
|
|
1291 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_adults.std_error, "TOTALADULT-F1-SE");
|
23
|
1292 F2_total_adults = m_se[[5]];
|
|
1293 F2_total_adults.std_error = m_se[[6]];
|
31
|
1294 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_adults, "TOTALADULT-F2");
|
|
1295 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_adults.std_error, "TOTALADULT-F2-SE");
|
10
|
1296 }
|
|
1297 }
|
6
|
1298
|
31
|
1299 # Save the analyzed data for combined generations.
|
34
|
1300 file_path = paste("output_data_dir", "04_combined_generations.csv", sep="/");
|
|
1301 write.csv(temperature_data_frame, file=file_path, row.names=F);
|
31
|
1302 if (plot_generations_separately) {
|
|
1303 # Save the analyzed data for generation P.
|
34
|
1304 file_path = paste("output_data_dir", "01_generation_P.csv", sep="/");
|
|
1305 write.csv(temperature_data_frame_P, file=file_path, row.names=F);
|
31
|
1306 # Save the analyzed data for generation F1.
|
34
|
1307 file_path = paste("output_data_dir", "02_generation_F1.csv", sep="/");
|
|
1308 write.csv(temperature_data_frame_F1, file=file_path, row.names=F);
|
31
|
1309 # Save the analyzed data for generation F2.
|
34
|
1310 file_path = paste("output_data_dir", "03_generation_F2.csv", sep="/");
|
|
1311 write.csv(temperature_data_frame_F2, file=file_path, row.names=F);
|
31
|
1312 }
|
6
|
1313 # Display the total number of days in the Galaxy history item blurb.
|
8
|
1314 cat("Number of days: ", opt$num_days, "\n");
|
10
|
1315 # Information needed for plots plots.
|
8
|
1316 days = c(1:opt$num_days);
|
|
1317 start_date = temperature_data_frame$DATE[1];
|
|
1318 end_date = temperature_data_frame$DATE[opt$num_days];
|
5
|
1319
|
10
|
1320 if (plot_generations_separately) {
|
15
|
1321 for (life_stage in life_stages) {
|
10
|
1322 if (life_stage == "Egg") {
|
|
1323 # Start PDF device driver.
|
|
1324 dev.new(width=20, height=30);
|
19
|
1325 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf")
|
10
|
1326 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1327 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1328 # Egg population size by generation.
|
18
|
1329 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100;
|
34
|
1330 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
10
|
1331 opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs,
|
|
1332 group3_std_error=F2_eggs.std_error);
|
|
1333 # Turn off device driver to flush output.
|
|
1334 dev.off();
|
|
1335 } else if (life_stage == "Nymph") {
|
16
|
1336 for (life_stage_nymph in life_stages_nymph) {
|
|
1337 # Start PDF device driver.
|
|
1338 dev.new(width=20, height=30);
|
19
|
1339 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", life_stage_nymph=life_stage_nymph)
|
16
|
1340 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1341 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
20
|
1342 if (life_stage_nymph=="Young") {
|
|
1343 # Young nymph population size by generation.
|
|
1344 maxval = max(P_young_nymphs+F1_young_nymphs+F2_young_nymphs) + 100;
|
|
1345 group = P_young_nymphs;
|
|
1346 group_std_error = P_young_nymphs.std_error;
|
|
1347 group2 = F1_young_nymphs;
|
|
1348 group2_std_error = F1_young_nymphs.std_error;
|
|
1349 group3 = F2_young_nymphs;
|
|
1350 group3_std_error = F2_young_nymphs.std_error;
|
|
1351 } else if (life_stage_nymph=="Old") {
|
|
1352 # Total nymph population size by generation.
|
|
1353 maxval = max(P_old_nymphs+F1_old_nymphs+F2_old_nymphs) + 100;
|
|
1354 group = P_old_nymphs;
|
|
1355 group_std_error = P_old_nymphs.std_error;
|
|
1356 group2 = F1_old_nymphs;
|
|
1357 group2_std_error = F1_old_nymphs.std_error;
|
|
1358 group3 = F2_old_nymphs;
|
|
1359 group3_std_error = F2_old_nymphs.std_error;
|
|
1360 } else if (life_stage_nymph=="Total") {
|
|
1361 # Total nymph population size by generation.
|
|
1362 maxval = max(P_total_nymphs+F1_total_nymphs+F2_total_nymphs) + 100;
|
|
1363 group = P_total_nymphs;
|
|
1364 group_std_error = P_total_nymphs.std_error;
|
|
1365 group2 = F1_total_nymphs;
|
|
1366 group2_std_error = F1_total_nymphs.std_error;
|
|
1367 group3 = F2_total_nymphs;
|
|
1368 group3_std_error = F2_total_nymphs.std_error;
|
|
1369 }
|
34
|
1370 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
20
|
1371 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error,
|
|
1372 group3=group3, group3_std_error=group3_std_error, life_stages_nymph=life_stage_nymph);
|
16
|
1373 # Turn off device driver to flush output.
|
|
1374 dev.off();
|
|
1375 }
|
10
|
1376 } else if (life_stage == "Adult") {
|
16
|
1377 for (life_stage_adult in life_stages_adult) {
|
|
1378 # Start PDF device driver.
|
|
1379 dev.new(width=20, height=30);
|
19
|
1380 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", life_stage_adult=life_stage_adult)
|
16
|
1381 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1382 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
23
|
1383 if (life_stage_adult=="Pre-vittelogenic") {
|
|
1384 # Pre-vittelogenic adult population size by generation.
|
|
1385 maxval = max(P_previttelogenic_adults+F1_previttelogenic_adults+F2_previttelogenic_adults) + 100;
|
|
1386 group = P_previttelogenic_adults;
|
|
1387 group_std_error = P_previttelogenic_adults.std_error;
|
|
1388 group2 = F1_previttelogenic_adults;
|
|
1389 group2_std_error = F1_previttelogenic_adults.std_error;
|
|
1390 group3 = F2_previttelogenic_adults;
|
|
1391 group3_std_error = F2_previttelogenic_adults.std_error;
|
|
1392 } else if (life_stage_adult=="Vittelogenic") {
|
|
1393 # Vittelogenic adult population size by generation.
|
|
1394 maxval = max(P_vittelogenic_adults+F1_vittelogenic_adults+F2_vittelogenic_adults) + 100;
|
|
1395 group = P_vittelogenic_adults;
|
|
1396 group_std_error = P_vittelogenic_adults.std_error;
|
|
1397 group2 = F1_vittelogenic_adults;
|
|
1398 group2_std_error = F1_vittelogenic_adults.std_error;
|
|
1399 group3 = F2_vittelogenic_adults;
|
|
1400 group3_std_error = F2_vittelogenic_adults.std_error;
|
|
1401 } else if (life_stage_adult=="Diapausing") {
|
|
1402 # Diapausing adult population size by generation.
|
|
1403 maxval = max(P_diapausing_adults+F1_diapausing_adults+F2_diapausing_adults) + 100;
|
|
1404 group = P_diapausing_adults;
|
|
1405 group_std_error = P_diapausing_adults.std_error;
|
|
1406 group2 = F1_diapausing_adults;
|
|
1407 group2_std_error = F1_diapausing_adults.std_error;
|
|
1408 group3 = F2_diapausing_adults;
|
|
1409 group3_std_error = F2_diapausing_adults.std_error;
|
|
1410 } else if (life_stage_adult=="Total") {
|
|
1411 # Total adult population size by generation.
|
|
1412 maxval = max(P_total_adults+F1_total_adults+F2_total_adults) + 100;
|
|
1413 group = P_total_adults;
|
|
1414 group_std_error = P_total_adults.std_error;
|
|
1415 group2 = F1_total_adults;
|
|
1416 group2_std_error = F1_total_adults.std_error;
|
|
1417 group3 = F2_total_adults;
|
|
1418 group3_std_error = F2_total_adults.std_error;
|
|
1419 }
|
34
|
1420 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
23
|
1421 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error,
|
|
1422 group3=group3, group3_std_error=group3_std_error, life_stages_adult=life_stage_adult);
|
16
|
1423 # Turn off device driver to flush output.
|
|
1424 dev.off();
|
|
1425 }
|
10
|
1426 } else if (life_stage == "Total") {
|
|
1427 # Start PDF device driver.
|
18
|
1428 # Name collection elements so that they
|
|
1429 # are displayed in logical order.
|
10
|
1430 dev.new(width=20, height=30);
|
19
|
1431 file_path = get_file_path(life_stage, "total_pop_by_generation.pdf")
|
10
|
1432 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1433 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1434 # Total population size by generation.
|
18
|
1435 maxval = max(P+F1+F2) + 100;
|
34
|
1436 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
10
|
1437 opt$replications, life_stage, group=P, group_std_error=P.std_error, group2=F1, group2_std_error=F1.std_error, group3=F2, group3_std_error=F2.std_error);
|
|
1438 # Turn off device driver to flush output.
|
|
1439 dev.off();
|
|
1440 }
|
15
|
1441 }
|
10
|
1442 } else {
|
|
1443 for (life_stage in life_stages) {
|
|
1444 if (life_stage == "Egg") {
|
|
1445 # Start PDF device driver.
|
|
1446 dev.new(width=20, height=30);
|
19
|
1447 file_path = get_file_path(life_stage, "egg_pop.pdf")
|
10
|
1448 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1449 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1450 # Egg population size.
|
18
|
1451 maxval = max(eggs+eggs.std_error) + 100;
|
34
|
1452 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
10
|
1453 opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error);
|
|
1454 # Turn off device driver to flush output.
|
|
1455 dev.off();
|
|
1456 } else if (life_stage == "Nymph") {
|
16
|
1457 for (life_stage_nymph in life_stages_nymph) {
|
|
1458 # Start PDF device driver.
|
|
1459 dev.new(width=20, height=30);
|
19
|
1460 file_path = get_file_path(life_stage, "nymph_pop.pdf", life_stage_nymph=life_stage_nymph)
|
16
|
1461 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1462 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1463 if (life_stage_nymph=="Total") {
|
|
1464 # Total nymph population size.
|
|
1465 group = total_nymphs;
|
|
1466 group_std_error = total_nymphs.std_error;
|
|
1467 } else if (life_stage_nymph=="Young") {
|
|
1468 # Young nymph population size.
|
|
1469 group = young_nymphs;
|
|
1470 group_std_error = young_nymphs.std_error;
|
|
1471 } else if (life_stage_nymph=="Old") {
|
|
1472 # Old nymph population size.
|
|
1473 group = old_nymphs;
|
|
1474 group_std_error = old_nymphs.std_error;
|
|
1475 }
|
18
|
1476 maxval = max(group+group_std_error) + 100;
|
34
|
1477 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
16
|
1478 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_nymph=life_stage_nymph);
|
|
1479 # Turn off device driver to flush output.
|
|
1480 dev.off();
|
|
1481 }
|
10
|
1482 } else if (life_stage == "Adult") {
|
16
|
1483 for (life_stage_adult in life_stages_adult) {
|
|
1484 # Start PDF device driver.
|
|
1485 dev.new(width=20, height=30);
|
19
|
1486 file_path = get_file_path(life_stage, "adult_pop.pdf", life_stage_adult=life_stage_adult)
|
16
|
1487 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1488 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1489 if (life_stage_adult=="Total") {
|
|
1490 # Total adult population size.
|
|
1491 group = total_adults;
|
|
1492 group_std_error = total_adults.std_error
|
|
1493 } else if (life_stage_adult=="Pre-vittelogenic") {
|
|
1494 # Pre-vittelogenic adult population size.
|
|
1495 group = previttelogenic_adults;
|
|
1496 group_std_error = previttelogenic_adults.std_error
|
|
1497 } else if (life_stage_adult=="Vittelogenic") {
|
|
1498 # Vittelogenic adult population size.
|
|
1499 group = vittelogenic_adults;
|
|
1500 group_std_error = vittelogenic_adults.std_error
|
|
1501 } else if (life_stage_adult=="Diapausing") {
|
|
1502 # Diapausing adult population size.
|
|
1503 group = diapausing_adults;
|
|
1504 group_std_error = diapausing_adults.std_error
|
|
1505 }
|
18
|
1506 maxval = max(group+group_std_error) + 100;
|
34
|
1507 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
16
|
1508 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_adult=life_stage_adult);
|
|
1509 # Turn off device driver to flush output.
|
|
1510 dev.off();
|
|
1511 }
|
10
|
1512 } else if (life_stage == "Total") {
|
|
1513 # Start PDF device driver.
|
|
1514 dev.new(width=20, height=30);
|
19
|
1515 file_path = get_file_path(life_stage, "total_pop.pdf")
|
10
|
1516 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1517 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1518 # Total population size.
|
18
|
1519 maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100;
|
34
|
1520 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
16
|
1521 opt$replications, life_stage, group=total_adults, group_std_error=total_adults.std_error, group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs,
|
10
|
1522 group3_std_error=eggs.std_error);
|
|
1523 # Turn off device driver to flush output.
|
|
1524 dev.off();
|
|
1525 }
|
|
1526 }
|
|
1527 }
|