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