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