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"),
|
|
18 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"),
|
|
19 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"),
|
|
20 make_option(c("--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"),
|
|
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"),
|
|
23 make_option(c("--replications"), action="store", dest="replications", type="integer", help="Number of replications"),
|
10
|
24 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"),
|
|
25 make_option(c("--plot_std_error"), action="store", dest="plot_std_error", help="Plot Standard error"),
|
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
|
|
33 add_daylight_length = function(temperature_data_frame, num_columns, num_rows) {
|
|
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.
|
8
|
51 temperature_data_frame[, num_columns+1] = daylight_length_vector;
|
|
52 return(temperature_data_frame);
|
5
|
53 }
|
|
54
|
8
|
55 get_date_labels = function(temperature_data_frame, num_rows) {
|
|
56 # Keep track of the years to see if spanning years.
|
|
57 month_labels = list();
|
|
58 current_month_label = NULL;
|
|
59 for (i in 1:num_rows) {
|
|
60 # Get the year and month from the date which
|
|
61 # has the format YYYY-MM-DD.
|
|
62 date = format(temperature_data_frame$DATE[i]);
|
|
63 items = strsplit(date, "-")[[1]];
|
|
64 month = items[2];
|
|
65 month_label = month.abb[as.integer(month)];
|
|
66 if (!identical(current_month_label, month_label)) {
|
|
67 month_labels[length(month_labels)+1] = month_label;
|
|
68 current_month_label = month_label;
|
|
69 }
|
|
70 }
|
|
71 return(c(unlist(month_labels)));
|
6
|
72 }
|
|
73
|
19
|
74 get_file_path = function(life_stage, base_name, life_stage_nymph=NULL, life_stage_adult=NULL) {
|
|
75 if (!is.null(life_stage_nymph)) {
|
|
76 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph);
|
|
77 file_name = paste(lsi, tolower(life_stage_nymph), base_name, sep="_");
|
|
78 } else if (!is.null(life_stage_adult)) {
|
|
79 lsi = get_life_stage_index(life_stage, life_stage_adult=life_stage_adult);
|
|
80 file_name = paste(lsi, tolower(life_stage_adult), base_name, sep="_");
|
|
81 } else {
|
|
82 lsi = get_life_stage_index(life_stage);
|
|
83 file_name = paste(lsi, base_name, sep="_");
|
|
84 }
|
|
85 file_path = paste("output_dir", file_name, sep="/");
|
|
86 return(file_path);
|
|
87 }
|
|
88
|
18
|
89 get_life_stage_index = function(life_stage, life_stage_nymph=NULL, life_stage_adult=NULL) {
|
|
90 # Name collection elements so that they
|
|
91 # are displayed in logical order.
|
|
92 if (life_stage=="Egg") {
|
|
93 lsi = "01";
|
|
94 } else if (life_stage=="Nymph") {
|
|
95 if (life_stage_nymph=="Young") {
|
|
96 lsi = "02";
|
|
97 } else if (life_stage_nymph=="Old") {
|
|
98 lsi = "03";
|
|
99 } else if (life_stage_nymph=="Total") {
|
|
100 lsi="04";
|
|
101 }
|
|
102 } else if (life_stage=="Adult") {
|
|
103 if (life_stage_adult=="Pre-vittelogenic") {
|
|
104 lsi = "05";
|
|
105 } else if (life_stage_adult=="Vittelogenic") {
|
|
106 lsi = "06";
|
|
107 } else if (life_stage_adult=="Diapausing") {
|
|
108 lsi = "07";
|
|
109 } else if (life_stage_adult=="Total") {
|
|
110 lsi = "08";
|
|
111 }
|
|
112 } else if (life_stage=="Total") {
|
|
113 lsi = "09";
|
|
114 }
|
|
115 return(lsi);
|
|
116 }
|
|
117
|
20
|
118 get_mean_and_std_error = function(p_replications, f1_replications, f2_replications) {
|
|
119 # P mean.
|
|
120 p_m = apply(p_replications, 1, mean);
|
|
121 # P standard error.
|
|
122 p_se = apply(p_replications, 1, sd) / sqrt(opt$replications);
|
|
123 # F1 mean.
|
|
124 f1_m = apply(f1_replications, 1, mean);
|
|
125 # F1 standard error.
|
|
126 f1_se = apply(f1_replications, 1, sd) / sqrt(opt$replications);
|
|
127 # F2 mean.
|
|
128 f2_m = apply(f2_replications, 1, mean);
|
|
129 # F2 standard error.
|
|
130 f2_se = apply(f2_replications, 1, sd) / sqrt(opt$replications);
|
|
131 return(list(p_m, p_se, f1_m, f1_se, f2_m, f2_se))
|
|
132 }
|
|
133
|
5
|
134 get_temperature_at_hour = function(latitude, temperature_data_frame, row, num_days) {
|
8
|
135 # Base development threshold for Brown Marmorated Stink Bug
|
5
|
136 # insect phenology model.
|
8
|
137 threshold = 14.17;
|
5
|
138 # Minimum temperature for current row.
|
8
|
139 curr_min_temp = temperature_data_frame$TMIN[row];
|
5
|
140 # Maximum temperature for current row.
|
8
|
141 curr_max_temp = temperature_data_frame$TMAX[row];
|
5
|
142 # Mean temperature for current row.
|
8
|
143 curr_mean_temp = 0.5 * (curr_min_temp + curr_max_temp);
|
5
|
144 # Initialize degree day accumulation
|
8
|
145 averages = 0;
|
6
|
146 if (curr_max_temp < threshold) {
|
8
|
147 averages = 0;
|
5
|
148 }
|
|
149 else {
|
|
150 # Initialize hourly temperature.
|
8
|
151 T = NULL;
|
5
|
152 # Initialize degree hour vector.
|
8
|
153 dh = NULL;
|
5
|
154 # Daylight length for current row.
|
8
|
155 y = temperature_data_frame$DAYLEN[row];
|
5
|
156 # Darkness length.
|
8
|
157 z = 24 - y;
|
5
|
158 # Lag coefficient.
|
8
|
159 a = 1.86;
|
5
|
160 # Darkness coefficient.
|
8
|
161 b = 2.20;
|
5
|
162 # Sunrise time.
|
8
|
163 risetime = 12 - y / 2;
|
5
|
164 # Sunset time.
|
8
|
165 settime = 12 + y / 2;
|
|
166 ts = (curr_max_temp - curr_min_temp) * sin(pi * (settime - 5) / (y + 2 * a)) + curr_min_temp;
|
5
|
167 for (i in 1:24) {
|
|
168 if (i > risetime && i < settime) {
|
|
169 # Number of hours after Tmin until sunset.
|
8
|
170 m = i - 5;
|
|
171 T[i] = (curr_max_temp - curr_min_temp) * sin(pi * m / (y + 2 * a)) + curr_min_temp;
|
5
|
172 if (T[i] < 8.4) {
|
8
|
173 dh[i] = 0;
|
5
|
174 }
|
|
175 else {
|
8
|
176 dh[i] = T[i] - 8.4;
|
5
|
177 }
|
|
178 }
|
6
|
179 else if (i > settime) {
|
8
|
180 n = i - settime;
|
|
181 T[i] = curr_min_temp + (ts - curr_min_temp) * exp( - b * n / z);
|
5
|
182 if (T[i] < 8.4) {
|
8
|
183 dh[i] = 0;
|
5
|
184 }
|
|
185 else {
|
8
|
186 dh[i] = T[i] - 8.4;
|
5
|
187 }
|
|
188 }
|
|
189 else {
|
8
|
190 n = i + 24 - settime;
|
|
191 T[i] = curr_min_temp + (ts - curr_min_temp) * exp( - b * n / z);
|
5
|
192 if (T[i] < 8.4) {
|
8
|
193 dh[i] = 0;
|
5
|
194 }
|
|
195 else {
|
8
|
196 dh[i] = T[i] - 8.4;
|
5
|
197 }
|
|
198 }
|
|
199 }
|
8
|
200 averages = sum(dh) / 24;
|
5
|
201 }
|
6
|
202 return(c(curr_mean_temp, averages))
|
5
|
203 }
|
|
204
|
6
|
205 mortality.adult = function(temperature) {
|
|
206 if (temperature < 12.7) {
|
8
|
207 mortality.probability = 0.002;
|
6
|
208 }
|
|
209 else {
|
8
|
210 mortality.probability = temperature * 0.0005 + 0.02;
|
6
|
211 }
|
|
212 return(mortality.probability)
|
5
|
213 }
|
|
214
|
|
215 mortality.egg = function(temperature) {
|
|
216 if (temperature < 12.7) {
|
8
|
217 mortality.probability = 0.8;
|
5
|
218 }
|
|
219 else {
|
8
|
220 mortality.probability = 0.8 - temperature / 40.0;
|
6
|
221 if (mortality.probability < 0) {
|
8
|
222 mortality.probability = 0.01;
|
5
|
223 }
|
|
224 }
|
6
|
225 return(mortality.probability)
|
5
|
226 }
|
|
227
|
|
228 mortality.nymph = function(temperature) {
|
|
229 if (temperature < 12.7) {
|
8
|
230 mortality.probability = 0.03;
|
5
|
231 }
|
|
232 else {
|
8
|
233 mortality.probability = temperature * 0.0008 + 0.03;
|
5
|
234 }
|
8
|
235 return(mortality.probability);
|
6
|
236 }
|
|
237
|
|
238 parse_input_data = function(input_file, num_rows) {
|
|
239 # Read in the input temperature datafile into a data frame.
|
8
|
240 temperature_data_frame = read.csv(file=input_file, header=T, strip.white=TRUE, sep=",");
|
|
241 num_columns = dim(temperature_data_frame)[2];
|
6
|
242 if (num_columns == 6) {
|
|
243 # The input data has the following 6 columns:
|
|
244 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX
|
|
245 # Set the column names for access when adding daylight length..
|
8
|
246 colnames(temperature_data_frame) = c("LATITUDE","LONGITUDE", "DATE", "DOY", "TMIN", "TMAX");
|
6
|
247 # Add a column containing the daylight length for each day.
|
8
|
248 temperature_data_frame = add_daylight_length(temperature_data_frame, num_columns, num_rows);
|
6
|
249 # Reset the column names with the additional column for later access.
|
8
|
250 colnames(temperature_data_frame) = c("LATITUDE","LONGITUDE", "DATE", "DOY", "TMIN", "TMAX", "DAYLEN");
|
6
|
251 }
|
8
|
252 return(temperature_data_frame);
|
5
|
253 }
|
|
254
|
10
|
255 render_chart = function(date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval,
|
20
|
256 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL,
|
|
257 life_stages_adult=NULL, life_stages_nymph=NULL) {
|
10
|
258 if (chart_type=="pop_size_by_life_stage") {
|
|
259 if (life_stage=="Total") {
|
|
260 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
261 legend_text = c("Egg", "Nymph", "Adult");
|
|
262 columns = c(4, 2, 1);
|
|
263 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
264 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3);
|
|
265 lines(days, group2, lwd=2, lty=1, col=2);
|
|
266 lines(days, group3, lwd=2, lty=1, col=4);
|
|
267 axis(1, at=c(1:length(date_labels)) * 30 - 15, cex.axis=3, labels=date_labels);
|
|
268 axis(2, cex.axis=3);
|
|
269 if (plot_std_error=="yes") {
|
|
270 # Standard error for group.
|
|
271 lines(days, group+group_std_error, lty=2);
|
|
272 lines(days, group-group_std_error, lty=2);
|
|
273 # Standard error for group2.
|
|
274 lines(days, group2+group2_std_error, col=2, lty=2);
|
|
275 lines(days, group2-group2_std_error, col=2, lty=2);
|
|
276 # Standard error for group3.
|
|
277 lines(days, group3+group3_std_error, col=4, lty=2);
|
|
278 lines(days, group3-group3_std_error, col=4, lty=2);
|
|
279 }
|
|
280 } else {
|
|
281 if (life_stage=="Egg") {
|
|
282 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
283 legend_text = c(life_stage);
|
15
|
284 columns = c(4);
|
10
|
285 } else if (life_stage=="Nymph") {
|
16
|
286 stage = paste(life_stages_nymph, "Nymph Pop :", sep=" ");
|
10
|
287 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
16
|
288 legend_text = c(paste(life_stages_nymph, life_stage, sep=" "));
|
10
|
289 columns = c(2);
|
|
290 } else if (life_stage=="Adult") {
|
|
291 stage = paste(life_stages_adult, "Adult Pop", sep=" ");
|
|
292 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
293 legend_text = c(paste(life_stages_adult, life_stage, sep=" "));
|
|
294 columns = c(1);
|
|
295 }
|
|
296 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
297 legend("topleft", legend_text, lty=c(1), col="black", cex=3);
|
|
298 axis(1, at=c(1:length(date_labels)) * 30 - 15, cex.axis=3, labels=date_labels);
|
|
299 axis(2, cex.axis=3);
|
|
300 if (plot_std_error=="yes") {
|
|
301 # Standard error for group.
|
|
302 lines(days, group+group_std_error, lty=2);
|
|
303 lines(days, group-group_std_error, lty=2);
|
|
304 }
|
|
305 }
|
|
306 } else if (chart_type=="pop_size_by_generation") {
|
|
307 if (life_stage=="Total") {
|
|
308 title_str = ": Total Pop by Gen :";
|
|
309 } else if (life_stage=="Egg") {
|
|
310 title_str = ": Egg Pop by Gen :";
|
|
311 } else if (life_stage=="Nymph") {
|
16
|
312 title_str = paste(":", life_stages_nymph, "Nymph Pop by Gen", ":", sep=" ");
|
10
|
313 } else if (life_stage=="Adult") {
|
|
314 title_str = paste(":", life_stages_adult, "Adult Pop by Gen", ":", sep=" ");
|
|
315 }
|
|
316 title = paste(insect, ": Reps", replications, title_str, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
8
|
317 legend_text = c("P", "F1", "F2");
|
|
318 columns = c(1, 2, 4);
|
10
|
319 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
320 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3);
|
|
321 lines(days, group2, lwd=2, lty=1, col=2);
|
|
322 lines(days, group3, lwd=2, lty=1, col=4);
|
|
323 axis(1, at=c(1:length(date_labels)) * 30 - 15, cex.axis=3, labels=date_labels);
|
|
324 axis(2, cex.axis=3);
|
|
325 if (plot_std_error=="yes") {
|
|
326 # Standard error for group.
|
|
327 lines(days, group+group_std_error, lty=2);
|
|
328 lines(days, group-group_std_error, lty=2);
|
|
329 # Standard error for group2.
|
|
330 lines(days, group2+group2_std_error, col=2, lty=2);
|
|
331 lines(days, group2-group2_std_error, col=2, lty=2);
|
|
332 # Standard error for group3.
|
|
333 lines(days, group3+group3_std_error, col=4, lty=2);
|
|
334 lines(days, group3-group3_std_error, col=4, lty=2);
|
|
335 }
|
5
|
336 }
|
|
337 }
|
|
338
|
10
|
339 # Determine if we're plotting generations separately.
|
|
340 if (opt$plot_generations_separately=="yes") {
|
|
341 plot_generations_separately = TRUE;
|
|
342 } else {
|
|
343 plot_generations_separately = FALSE;
|
|
344 }
|
|
345 # Read the temperature data into a data frame.
|
8
|
346 temperature_data_frame = parse_input_data(opt$input, opt$num_days);
|
10
|
347 # Get the date labels for plots.
|
|
348 date_labels = get_date_labels(temperature_data_frame, opt$num_days);
|
|
349 # All latitude values are the same, so get the value for plots from the first row.
|
8
|
350 latitude = temperature_data_frame$LATITUDE[1];
|
10
|
351 # Get the number of days for plots.
|
8
|
352 num_columns = dim(temperature_data_frame)[2];
|
20
|
353 # Determine the specified life stages for processing.
|
10
|
354 # Split life_stages into a list of strings for plots.
|
|
355 life_stages_str = as.character(opt$life_stages);
|
|
356 life_stages = strsplit(life_stages_str, ",")[[1]];
|
|
357 # Determine the data we need to generate for plotting.
|
|
358 process_eggs = FALSE;
|
|
359 process_nymphs = FALSE;
|
20
|
360 process_young_nymphs = FALSE;
|
|
361 process_old_nymphs = FALSE;
|
|
362 process_total_nymphs = FALSE;
|
10
|
363 process_adults = FALSE;
|
20
|
364 process_previtellogenic_adults = FALSE;
|
|
365 process_vitellogenic_adults = FALSE;
|
|
366 process_diapausing_adults = FALSE;
|
|
367 process_total_adults = FALSE;
|
10
|
368 for (life_stage in life_stages) {
|
|
369 if (life_stage=="Total") {
|
|
370 process_eggs = TRUE;
|
|
371 process_nymphs = TRUE;
|
|
372 process_adults = TRUE;
|
|
373 } else if (life_stage=="Egg") {
|
|
374 process_eggs = TRUE;
|
|
375 } else if (life_stage=="Nymph") {
|
|
376 process_nymphs = TRUE;
|
|
377 } else if (life_stage=="Adult") {
|
|
378 process_adults = TRUE;
|
|
379 }
|
|
380 }
|
20
|
381 if (process_nymphs) {
|
|
382 # Split life_stages_nymph into a list of strings for plots.
|
|
383 life_stages_nymph_str = as.character(opt$life_stages_nymph);
|
|
384 life_stages_nymph = strsplit(life_stages_nymph_str, ",")[[1]];
|
|
385 for (life_stage_nymph in opt$life_stages_nymph) {
|
|
386 if (life_stage_nymph=="Young") {
|
|
387 process_young_nymphs = TRUE;
|
|
388 } else if (life_stage_nymph=="Old") {
|
|
389 process_old_nymphs = TRUE;
|
|
390 } else if (life_stage_nymph=="Total") {
|
|
391 process_total_nymphs = TRUE;
|
|
392 }
|
|
393 }
|
|
394 }
|
16
|
395 if (process_adults) {
|
|
396 # Split life_stages_adult into a list of strings for plots.
|
|
397 life_stages_adult_str = as.character(opt$life_stages_adult);
|
|
398 life_stages_adult = strsplit(life_stages_adult_str, ",")[[1]];
|
20
|
399 for (life_stage_adult in opt$life_stages_adult) {
|
|
400 if (life_stage_adult=="Previtellogenic") {
|
|
401 process_previtellogenic_adults = TRUE;
|
|
402 } else if (life_stage_adult=="Vitellogenic") {
|
|
403 process_vitellogenic_adults = TRUE;
|
|
404 } else if (life_stage_adult=="Diapausing") {
|
|
405 process_diapausing_adults = TRUE;
|
|
406 } else if (life_stage_adult=="Total") {
|
|
407 process_total_adults = TRUE;
|
|
408 }
|
|
409 }
|
16
|
410 }
|
20
|
411
|
6
|
412 # Initialize matrices.
|
10
|
413 if (process_eggs) {
|
|
414 Eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
415 }
|
20
|
416 if (process_young_nymphs==TRUE | process_total_nymphs==TRUE) {
|
10
|
417 YoungNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
20
|
418 }
|
|
419 if (process_old_nymphs==TRUE | process_total_nymphs==TRUE) {
|
10
|
420 OldNymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
421 }
|
|
422 if (process_adults) {
|
|
423 Previtellogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
424 Vitellogenic.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
425 Diapausing.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
426 }
|
8
|
427 newborn.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
428 adult.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
429 death.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
10
|
430 if (plot_generations_separately) {
|
|
431 # P is Parental, or overwintered adults.
|
|
432 P.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
433 # F1 is the first field-produced generation.
|
|
434 F1.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
435 # F2 is the second field-produced generation.
|
|
436 F2.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
437 if (process_eggs) {
|
|
438 P_eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
439 F1_eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
440 F2_eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
441 }
|
20
|
442 if (process_young_nymphs) {
|
|
443 P_young_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
444 F1_young_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
445 F2_young_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
446 }
|
|
447 if (process_old_nymphs) {
|
|
448 P_old_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
449 F1_old_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
450 F2_old_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
451 }
|
|
452 if (process_total_nymphs) {
|
|
453 P_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
454 F1_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
455 F2_total_nymphs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
10
|
456 }
|
|
457 if (process_adults) {
|
|
458 P_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
459 F1_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
460 F2_adults.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
|
461 }
|
|
462 }
|
|
463 # Total population.
|
8
|
464 population.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
|
5
|
465
|
6
|
466 # Process replications.
|
18
|
467 for (current_replication in 1:opt$replications) {
|
6
|
468 # Start with the user-defined number of insects per replication.
|
8
|
469 num_insects = opt$insects_per_replication;
|
6
|
470 # Generation, Stage, degree-days, T, Diapause.
|
8
|
471 vector.ini = c(0, 3, 0, 0, 0);
|
10
|
472 # Replicate to create a matrix where the columns are
|
|
473 # Generation, Stage, degree-days, T, Diapause and the
|
|
474 # rows are the initial number of insects per replication.
|
8
|
475 vector.matrix = rep(vector.ini, num_insects);
|
10
|
476 # Complete transposed matrix for the population, so now
|
|
477 # the rows are Generation, Stage, degree-days, T, Diapause
|
8
|
478 vector.matrix = base::t(matrix(vector.matrix, nrow=5));
|
5
|
479 # Time series of population size.
|
10
|
480 if (process_eggs) {
|
|
481 Eggs = rep(0, opt$num_days);
|
|
482 }
|
|
483 if (process_nymphs) {
|
|
484 YoungNymphs = rep(0, opt$num_days);
|
|
485 OldNymphs = rep(0, opt$num_days);
|
|
486 }
|
|
487 if (process_adults) {
|
|
488 Previtellogenic = rep(0, opt$num_days);
|
|
489 Vitellogenic = rep(0, opt$num_days);
|
|
490 Diapausing = rep(0, opt$num_days);
|
|
491 }
|
8
|
492 N.newborn = rep(0, opt$num_days);
|
|
493 N.adult = rep(0, opt$num_days);
|
|
494 N.death = rep(0, opt$num_days);
|
|
495 overwintering_adult.population = rep(0, opt$num_days);
|
|
496 first_generation.population = rep(0, opt$num_days);
|
|
497 second_generation.population = rep(0, opt$num_days);
|
10
|
498 if (plot_generations_separately) {
|
|
499 # P is Parental, or overwintered adults.
|
|
500 # F1 is the first field-produced generation.
|
|
501 # F2 is the second field-produced generation.
|
|
502 if (process_eggs) {
|
|
503 P.egg = rep(0, opt$num_days);
|
|
504 F1.egg = rep(0, opt$num_days);
|
|
505 F2.egg = rep(0, opt$num_days);
|
|
506 }
|
20
|
507 if (process_young_nymphs) {
|
|
508 P.young_nymph = rep(0, opt$num_days);
|
|
509 F1.young_nymph = rep(0, opt$num_days);
|
|
510 F2.young_nymph = rep(0, opt$num_days);
|
|
511 }
|
|
512 if (process_old_nymphs) {
|
|
513 P.old_nymph = rep(0, opt$num_days);
|
|
514 F1.old_nymph = rep(0, opt$num_days);
|
|
515 F2.old_nymph = rep(0, opt$num_days);
|
|
516 }
|
|
517 if (process_total_nymphs) {
|
|
518 P.total_nymph = rep(0, opt$num_days);
|
|
519 F1.total_nymph = rep(0, opt$num_days);
|
|
520 F2.total_nymph = rep(0, opt$num_days);
|
10
|
521 }
|
|
522 if (process_adults) {
|
|
523 P.adult = rep(0, opt$num_days);
|
|
524 F1.adult = rep(0, opt$num_days);
|
|
525 F2.adult = rep(0, opt$num_days);
|
|
526 }
|
|
527 }
|
8
|
528 total.population = NULL;
|
|
529 averages.day = rep(0, opt$num_days);
|
5
|
530 # All the days included in the input temperature dataset.
|
|
531 for (row in 1:opt$num_days) {
|
|
532 # Get the integer day of the year for the current row.
|
8
|
533 doy = temperature_data_frame$DOY[row];
|
5
|
534 # Photoperiod in the day.
|
8
|
535 photoperiod = temperature_data_frame$DAYLEN[row];
|
|
536 temp.profile = get_temperature_at_hour(latitude, temperature_data_frame, row, opt$num_days);
|
|
537 mean.temp = temp.profile[1];
|
|
538 averages.temp = temp.profile[2];
|
|
539 averages.day[row] = averages.temp;
|
5
|
540 # Trash bin for death.
|
8
|
541 death.vector = NULL;
|
5
|
542 # Newborn.
|
8
|
543 birth.vector = NULL;
|
5
|
544 # All individuals.
|
6
|
545 for (i in 1:num_insects) {
|
|
546 # Individual record.
|
8
|
547 vector.individual = vector.matrix[i,];
|
6
|
548 # Adjustment for late season mortality rate (still alive?).
|
5
|
549 if (latitude < 40.0) {
|
8
|
550 post.mortality = 1;
|
|
551 day.kill = 300;
|
5
|
552 }
|
|
553 else {
|
8
|
554 post.mortality = 2;
|
|
555 day.kill = 250;
|
5
|
556 }
|
6
|
557 if (vector.individual[2] == 0) {
|
5
|
558 # Egg.
|
8
|
559 death.probability = opt$egg_mortality * mortality.egg(mean.temp);
|
5
|
560 }
|
6
|
561 else if (vector.individual[2] == 1 | vector.individual[2] == 2) {
|
18
|
562 # Nymph.
|
8
|
563 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp);
|
5
|
564 }
|
6
|
565 else if (vector.individual[2] == 3 | vector.individual[2] == 4 | vector.individual[2] == 5) {
|
|
566 # Adult.
|
5
|
567 if (doy < day.kill) {
|
8
|
568 death.probability = opt$adult_mortality * mortality.adult(mean.temp);
|
5
|
569 }
|
|
570 else {
|
|
571 # Increase adult mortality after fall equinox.
|
8
|
572 death.probability = opt$adult_mortality * post.mortality * mortality.adult(mean.temp);
|
5
|
573 }
|
|
574 }
|
6
|
575 # Dependent on temperature and life stage?
|
8
|
576 u.d = runif(1);
|
6
|
577 if (u.d < death.probability) {
|
8
|
578 death.vector = c(death.vector, i);
|
6
|
579 }
|
5
|
580 else {
|
6
|
581 # End of diapause.
|
|
582 if (vector.individual[1] == 0 && vector.individual[2] == 3) {
|
5
|
583 # Overwintering adult (previttelogenic).
|
6
|
584 if (photoperiod > opt$photoperiod && vector.individual[3] > 68 && doy < 180) {
|
5
|
585 # Add 68C to become fully reproductively matured.
|
|
586 # Transfer to vittelogenic.
|
8
|
587 vector.individual = c(0, 4, 0, 0, 0);
|
|
588 vector.matrix[i,] = vector.individual;
|
5
|
589 }
|
|
590 else {
|
6
|
591 # Add to # Add average temperature for current day.
|
8
|
592 vector.individual[3] = vector.individual[3] + averages.temp;
|
5
|
593 # Add 1 day in current stage.
|
8
|
594 vector.individual[4] = vector.individual[4] + 1;
|
|
595 vector.matrix[i,] = vector.individual;
|
5
|
596 }
|
|
597 }
|
6
|
598 if (vector.individual[1] != 0 && vector.individual[2] == 3) {
|
5
|
599 # Not overwintering adult (previttelogenic).
|
8
|
600 current.gen = vector.individual[1];
|
6
|
601 if (vector.individual[3] > 68) {
|
5
|
602 # Add 68C to become fully reproductively matured.
|
|
603 # Transfer to vittelogenic.
|
8
|
604 vector.individual = c(current.gen, 4, 0, 0, 0);
|
|
605 vector.matrix[i,] = vector.individual;
|
5
|
606 }
|
|
607 else {
|
6
|
608 # Add average temperature for current day.
|
8
|
609 vector.individual[3] = vector.individual[3] + averages.temp;
|
5
|
610 # Add 1 day in current stage.
|
8
|
611 vector.individual[4] = vector.individual[4] + 1;
|
|
612 vector.matrix[i,] = vector.individual;
|
5
|
613 }
|
|
614 }
|
6
|
615 # Oviposition -- where population dynamics comes from.
|
|
616 if (vector.individual[2] == 4 && vector.individual[1] == 0 && mean.temp > 10) {
|
5
|
617 # Vittelogenic stage, overwintering generation.
|
6
|
618 if (vector.individual[4] == 0) {
|
5
|
619 # Just turned in vittelogenic stage.
|
8
|
620 num_insects.birth = round(runif(1, 2 + opt$min_clutch_size, 8 + opt$max_clutch_size));
|
5
|
621 }
|
|
622 else {
|
|
623 # Daily probability of birth.
|
8
|
624 p.birth = opt$oviposition * 0.01;
|
|
625 u1 = runif(1);
|
5
|
626 if (u1 < p.birth) {
|
8
|
627 num_insects.birth = round(runif(1, 2, 8));
|
5
|
628 }
|
|
629 }
|
6
|
630 # Add average temperature for current day.
|
8
|
631 vector.individual[3] = vector.individual[3] + averages.temp;
|
5
|
632 # Add 1 day in current stage.
|
8
|
633 vector.individual[4] = vector.individual[4] + 1;
|
|
634 vector.matrix[i,] = vector.individual;
|
6
|
635 if (num_insects.birth > 0) {
|
5
|
636 # Add new birth -- might be in different generations.
|
8
|
637 new.gen = vector.individual[1] + 1;
|
5
|
638 # Egg profile.
|
8
|
639 new.individual = c(new.gen, 0, 0, 0, 0);
|
|
640 new.vector = rep(new.individual, num_insects.birth);
|
5
|
641 # Update batch of egg profile.
|
8
|
642 new.vector = t(matrix(new.vector, nrow=5));
|
5
|
643 # Group with total eggs laid in that day.
|
8
|
644 birth.vector = rbind(birth.vector, new.vector);
|
5
|
645 }
|
|
646 }
|
6
|
647 # Oviposition -- for generation 1.
|
|
648 if (vector.individual[2] == 4 && vector.individual[1] == 1 && mean.temp > 12.5 && doy < 222) {
|
5
|
649 # Vittelogenic stage, 1st generation
|
6
|
650 if (vector.individual[4] == 0) {
|
5
|
651 # Just turned in vittelogenic stage.
|
8
|
652 num_insects.birth = round(runif(1, 2+opt$min_clutch_size, 8+opt$max_clutch_size));
|
5
|
653 }
|
|
654 else {
|
|
655 # Daily probability of birth.
|
8
|
656 p.birth = opt$oviposition * 0.01;
|
|
657 u1 = runif(1);
|
5
|
658 if (u1 < p.birth) {
|
8
|
659 num_insects.birth = round(runif(1, 2, 8));
|
5
|
660 }
|
|
661 }
|
6
|
662 # Add average temperature for current day.
|
8
|
663 vector.individual[3] = vector.individual[3] + averages.temp;
|
5
|
664 # Add 1 day in current stage.
|
8
|
665 vector.individual[4] = vector.individual[4] + 1;
|
|
666 vector.matrix[i,] = vector.individual;
|
6
|
667 if (num_insects.birth > 0) {
|
5
|
668 # Add new birth -- might be in different generations.
|
8
|
669 new.gen = vector.individual[1] + 1;
|
5
|
670 # Egg profile.
|
8
|
671 new.individual = c(new.gen, 0, 0, 0, 0);
|
|
672 new.vector = rep(new.individual, num_insects.birth);
|
5
|
673 # Update batch of egg profile.
|
8
|
674 new.vector = t(matrix(new.vector, nrow=5));
|
5
|
675 # Group with total eggs laid in that day.
|
8
|
676 birth.vector = rbind(birth.vector, new.vector);
|
5
|
677 }
|
|
678 }
|
6
|
679 # Egg to young nymph.
|
|
680 if (vector.individual[2] == 0) {
|
|
681 # Add average temperature for current day.
|
8
|
682 vector.individual[3] = vector.individual[3] + averages.temp;
|
6
|
683 if (vector.individual[3] >= (68+opt$young_nymph_accumulation)) {
|
|
684 # From egg to young nymph, degree-days requirement met.
|
8
|
685 current.gen = vector.individual[1];
|
5
|
686 # Transfer to young nymph stage.
|
8
|
687 vector.individual = c(current.gen, 1, 0, 0, 0);
|
5
|
688 }
|
|
689 else {
|
|
690 # Add 1 day in current stage.
|
8
|
691 vector.individual[4] = vector.individual[4] + 1;
|
5
|
692 }
|
8
|
693 vector.matrix[i,] = vector.individual;
|
5
|
694 }
|
6
|
695 # Young nymph to old nymph.
|
|
696 if (vector.individual[2] == 1) {
|
|
697 # Add average temperature for current day.
|
8
|
698 vector.individual[3] = vector.individual[3] + averages.temp;
|
6
|
699 if (vector.individual[3] >= (250+opt$old_nymph_accumulation)) {
|
|
700 # From young to old nymph, degree_days requirement met.
|
8
|
701 current.gen = vector.individual[1];
|
5
|
702 # Transfer to old nym stage.
|
8
|
703 vector.individual = c(current.gen, 2, 0, 0, 0);
|
5
|
704 if (photoperiod < opt$photoperiod && doy > 180) {
|
8
|
705 vector.individual[5] = 1;
|
5
|
706 } # Prepare for diapausing.
|
|
707 }
|
|
708 else {
|
|
709 # Add 1 day in current stage.
|
8
|
710 vector.individual[4] = vector.individual[4] + 1;
|
5
|
711 }
|
8
|
712 vector.matrix[i,] = vector.individual;
|
6
|
713 }
|
|
714 # Old nymph to adult: previttelogenic or diapausing?
|
|
715 if (vector.individual[2] == 2) {
|
|
716 # Add average temperature for current day.
|
8
|
717 vector.individual[3] = vector.individual[3] + averages.temp;
|
6
|
718 if (vector.individual[3] >= (200+opt$adult_accumulation)) {
|
|
719 # From old to adult, degree_days requirement met.
|
8
|
720 current.gen = vector.individual[1];
|
6
|
721 if (vector.individual[5] == 0) {
|
|
722 # Previttelogenic.
|
8
|
723 vector.individual = c(current.gen, 3, 0, 0, 0);
|
5
|
724 }
|
|
725 else {
|
|
726 # Diapausing.
|
8
|
727 vector.individual = c(current.gen, 5, 0, 0, 1);
|
5
|
728 }
|
|
729 }
|
|
730 else {
|
|
731 # Add 1 day in current stage.
|
8
|
732 vector.individual[4] = vector.individual[4] + 1;
|
5
|
733 }
|
8
|
734 vector.matrix[i,] = vector.individual;
|
5
|
735 }
|
6
|
736 # Growing of diapausing adult (unimportant, but still necessary).
|
|
737 if (vector.individual[2] == 5) {
|
8
|
738 vector.individual[3] = vector.individual[3] + averages.temp;
|
|
739 vector.individual[4] = vector.individual[4] + 1;
|
|
740 vector.matrix[i,] = vector.individual;
|
5
|
741 }
|
|
742 } # Else if it is still alive.
|
|
743 } # End of the individual bug loop.
|
6
|
744
|
|
745 # Number of deaths.
|
8
|
746 num_insects.death = length(death.vector);
|
6
|
747 if (num_insects.death > 0) {
|
|
748 # Remove record of dead.
|
8
|
749 vector.matrix = vector.matrix[-death.vector,];
|
5
|
750 }
|
6
|
751 # Number of births.
|
8
|
752 num_insects.newborn = length(birth.vector[,1]);
|
|
753 vector.matrix = rbind(vector.matrix, birth.vector);
|
5
|
754 # Update population size for the next day.
|
8
|
755 num_insects = num_insects - num_insects.death + num_insects.newborn;
|
5
|
756
|
10
|
757 # Aggregate results by day. Due to multiple transpose calls
|
|
758 # on vector.matrix above, the columns of vector.matrix
|
|
759 # are now Generation, Stage, degree-days, T, Diapause,
|
|
760 if (process_eggs) {
|
|
761 # For egg population size, column 2 (Stage), must be 0.
|
|
762 Eggs[row] = sum(vector.matrix[,2]==0);
|
|
763 }
|
20
|
764 if (process_young_nymphs) {
|
10
|
765 # For young nymph population size, column 2 (Stage) must be 1.
|
|
766 YoungNymphs[row] = sum(vector.matrix[,2]==1);
|
20
|
767 }
|
|
768 if (process_old_nymphs) {
|
10
|
769 # For old nymph population size, column 2 (Stage) must be 2.
|
|
770 OldNymphs[row] = sum(vector.matrix[,2]==2);
|
|
771 }
|
|
772 if (process_adults) {
|
|
773 # For pre-vitellogenic population size, column 2 (Stage) must be 3.
|
|
774 Previtellogenic[row] = sum(vector.matrix[,2]==3);
|
|
775 # For vitellogenic population size, column 2 (Stage) must be 4.
|
|
776 Vitellogenic[row] = sum(vector.matrix[,2]==4);
|
|
777 # For diapausing population size, column 2 (Stage) must be 5.
|
|
778 Diapausing[row] = sum(vector.matrix[,2]==5);
|
|
779 }
|
5
|
780
|
6
|
781 # Newborn population size.
|
8
|
782 N.newborn[row] = num_insects.newborn;
|
6
|
783 # Adult population size.
|
8
|
784 N.adult[row] = sum(vector.matrix[,2]==3) + sum(vector.matrix[,2]==4) + sum(vector.matrix[,2]==5);
|
6
|
785 # Dead population size.
|
8
|
786 N.death[row] = num_insects.death;
|
6
|
787
|
8
|
788 total.population = c(total.population, num_insects);
|
6
|
789
|
10
|
790 # For overwintering adult (P) population
|
|
791 # size, column 1 (Generation) must be 0.
|
8
|
792 overwintering_adult.population[row] = sum(vector.matrix[,1]==0);
|
10
|
793 # For first field generation (F1) population
|
|
794 # size, column 1 (Generation) must be 1.
|
8
|
795 first_generation.population[row] = sum(vector.matrix[,1]==1);
|
10
|
796 # For second field generation (F2) population
|
|
797 # size, column 1 (Generation) must be 2.
|
8
|
798 second_generation.population[row] = sum(vector.matrix[,1]==2);
|
5
|
799
|
10
|
800 if (plot_generations_separately) {
|
|
801 if (process_eggs) {
|
18
|
802 # For egg life stage of generation P population size,
|
10
|
803 # column 1 (generation) is 0 and column 2 (Stage) is 0.
|
|
804 P.egg[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==0);
|
|
805 # For egg life stage of generation F1 population size,
|
|
806 # column 1 (generation) is 1 and column 2 (Stage) is 0.
|
|
807 F1.egg[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==0);
|
|
808 # For egg life stage of generation F2 population size,
|
|
809 # column 1 (generation) is 2 and column 2 (Stage) is 0.
|
|
810 F2.egg[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==0);
|
|
811 }
|
20
|
812 if (process_young_nymphs) {
|
|
813 # For young nymph life stage of generation P population
|
|
814 # size, the following combination is required:
|
|
815 # - column 1 (Generation) is 0 and column 2 (Stage) is 1 (Young nymph)
|
|
816 P.young_nymph[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==1);
|
|
817 # For young nymph life stage of generation F1 population
|
|
818 # size, the following combination is required:
|
|
819 # - column 1 (Generation) is 1 and column 2 (Stage) is 1 (Young nymph)
|
|
820 F1.young_nymph[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==1);
|
|
821 # For young nymph life stage of generation F2 population
|
|
822 # size, the following combination is required:
|
|
823 # - column 1 (Generation) is 2 and column 2 (Stage) is 1 (Young nymph)
|
|
824 F2.young_nymph[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==1);
|
|
825 }
|
|
826 if (process_old_nymphs) {
|
|
827 # For old nymph life stage of generation P population
|
|
828 # size, the following combination is required:
|
|
829 # - column 1 (Generation) is 0 and column 2 (Stage) is 2 (Old nymph)
|
|
830 P.old_nymph[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==2);
|
|
831 # For old nymph life stage of generation F1 population
|
|
832 # size, the following combination is required:
|
|
833 # - column 1 (Generation) is 1 and column 2 (Stage) is 2 (Old nymph)
|
|
834 F1.old_nymph[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==2);
|
|
835 # For old nymph life stage of generation F2 population
|
|
836 # size, the following combination is required:
|
|
837 # - column 1 (Generation) is 2 and column 2 (Stage) is 2 (Old nymph)
|
|
838 F2.old_nymph[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==2);
|
|
839 }
|
|
840 if (process_total_nymphs) {
|
|
841 # For total nymph life stage of generation P population
|
10
|
842 # size, one of the following combinations is required:
|
|
843 # - column 1 (Generation) is 0 and column 2 (Stage) is 1 (Young nymph)
|
|
844 # - column 1 (Generation) is 0 and column 2 (Stage) is 2 (Old nymph)
|
20
|
845 P.total_nymph[row] = sum((vector.matrix[,1]==0 & vector.matrix[,2]==1) | (vector.matrix[,1]==0 & vector.matrix[,2]==2));
|
|
846 # For total nymph life stage of generation F1 population
|
10
|
847 # size, one of the following combinations is required:
|
|
848 # - column 1 (Generation) is 1 and column 2 (Stage) is 1 (Young nymph)
|
|
849 # - column 1 (Generation) is 1 and column 2 (Stage) is 2 (Old nymph)
|
20
|
850 F1.total_nymph[row] = sum((vector.matrix[,1]==1 & vector.matrix[,2]==1) | (vector.matrix[,1]==1 & vector.matrix[,2]==2));
|
|
851 # For total nymph life stage of generation F2 population
|
10
|
852 # size, one of the following combinations is required:
|
|
853 # - column 1 (Generation) is 2 and column 2 (Stage) is 1 (Young nymph)
|
|
854 # - column 1 (Generation) is 2 and column 2 (Stage) is 2 (Old nymph)
|
20
|
855 F2.total_nymph[row] = sum((vector.matrix[,1]==2 & vector.matrix[,2]==1) | (vector.matrix[,1]==2 & vector.matrix[,2]==2));
|
10
|
856 }
|
|
857 if (process_adults) {
|
|
858 # For adult life stage of generation P population
|
|
859 # size, one of the following combinations is required:
|
|
860 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vitellogenic)
|
|
861 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vitellogenic)
|
|
862 # - column 1 (Generation) is 0 and column 2 (Stage) is 5 (Diapausing)
|
|
863 P.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));
|
|
864 # For adult life stage of generation F1 population
|
|
865 # size, one of the following combinations is required:
|
|
866 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vitellogenic)
|
|
867 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vitellogenic)
|
|
868 # - column 1 (Generation) is 1 and column 2 (Stage) is 5 (Diapausing)
|
|
869 F1.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));
|
|
870 # For adult life stage of generation F2 population
|
|
871 # size, one of the following combinations is required:
|
|
872 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vitellogenic)
|
|
873 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vitellogenic)
|
|
874 # - column 1 (Generation) is 2 and column 2 (Stage) is 5 (Diapausing)
|
|
875 F2.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));
|
|
876 }
|
|
877 }
|
6
|
878 } # End of days specified in the input temperature data.
|
5
|
879
|
8
|
880 averages.cum = cumsum(averages.day);
|
5
|
881
|
6
|
882 # Define the output values.
|
10
|
883 if (process_eggs) {
|
18
|
884 Eggs.replications[,current_replication] = Eggs;
|
10
|
885 }
|
20
|
886 if (process_young_nymphs==TRUE | process_total_nymphs==TRUE) {
|
18
|
887 YoungNymphs.replications[,current_replication] = YoungNymphs;
|
20
|
888 }
|
|
889 if (process_old_nymphs==TRUE | process_total_nymphs==TRUE) {
|
18
|
890 OldNymphs.replications[,current_replication] = OldNymphs;
|
10
|
891 }
|
|
892 if (process_adults) {
|
18
|
893 Previtellogenic.replications[,current_replication] = Previtellogenic;
|
|
894 Vitellogenic.replications[,current_replication] = Vitellogenic;
|
|
895 Diapausing.replications[,current_replication] = Diapausing;
|
10
|
896 }
|
18
|
897 newborn.replications[,current_replication] = N.newborn;
|
|
898 adult.replications[,current_replication] = N.adult;
|
|
899 death.replications[,current_replication] = N.death;
|
10
|
900 if (plot_generations_separately) {
|
|
901 # P is Parental, or overwintered adults.
|
18
|
902 P.replications[,current_replication] = overwintering_adult.population;
|
10
|
903 # F1 is the first field-produced generation.
|
18
|
904 F1.replications[,current_replication] = first_generation.population;
|
10
|
905 # F2 is the second field-produced generation.
|
18
|
906 F2.replications[,current_replication] = second_generation.population;
|
10
|
907 if (process_eggs) {
|
18
|
908 P_eggs.replications[,current_replication] = P.egg;
|
|
909 F1_eggs.replications[,current_replication] = F1.egg;
|
|
910 F2_eggs.replications[,current_replication] = F2.egg;
|
10
|
911 }
|
20
|
912 if (process_young_nymphs) {
|
|
913 P_young_nymphs.replications[,current_replication] = P.young_nymph;
|
|
914 F1_young_nymphs.replications[,current_replication] = F1.young_nymph;
|
|
915 F2_young_nymphs.replications[,current_replication] = F2.young_nymph;
|
|
916 }
|
|
917 if (process_old_nymphs) {
|
|
918 P_old_nymphs.replications[,current_replication] = P.old_nymph;
|
|
919 F1_old_nymphs.replications[,current_replication] = F1.old_nymph;
|
|
920 F2_old_nymphs.replications[,current_replication] = F2.old_nymph;
|
|
921 }
|
|
922 if (process_total_nymphs) {
|
|
923 P_total_nymphs.replications[,current_replication] = P.total_nymph;
|
|
924 F1_total_nymphs.replications[,current_replication] = F1.total_nymph;
|
|
925 F2_total_nymphs.replications[,current_replication] = F2.total_nymph;
|
10
|
926 }
|
|
927 if (process_adults) {
|
18
|
928 P_adults.replications[,current_replication] = P.adult;
|
|
929 F1_adults.replications[,current_replication] = F1.adult;
|
|
930 F2_adults.replications[,current_replication] = F2.adult;
|
10
|
931 }
|
|
932 }
|
18
|
933 population.replications[,current_replication] = total.population;
|
|
934 # End processing replications.
|
5
|
935 }
|
|
936
|
10
|
937 if (process_eggs) {
|
|
938 # Mean value for eggs.
|
|
939 eggs = apply(Eggs.replications, 1, mean);
|
|
940 # Standard error for eggs.
|
|
941 eggs.std_error = apply(Eggs.replications, 1, sd) / sqrt(opt$replications);
|
|
942 }
|
|
943 if (process_nymphs) {
|
|
944 # Calculate nymph populations for selected life stage.
|
16
|
945 for (life_stage_nymph in life_stages_nymph) {
|
18
|
946 if (life_stage_nymph=="Total") {
|
16
|
947 # Mean value for all nymphs.
|
|
948 total_nymphs = apply((YoungNymphs.replications+OldNymphs.replications), 1, mean);
|
|
949 # Standard error for all nymphs.
|
|
950 total_nymphs.std_error = apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd);
|
18
|
951 } else if (life_stage_nymph=="Young") {
|
16
|
952 # Mean value for young nymphs.
|
|
953 young_nymphs = apply(YoungNymphs.replications, 1, mean);
|
|
954 # Standard error for young nymphs.
|
|
955 young_nymphs.std_error = apply(YoungNymphs.replications / sqrt(opt$replications), 1, sd);
|
18
|
956 } else if (life_stage_nymph=="Old") {
|
16
|
957 # Mean value for old nymphs.
|
|
958 old_nymphs = apply(OldNymphs.replications, 1, mean);
|
|
959 # Standard error for old nymphs.
|
|
960 old_nymphs.std_error = apply(OldNymphs.replications / sqrt(opt$replications), 1, sd);
|
|
961 }
|
10
|
962 }
|
|
963 }
|
|
964 if (process_adults) {
|
|
965 # Calculate adult populations for selected life stage.
|
16
|
966 for (life_stage_adult in life_stages_adult) {
|
18
|
967 if (life_stage_adult=="Total") {
|
16
|
968 # Mean value for all adults.
|
|
969 total_adults = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, mean);
|
|
970 # Standard error for all adults.
|
|
971 total_adults.std_error = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications);
|
18
|
972 } else if (life_stage_adult == "Pre-vittelogenic") {
|
16
|
973 # Mean value for previtellogenic adults.
|
|
974 previttelogenic_adults = apply(Previtellogenic.replications, 1, mean);
|
|
975 # Standard error for previtellogenic adults.
|
|
976 previttelogenic_adults.std_error = apply(Previtellogenic.replications, 1, sd) / sqrt(opt$replications);
|
18
|
977 } else if (life_stage_adult == "Vittelogenic") {
|
16
|
978 # Mean value for vitellogenic adults.
|
|
979 vittelogenic_adults = apply(Vitellogenic.replications, 1, mean);
|
|
980 # Standard error for vitellogenic adults.
|
|
981 vittelogenic_adults.std_error = apply(Vitellogenic.replications, 1, sd) / sqrt(opt$replications);
|
18
|
982 } else if (life_stage_adult == "Diapausing") {
|
16
|
983 # Mean value for vitellogenic adults.
|
|
984 diapausing_adults = apply(Diapausing.replications, 1, mean);
|
|
985 # Standard error for vitellogenic adults.
|
|
986 diapausing_adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications);
|
|
987 }
|
10
|
988 }
|
|
989 }
|
5
|
990
|
10
|
991 if (plot_generations_separately) {
|
20
|
992 m_se = get_mean_and_std_error(P.replications, F1.replications, F2.replications);
|
|
993 P = m_se[[1]];
|
|
994 P.std_error = m_se[[2]];
|
|
995 F1 = m_se[[3]];
|
|
996 F1.std_error = m_se[[4]];
|
|
997 F2 = m_se[[5]];
|
|
998 F2.std_error = m_se[[6]];
|
10
|
999 if (process_eggs) {
|
20
|
1000 m_se = get_mean_and_std_error(P_eggs.replications, F1_eggs.replications, F2_eggs.replications);
|
|
1001 P_eggs = m_se[[1]];
|
|
1002 P_eggs.std_error = m_se[[2]];
|
|
1003 F1_eggs = m_se[[3]];
|
|
1004 F1_eggs.std_error = m_se[[4]];
|
|
1005 F2_eggs = m_se[[5]];
|
|
1006 F2_eggs.std_error = m_se[[6]];
|
|
1007 }
|
|
1008 if (process_young_nymphs) {
|
|
1009 m_se = get_mean_and_std_error(P_young_nymphs.replications, F1_young_nymphs.replications, F2_young_nymphs.replications);
|
|
1010 P_young_nymphs = m_se[[1]];
|
|
1011 P_young_nymphs.std_error = m_se[[2]];
|
|
1012 F1_young_nymphs = m_se[[3]];
|
|
1013 F1_young_nymphs.std_error = m_se[[4]];
|
|
1014 F2_young_nymphs = m_se[[5]];
|
|
1015 F2_young_nymphs.std_error = m_se[[6]];
|
10
|
1016 }
|
20
|
1017 if (process_old_nymphs) {
|
|
1018 m_se = get_mean_and_std_error(P_old_nymphs.replications, F1_old_nymphs.replications, F2_old_nymphs.replications);
|
|
1019 P_old_nymphs = m_se[[1]];
|
|
1020 P_old_nymphs.std_error = m_se[[2]];
|
|
1021 F1_old_nymphs = m_se[[3]];
|
|
1022 F1_old_nymphs.std_error = m_se[[4]];
|
|
1023 F2_old_nymphs = m_se[[5]];
|
|
1024 F2_old_nymphs.std_error = m_se[[6]];
|
|
1025 }
|
|
1026 if (process_total_nymphs) {
|
|
1027 m_se = get_mean_and_std_error(P_total_nymphs.replications, F1_total_nymphs.replications, F2_total_nymphs.replications);
|
|
1028 P_total_nymphs = m_se[[1]];
|
|
1029 P_total_nymphs.std_error = m_se[[2]];
|
|
1030 F1_total_nymphs = m_se[[3]];
|
|
1031 F1_total_nymphs.std_error = m_se[[4]];
|
|
1032 F2_total_nymphs = m_se[[5]];
|
|
1033 F2_total_nymphs.std_error = m_se[[6]];
|
10
|
1034 }
|
|
1035 if (process_adults) {
|
20
|
1036 # Mean value for P_adults.
|
10
|
1037 P_adults = apply(P_adults.replications, 1, mean);
|
|
1038 # Standard error for P_adults.
|
|
1039 P_adults.std_error = apply(P_adults.replications, 1, sd) / sqrt(opt$replications);
|
|
1040 # Mean value for F1 adults.
|
|
1041 F1_adults = apply(F1_adults.replications, 1, mean);
|
20
|
1042 # Standard error for F1_adults.
|
10
|
1043 F1_adults.std_error = apply(F1_adults.replications, 1, sd) / sqrt(opt$replications);
|
20
|
1044 # Mean value for F2_adults.
|
10
|
1045 F2_adults = apply(F2_adults.replications, 1, mean);
|
20
|
1046 # Standard error for F2_adults.
|
10
|
1047 F2_adults.std_error = apply(F2_adults.replications, 1, sd) / sqrt(opt$replications);
|
|
1048 }
|
|
1049 }
|
6
|
1050
|
|
1051 # Display the total number of days in the Galaxy history item blurb.
|
8
|
1052 cat("Number of days: ", opt$num_days, "\n");
|
5
|
1053
|
10
|
1054 # Information needed for plots plots.
|
8
|
1055 days = c(1:opt$num_days);
|
|
1056 start_date = temperature_data_frame$DATE[1];
|
|
1057 end_date = temperature_data_frame$DATE[opt$num_days];
|
5
|
1058
|
10
|
1059 if (plot_generations_separately) {
|
15
|
1060 for (life_stage in life_stages) {
|
10
|
1061 if (life_stage == "Egg") {
|
|
1062 # Start PDF device driver.
|
|
1063 dev.new(width=20, height=30);
|
19
|
1064 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf")
|
10
|
1065 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1066 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1067 # Egg population size by generation.
|
18
|
1068 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100;
|
10
|
1069 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
|
1070 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,
|
|
1071 group3_std_error=F2_eggs.std_error);
|
|
1072 # Turn off device driver to flush output.
|
|
1073 dev.off();
|
|
1074 } else if (life_stage == "Nymph") {
|
16
|
1075 for (life_stage_nymph in life_stages_nymph) {
|
|
1076 # Start PDF device driver.
|
|
1077 dev.new(width=20, height=30);
|
19
|
1078 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", life_stage_nymph=life_stage_nymph)
|
16
|
1079 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1080 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
20
|
1081 if (life_stage_nymph=="Young") {
|
|
1082 # Young nymph population size by generation.
|
|
1083 maxval = max(P_young_nymphs+F1_young_nymphs+F2_young_nymphs) + 100;
|
|
1084 group = P_young_nymphs;
|
|
1085 group_std_error = P_young_nymphs.std_error;
|
|
1086 group2 = F1_young_nymphs;
|
|
1087 group2_std_error = F1_young_nymphs.std_error;
|
|
1088 group3 = F2_young_nymphs;
|
|
1089 group3_std_error = F2_young_nymphs.std_error;
|
|
1090 } else if (life_stage_nymph=="Old") {
|
|
1091 # Total nymph population size by generation.
|
|
1092 maxval = max(P_old_nymphs+F1_old_nymphs+F2_old_nymphs) + 100;
|
|
1093 group = P_old_nymphs;
|
|
1094 group_std_error = P_old_nymphs.std_error;
|
|
1095 group2 = F1_old_nymphs;
|
|
1096 group2_std_error = F1_old_nymphs.std_error;
|
|
1097 group3 = F2_old_nymphs;
|
|
1098 group3_std_error = F2_old_nymphs.std_error;
|
|
1099 } else if (life_stage_nymph=="Total") {
|
|
1100 # Total nymph population size by generation.
|
|
1101 maxval = max(P_total_nymphs+F1_total_nymphs+F2_total_nymphs) + 100;
|
|
1102 group = P_total_nymphs;
|
|
1103 group_std_error = P_total_nymphs.std_error;
|
|
1104 group2 = F1_total_nymphs;
|
|
1105 group2_std_error = F1_total_nymphs.std_error;
|
|
1106 group3 = F2_total_nymphs;
|
|
1107 group3_std_error = F2_total_nymphs.std_error;
|
|
1108 }
|
16
|
1109 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
20
|
1110 opt$replications, life_stage, group=group, group_std_error=group_std_error, group2=group2, group2_std_error=group2_std_error,
|
|
1111 group3=group3, group3_std_error=group3_std_error, life_stages_nymph=life_stage_nymph);
|
16
|
1112 # Turn off device driver to flush output.
|
|
1113 dev.off();
|
|
1114 }
|
10
|
1115 } else if (life_stage == "Adult") {
|
16
|
1116 for (life_stage_adult in life_stages_adult) {
|
|
1117 # Start PDF device driver.
|
|
1118 dev.new(width=20, height=30);
|
19
|
1119 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", life_stage_adult=life_stage_adult)
|
16
|
1120 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1121 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1122 # Adult population size by generation.
|
18
|
1123 maxval = max(P_adults+F1_adults+F2_adults) + 100;
|
16
|
1124 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
|
1125 opt$replications, life_stage, group=P_adults, group_std_error=P_adults.std_error, group2=F1_adults, group2_std_error=F1_adults.std_error,
|
|
1126 group3=F2_adults, group3_std_error=F2_adults.std_error, life_stages_adult=life_stage_adult);
|
|
1127 # Turn off device driver to flush output.
|
|
1128 dev.off();
|
|
1129 }
|
10
|
1130 } else if (life_stage == "Total") {
|
|
1131 # Start PDF device driver.
|
18
|
1132 # Name collection elements so that they
|
|
1133 # are displayed in logical order.
|
10
|
1134 dev.new(width=20, height=30);
|
19
|
1135 file_path = get_file_path(life_stage, "total_pop_by_generation.pdf")
|
10
|
1136 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1137 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1138 # Total population size by generation.
|
18
|
1139 maxval = max(P+F1+F2) + 100;
|
10
|
1140 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
|
1141 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);
|
|
1142 # Turn off device driver to flush output.
|
|
1143 dev.off();
|
|
1144 }
|
15
|
1145 }
|
10
|
1146 } else {
|
|
1147 for (life_stage in life_stages) {
|
|
1148 if (life_stage == "Egg") {
|
|
1149 # Start PDF device driver.
|
|
1150 dev.new(width=20, height=30);
|
19
|
1151 file_path = get_file_path(life_stage, "egg_pop.pdf")
|
10
|
1152 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1153 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1154 # Egg population size.
|
18
|
1155 maxval = max(eggs+eggs.std_error) + 100;
|
10
|
1156 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
|
1157 opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error);
|
|
1158 # Turn off device driver to flush output.
|
|
1159 dev.off();
|
|
1160 } else if (life_stage == "Nymph") {
|
16
|
1161 for (life_stage_nymph in life_stages_nymph) {
|
|
1162 # Start PDF device driver.
|
|
1163 dev.new(width=20, height=30);
|
19
|
1164 file_path = get_file_path(life_stage, "nymph_pop.pdf", life_stage_nymph=life_stage_nymph)
|
16
|
1165 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1166 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1167 if (life_stage_nymph=="Total") {
|
|
1168 # Total nymph population size.
|
|
1169 group = total_nymphs;
|
|
1170 group_std_error = total_nymphs.std_error;
|
|
1171 } else if (life_stage_nymph=="Young") {
|
|
1172 # Young nymph population size.
|
|
1173 group = young_nymphs;
|
|
1174 group_std_error = young_nymphs.std_error;
|
|
1175 } else if (life_stage_nymph=="Old") {
|
|
1176 # Old nymph population size.
|
|
1177 group = old_nymphs;
|
|
1178 group_std_error = old_nymphs.std_error;
|
|
1179 }
|
18
|
1180 maxval = max(group+group_std_error) + 100;
|
16
|
1181 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
|
1182 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_nymph=life_stage_nymph);
|
|
1183 # Turn off device driver to flush output.
|
|
1184 dev.off();
|
|
1185 }
|
10
|
1186 } else if (life_stage == "Adult") {
|
16
|
1187 for (life_stage_adult in life_stages_adult) {
|
|
1188 # Start PDF device driver.
|
|
1189 dev.new(width=20, height=30);
|
19
|
1190 file_path = get_file_path(life_stage, "adult_pop.pdf", life_stage_adult=life_stage_adult)
|
16
|
1191 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1192 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1193 if (life_stage_adult=="Total") {
|
|
1194 # Total adult population size.
|
|
1195 group = total_adults;
|
|
1196 group_std_error = total_adults.std_error
|
|
1197 } else if (life_stage_adult=="Pre-vittelogenic") {
|
|
1198 # Pre-vittelogenic adult population size.
|
|
1199 group = previttelogenic_adults;
|
|
1200 group_std_error = previttelogenic_adults.std_error
|
|
1201 } else if (life_stage_adult=="Vittelogenic") {
|
|
1202 # Vittelogenic adult population size.
|
|
1203 group = vittelogenic_adults;
|
|
1204 group_std_error = vittelogenic_adults.std_error
|
|
1205 } else if (life_stage_adult=="Diapausing") {
|
|
1206 # Diapausing adult population size.
|
|
1207 group = diapausing_adults;
|
|
1208 group_std_error = diapausing_adults.std_error
|
|
1209 }
|
18
|
1210 maxval = max(group+group_std_error) + 100;
|
16
|
1211 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
|
1212 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_adult=life_stage_adult);
|
|
1213 # Turn off device driver to flush output.
|
|
1214 dev.off();
|
|
1215 }
|
10
|
1216 } else if (life_stage == "Total") {
|
|
1217 # Start PDF device driver.
|
|
1218 dev.new(width=20, height=30);
|
19
|
1219 file_path = get_file_path(life_stage, "total_pop.pdf")
|
10
|
1220 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1221 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1222 # Total population size.
|
18
|
1223 maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100;
|
10
|
1224 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
|
16
|
1225 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
|
1226 group3_std_error=eggs.std_error);
|
|
1227 # Turn off device driver to flush output.
|
|
1228 dev.off();
|
|
1229 }
|
|
1230 }
|
|
1231 }
|