85
|
1 #!/usr/bin/env Rscript
|
|
2
|
|
3 suppressPackageStartupMessages(library("optparse"))
|
|
4
|
|
5 option_list <- list(
|
109
|
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"),
|
117
|
9 make_option(c("--end_date"), action="store", dest="end_date", default=NULL, help="End date for custom date interval"),
|
112
|
10 make_option(c("--input_norm"), action="store", dest="input_norm", help="30 year normals temperature data for selected station"),
|
|
11 make_option(c("--input_ytd"), action="store", dest="input_ytd", default=NULL, help="Year-to-date temperature data for selected location"),
|
109
|
12 make_option(c("--insect"), action="store", dest="insect", help="Insect name"),
|
|
13 make_option(c("--insects_per_replication"), action="store", dest="insects_per_replication", type="integer", help="Number of insects with which to start each replication"),
|
112
|
14 make_option(c("--life_stages"), action="store", dest="life_stages", help="Selected life stages for plotting"),
|
|
15 make_option(c("--life_stages_adult"), action="store", dest="life_stages_adult", default=NULL, help="Adult life stages for plotting"),
|
|
16 make_option(c("--life_stages_nymph"), action="store", dest="life_stages_nymph", default=NULL, help="Nymph life stages for plotting"),
|
|
17 make_option(c("--location"), action="store", dest="location", default=NULL, help="Selected location"),
|
109
|
18 make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"),
|
|
19 make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"),
|
112
|
20 make_option(c("--num_days_ytd"), action="store", dest="num_days_ytd", default=NULL, type="integer", help="Total number of days in the year-to-date temperature dataset"),
|
109
|
21 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"),
|
|
22 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"),
|
|
23 make_option(c("--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"),
|
|
24 make_option(c("--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"),
|
112
|
25 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"),
|
|
26 make_option(c("--plot_std_error"), action="store", dest="plot_std_error", help="Plot Standard error"),
|
109
|
27 make_option(c("--replications"), action="store", dest="replications", type="integer", help="Number of replications"),
|
117
|
28 make_option(c("--start_date"), action="store", dest="start_date", default=NULL, help="Start date for custom date interval"),
|
109
|
29 make_option(c("--young_nymph_accumulation"), action="store", dest="young_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (egg->young nymph)")
|
85
|
30 )
|
|
31
|
111
|
32 parser <- OptionParser(usage="%prog [options] file", option_list=option_list);
|
|
33 args <- parse_args(parser, positional_arguments=TRUE);
|
|
34 opt <- args$options;
|
85
|
35
|
122
|
36 add_daylight_length = function(temperature_data_frame) {
|
|
37 # Return temperature_data_frame with an added column
|
|
38 # of daylight length (photoperido profile).
|
|
39 num_rows = dim(temperature_data_frame)[1];
|
|
40 # From Forsythe 1995.
|
111
|
41 p = 0.8333;
|
|
42 latitude = temperature_data_frame$LATITUDE[1];
|
|
43 daylight_length_vector = NULL;
|
85
|
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.
|
111
|
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));
|
85
|
50 # Compute the length of daylight for the day of the year.
|
111
|
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;
|
85
|
53 }
|
|
54 # Append daylight_length_vector as a new column to temperature_data_frame.
|
112
|
55 temperature_data_frame = append_vector(temperature_data_frame, daylight_length_vector, "DAYLEN");
|
111
|
56 return(temperature_data_frame);
|
85
|
57 }
|
|
58
|
112
|
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);
|
102
|
67 }
|
|
68
|
119
|
69 extract_date_interval_rows = function(df, start_date, end_date) {
|
120
|
70 date_interval_rows = df[df$DATE >= start_date & df$DATE <= end_date];
|
119
|
71 return(date_interval_rows);
|
|
72 }
|
|
73
|
122
|
74 from_30_year_normals = function(temperature_data_frame, norm_data_frame, start_date_doy, end_date_doy) {
|
|
75 # The data we want is fully contained within the 30 year normals data.
|
|
76 first_norm_row = which(norm_data_frame$DOY==start_date_doy);
|
|
77 last_norm_row = which(norm_data_frame$DOY==end_date_doy);
|
|
78 norm_data_frame_rows = last_norm_row - first_norm_row;
|
|
79 j = 0;
|
|
80 for (i in first_norm_row:last_norm_row) {
|
|
81 j = j + 1;
|
|
82 temperature_data_frame[j,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i);
|
|
83 }
|
|
84 return (temperature_data_frame);
|
|
85 }
|
|
86
|
112
|
87 get_file_path = function(life_stage, base_name, life_stage_nymph=NULL, life_stage_adult=NULL) {
|
|
88 if (!is.null(life_stage_nymph)) {
|
|
89 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph);
|
|
90 file_name = paste(lsi, tolower(life_stage_nymph), base_name, sep="_");
|
|
91 } else if (!is.null(life_stage_adult)) {
|
|
92 lsi = get_life_stage_index(life_stage, life_stage_adult=life_stage_adult);
|
|
93 file_name = paste(lsi, tolower(life_stage_adult), base_name, sep="_");
|
|
94 } else {
|
|
95 lsi = get_life_stage_index(life_stage);
|
|
96 file_name = paste(lsi, base_name, sep="_");
|
|
97 }
|
|
98 file_path = paste("output_plots_dir", file_name, sep="/");
|
|
99 return(file_path);
|
102
|
100 }
|
|
101
|
112
|
102 get_life_stage_index = function(life_stage, life_stage_nymph=NULL, life_stage_adult=NULL) {
|
|
103 # Name collection elements so that they
|
|
104 # are displayed in logical order.
|
|
105 if (life_stage=="Egg") {
|
|
106 lsi = "01";
|
|
107 } else if (life_stage=="Nymph") {
|
|
108 if (life_stage_nymph=="Young") {
|
|
109 lsi = "02";
|
|
110 } else if (life_stage_nymph=="Old") {
|
|
111 lsi = "03";
|
|
112 } else if (life_stage_nymph=="Total") {
|
|
113 lsi="04";
|
|
114 }
|
|
115 } else if (life_stage=="Adult") {
|
|
116 if (life_stage_adult=="Pre-vittelogenic") {
|
|
117 lsi = "05";
|
|
118 } else if (life_stage_adult=="Vittelogenic") {
|
|
119 lsi = "06";
|
|
120 } else if (life_stage_adult=="Diapausing") {
|
|
121 lsi = "07";
|
|
122 } else if (life_stage_adult=="Total") {
|
|
123 lsi = "08";
|
|
124 }
|
|
125 } else if (life_stage=="Total") {
|
|
126 lsi = "09";
|
|
127 }
|
|
128 return(lsi);
|
111
|
129 }
|
|
130
|
112
|
131 get_mean_and_std_error = function(p_replications, f1_replications, f2_replications) {
|
|
132 # P mean.
|
|
133 p_m = apply(p_replications, 1, mean);
|
|
134 # P standard error.
|
|
135 p_se = apply(p_replications, 1, sd) / sqrt(opt$replications);
|
|
136 # F1 mean.
|
|
137 f1_m = apply(f1_replications, 1, mean);
|
|
138 # F1 standard error.
|
|
139 f1_se = apply(f1_replications, 1, sd) / sqrt(opt$replications);
|
|
140 # F2 mean.
|
|
141 f2_m = apply(f2_replications, 1, mean);
|
|
142 # F2 standard error.
|
|
143 f2_se = apply(f2_replications, 1, sd) / sqrt(opt$replications);
|
|
144 return(list(p_m, p_se, f1_m, f1_se, f2_m, f2_se))
|
|
145 }
|
111
|
146
|
112
|
147 get_next_normals_row = function(norm_data_frame, year, is_leap_year, index) {
|
|
148 # Return the next 30 year normals row formatted
|
|
149 # appropriately for the year-to-date data.
|
|
150 latitude = norm_data_frame[index,"LATITUDE"][1];
|
|
151 longitude = norm_data_frame[index,"LONGITUDE"][1];
|
|
152 # Format the date.
|
|
153 mmdd = norm_data_frame[index,"MMDD"][1];
|
|
154 date_str = paste(year, mmdd, sep="-");
|
|
155 doy = norm_data_frame[index,"DOY"][1];
|
|
156 if (!is_leap_year) {
|
|
157 # Since all normals data includes Feb 29, we have to
|
|
158 # subtract 1 from DOY if we're not in a leap year since
|
|
159 # we removed the Feb 29 row from the data frame above.
|
|
160 doy = as.integer(doy) - 1;
|
111
|
161 }
|
112
|
162 tmin = norm_data_frame[index,"TMIN"][1];
|
|
163 tmax = norm_data_frame[index,"TMAX"][1];
|
|
164 return(list(latitude, longitude, date_str, doy, tmin, tmax));
|
102
|
165 }
|
|
166
|
117
|
167 get_temperature_at_hour = function(latitude, temperature_data_frame, row) {
|
111
|
168 # Base development threshold for Brown Marmorated Stink Bug
|
85
|
169 # insect phenology model.
|
111
|
170 threshold = 14.17;
|
85
|
171 # Minimum temperature for current row.
|
111
|
172 curr_min_temp = temperature_data_frame$TMIN[row];
|
85
|
173 # Maximum temperature for current row.
|
111
|
174 curr_max_temp = temperature_data_frame$TMAX[row];
|
85
|
175 # Mean temperature for current row.
|
111
|
176 curr_mean_temp = 0.5 * (curr_min_temp + curr_max_temp);
|
85
|
177 # Initialize degree day accumulation
|
111
|
178 averages = 0;
|
102
|
179 if (curr_max_temp < threshold) {
|
111
|
180 averages = 0;
|
85
|
181 }
|
|
182 else {
|
|
183 # Initialize hourly temperature.
|
111
|
184 T = NULL;
|
85
|
185 # Initialize degree hour vector.
|
111
|
186 dh = NULL;
|
85
|
187 # Daylight length for current row.
|
111
|
188 y = temperature_data_frame$DAYLEN[row];
|
85
|
189 # Darkness length.
|
111
|
190 z = 24 - y;
|
85
|
191 # Lag coefficient.
|
111
|
192 a = 1.86;
|
85
|
193 # Darkness coefficient.
|
111
|
194 b = 2.20;
|
85
|
195 # Sunrise time.
|
111
|
196 risetime = 12 - y / 2;
|
85
|
197 # Sunset time.
|
111
|
198 settime = 12 + y / 2;
|
|
199 ts = (curr_max_temp - curr_min_temp) * sin(pi * (settime - 5) / (y + 2 * a)) + curr_min_temp;
|
85
|
200 for (i in 1:24) {
|
|
201 if (i > risetime && i < settime) {
|
|
202 # Number of hours after Tmin until sunset.
|
111
|
203 m = i - 5;
|
|
204 T[i] = (curr_max_temp - curr_min_temp) * sin(pi * m / (y + 2 * a)) + curr_min_temp;
|
85
|
205 if (T[i] < 8.4) {
|
111
|
206 dh[i] = 0;
|
85
|
207 }
|
|
208 else {
|
111
|
209 dh[i] = T[i] - 8.4;
|
85
|
210 }
|
|
211 }
|
96
|
212 else if (i > settime) {
|
111
|
213 n = i - settime;
|
|
214 T[i] = curr_min_temp + (ts - curr_min_temp) * exp( - b * n / z);
|
85
|
215 if (T[i] < 8.4) {
|
111
|
216 dh[i] = 0;
|
85
|
217 }
|
|
218 else {
|
111
|
219 dh[i] = T[i] - 8.4;
|
85
|
220 }
|
|
221 }
|
|
222 else {
|
111
|
223 n = i + 24 - settime;
|
|
224 T[i] = curr_min_temp + (ts - curr_min_temp) * exp( - b * n / z);
|
85
|
225 if (T[i] < 8.4) {
|
111
|
226 dh[i] = 0;
|
85
|
227 }
|
|
228 else {
|
111
|
229 dh[i] = T[i] - 8.4;
|
85
|
230 }
|
|
231 }
|
|
232 }
|
111
|
233 averages = sum(dh) / 24;
|
85
|
234 }
|
103
|
235 return(c(curr_mean_temp, averages))
|
85
|
236 }
|
|
237
|
112
|
238 get_tick_index = function(index, last_tick, ticks, month_labels) {
|
|
239 # The R code tries hard not to draw overlapping tick labels, and so
|
|
240 # will omit labels where they would abut or overlap previously drawn
|
|
241 # labels. This can result in, for example, every other tick being
|
|
242 # labelled. We'll keep track of the last tick to make sure all of
|
|
243 # the month labels are displayed, and missing ticks are restricted
|
|
244 # to Sundays which have no labels anyway.
|
|
245 if (last_tick==0) {
|
|
246 return(length(ticks)+1);
|
|
247 }
|
|
248 last_saved_tick = ticks[[length(ticks)]];
|
|
249 if (index-last_saved_tick<3) {
|
|
250 last_saved_month = month_labels[[length(month_labels)]];
|
|
251 if (last_saved_month=="") {
|
|
252 # We're safe overwriting a tick
|
|
253 # with no label (i.e., a Sunday tick).
|
|
254 return(length(ticks));
|
|
255 } else {
|
|
256 # Don't eliminate a Month label.
|
|
257 return(NULL);
|
|
258 }
|
|
259 }
|
|
260 return(length(ticks)+1);
|
|
261 }
|
|
262
|
|
263 get_total_days = function(is_leap_year) {
|
|
264 # Get the total number of days in the current year.
|
|
265 if (is_leap_year) {
|
|
266 return(366);
|
|
267 } else {
|
|
268 return(365);
|
|
269 }
|
|
270 }
|
|
271
|
123
|
272 get_x_axis_ticks_and_labels = function(temperature_data_frame, prepend_end_doy_norm, append_start_doy_norm, date_interval) {
|
122
|
273 # Generate a list of ticks and labels for plotting the
|
|
274 # x axis. There are several scenarios that affect this.
|
123
|
275 # 1. If date_interval is TRUE:
|
122
|
276 # a.
|
|
277 if (prepend_end_doy_norm > 0) {
|
|
278 prepend_end_norm_row = which(temperature_data_frame$DOY==prepend_end_doy_norm);
|
|
279 } else {
|
|
280 prepend_end_norm_row = 0;
|
|
281 }
|
|
282 if (append_start_doy_norm > 0) {
|
|
283 append_start_norm_row = which(temperature_data_frame$DOY==append_start_doy_norm);
|
|
284 } else {
|
|
285 append_start_norm_row = 0;
|
|
286 }
|
|
287 num_rows = dim(temperature_data_frame)[1];
|
112
|
288 month_labels = list();
|
|
289 ticks = list();
|
|
290 current_month_label = NULL;
|
|
291 last_tick = 0;
|
|
292 for (i in 1:num_rows) {
|
122
|
293 # We're plotting the entire year, so ticks will
|
|
294 # occur on Sundays and the first of each month.
|
|
295 if (i == prepend_end_norm_row) {
|
112
|
296 # Add a tick for the end of the 30 year normnals data
|
|
297 # that was prepended to the year-to-date data.
|
|
298 tick_index = get_tick_index(i, last_tick, ticks, month_labels)
|
|
299 ticks[tick_index] = i;
|
|
300 month_labels[tick_index] = "End prepended 30 year normals";
|
|
301 last_tick = i;
|
122
|
302 } else if (i == append_start_doy_norm) {
|
112
|
303 # Add a tick for the start of the 30 year normnals data
|
|
304 # that was appended to the year-to-date data.
|
|
305 tick_index = get_tick_index(i, last_tick, ticks, month_labels)
|
|
306 ticks[tick_index] = i;
|
|
307 month_labels[tick_index] = "Start appended 30 year normals";
|
|
308 last_tick = i;
|
|
309 } else if (i==num_rows) {
|
|
310 # Add a tick for the last day of the year.
|
|
311 tick_index = get_tick_index(i, last_tick, ticks, month_labels)
|
|
312 ticks[tick_index] = i;
|
|
313 month_labels[tick_index] = "";
|
|
314 last_tick = i;
|
|
315 } else {
|
|
316 # Get the year and month from the date which
|
|
317 # has the format YYYY-MM-DD.
|
|
318 date = format(temperature_data_frame$DATE[i]);
|
|
319 # Get the month label.
|
|
320 items = strsplit(date, "-")[[1]];
|
|
321 month = items[2];
|
|
322 month_label = month.abb[as.integer(month)];
|
|
323 if (!identical(current_month_label, month_label)) {
|
122
|
324 # Add a tick for the month.
|
112
|
325 tick_index = get_tick_index(i, last_tick, ticks, month_labels)
|
|
326 ticks[tick_index] = i;
|
|
327 month_labels[tick_index] = month_label;
|
|
328 current_month_label = month_label;
|
|
329 last_tick = i;
|
|
330 }
|
|
331 tick_index = get_tick_index(i, last_tick, ticks, month_labels)
|
|
332 if (!is.null(tick_index)) {
|
123
|
333 if (date_interval) {
|
122
|
334 # Add a tick for every day.
|
112
|
335 ticks[tick_index] = i;
|
|
336 # Add a blank month label so it is not displayed.
|
|
337 month_labels[tick_index] = "";
|
|
338 last_tick = i;
|
122
|
339 } else {
|
|
340 # Get the day.
|
|
341 day = weekdays(as.Date(date));
|
|
342 if (day=="Sunday") {
|
|
343 # Add a tick if we're on a Sunday.
|
|
344 ticks[tick_index] = i;
|
|
345 # Add a blank month label so it is not displayed.
|
|
346 month_labels[tick_index] = "";
|
|
347 last_tick = i;
|
|
348 }
|
112
|
349 }
|
|
350 }
|
|
351 }
|
|
352 }
|
|
353 return(list(ticks, month_labels));
|
|
354 }
|
|
355
|
|
356 is_leap_year = function(date_str) {
|
|
357 # Extract the year from the date_str.
|
|
358 date = format(date_str);
|
|
359 items = strsplit(date, "-")[[1]];
|
|
360 year = as.integer(items[1]);
|
|
361 if (((year %% 4 == 0) & (year %% 100 != 0)) | (year %% 400 == 0)) {
|
|
362 return(TRUE);
|
|
363 } else {
|
|
364 return(FALSE);
|
|
365 }
|
|
366 }
|
|
367
|
102
|
368 mortality.adult = function(temperature) {
|
|
369 if (temperature < 12.7) {
|
111
|
370 mortality.probability = 0.002;
|
102
|
371 }
|
|
372 else {
|
111
|
373 mortality.probability = temperature * 0.0005 + 0.02;
|
102
|
374 }
|
|
375 return(mortality.probability)
|
85
|
376 }
|
|
377
|
|
378 mortality.egg = function(temperature) {
|
|
379 if (temperature < 12.7) {
|
111
|
380 mortality.probability = 0.8;
|
85
|
381 }
|
|
382 else {
|
111
|
383 mortality.probability = 0.8 - temperature / 40.0;
|
102
|
384 if (mortality.probability < 0) {
|
111
|
385 mortality.probability = 0.01;
|
85
|
386 }
|
|
387 }
|
102
|
388 return(mortality.probability)
|
85
|
389 }
|
|
390
|
|
391 mortality.nymph = function(temperature) {
|
|
392 if (temperature < 12.7) {
|
111
|
393 mortality.probability = 0.03;
|
85
|
394 }
|
|
395 else {
|
111
|
396 mortality.probability = temperature * 0.0008 + 0.03;
|
85
|
397 }
|
111
|
398 return(mortality.probability);
|
102
|
399 }
|
|
400
|
122
|
401 parse_input_data = function(input_ytd, input_norm, location, start_date, end_date) {
|
|
402 # The end DOY for norm data prepended to ytd data.
|
|
403 prepend_end_doy_norm = 0;
|
|
404 # The start DOY for norm data appended to ytd data.
|
|
405 append_start_doy_norm = 0;
|
112
|
406 if (is.null(input_ytd)) {
|
122
|
407 # We're processing only the 30 year normals data.
|
|
408 processing_year_to_date_data = FALSE;
|
|
409 } else {
|
|
410 processing_year_to_date_data = TRUE;
|
|
411 }
|
|
412 if (is.null(start_date) && is.null(end_date)) {
|
|
413 # We're processing the entire year, possibly merging
|
|
414 # data from input_norm with data from input_ytd.
|
123
|
415 date_interval = FALSE;
|
122
|
416 } else {
|
123
|
417 date_interval = TRUE;
|
122
|
418 # Get the DOY for start_date and end_date.
|
|
419 start_date_doy = strftime(start_date, format="%j");
|
|
420 end_date_doy = strftime(end_date, format="%j");
|
|
421 }
|
|
422 # Read the input_norm temperature datafile into a data frame.
|
|
423 # The input_norm data has the following 10 columns:
|
|
424 # STATIONID, LATITUDE, LONGITUDE, ELEV_M, NAME, ST, MMDD, DOY, TMIN, TMAX
|
|
425 norm_data_frame = read.csv(file=input_norm, header=T, strip.white=TRUE, stringsAsFactors=FALSE, sep=",");
|
|
426 # Set the norm_data_frame column names for access.
|
|
427 colnames(norm_data_frame) = c("STATIONID", "LATITUDE","LONGITUDE", "ELEV_M", "NAME", "ST", "MMDD", "DOY", "TMIN", "TMAX");
|
|
428 if (processing_year_to_date_data) {
|
|
429 # Read the input_ytd temperature data file into a data frame.
|
|
430 # The input_ytd data has the following 6 columns:
|
|
431 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX
|
|
432 temperature_data_frame = read.csv(file=input_ytd, header=T, strip.white=TRUE, stringsAsFactors=FALSE, sep=",");
|
|
433 # Set the temperature_data_frame column names for access.
|
|
434 colnames(temperature_data_frame) = c("LATITUDE", "LONGITUDE", "DATE", "DOY", "TMIN", "TMAX");
|
123
|
435 if (date_interval) {
|
122
|
436 # We're plotting a date interval.
|
|
437 start_date_ytd_row = which(temperature_data_frame$DATE==start_date);
|
|
438 if (start_date_ytd_row > 0) {
|
|
439 # The start date is contained within the input_ytd data.
|
|
440 start_doy_ytd = as.integer(temperature_data_frame$DOY[start_date_ytd_row]);
|
|
441 } else {
|
|
442 # The start date is contained within the input_norm data.
|
|
443 start_date_norm_row = which(norm_data_frame$DATE==start_date);
|
|
444 }
|
|
445 end_date_ytd_row = which(temperature_data_frame$DATE==end_date);
|
|
446 if (end_date_ytd_row > 0) {
|
|
447 # The end date is contained within the input_ytd data.
|
|
448 end_doy_ytd = as.integer(temperature_data_frame$DOY[end_date_ytd_row]);
|
|
449 }
|
|
450 date_str = start_date;
|
123
|
451 # Extract the year from the start date.
|
|
452 date_str_items = strsplit(date_str, "-")[[1]];
|
|
453 year = date_str_items[1];
|
122
|
454 } else {
|
|
455 # We're plotting an entire year.
|
|
456 # Get the number of days contained in temperature_data_frame.
|
|
457 num_rows = dim(temperature_data_frame)[1];
|
|
458 # Get the start date and end date from temperature_data_frame.
|
|
459 start_date_ytd_row = 1;
|
123
|
460 # Temporarily set start_date to get the year.
|
122
|
461 start_date = temperature_data_frame$DATE[1];
|
|
462 end_date_ytd_row = num_rows;
|
|
463 end_date = temperature_data_frame$DATE[num_rows];
|
|
464 date_str = format(start_date);
|
123
|
465 # Extract the year from the start date.
|
|
466 date_str_items = strsplit(date_str, "-")[[1]];
|
|
467 # Get the year.
|
|
468 year = date_str_items[1];
|
|
469 # Properly set the start_date to be Jan 1 of the year.
|
|
470 start_date = paste(year, "01", "01", sep="-");
|
|
471 # Properly set the end_date to be Dec 31 of the year.
|
|
472 end_date = paste(year, "12", "31", sep="-");
|
122
|
473 # Save the first DOY to later check if start_date is Jan 1.
|
|
474 start_doy_ytd = as.integer(temperature_data_frame$DOY[1]);
|
|
475 end_doy_ytd = as.integer(temperature_data_frame$DOY[num_rows]);
|
|
476 }
|
|
477 } else {
|
|
478 # We're processing only the 30 year normals data, so create an empty
|
112
|
479 # data frame for containing temperature data after it is converted
|
|
480 # from the 30 year normals format to the year-to-date format.
|
|
481 temperature_data_frame = data.frame(matrix(ncol=6, nrow=0));
|
|
482 colnames(temperature_data_frame) = c("LATITUDE", "LONGITUDE", "DATE", "DOY", "TMIN", "TMAX");
|
123
|
483 if (date_interval) {
|
122
|
484 # We're plotting a date interval.
|
|
485 # Extract the year, month and day from the start date.
|
117
|
486 start_date_str = format(start_date);
|
|
487 start_date_str_items = strsplit(start_date_str, "-")[[1]];
|
122
|
488 year = start_date_str_items[1];
|
117
|
489 start_date_month = start_date_str_items[2];
|
|
490 start_date_day = start_date_str_items[3];
|
|
491 start_date = paste(year, start_date_month, start_date_day, sep="-");
|
|
492 # Extract the month and day from the end date.
|
|
493 end_date_str = format(start_date);
|
|
494 end_date_str_items = strsplit(end_date_str, "-")[[1]];
|
|
495 end_date_month = end_date_str_items[2];
|
|
496 end_date_day = end_date_str_items[3];
|
123
|
497 end_date = paste(year, end_date_month, end_date_day, sep="-");
|
122
|
498 } else {
|
|
499 # We're plotting an entire year.
|
|
500 # Base all dates on the current date since 30 year
|
|
501 # normals data does not include any dates.
|
|
502 year = format(Sys.Date(), "%Y");
|
|
503 start_date = paste(year, "01", "01", sep="-");
|
|
504 end_date = paste(year, "12", "31", sep="-");
|
117
|
505 }
|
112
|
506 }
|
|
507 # See if we're in a leap year.
|
|
508 is_leap_year = is_leap_year(start_date);
|
|
509 # All normals data includes Feb 29 which is row 60 in
|
|
510 # the data, so delete that row if we're not in a leap year.
|
|
511 if (!is_leap_year) {
|
|
512 norm_data_frame = norm_data_frame[-c(60),];
|
102
|
513 }
|
122
|
514 # Set the location to be the station name if the user elected not to enter it.
|
|
515 if (is.null(location) | length(location) == 0) {
|
112
|
516 location = norm_data_frame$NAME[1];
|
|
517 }
|
122
|
518 if (processing_year_to_date_data) {
|
|
519 # Merge the year-to-date data with the 30 year normals data.
|
123
|
520 if (date_interval) {
|
122
|
521 # The values of start_date_ytd_row and end_date_ytd_row were set above.
|
|
522 if (start_date_ytd_row > 0 & end_date_ytd_row > 0) {
|
|
523 # The date interval is contained within the input_ytd
|
|
524 # data, so we don't need to merge the 30 year normals data.
|
|
525 temperature_data_frame = temperature_data_frame[start_date_ytd_row:end_date_ytd_row,];
|
|
526 } else if (start_date_ytd_row == 0 & end_date_ytd_row > 0) {
|
|
527 # The date interval starts in input_norm and ends in
|
|
528 # input_ytd, so prepend appropriate rows from input_norm
|
|
529 # to appropriate rows from input_ytd.
|
|
530 first_norm_row = which(norm_data_frame$DOY==start_date_doy);
|
|
531 # Get the first DOY from temperature_data_frame.
|
|
532 first_ytd_doy = temperature_data_frame$DOY[1];
|
|
533 # End DOY of input_norm data prepended to input_ytd.
|
|
534 prepend_end_doy_norm = first_ytd_doy - 1;
|
|
535 # Get the number of rows for the restricted date interval
|
|
536 # that are contained in temperature_data_frame.
|
|
537 temperature_data_frame_rows = end_date_ytd_row;
|
|
538 # Get the last row needed from the 30 year normals data.
|
|
539 last_norm_row = which(norm_data_frame$DOY==prepend_end_doy_norm);
|
|
540 # Get the number of rows for the restricted date interval
|
|
541 # that are contained in norm_data_frame.
|
|
542 norm_data_frame_rows = last_norm_row - first_norm_row;
|
|
543 # Create a temporary data frame to contain the 30 year normals
|
|
544 # data from the start date to the date immediately prior to the
|
|
545 # first row of the input_ytd data.
|
|
546 tmp_norm_data_frame = data.frame(matrix(ncol=6, nrow=temperature_data_frame_rows+norm_data_frame_rows));
|
|
547 for (i in first_norm_row:last_norm_row) {
|
|
548 # Populate the temp_data_frame row with
|
|
549 # values from norm_data_frame.
|
|
550 tmp_norm_data_frame[i,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i);
|
|
551 }
|
|
552 # Create a second temporary data frame containing the
|
|
553 # appropriate rows from temperature_data_frame.
|
|
554 tmp_temperature_data_frame = temperature_data_frame[1:first_norm_row-1,];
|
|
555 # Merge the 2 temporary data frames.
|
|
556 temperature_data_frame = rbind(tmp_norm_data_frame, tmp_temperature_data_frame);
|
|
557 } else if (start_date_ytd_row > 0 & end_date_ytd_row == 0) {
|
|
558 # The date interval starts in input_ytd and ends in input_norm,
|
|
559 # so append appropriate rows from input_norm to appropriate rows
|
|
560 # from input_ytd.
|
|
561 num_rows = dim(temperature_data_frame)[1];
|
|
562 # Get the number of rows for the restricted date interval
|
|
563 # that are contained in temperature_data_frame.
|
|
564 temperature_data_frame_rows = num_rows - start_date_ytd_row
|
|
565 # Get the DOY of the last row in the input_ytd data.
|
|
566 last_ytd_doy = temperature_data_frame$DOY[num_rows];
|
|
567 # Get the DOYs for the first and last rows from norm_data_frame
|
|
568 # that will be appended to temperature_data_frame.
|
|
569 append_start_doy_norm = last_ytd_doy + 1;
|
|
570 # Get the row from norm_data_frame containing first_norm_doy.
|
|
571 first_norm_row = which(norm_data_frame$DOY == append_start_doy_norm);
|
|
572 # Get the row from norm_data_frame containing end_date_doy.
|
|
573 last_norm_row = which(norm_data_frame$DOY == end_date_doy);
|
|
574 # Get the number of rows for the restricted date interval
|
|
575 # that are contained in norm_data_frame.
|
|
576 norm_data_frame_rows = last_norm_row - first_norm_row;
|
|
577 # Create a temporary data frame to contain the data
|
|
578 # taken from both temperateu_data_frame and norm_data_frame
|
|
579 # for the date interval.
|
|
580 tmp_data_frame = data.frame(matrix(ncol=6, nrow=temperature_data_frame_rows+norm_data_frame_rows));
|
|
581 # Populate tmp_data_frame with the appropriate rows from temperature_data_frame.
|
|
582 tmp_data_frame[temperature_data_frame_rows,] = temperature_data_frame[start_date_ytd_row:temperature_data_frame_rows,];
|
|
583 # Apppend the appropriate rows from norm_data_frame to tmp_data_frame.
|
|
584 for (i in first_norm_row:last_norm_row) {
|
|
585 tmp_data_frame[i,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i);
|
|
586 }
|
|
587 temperature_data_frame = tmp_data_frame[,];
|
|
588 } else if (start_date_ytd_row == 0 & end_date_ytd_row == 0) {
|
|
589 # The date interval is contained witin input_norm.
|
|
590 temperature_data_frame = from_30_year_normals(temperature_data_frame, norm_data_frame, start_date_doy, end_date_doy);
|
|
591 }
|
|
592 } else {
|
|
593 # We're plotting an entire year.
|
|
594 if (start_doy_ytd > 1) {
|
|
595 # The input_ytd data starts after Jan 1, so prepend
|
|
596 # appropriate rows from input_norm to temperature_data_frame.
|
|
597 prepend_end_doy_norm = start_doy_ytd - 1;
|
|
598 first_norm_row = 1;
|
|
599 last_norm_row = which(norm_data_frame$DOY == prepend_end_doy_norm);
|
|
600 # Create a temporary data frame to contain the input_norm data
|
|
601 # from Jan 1 to the date immediately prior to start_date.
|
|
602 tmp_data_frame = temperature_data_frame[FALSE,];
|
|
603 # Populate tmp_data_frame with appropriate rows from norm_data_frame.
|
|
604 for (i in first_norm_row:last_norm_row) {
|
|
605 tmp_data_frame[i,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i);
|
|
606 }
|
|
607 # Merge the temporary data frame with temperature_data_frame.
|
|
608 temperature_data_frame = rbind(tmp_data_frame, temperature_data_frame);
|
|
609 }
|
|
610 # Set the value of total_days.
|
|
611 total_days = get_total_days(is_leap_year);
|
|
612 if (end_doy_ytd < total_days) {
|
|
613 # Define the next row for the year-to-date data from the 30 year normals data.
|
|
614 append_start_doy_norm = end_doy_ytd + 1;
|
|
615 first_norm_row = which(norm_data_frame$DOY == append_start_doy_norm);
|
|
616 # Append the 30 year normals data to the year-to-date data.
|
123
|
617 for (i in first_norm_row:total_days) {
|
122
|
618 temperature_data_frame[i,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i);
|
|
619 }
|
|
620 }
|
112
|
621 }
|
|
622 } else {
|
122
|
623 # We're processing only the 30 year normals data.
|
123
|
624 if (date_interval) {
|
122
|
625 # Populate temperature_data_frame from norm_data_frame.
|
|
626 temperature_data_frame = from_30_year_normals(temperature_data_frame, norm_data_frame, start_date_doy, end_date_doy);
|
|
627 } else {
|
|
628 total_days = get_total_days(is_leap_year);
|
|
629 for (i in 1:total_days) {
|
|
630 temperature_data_frame[i,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i);
|
112
|
631 }
|
|
632 }
|
|
633 }
|
|
634 # Add a column containing the daylight length for each day.
|
122
|
635 temperature_data_frame = add_daylight_length(temperature_data_frame);
|
|
636 return(list(temperature_data_frame, start_date, end_date, prepend_end_doy_norm, append_start_doy_norm, is_leap_year, location));
|
85
|
637 }
|
|
638
|
112
|
639 render_chart = function(ticks, date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval,
|
|
640 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL,
|
|
641 life_stages_adult=NULL, life_stages_nymph=NULL) {
|
|
642 if (chart_type=="pop_size_by_life_stage") {
|
|
643 if (life_stage=="Total") {
|
|
644 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
645 legend_text = c("Egg", "Nymph", "Adult");
|
|
646 columns = c(4, 2, 1);
|
|
647 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=FALSE, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
648 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3);
|
|
649 lines(days, group2, lwd=2, lty=1, col=2);
|
|
650 lines(days, group3, lwd=2, lty=1, col=4);
|
|
651 axis(side=1, at=ticks, labels=date_labels, las=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
652 axis(side=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
653 if (plot_std_error=="yes") {
|
|
654 # Standard error for group.
|
|
655 lines(days, group+group_std_error, lty=2);
|
|
656 lines(days, group-group_std_error, lty=2);
|
|
657 # Standard error for group2.
|
|
658 lines(days, group2+group2_std_error, col=2, lty=2);
|
|
659 lines(days, group2-group2_std_error, col=2, lty=2);
|
|
660 # Standard error for group3.
|
|
661 lines(days, group3+group3_std_error, col=4, lty=2);
|
|
662 lines(days, group3-group3_std_error, col=4, lty=2);
|
|
663 }
|
|
664 } else {
|
|
665 if (life_stage=="Egg") {
|
|
666 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
667 legend_text = c(life_stage);
|
|
668 columns = c(4);
|
|
669 } else if (life_stage=="Nymph") {
|
|
670 stage = paste(life_stages_nymph, "Nymph Pop :", sep=" ");
|
|
671 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
672 legend_text = c(paste(life_stages_nymph, life_stage, sep=" "));
|
|
673 columns = c(2);
|
|
674 } else if (life_stage=="Adult") {
|
|
675 stage = paste(life_stages_adult, "Adult Pop", sep=" ");
|
|
676 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
|
677 legend_text = c(paste(life_stages_adult, life_stage, sep=" "));
|
|
678 columns = c(1);
|
|
679 }
|
|
680 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=FALSE, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
681 legend("topleft", legend_text, lty=c(1), col="black", cex=3);
|
|
682 axis(side=1, at=ticks, labels=date_labels, las=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
683 axis(side=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
684 if (plot_std_error=="yes") {
|
|
685 # Standard error for group.
|
|
686 lines(days, group+group_std_error, lty=2);
|
|
687 lines(days, group-group_std_error, lty=2);
|
|
688 }
|
|
689 }
|
|
690 } else if (chart_type=="pop_size_by_generation") {
|
|
691 if (life_stage=="Total") {
|
|
692 title_str = ": Total Pop by Gen :";
|
|
693 } else if (life_stage=="Egg") {
|
|
694 title_str = ": Egg Pop by Gen :";
|
|
695 } else if (life_stage=="Nymph") {
|
|
696 title_str = paste(":", life_stages_nymph, "Nymph Pop by Gen", ":", sep=" ");
|
|
697 } else if (life_stage=="Adult") {
|
|
698 title_str = paste(":", life_stages_adult, "Adult Pop by Gen", ":", sep=" ");
|
|
699 }
|
|
700 title = paste(insect, ": Reps", replications, title_str, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
|
111
|
701 legend_text = c("P", "F1", "F2");
|
|
702 columns = c(1, 2, 4);
|
112
|
703 plot(days, group, main=title, type="l", ylim=c(0, maxval), axes=FALSE, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
704 legend("topleft", legend_text, lty=c(1, 1, 1), col=columns, cex=3);
|
|
705 lines(days, group2, lwd=2, lty=1, col=2);
|
|
706 lines(days, group3, lwd=2, lty=1, col=4);
|
|
707 axis(side=1, at=ticks, labels=date_labels, las=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
708 axis(side=2, font.axis=3, xpd=TRUE, cex=3, cex.lab=3, cex.axis=3, cex.main=3);
|
|
709 if (plot_std_error=="yes") {
|
|
710 # Standard error for group.
|
|
711 lines(days, group+group_std_error, lty=2);
|
|
712 lines(days, group-group_std_error, lty=2);
|
|
713 # Standard error for group2.
|
|
714 lines(days, group2+group2_std_error, col=2, lty=2);
|
|
715 lines(days, group2-group2_std_error, col=2, lty=2);
|
|
716 # Standard error for group3.
|
|
717 lines(days, group3+group3_std_error, col=4, lty=2);
|
|
718 lines(days, group3-group3_std_error, col=4, lty=2);
|
|
719 }
|
85
|
720 }
|
|
721 }
|
|
722
|
117
|
723 stop_err = function(msg) {
|
|
724 cat(msg, file=stderr());
|
|
725 quit(save="no", status=1);
|
|
726 }
|
|
727
|
|
728 validate_date = function(date_str) {
|
|
729 valid_date = as.Date(date_str, format="%Y-%m-%d");
|
|
730 if( class(valid_date)=="try-error" || is.na(valid_date)) {
|
|
731 msg = paste("Invalid date: ", date_str, ", valid date format is yyyy-mm-dd.", sep="");
|
|
732 stop_err(msg);
|
|
733 }
|
|
734 return(valid_date);
|
|
735 }
|
|
736
|
123
|
737 if (is.null(opt$input_ytd)) {
|
122
|
738 processing_year_to_date_data = FALSE;
|
|
739 } else {
|
|
740 processing_year_to_date_data = TRUE;
|
|
741 }
|
112
|
742 # Determine if we're plotting generations separately.
|
|
743 if (opt$plot_generations_separately=="yes") {
|
|
744 plot_generations_separately = TRUE;
|
|
745 } else {
|
|
746 plot_generations_separately = FALSE;
|
|
747 }
|
117
|
748 if (is.null(opt$start_date) && is.null(opt$end_date)) {
|
122
|
749 # We're plotting an entire year.
|
123
|
750 date_interval = FALSE;
|
122
|
751 # Display the total number of days in the Galaxy history item blurb.
|
|
752 if (processing_year_to_date_data) {
|
|
753 cat("Number of days year-to-date: ", opt$num_days_ytd, "\n");
|
|
754 } else {
|
|
755 if (is_leap_year) {
|
|
756 num_days = 366;
|
|
757 } else {
|
|
758 num_days = 365;
|
|
759 }
|
|
760 cat("Number of days in year: ", num_days, "\n");
|
|
761 }
|
117
|
762 } else {
|
|
763 # FIXME: currently custom date fields are free text, but
|
|
764 # Galaxy should soon include support for a date selector
|
|
765 # at which point this tool should be enhanced to use it.
|
|
766 # Validate start_date.
|
123
|
767 date_interval = TRUE;
|
122
|
768 # Calaculate the number of days in the date interval rather
|
|
769 # than using the number of rows in the input temperature data.
|
|
770 start_date = validate_date(opt$start_date);
|
117
|
771 # Validate end_date.
|
|
772 end_date = validate_date(opt$end_date);
|
|
773 if (start_date >= end_date) {
|
122
|
774 stop_err("The start date must be between 1 and 50 days before the end date when setting date intervals for plots.");
|
117
|
775 }
|
122
|
776 # Calculate the number of days in the date interval.
|
117
|
777 num_days = difftime(start_date, end_date, units=c("days"));
|
|
778 if (num_days > 50) {
|
122
|
779 # We need to restrict date intervals since
|
117
|
780 # plots render tick marks for each day.
|
122
|
781 stop_err("Date intervals for plotting cannot exceed 50 days.");
|
117
|
782 }
|
122
|
783 # Display the total number of days in the Galaxy history item blurb.
|
|
784 cat("Number of days in date interval: ", num_days, "\n");
|
117
|
785 }
|
123
|
786 # Parse the inputs.
|
|
787 data_list = parse_input_data(opt$input_ytd, opt$input_norm, opt$location, opt$start_date, opt$end_date);
|
|
788 temperature_data_frame = data_list[[1]];
|
|
789 # Information needed for plots, some of these values are
|
|
790 # being reset here since in some case they were set above.
|
|
791 start_date = data_list[[2]];
|
|
792 end_date = data_list[[3]];
|
|
793 prepend_end_doy_norm = data_list[[4]];
|
|
794 append_start_doy_norm = data_list[[5]];
|
|
795 is_leap_year = data_list[[6]];
|
|
796 location = data_list[[7]];
|
112
|
797
|
|
798 # Create copies of the temperature data for generations P, F1 and F2 if we're plotting generations separately.
|
|
799 if (plot_generations_separately) {
|
|
800 temperature_data_frame_P = data.frame(temperature_data_frame);
|
|
801 temperature_data_frame_F1 = data.frame(temperature_data_frame);
|
|
802 temperature_data_frame_F2 = data.frame(temperature_data_frame);
|
|
803 }
|
|
804
|
|
805 # Get the ticks date labels for plots.
|
123
|
806 ticks_and_labels = get_x_axis_ticks_and_labels(temperature_data_frame, prepend_end_doy_norm, append_start_doy_norm, date_interval);
|
112
|
807 ticks = c(unlist(ticks_and_labels[1]));
|
|
808 date_labels = c(unlist(ticks_and_labels[2]));
|
|
809 # All latitude values are the same, so get the value for plots from the first row.
|
111
|
810 latitude = temperature_data_frame$LATITUDE[1];
|
112
|
811
|
|
812 # Determine the specified life stages for processing.
|
|
813 # Split life_stages into a list of strings for plots.
|
|
814 life_stages_str = as.character(opt$life_stages);
|
|
815 life_stages = strsplit(life_stages_str, ",")[[1]];
|
85
|
816
|
112
|
817 # Determine the data we need to generate for plotting.
|
|
818 process_eggs = FALSE;
|
|
819 process_nymphs = FALSE;
|
|
820 process_young_nymphs = FALSE;
|
|
821 process_old_nymphs = FALSE;
|
|
822 process_total_nymphs = FALSE;
|
|
823 process_adults = FALSE;
|
|
824 process_previttelogenic_adults = FALSE;
|
|
825 process_vittelogenic_adults = FALSE;
|
|
826 process_diapausing_adults = FALSE;
|
|
827 process_total_adults = FALSE;
|
|
828 for (life_stage in life_stages) {
|
|
829 if (life_stage=="Total") {
|
|
830 process_eggs = TRUE;
|
|
831 process_nymphs = TRUE;
|
|
832 process_adults = TRUE;
|
|
833 } else if (life_stage=="Egg") {
|
|
834 process_eggs = TRUE;
|
|
835 } else if (life_stage=="Nymph") {
|
|
836 process_nymphs = TRUE;
|
|
837 } else if (life_stage=="Adult") {
|
|
838 process_adults = TRUE;
|
|
839 }
|
|
840 }
|
|
841 if (process_nymphs) {
|
|
842 # Split life_stages_nymph into a list of strings for plots.
|
|
843 life_stages_nymph_str = as.character(opt$life_stages_nymph);
|
|
844 life_stages_nymph = strsplit(life_stages_nymph_str, ",")[[1]];
|
|
845 for (life_stage_nymph in life_stages_nymph) {
|
|
846 if (life_stage_nymph=="Young") {
|
|
847 process_young_nymphs = TRUE;
|
|
848 } else if (life_stage_nymph=="Old") {
|
|
849 process_old_nymphs = TRUE;
|
|
850 } else if (life_stage_nymph=="Total") {
|
|
851 process_total_nymphs = TRUE;
|
|
852 }
|
|
853 }
|
|
854 }
|
|
855 if (process_adults) {
|
|
856 # Split life_stages_adult into a list of strings for plots.
|
|
857 life_stages_adult_str = as.character(opt$life_stages_adult);
|
|
858 life_stages_adult = strsplit(life_stages_adult_str, ",")[[1]];
|
|
859 for (life_stage_adult in life_stages_adult) {
|
|
860 if (life_stage_adult=="Pre-vittelogenic") {
|
|
861 process_previttelogenic_adults = TRUE;
|
|
862 } else if (life_stage_adult=="Vittelogenic") {
|
|
863 process_vittelogenic_adults = TRUE;
|
|
864 } else if (life_stage_adult=="Diapausing") {
|
|
865 process_diapausing_adults = TRUE;
|
|
866 } else if (life_stage_adult=="Total") {
|
|
867 process_total_adults = TRUE;
|
|
868 }
|
|
869 }
|
|
870 }
|
97
|
871 # Initialize matrices.
|
122
|
872 total_days = dim(temperature_data_frame)[1];
|
112
|
873 if (process_eggs) {
|
|
874 Eggs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
875 }
|
|
876 if (process_young_nymphs | process_total_nymphs) {
|
|
877 YoungNymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
878 }
|
|
879 if (process_old_nymphs | process_total_nymphs) {
|
|
880 OldNymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
881 }
|
|
882 if (process_previttelogenic_adults | process_total_adults) {
|
|
883 Previttelogenic.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
884 }
|
|
885 if (process_vittelogenic_adults | process_total_adults) {
|
|
886 Vittelogenic.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
887 }
|
|
888 if (process_diapausing_adults | process_total_adults) {
|
|
889 Diapausing.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
890 }
|
|
891 newborn.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
892 adult.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
893 death.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
894 if (plot_generations_separately) {
|
|
895 # P is Parental, or overwintered adults.
|
|
896 P.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
897 # F1 is the first field-produced generation.
|
|
898 F1.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
899 # F2 is the second field-produced generation.
|
|
900 F2.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
901 if (process_eggs) {
|
|
902 P_eggs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
903 F1_eggs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
904 F2_eggs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
905 }
|
|
906 if (process_young_nymphs) {
|
|
907 P_young_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
908 F1_young_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
909 F2_young_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
910 }
|
|
911 if (process_old_nymphs) {
|
|
912 P_old_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
913 F1_old_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
914 F2_old_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
915 }
|
|
916 if (process_total_nymphs) {
|
|
917 P_total_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
918 F1_total_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
919 F2_total_nymphs.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
920 }
|
|
921 if (process_previttelogenic_adults) {
|
|
922 P_previttelogenic_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
923 F1_previttelogenic_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
924 F2_previttelogenic_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
925 }
|
|
926 if (process_vittelogenic_adults) {
|
|
927 P_vittelogenic_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
928 F1_vittelogenic_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
929 F2_vittelogenic_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
930 }
|
|
931 if (process_diapausing_adults) {
|
|
932 P_diapausing_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
933 F1_diapausing_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
934 F2_diapausing_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
935 }
|
|
936 if (process_total_adults) {
|
|
937 P_total_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
938 F1_total_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
939 F2_total_adults.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
|
940 }
|
|
941 }
|
|
942 # Total population.
|
|
943 population.replications = matrix(rep(0, total_days*opt$replications), ncol=opt$replications);
|
103
|
944
|
102
|
945 # Process replications.
|
112
|
946 for (current_replication in 1:opt$replications) {
|
109
|
947 # Start with the user-defined number of insects per replication.
|
111
|
948 num_insects = opt$insects_per_replication;
|
90
|
949 # Generation, Stage, degree-days, T, Diapause.
|
111
|
950 vector.ini = c(0, 3, 0, 0, 0);
|
112
|
951 # Replicate to create a matrix where the columns are
|
|
952 # Generation, Stage, degree-days, T, Diapause and the
|
|
953 # rows are the initial number of insects per replication.
|
111
|
954 vector.matrix = rep(vector.ini, num_insects);
|
112
|
955 # Complete transposed matrix for the population, so now
|
|
956 # the rows are Generation, Stage, degree-days, T, Diapause
|
111
|
957 vector.matrix = base::t(matrix(vector.matrix, nrow=5));
|
85
|
958 # Time series of population size.
|
112
|
959 if (process_eggs) {
|
|
960 Eggs = rep(0, total_days);
|
|
961 }
|
|
962 if (process_young_nymphs | process_total_nymphs) {
|
|
963 YoungNymphs = rep(0, total_days);
|
|
964 }
|
|
965 if (process_old_nymphs | process_total_nymphs) {
|
|
966 OldNymphs = rep(0, total_days);
|
|
967 }
|
|
968 if (process_previttelogenic_adults | process_total_adults) {
|
|
969 Previttelogenic = rep(0, total_days);
|
|
970 }
|
|
971 if (process_vittelogenic_adults | process_total_adults) {
|
|
972 Vittelogenic = rep(0, total_days);
|
|
973 }
|
|
974 if (process_diapausing_adults | process_total_adults) {
|
|
975 Diapausing = rep(0, total_days);
|
|
976 }
|
|
977 N.newborn = rep(0, total_days);
|
|
978 N.adult = rep(0, total_days);
|
|
979 N.death = rep(0, total_days);
|
|
980 overwintering_adult.population = rep(0, total_days);
|
|
981 first_generation.population = rep(0, total_days);
|
|
982 second_generation.population = rep(0, total_days);
|
|
983 if (plot_generations_separately) {
|
|
984 # P is Parental, or overwintered adults.
|
|
985 # F1 is the first field-produced generation.
|
|
986 # F2 is the second field-produced generation.
|
|
987 if (process_eggs) {
|
|
988 P.egg = rep(0, total_days);
|
|
989 F1.egg = rep(0, total_days);
|
|
990 F2.egg = rep(0, total_days);
|
|
991 }
|
|
992 if (process_young_nymphs) {
|
|
993 P.young_nymph = rep(0, total_days);
|
|
994 F1.young_nymph = rep(0, total_days);
|
|
995 F2.young_nymph = rep(0, total_days);
|
|
996 }
|
|
997 if (process_old_nymphs) {
|
|
998 P.old_nymph = rep(0, total_days);
|
|
999 F1.old_nymph = rep(0, total_days);
|
|
1000 F2.old_nymph = rep(0, total_days);
|
|
1001 }
|
|
1002 if (process_total_nymphs) {
|
|
1003 P.total_nymph = rep(0, total_days);
|
|
1004 F1.total_nymph = rep(0, total_days);
|
|
1005 F2.total_nymph = rep(0, total_days);
|
|
1006 }
|
|
1007 if (process_previttelogenic_adults) {
|
|
1008 P.previttelogenic_adult = rep(0, total_days);
|
|
1009 F1.previttelogenic_adult = rep(0, total_days);
|
|
1010 F2.previttelogenic_adult = rep(0, total_days);
|
|
1011 }
|
|
1012 if (process_vittelogenic_adults) {
|
|
1013 P.vittelogenic_adult = rep(0, total_days);
|
|
1014 F1.vittelogenic_adult = rep(0, total_days);
|
|
1015 F2.vittelogenic_adult = rep(0, total_days);
|
|
1016 }
|
|
1017 if (process_diapausing_adults) {
|
|
1018 P.diapausing_adult = rep(0, total_days);
|
|
1019 F1.diapausing_adult = rep(0, total_days);
|
|
1020 F2.diapausing_adult = rep(0, total_days);
|
|
1021 }
|
|
1022 if (process_total_adults) {
|
|
1023 P.total_adult = rep(0, total_days);
|
|
1024 F1.total_adult = rep(0, total_days);
|
|
1025 F2.total_adult = rep(0, total_days);
|
|
1026 }
|
|
1027 }
|
111
|
1028 total.population = NULL;
|
112
|
1029 averages.day = rep(0, total_days);
|
|
1030 # All the days included in the input_ytd temperature dataset.
|
|
1031 for (row in 1:total_days) {
|
85
|
1032 # Get the integer day of the year for the current row.
|
111
|
1033 doy = temperature_data_frame$DOY[row];
|
85
|
1034 # Photoperiod in the day.
|
111
|
1035 photoperiod = temperature_data_frame$DAYLEN[row];
|
117
|
1036 temp.profile = get_temperature_at_hour(latitude, temperature_data_frame, row);
|
111
|
1037 mean.temp = temp.profile[1];
|
|
1038 averages.temp = temp.profile[2];
|
|
1039 averages.day[row] = averages.temp;
|
85
|
1040 # Trash bin for death.
|
111
|
1041 death.vector = NULL;
|
85
|
1042 # Newborn.
|
111
|
1043 birth.vector = NULL;
|
85
|
1044 # All individuals.
|
92
|
1045 for (i in 1:num_insects) {
|
103
|
1046 # Individual record.
|
111
|
1047 vector.individual = vector.matrix[i,];
|
103
|
1048 # Adjustment for late season mortality rate (still alive?).
|
85
|
1049 if (latitude < 40.0) {
|
111
|
1050 post.mortality = 1;
|
|
1051 day.kill = 300;
|
85
|
1052 }
|
|
1053 else {
|
111
|
1054 post.mortality = 2;
|
|
1055 day.kill = 250;
|
85
|
1056 }
|
102
|
1057 if (vector.individual[2] == 0) {
|
85
|
1058 # Egg.
|
111
|
1059 death.probability = opt$egg_mortality * mortality.egg(mean.temp);
|
85
|
1060 }
|
102
|
1061 else if (vector.individual[2] == 1 | vector.individual[2] == 2) {
|
112
|
1062 # Nymph.
|
111
|
1063 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp);
|
85
|
1064 }
|
102
|
1065 else if (vector.individual[2] == 3 | vector.individual[2] == 4 | vector.individual[2] == 5) {
|
103
|
1066 # Adult.
|
85
|
1067 if (doy < day.kill) {
|
111
|
1068 death.probability = opt$adult_mortality * mortality.adult(mean.temp);
|
85
|
1069 }
|
|
1070 else {
|
|
1071 # Increase adult mortality after fall equinox.
|
111
|
1072 death.probability = opt$adult_mortality * post.mortality * mortality.adult(mean.temp);
|
85
|
1073 }
|
|
1074 }
|
103
|
1075 # Dependent on temperature and life stage?
|
111
|
1076 u.d = runif(1);
|
102
|
1077 if (u.d < death.probability) {
|
111
|
1078 death.vector = c(death.vector, i);
|
96
|
1079 }
|
85
|
1080 else {
|
103
|
1081 # End of diapause.
|
102
|
1082 if (vector.individual[1] == 0 && vector.individual[2] == 3) {
|
112
|
1083 # Overwintering adult (pre-vittelogenic).
|
102
|
1084 if (photoperiod > opt$photoperiod && vector.individual[3] > 68 && doy < 180) {
|
85
|
1085 # Add 68C to become fully reproductively matured.
|
|
1086 # Transfer to vittelogenic.
|
111
|
1087 vector.individual = c(0, 4, 0, 0, 0);
|
|
1088 vector.matrix[i,] = vector.individual;
|
85
|
1089 }
|
|
1090 else {
|
112
|
1091 # Add average temperature for current day.
|
111
|
1092 vector.individual[3] = vector.individual[3] + averages.temp;
|
85
|
1093 # Add 1 day in current stage.
|
111
|
1094 vector.individual[4] = vector.individual[4] + 1;
|
|
1095 vector.matrix[i,] = vector.individual;
|
85
|
1096 }
|
|
1097 }
|
102
|
1098 if (vector.individual[1] != 0 && vector.individual[2] == 3) {
|
112
|
1099 # Not overwintering adult (pre-vittelogenic).
|
111
|
1100 current.gen = vector.individual[1];
|
102
|
1101 if (vector.individual[3] > 68) {
|
85
|
1102 # Add 68C to become fully reproductively matured.
|
|
1103 # Transfer to vittelogenic.
|
111
|
1104 vector.individual = c(current.gen, 4, 0, 0, 0);
|
|
1105 vector.matrix[i,] = vector.individual;
|
85
|
1106 }
|
|
1107 else {
|
103
|
1108 # Add average temperature for current day.
|
111
|
1109 vector.individual[3] = vector.individual[3] + averages.temp;
|
85
|
1110 # Add 1 day in current stage.
|
111
|
1111 vector.individual[4] = vector.individual[4] + 1;
|
|
1112 vector.matrix[i,] = vector.individual;
|
85
|
1113 }
|
|
1114 }
|
109
|
1115 # Oviposition -- where population dynamics comes from.
|
102
|
1116 if (vector.individual[2] == 4 && vector.individual[1] == 0 && mean.temp > 10) {
|
85
|
1117 # Vittelogenic stage, overwintering generation.
|
102
|
1118 if (vector.individual[4] == 0) {
|
85
|
1119 # Just turned in vittelogenic stage.
|
111
|
1120 num_insects.birth = round(runif(1, 2 + opt$min_clutch_size, 8 + opt$max_clutch_size));
|
85
|
1121 }
|
|
1122 else {
|
|
1123 # Daily probability of birth.
|
111
|
1124 p.birth = opt$oviposition * 0.01;
|
|
1125 u1 = runif(1);
|
85
|
1126 if (u1 < p.birth) {
|
111
|
1127 num_insects.birth = round(runif(1, 2, 8));
|
85
|
1128 }
|
|
1129 }
|
103
|
1130 # Add average temperature for current day.
|
111
|
1131 vector.individual[3] = vector.individual[3] + averages.temp;
|
85
|
1132 # Add 1 day in current stage.
|
111
|
1133 vector.individual[4] = vector.individual[4] + 1;
|
|
1134 vector.matrix[i,] = vector.individual;
|
90
|
1135 if (num_insects.birth > 0) {
|
85
|
1136 # Add new birth -- might be in different generations.
|
111
|
1137 new.gen = vector.individual[1] + 1;
|
85
|
1138 # Egg profile.
|
111
|
1139 new.individual = c(new.gen, 0, 0, 0, 0);
|
|
1140 new.vector = rep(new.individual, num_insects.birth);
|
85
|
1141 # Update batch of egg profile.
|
111
|
1142 new.vector = t(matrix(new.vector, nrow=5));
|
85
|
1143 # Group with total eggs laid in that day.
|
111
|
1144 birth.vector = rbind(birth.vector, new.vector);
|
85
|
1145 }
|
|
1146 }
|
109
|
1147 # Oviposition -- for generation 1.
|
102
|
1148 if (vector.individual[2] == 4 && vector.individual[1] == 1 && mean.temp > 12.5 && doy < 222) {
|
85
|
1149 # Vittelogenic stage, 1st generation
|
102
|
1150 if (vector.individual[4] == 0) {
|
85
|
1151 # Just turned in vittelogenic stage.
|
111
|
1152 num_insects.birth = round(runif(1, 2+opt$min_clutch_size, 8+opt$max_clutch_size));
|
85
|
1153 }
|
|
1154 else {
|
|
1155 # Daily probability of birth.
|
111
|
1156 p.birth = opt$oviposition * 0.01;
|
|
1157 u1 = runif(1);
|
85
|
1158 if (u1 < p.birth) {
|
111
|
1159 num_insects.birth = round(runif(1, 2, 8));
|
85
|
1160 }
|
|
1161 }
|
103
|
1162 # Add average temperature for current day.
|
111
|
1163 vector.individual[3] = vector.individual[3] + averages.temp;
|
85
|
1164 # Add 1 day in current stage.
|
111
|
1165 vector.individual[4] = vector.individual[4] + 1;
|
|
1166 vector.matrix[i,] = vector.individual;
|
90
|
1167 if (num_insects.birth > 0) {
|
85
|
1168 # Add new birth -- might be in different generations.
|
111
|
1169 new.gen = vector.individual[1] + 1;
|
85
|
1170 # Egg profile.
|
111
|
1171 new.individual = c(new.gen, 0, 0, 0, 0);
|
|
1172 new.vector = rep(new.individual, num_insects.birth);
|
85
|
1173 # Update batch of egg profile.
|
111
|
1174 new.vector = t(matrix(new.vector, nrow=5));
|
85
|
1175 # Group with total eggs laid in that day.
|
111
|
1176 birth.vector = rbind(birth.vector, new.vector);
|
85
|
1177 }
|
|
1178 }
|
109
|
1179 # Egg to young nymph.
|
102
|
1180 if (vector.individual[2] == 0) {
|
103
|
1181 # Add average temperature for current day.
|
111
|
1182 vector.individual[3] = vector.individual[3] + averages.temp;
|
102
|
1183 if (vector.individual[3] >= (68+opt$young_nymph_accumulation)) {
|
90
|
1184 # From egg to young nymph, degree-days requirement met.
|
111
|
1185 current.gen = vector.individual[1];
|
85
|
1186 # Transfer to young nymph stage.
|
111
|
1187 vector.individual = c(current.gen, 1, 0, 0, 0);
|
85
|
1188 }
|
|
1189 else {
|
|
1190 # Add 1 day in current stage.
|
111
|
1191 vector.individual[4] = vector.individual[4] + 1;
|
85
|
1192 }
|
111
|
1193 vector.matrix[i,] = vector.individual;
|
85
|
1194 }
|
109
|
1195 # Young nymph to old nymph.
|
102
|
1196 if (vector.individual[2] == 1) {
|
103
|
1197 # Add average temperature for current day.
|
111
|
1198 vector.individual[3] = vector.individual[3] + averages.temp;
|
102
|
1199 if (vector.individual[3] >= (250+opt$old_nymph_accumulation)) {
|
90
|
1200 # From young to old nymph, degree_days requirement met.
|
111
|
1201 current.gen = vector.individual[1];
|
85
|
1202 # Transfer to old nym stage.
|
111
|
1203 vector.individual = c(current.gen, 2, 0, 0, 0);
|
85
|
1204 if (photoperiod < opt$photoperiod && doy > 180) {
|
111
|
1205 vector.individual[5] = 1;
|
85
|
1206 } # Prepare for diapausing.
|
|
1207 }
|
|
1208 else {
|
|
1209 # Add 1 day in current stage.
|
111
|
1210 vector.individual[4] = vector.individual[4] + 1;
|
85
|
1211 }
|
111
|
1212 vector.matrix[i,] = vector.individual;
|
96
|
1213 }
|
112
|
1214 # Old nymph to adult: pre-vittelogenic or diapausing?
|
102
|
1215 if (vector.individual[2] == 2) {
|
103
|
1216 # Add average temperature for current day.
|
111
|
1217 vector.individual[3] = vector.individual[3] + averages.temp;
|
102
|
1218 if (vector.individual[3] >= (200+opt$adult_accumulation)) {
|
90
|
1219 # From old to adult, degree_days requirement met.
|
111
|
1220 current.gen = vector.individual[1];
|
102
|
1221 if (vector.individual[5] == 0) {
|
109
|
1222 # Previttelogenic.
|
111
|
1223 vector.individual = c(current.gen, 3, 0, 0, 0);
|
85
|
1224 }
|
|
1225 else {
|
|
1226 # Diapausing.
|
111
|
1227 vector.individual = c(current.gen, 5, 0, 0, 1);
|
85
|
1228 }
|
|
1229 }
|
|
1230 else {
|
|
1231 # Add 1 day in current stage.
|
111
|
1232 vector.individual[4] = vector.individual[4] + 1;
|
85
|
1233 }
|
111
|
1234 vector.matrix[i,] = vector.individual;
|
85
|
1235 }
|
109
|
1236 # Growing of diapausing adult (unimportant, but still necessary).
|
102
|
1237 if (vector.individual[2] == 5) {
|
111
|
1238 vector.individual[3] = vector.individual[3] + averages.temp;
|
|
1239 vector.individual[4] = vector.individual[4] + 1;
|
|
1240 vector.matrix[i,] = vector.individual;
|
85
|
1241 }
|
|
1242 } # Else if it is still alive.
|
|
1243 } # End of the individual bug loop.
|
107
|
1244
|
|
1245 # Number of deaths.
|
111
|
1246 num_insects.death = length(death.vector);
|
90
|
1247 if (num_insects.death > 0) {
|
102
|
1248 # Remove record of dead.
|
111
|
1249 vector.matrix = vector.matrix[-death.vector,];
|
85
|
1250 }
|
107
|
1251 # Number of births.
|
111
|
1252 num_insects.newborn = length(birth.vector[,1]);
|
|
1253 vector.matrix = rbind(vector.matrix, birth.vector);
|
85
|
1254 # Update population size for the next day.
|
111
|
1255 num_insects = num_insects - num_insects.death + num_insects.newborn;
|
85
|
1256
|
112
|
1257 # Aggregate results by day. Due to multiple transpose calls
|
|
1258 # on vector.matrix above, the columns of vector.matrix
|
|
1259 # are now Generation, Stage, degree-days, T, Diapause,
|
|
1260 if (process_eggs) {
|
|
1261 # For egg population size, column 2 (Stage), must be 0.
|
|
1262 Eggs[row] = sum(vector.matrix[,2]==0);
|
|
1263 }
|
|
1264 if (process_young_nymphs | process_total_nymphs) {
|
|
1265 # For young nymph population size, column 2 (Stage) must be 1.
|
|
1266 YoungNymphs[row] = sum(vector.matrix[,2]==1);
|
|
1267 }
|
|
1268 if (process_old_nymphs | process_total_nymphs) {
|
|
1269 # For old nymph population size, column 2 (Stage) must be 2.
|
|
1270 OldNymphs[row] = sum(vector.matrix[,2]==2);
|
|
1271 }
|
|
1272 if (process_previttelogenic_adults | process_total_adults) {
|
|
1273 # For pre-vittelogenic population size, column 2 (Stage) must be 3.
|
|
1274 Previttelogenic[row] = sum(vector.matrix[,2]==3);
|
|
1275 }
|
|
1276 if (process_vittelogenic_adults | process_total_adults) {
|
|
1277 # For vittelogenic population size, column 2 (Stage) must be 4.
|
|
1278 Vittelogenic[row] = sum(vector.matrix[,2]==4);
|
|
1279 }
|
|
1280 if (process_diapausing_adults | process_total_adults) {
|
|
1281 # For diapausing population size, column 2 (Stage) must be 5.
|
|
1282 Diapausing[row] = sum(vector.matrix[,2]==5);
|
|
1283 }
|
107
|
1284
|
|
1285 # Newborn population size.
|
111
|
1286 N.newborn[row] = num_insects.newborn;
|
107
|
1287 # Adult population size.
|
111
|
1288 N.adult[row] = sum(vector.matrix[,2]==3) + sum(vector.matrix[,2]==4) + sum(vector.matrix[,2]==5);
|
107
|
1289 # Dead population size.
|
111
|
1290 N.death[row] = num_insects.death;
|
107
|
1291
|
111
|
1292 total.population = c(total.population, num_insects);
|
107
|
1293
|
112
|
1294 # For overwintering adult (P) population
|
|
1295 # size, column 1 (Generation) must be 0.
|
111
|
1296 overwintering_adult.population[row] = sum(vector.matrix[,1]==0);
|
112
|
1297 # For first field generation (F1) population
|
|
1298 # size, column 1 (Generation) must be 1.
|
111
|
1299 first_generation.population[row] = sum(vector.matrix[,1]==1);
|
112
|
1300 # For second field generation (F2) population
|
|
1301 # size, column 1 (Generation) must be 2.
|
111
|
1302 second_generation.population[row] = sum(vector.matrix[,1]==2);
|
107
|
1303
|
112
|
1304 if (plot_generations_separately) {
|
|
1305 if (process_eggs) {
|
|
1306 # For egg life stage of generation P population size,
|
|
1307 # column 1 (generation) is 0 and column 2 (Stage) is 0.
|
|
1308 P.egg[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==0);
|
|
1309 # For egg life stage of generation F1 population size,
|
|
1310 # column 1 (generation) is 1 and column 2 (Stage) is 0.
|
|
1311 F1.egg[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==0);
|
|
1312 # For egg life stage of generation F2 population size,
|
|
1313 # column 1 (generation) is 2 and column 2 (Stage) is 0.
|
|
1314 F2.egg[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==0);
|
|
1315 }
|
|
1316 if (process_young_nymphs) {
|
|
1317 # For young nymph life stage of generation P population
|
|
1318 # size, the following combination is required:
|
|
1319 # - column 1 (Generation) is 0 and column 2 (Stage) is 1 (Young nymph)
|
|
1320 P.young_nymph[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==1);
|
|
1321 # For young nymph life stage of generation F1 population
|
|
1322 # size, the following combination is required:
|
|
1323 # - column 1 (Generation) is 1 and column 2 (Stage) is 1 (Young nymph)
|
|
1324 F1.young_nymph[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==1);
|
|
1325 # For young nymph life stage of generation F2 population
|
|
1326 # size, the following combination is required:
|
|
1327 # - column 1 (Generation) is 2 and column 2 (Stage) is 1 (Young nymph)
|
|
1328 F2.young_nymph[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==1);
|
|
1329 }
|
|
1330 if (process_old_nymphs) {
|
|
1331 # For old nymph life stage of generation P population
|
|
1332 # size, the following combination is required:
|
|
1333 # - column 1 (Generation) is 0 and column 2 (Stage) is 2 (Old nymph)
|
|
1334 P.old_nymph[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==2);
|
|
1335 # For old nymph life stage of generation F1 population
|
|
1336 # size, the following combination is required:
|
|
1337 # - column 1 (Generation) is 1 and column 2 (Stage) is 2 (Old nymph)
|
|
1338 F1.old_nymph[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==2);
|
|
1339 # For old nymph life stage of generation F2 population
|
|
1340 # size, the following combination is required:
|
|
1341 # - column 1 (Generation) is 2 and column 2 (Stage) is 2 (Old nymph)
|
|
1342 F2.old_nymph[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==2);
|
|
1343 }
|
|
1344 if (process_total_nymphs) {
|
|
1345 # For total nymph life stage of generation P population
|
|
1346 # size, one of the following combinations is required:
|
|
1347 # - column 1 (Generation) is 0 and column 2 (Stage) is 1 (Young nymph)
|
|
1348 # - column 1 (Generation) is 0 and column 2 (Stage) is 2 (Old nymph)
|
|
1349 P.total_nymph[row] = sum((vector.matrix[,1]==0 & vector.matrix[,2]==1) | (vector.matrix[,1]==0 & vector.matrix[,2]==2));
|
|
1350 # For total nymph life stage of generation F1 population
|
|
1351 # size, one of the following combinations is required:
|
|
1352 # - column 1 (Generation) is 1 and column 2 (Stage) is 1 (Young nymph)
|
|
1353 # - column 1 (Generation) is 1 and column 2 (Stage) is 2 (Old nymph)
|
|
1354 F1.total_nymph[row] = sum((vector.matrix[,1]==1 & vector.matrix[,2]==1) | (vector.matrix[,1]==1 & vector.matrix[,2]==2));
|
|
1355 # For total nymph life stage of generation F2 population
|
|
1356 # size, one of the following combinations is required:
|
|
1357 # - column 1 (Generation) is 2 and column 2 (Stage) is 1 (Young nymph)
|
|
1358 # - column 1 (Generation) is 2 and column 2 (Stage) is 2 (Old nymph)
|
|
1359 F2.total_nymph[row] = sum((vector.matrix[,1]==2 & vector.matrix[,2]==1) | (vector.matrix[,1]==2 & vector.matrix[,2]==2));
|
|
1360 }
|
|
1361 if (process_previttelogenic_adults) {
|
|
1362 # For previttelogenic adult life stage of generation P population
|
|
1363 # size, the following combination is required:
|
|
1364 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
1365 P.previttelogenic_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==3);
|
|
1366 # For previttelogenic adult life stage of generation F1 population
|
|
1367 # size, the following combination is required:
|
|
1368 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
1369 F1.previttelogenic_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==3);
|
|
1370 # For previttelogenic adult life stage of generation F2 population
|
|
1371 # size, the following combination is required:
|
|
1372 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
1373 F2.previttelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==3);
|
|
1374 }
|
|
1375 if (process_vittelogenic_adults) {
|
|
1376 # For vittelogenic adult life stage of generation P population
|
|
1377 # size, the following combination is required:
|
|
1378 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vittelogenic)
|
|
1379 P.vittelogenic_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==4);
|
|
1380 # For vittelogenic adult life stage of generation F1 population
|
|
1381 # size, the following combination is required:
|
|
1382 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vittelogenic)
|
|
1383 F1.vittelogenic_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==4);
|
|
1384 # For vittelogenic adult life stage of generation F2 population
|
|
1385 # size, the following combination is required:
|
|
1386 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vittelogenic)
|
|
1387 F2.vittelogenic_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==4);
|
|
1388 }
|
|
1389 if (process_diapausing_adults) {
|
|
1390 # For diapausing adult life stage of generation P population
|
|
1391 # size, the following combination is required:
|
|
1392 # - column 1 (Generation) is 0 and column 2 (Stage) is 5 (Diapausing)
|
|
1393 P.diapausing_adult[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==5);
|
|
1394 # For diapausing adult life stage of generation F1 population
|
|
1395 # size, the following combination is required:
|
|
1396 # - column 1 (Generation) is 1 and column 2 (Stage) is 5 (Diapausing)
|
|
1397 F1.diapausing_adult[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==5);
|
|
1398 # For diapausing adult life stage of generation F2 population
|
|
1399 # size, the following combination is required:
|
|
1400 # - column 1 (Generation) is 2 and column 2 (Stage) is 5 (Diapausing)
|
|
1401 F2.diapausing_adult[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==5);
|
|
1402 }
|
|
1403 if (process_total_adults) {
|
|
1404 # For total adult life stage of generation P population
|
|
1405 # size, one of the following combinations is required:
|
|
1406 # - column 1 (Generation) is 0 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
1407 # - column 1 (Generation) is 0 and column 2 (Stage) is 4 (Vittelogenic)
|
|
1408 # - column 1 (Generation) is 0 and column 2 (Stage) is 5 (Diapausing)
|
|
1409 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));
|
|
1410 # For total adult life stage of generation F1 population
|
|
1411 # size, one of the following combinations is required:
|
|
1412 # - column 1 (Generation) is 1 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
1413 # - column 1 (Generation) is 1 and column 2 (Stage) is 4 (Vittelogenic)
|
|
1414 # - column 1 (Generation) is 1 and column 2 (Stage) is 5 (Diapausing)
|
|
1415 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));
|
|
1416 # For total adult life stage of generation F2 population
|
|
1417 # size, one of the following combinations is required:
|
|
1418 # - column 1 (Generation) is 2 and column 2 (Stage) is 3 (Pre-vittelogenic)
|
|
1419 # - column 1 (Generation) is 2 and column 2 (Stage) is 4 (Vittelogenic)
|
|
1420 # - column 1 (Generation) is 2 and column 2 (Stage) is 5 (Diapausing)
|
|
1421 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));
|
|
1422 }
|
|
1423 }
|
|
1424 } # End of days specified in the input_ytd temperature data.
|
85
|
1425
|
111
|
1426 averages.cum = cumsum(averages.day);
|
85
|
1427
|
102
|
1428 # Define the output values.
|
112
|
1429 if (process_eggs) {
|
|
1430 Eggs.replications[,current_replication] = Eggs;
|
|
1431 }
|
|
1432 if (process_young_nymphs | process_total_nymphs) {
|
|
1433 YoungNymphs.replications[,current_replication] = YoungNymphs;
|
|
1434 }
|
|
1435 if (process_old_nymphs | process_total_nymphs) {
|
|
1436 OldNymphs.replications[,current_replication] = OldNymphs;
|
|
1437 }
|
|
1438 if (process_previttelogenic_adults | process_total_adults) {
|
|
1439 Previttelogenic.replications[,current_replication] = Previttelogenic;
|
|
1440 }
|
|
1441 if (process_vittelogenic_adults | process_total_adults) {
|
|
1442 Vittelogenic.replications[,current_replication] = Vittelogenic;
|
|
1443 }
|
|
1444 if (process_diapausing_adults | process_total_adults) {
|
|
1445 Diapausing.replications[,current_replication] = Diapausing;
|
|
1446 }
|
|
1447 newborn.replications[,current_replication] = N.newborn;
|
|
1448 adult.replications[,current_replication] = N.adult;
|
|
1449 death.replications[,current_replication] = N.death;
|
|
1450 if (plot_generations_separately) {
|
|
1451 # P is Parental, or overwintered adults.
|
|
1452 P.replications[,current_replication] = overwintering_adult.population;
|
|
1453 # F1 is the first field-produced generation.
|
|
1454 F1.replications[,current_replication] = first_generation.population;
|
|
1455 # F2 is the second field-produced generation.
|
|
1456 F2.replications[,current_replication] = second_generation.population;
|
|
1457 if (process_eggs) {
|
|
1458 P_eggs.replications[,current_replication] = P.egg;
|
|
1459 F1_eggs.replications[,current_replication] = F1.egg;
|
|
1460 F2_eggs.replications[,current_replication] = F2.egg;
|
|
1461 }
|
|
1462 if (process_young_nymphs) {
|
|
1463 P_young_nymphs.replications[,current_replication] = P.young_nymph;
|
|
1464 F1_young_nymphs.replications[,current_replication] = F1.young_nymph;
|
|
1465 F2_young_nymphs.replications[,current_replication] = F2.young_nymph;
|
|
1466 }
|
|
1467 if (process_old_nymphs) {
|
|
1468 P_old_nymphs.replications[,current_replication] = P.old_nymph;
|
|
1469 F1_old_nymphs.replications[,current_replication] = F1.old_nymph;
|
|
1470 F2_old_nymphs.replications[,current_replication] = F2.old_nymph;
|
|
1471 }
|
|
1472 if (process_total_nymphs) {
|
|
1473 P_total_nymphs.replications[,current_replication] = P.total_nymph;
|
|
1474 F1_total_nymphs.replications[,current_replication] = F1.total_nymph;
|
|
1475 F2_total_nymphs.replications[,current_replication] = F2.total_nymph;
|
|
1476 }
|
|
1477 if (process_previttelogenic_adults) {
|
|
1478 P_previttelogenic_adults.replications[,current_replication] = P.previttelogenic_adult;
|
|
1479 F1_previttelogenic_adults.replications[,current_replication] = F1.previttelogenic_adult;
|
|
1480 F2_previttelogenic_adults.replications[,current_replication] = F2.previttelogenic_adult;
|
|
1481 }
|
|
1482 if (process_vittelogenic_adults) {
|
|
1483 P_vittelogenic_adults.replications[,current_replication] = P.vittelogenic_adult;
|
|
1484 F1_vittelogenic_adults.replications[,current_replication] = F1.vittelogenic_adult;
|
|
1485 F2_vittelogenic_adults.replications[,current_replication] = F2.vittelogenic_adult;
|
|
1486 }
|
|
1487 if (process_diapausing_adults) {
|
|
1488 P_diapausing_adults.replications[,current_replication] = P.diapausing_adult;
|
|
1489 F1_diapausing_adults.replications[,current_replication] = F1.diapausing_adult;
|
|
1490 F2_diapausing_adults.replications[,current_replication] = F2.diapausing_adult;
|
|
1491 }
|
|
1492 if (process_total_adults) {
|
|
1493 P_total_adults.replications[,current_replication] = P.total_adult;
|
|
1494 F1_total_adults.replications[,current_replication] = F1.total_adult;
|
|
1495 F2_total_adults.replications[,current_replication] = F2.total_adult;
|
|
1496 }
|
|
1497 }
|
|
1498 population.replications[,current_replication] = total.population;
|
|
1499 # End processing replications.
|
|
1500 }
|
107
|
1501
|
112
|
1502 if (process_eggs) {
|
|
1503 # Mean value for eggs.
|
|
1504 eggs = apply(Eggs.replications, 1, mean);
|
|
1505 temperature_data_frame = append_vector(temperature_data_frame, eggs, "EGG");
|
|
1506 # Standard error for eggs.
|
|
1507 eggs.std_error = apply(Eggs.replications, 1, sd) / sqrt(opt$replications);
|
|
1508 temperature_data_frame = append_vector(temperature_data_frame, eggs.std_error, "EGGSE");
|
|
1509 }
|
|
1510 if (process_nymphs) {
|
|
1511 # Calculate nymph populations for selected life stage.
|
|
1512 for (life_stage_nymph in life_stages_nymph) {
|
|
1513 if (life_stage_nymph=="Young") {
|
|
1514 # Mean value for young nymphs.
|
|
1515 young_nymphs = apply(YoungNymphs.replications, 1, mean);
|
|
1516 temperature_data_frame = append_vector(temperature_data_frame, young_nymphs, "YOUNGNYMPH");
|
|
1517 # Standard error for young nymphs.
|
|
1518 young_nymphs.std_error = apply(YoungNymphs.replications / sqrt(opt$replications), 1, sd);
|
|
1519 temperature_data_frame = append_vector(temperature_data_frame, young_nymphs.std_error, "YOUNGNYMPHSE");
|
|
1520 } else if (life_stage_nymph=="Old") {
|
|
1521 # Mean value for old nymphs.
|
|
1522 old_nymphs = apply(OldNymphs.replications, 1, mean);
|
|
1523 temperature_data_frame = append_vector(temperature_data_frame, old_nymphs, "OLDNYMPH");
|
|
1524 # Standard error for old nymphs.
|
|
1525 old_nymphs.std_error = apply(OldNymphs.replications / sqrt(opt$replications), 1, sd);
|
|
1526 temperature_data_frame = append_vector(temperature_data_frame, old_nymphs.std_error, "OLDNYMPHSE");
|
|
1527 } else if (life_stage_nymph=="Total") {
|
|
1528 # Mean value for all nymphs.
|
|
1529 total_nymphs = apply((YoungNymphs.replications+OldNymphs.replications), 1, mean);
|
|
1530 temperature_data_frame = append_vector(temperature_data_frame, total_nymphs, "TOTALNYMPH");
|
|
1531 # Standard error for all nymphs.
|
|
1532 total_nymphs.std_error = apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd);
|
|
1533 temperature_data_frame = append_vector(temperature_data_frame, total_nymphs.std_error, "TOTALNYMPHSE");
|
|
1534 }
|
|
1535 }
|
|
1536 }
|
|
1537 if (process_adults) {
|
|
1538 # Calculate adult populations for selected life stage.
|
|
1539 for (life_stage_adult in life_stages_adult) {
|
|
1540 if (life_stage_adult == "Pre-vittelogenic") {
|
|
1541 # Mean value for previttelogenic adults.
|
|
1542 previttelogenic_adults = apply(Previttelogenic.replications, 1, mean);
|
|
1543 temperature_data_frame = append_vector(temperature_data_frame, previttelogenic_adults, "PRE-VITADULT");
|
|
1544 # Standard error for previttelogenic adults.
|
|
1545 previttelogenic_adults.std_error = apply(Previttelogenic.replications, 1, sd) / sqrt(opt$replications);
|
|
1546 temperature_data_frame = append_vector(temperature_data_frame, previttelogenic_adults.std_error, "PRE-VITADULTSE");
|
|
1547 } else if (life_stage_adult == "Vittelogenic") {
|
|
1548 # Mean value for vittelogenic adults.
|
|
1549 vittelogenic_adults = apply(Vittelogenic.replications, 1, mean);
|
|
1550 temperature_data_frame = append_vector(temperature_data_frame, vittelogenic_adults, "VITADULT");
|
|
1551 # Standard error for vittelogenic adults.
|
|
1552 vittelogenic_adults.std_error = apply(Vittelogenic.replications, 1, sd) / sqrt(opt$replications);
|
|
1553 temperature_data_frame = append_vector(temperature_data_frame, vittelogenic_adults.std_error, "VITADULTSE");
|
|
1554 } else if (life_stage_adult == "Diapausing") {
|
|
1555 # Mean value for vittelogenic adults.
|
|
1556 diapausing_adults = apply(Diapausing.replications, 1, mean);
|
|
1557 temperature_data_frame = append_vector(temperature_data_frame, diapausing_adults, "DIAPAUSINGADULT");
|
|
1558 # Standard error for vittelogenic adults.
|
|
1559 diapausing_adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications);
|
|
1560 temperature_data_frame = append_vector(temperature_data_frame, diapausing_adults.std_error, "DIAPAUSINGADULTSE");
|
|
1561 } else if (life_stage_adult=="Total") {
|
|
1562 # Mean value for all adults.
|
|
1563 total_adults = apply((Previttelogenic.replications+Vittelogenic.replications+Diapausing.replications), 1, mean);
|
|
1564 temperature_data_frame = append_vector(temperature_data_frame, total_adults, "TOTALADULT");
|
|
1565 # Standard error for all adults.
|
|
1566 total_adults.std_error = apply((Previttelogenic.replications+Vittelogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications);
|
|
1567 temperature_data_frame = append_vector(temperature_data_frame, total_adults.std_error, "TOTALADULTSE");
|
|
1568 }
|
|
1569 }
|
85
|
1570 }
|
|
1571
|
112
|
1572 if (plot_generations_separately) {
|
|
1573 m_se = get_mean_and_std_error(P.replications, F1.replications, F2.replications);
|
|
1574 P = m_se[[1]];
|
|
1575 P.std_error = m_se[[2]];
|
|
1576 F1 = m_se[[3]];
|
|
1577 F1.std_error = m_se[[4]];
|
|
1578 F2 = m_se[[5]];
|
|
1579 F2.std_error = m_se[[6]];
|
|
1580 if (process_eggs) {
|
|
1581 m_se = get_mean_and_std_error(P_eggs.replications, F1_eggs.replications, F2_eggs.replications);
|
|
1582 P_eggs = m_se[[1]];
|
|
1583 P_eggs.std_error = m_se[[2]];
|
|
1584 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_eggs, "EGG-P");
|
|
1585 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_eggs.std_error, "EGG-P-SE");
|
|
1586 F1_eggs = m_se[[3]];
|
|
1587 F1_eggs.std_error = m_se[[4]];
|
|
1588 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_eggs, "EGG-F1");
|
|
1589 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_eggs.std_error, "EGG-F1-SE");
|
|
1590 F2_eggs = m_se[[5]];
|
|
1591 F2_eggs.std_error = m_se[[6]];
|
|
1592 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_eggs, "EGG-F2");
|
|
1593 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_eggs.std_error, "EGG-F2-SE");
|
|
1594 }
|
|
1595 if (process_young_nymphs) {
|
|
1596 m_se = get_mean_and_std_error(P_young_nymphs.replications, F1_young_nymphs.replications, F2_young_nymphs.replications);
|
|
1597 P_young_nymphs = m_se[[1]];
|
|
1598 P_young_nymphs.std_error = m_se[[2]];
|
|
1599 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_young_nymphs, "YOUNGNYMPH-P");
|
|
1600 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_young_nymphs.std_error, "YOUNGNYMPH-P-SE");
|
|
1601 F1_young_nymphs = m_se[[3]];
|
|
1602 F1_young_nymphs.std_error = m_se[[4]];
|
|
1603 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_young_nymphs, "YOUNGNYMPH-F1");
|
|
1604 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_young_nymphs.std_error, "YOUNGNYMPH-F1-SE");
|
|
1605 F2_young_nymphs = m_se[[5]];
|
|
1606 F2_young_nymphs.std_error = m_se[[6]];
|
|
1607 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_young_nymphs, "YOUNGNYMPH-F2");
|
|
1608 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_young_nymphs.std_error, "YOUNGNYMPH-F2-SE");
|
|
1609 }
|
|
1610 if (process_old_nymphs) {
|
|
1611 m_se = get_mean_and_std_error(P_old_nymphs.replications, F1_old_nymphs.replications, F2_old_nymphs.replications);
|
|
1612 P_old_nymphs = m_se[[1]];
|
|
1613 P_old_nymphs.std_error = m_se[[2]];
|
|
1614 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_old_nymphs, "OLDNYMPH-P");
|
|
1615 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_old_nymphs.std_error, "OLDNYMPH-P-SE");
|
|
1616 F1_old_nymphs = m_se[[3]];
|
|
1617 F1_old_nymphs.std_error = m_se[[4]];
|
|
1618 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_old_nymphs, "OLDNYMPH-F1");
|
|
1619 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_old_nymphs.std_error, "OLDNYMPH-F1-SE");
|
|
1620 F2_old_nymphs = m_se[[5]];
|
|
1621 F2_old_nymphs.std_error = m_se[[6]];
|
|
1622 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_old_nymphs, "OLDNYMPH-F2");
|
|
1623 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_old_nymphs.std_error, "OLDNYMPH-F2-SE");
|
|
1624 }
|
|
1625 if (process_total_nymphs) {
|
|
1626 m_se = get_mean_and_std_error(P_total_nymphs.replications, F1_total_nymphs.replications, F2_total_nymphs.replications);
|
|
1627 P_total_nymphs = m_se[[1]];
|
|
1628 P_total_nymphs.std_error = m_se[[2]];
|
|
1629 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_nymphs, "TOTALNYMPH-P");
|
|
1630 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_nymphs.std_error, "TOTALNYMPH-P-SE");
|
|
1631 F1_total_nymphs = m_se[[3]];
|
|
1632 F1_total_nymphs.std_error = m_se[[4]];
|
|
1633 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_nymphs, "TOTALNYMPH-F1");
|
|
1634 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_nymphs.std_error, "TOTALNYMPH-F1-SE");
|
|
1635 F2_total_nymphs = m_se[[5]];
|
|
1636 F2_total_nymphs.std_error = m_se[[6]];
|
|
1637 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_nymphs, "TOTALNYMPH-F2");
|
|
1638 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_nymphs.std_error, "TOTALNYMPH-F2-SE");
|
|
1639 }
|
|
1640 if (process_previttelogenic_adults) {
|
|
1641 m_se = get_mean_and_std_error(P_previttelogenic_adults.replications, F1_previttelogenic_adults.replications, F2_previttelogenic_adults.replications);
|
|
1642 P_previttelogenic_adults = m_se[[1]];
|
|
1643 P_previttelogenic_adults.std_error = m_se[[2]];
|
|
1644 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_previttelogenic_adults, "PRE-VITADULT-P");
|
|
1645 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_previttelogenic_adults.std_error, "PRE-VITADULT-P-SE");
|
|
1646 F1_previttelogenic_adults = m_se[[3]];
|
|
1647 F1_previttelogenic_adults.std_error = m_se[[4]];
|
|
1648 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_previttelogenic_adults, "PRE-VITADULT-F1");
|
|
1649 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_previttelogenic_adults.std_error, "PRE-VITADULT-F1-SE");
|
|
1650 F2_previttelogenic_adults = m_se[[5]];
|
|
1651 F2_previttelogenic_adults.std_error = m_se[[6]];
|
|
1652 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_previttelogenic_adults, "PRE-VITADULT-F2");
|
|
1653 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_previttelogenic_adults.std_error, "PRE-VITADULT-F2-SE");
|
|
1654 }
|
|
1655 if (process_vittelogenic_adults) {
|
|
1656 m_se = get_mean_and_std_error(P_vittelogenic_adults.replications, F1_vittelogenic_adults.replications, F2_vittelogenic_adults.replications);
|
|
1657 P_vittelogenic_adults = m_se[[1]];
|
|
1658 P_vittelogenic_adults.std_error = m_se[[2]];
|
|
1659 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_vittelogenic_adults, "VITADULT-P");
|
|
1660 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_vittelogenic_adults.std_error, "VITADULT-P-SE");
|
|
1661 F1_vittelogenic_adults = m_se[[3]];
|
|
1662 F1_vittelogenic_adults.std_error = m_se[[4]];
|
|
1663 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_vittelogenic_adults, "VITADULT-F1");
|
|
1664 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_vittelogenic_adults.std_error, "VITADULT-F1-SE");
|
|
1665 F2_vittelogenic_adults = m_se[[5]];
|
|
1666 F2_vittelogenic_adults.std_error = m_se[[6]];
|
|
1667 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_vittelogenic_adults, "VITADULT-F2");
|
|
1668 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_vittelogenic_adults.std_error, "VITADULT-F2-SE");
|
|
1669 }
|
|
1670 if (process_diapausing_adults) {
|
|
1671 m_se = get_mean_and_std_error(P_diapausing_adults.replications, F1_diapausing_adults.replications, F2_diapausing_adults.replications);
|
|
1672 P_diapausing_adults = m_se[[1]];
|
|
1673 P_diapausing_adults.std_error = m_se[[2]];
|
|
1674 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_diapausing_adults, "DIAPAUSINGADULT-P");
|
|
1675 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_diapausing_adults.std_error, "DIAPAUSINGADULT-P-SE");
|
|
1676 F1_diapausing_adults = m_se[[3]];
|
|
1677 F1_diapausing_adults.std_error = m_se[[4]];
|
|
1678 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_diapausing_adults, "DIAPAUSINGADULT-F1");
|
|
1679 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_diapausing_adults.std_error, "DIAPAUSINGADULT-F1-SE");
|
|
1680 F2_diapausing_adults = m_se[[5]];
|
|
1681 F2_diapausing_adults.std_error = m_se[[6]];
|
|
1682 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_diapausing_adults, "DIAPAUSINGADULT-F2");
|
|
1683 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_diapausing_adults.std_error, "DIAPAUSINGADULT-F2-SE");
|
|
1684 }
|
|
1685 if (process_total_adults) {
|
|
1686 m_se = get_mean_and_std_error(P_total_adults.replications, F1_total_adults.replications, F2_total_adults.replications);
|
|
1687 P_total_adults = m_se[[1]];
|
|
1688 P_total_adults.std_error = m_se[[2]];
|
|
1689 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_adults, "TOTALADULT-P");
|
|
1690 temperature_data_frame_P = append_vector(temperature_data_frame_P, P_total_adults.std_error, "TOTALADULT-P-SE");
|
|
1691 F1_total_adults = m_se[[3]];
|
|
1692 F1_total_adults.std_error = m_se[[4]];
|
|
1693 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_adults, "TOTALADULT-F1");
|
|
1694 temperature_data_frame_F1 = append_vector(temperature_data_frame_F1, F1_total_adults.std_error, "TOTALADULT-F1-SE");
|
|
1695 F2_total_adults = m_se[[5]];
|
|
1696 F2_total_adults.std_error = m_se[[6]];
|
|
1697 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_adults, "TOTALADULT-F2");
|
|
1698 temperature_data_frame_F2 = append_vector(temperature_data_frame_F2, F2_total_adults.std_error, "TOTALADULT-F2-SE");
|
|
1699 }
|
|
1700 }
|
103
|
1701
|
112
|
1702 # Save the analyzed data for combined generations.
|
|
1703 file_path = paste("output_data_dir", "04_combined_generations.csv", sep="/");
|
|
1704 write.csv(temperature_data_frame, file=file_path, row.names=F);
|
|
1705 if (plot_generations_separately) {
|
|
1706 # Save the analyzed data for generation P.
|
|
1707 file_path = paste("output_data_dir", "01_generation_P.csv", sep="/");
|
|
1708 write.csv(temperature_data_frame_P, file=file_path, row.names=F);
|
|
1709 # Save the analyzed data for generation F1.
|
|
1710 file_path = paste("output_data_dir", "02_generation_F1.csv", sep="/");
|
|
1711 write.csv(temperature_data_frame_F1, file=file_path, row.names=F);
|
|
1712 # Save the analyzed data for generation F2.
|
|
1713 file_path = paste("output_data_dir", "03_generation_F2.csv", sep="/");
|
|
1714 write.csv(temperature_data_frame_F2, file=file_path, row.names=F);
|
|
1715 }
|
103
|
1716
|
122
|
1717 total_days_vector = c(1:dim(temperature_data_frame)[1]);
|
112
|
1718 if (plot_generations_separately) {
|
|
1719 for (life_stage in life_stages) {
|
|
1720 if (life_stage == "Egg") {
|
|
1721 # Start PDF device driver.
|
|
1722 dev.new(width=20, height=30);
|
|
1723 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf")
|
|
1724 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1725 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1726 # Egg population size by generation.
|
|
1727 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100;
|
|
1728 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, location, latitude,
|
|
1729 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error,
|
|
1730 group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs, group3_std_error=F2_eggs.std_error);
|
|
1731 # Turn off device driver to flush output.
|
|
1732 dev.off();
|
|
1733 } else if (life_stage == "Nymph") {
|
|
1734 for (life_stage_nymph in life_stages_nymph) {
|
|
1735 # Start PDF device driver.
|
|
1736 dev.new(width=20, height=30);
|
|
1737 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", life_stage_nymph=life_stage_nymph)
|
|
1738 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1739 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1740 if (life_stage_nymph=="Young") {
|
|
1741 # Young nymph population size by generation.
|
|
1742 maxval = max(P_young_nymphs+F1_young_nymphs+F2_young_nymphs) + 100;
|
|
1743 group = P_young_nymphs;
|
|
1744 group_std_error = P_young_nymphs.std_error;
|
|
1745 group2 = F1_young_nymphs;
|
|
1746 group2_std_error = F1_young_nymphs.std_error;
|
|
1747 group3 = F2_young_nymphs;
|
|
1748 group3_std_error = F2_young_nymphs.std_error;
|
|
1749 } else if (life_stage_nymph=="Old") {
|
|
1750 # Total nymph population size by generation.
|
|
1751 maxval = max(P_old_nymphs+F1_old_nymphs+F2_old_nymphs) + 100;
|
|
1752 group = P_old_nymphs;
|
|
1753 group_std_error = P_old_nymphs.std_error;
|
|
1754 group2 = F1_old_nymphs;
|
|
1755 group2_std_error = F1_old_nymphs.std_error;
|
|
1756 group3 = F2_old_nymphs;
|
|
1757 group3_std_error = F2_old_nymphs.std_error;
|
|
1758 } else if (life_stage_nymph=="Total") {
|
|
1759 # Total nymph population size by generation.
|
|
1760 maxval = max(P_total_nymphs+F1_total_nymphs+F2_total_nymphs) + 100;
|
|
1761 group = P_total_nymphs;
|
|
1762 group_std_error = P_total_nymphs.std_error;
|
|
1763 group2 = F1_total_nymphs;
|
|
1764 group2_std_error = F1_total_nymphs.std_error;
|
|
1765 group3 = F2_total_nymphs;
|
|
1766 group3_std_error = F2_total_nymphs.std_error;
|
|
1767 }
|
|
1768 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, location, latitude,
|
|
1769 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=group, group_std_error=group_std_error,
|
|
1770 group2=group2, group2_std_error=group2_std_error, group3=group3, group3_std_error=group3_std_error, life_stages_nymph=life_stage_nymph);
|
|
1771 # Turn off device driver to flush output.
|
|
1772 dev.off();
|
|
1773 }
|
|
1774 } else if (life_stage == "Adult") {
|
|
1775 for (life_stage_adult in life_stages_adult) {
|
|
1776 # Start PDF device driver.
|
|
1777 dev.new(width=20, height=30);
|
|
1778 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", life_stage_adult=life_stage_adult)
|
|
1779 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1780 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1781 if (life_stage_adult=="Pre-vittelogenic") {
|
|
1782 # Pre-vittelogenic adult population size by generation.
|
|
1783 maxval = max(P_previttelogenic_adults+F1_previttelogenic_adults+F2_previttelogenic_adults) + 100;
|
|
1784 group = P_previttelogenic_adults;
|
|
1785 group_std_error = P_previttelogenic_adults.std_error;
|
|
1786 group2 = F1_previttelogenic_adults;
|
|
1787 group2_std_error = F1_previttelogenic_adults.std_error;
|
|
1788 group3 = F2_previttelogenic_adults;
|
|
1789 group3_std_error = F2_previttelogenic_adults.std_error;
|
|
1790 } else if (life_stage_adult=="Vittelogenic") {
|
|
1791 # Vittelogenic adult population size by generation.
|
|
1792 maxval = max(P_vittelogenic_adults+F1_vittelogenic_adults+F2_vittelogenic_adults) + 100;
|
|
1793 group = P_vittelogenic_adults;
|
|
1794 group_std_error = P_vittelogenic_adults.std_error;
|
|
1795 group2 = F1_vittelogenic_adults;
|
|
1796 group2_std_error = F1_vittelogenic_adults.std_error;
|
|
1797 group3 = F2_vittelogenic_adults;
|
|
1798 group3_std_error = F2_vittelogenic_adults.std_error;
|
|
1799 } else if (life_stage_adult=="Diapausing") {
|
|
1800 # Diapausing adult population size by generation.
|
|
1801 maxval = max(P_diapausing_adults+F1_diapausing_adults+F2_diapausing_adults) + 100;
|
|
1802 group = P_diapausing_adults;
|
|
1803 group_std_error = P_diapausing_adults.std_error;
|
|
1804 group2 = F1_diapausing_adults;
|
|
1805 group2_std_error = F1_diapausing_adults.std_error;
|
|
1806 group3 = F2_diapausing_adults;
|
|
1807 group3_std_error = F2_diapausing_adults.std_error;
|
|
1808 } else if (life_stage_adult=="Total") {
|
|
1809 # Total adult population size by generation.
|
|
1810 maxval = max(P_total_adults+F1_total_adults+F2_total_adults) + 100;
|
|
1811 group = P_total_adults;
|
|
1812 group_std_error = P_total_adults.std_error;
|
|
1813 group2 = F1_total_adults;
|
|
1814 group2_std_error = F1_total_adults.std_error;
|
|
1815 group3 = F2_total_adults;
|
|
1816 group3_std_error = F2_total_adults.std_error;
|
|
1817 }
|
|
1818 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, location, latitude,
|
|
1819 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=group, group_std_error=group_std_error,
|
|
1820 group2=group2, group2_std_error=group2_std_error, group3=group3, group3_std_error=group3_std_error, life_stages_adult=life_stage_adult);
|
|
1821 # Turn off device driver to flush output.
|
|
1822 dev.off();
|
|
1823 }
|
|
1824 } else if (life_stage == "Total") {
|
|
1825 # Start PDF device driver.
|
|
1826 # Name collection elements so that they
|
|
1827 # are displayed in logical order.
|
|
1828 dev.new(width=20, height=30);
|
|
1829 file_path = get_file_path(life_stage, "total_pop_by_generation.pdf")
|
|
1830 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1831 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1832 # Total population size by generation.
|
|
1833 maxval = max(P+F1+F2) + 100;
|
|
1834 render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, location, latitude,
|
|
1835 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=P, group_std_error=P.std_error,
|
|
1836 group2=F1, group2_std_error=F1.std_error, group3=F2, group3_std_error=F2.std_error);
|
|
1837 # Turn off device driver to flush output.
|
|
1838 dev.off();
|
|
1839 }
|
|
1840 }
|
|
1841 } else {
|
|
1842 for (life_stage in life_stages) {
|
|
1843 if (life_stage == "Egg") {
|
|
1844 # Start PDF device driver.
|
|
1845 dev.new(width=20, height=30);
|
|
1846 file_path = get_file_path(life_stage, "egg_pop.pdf")
|
|
1847 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1848 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1849 # Egg population size.
|
|
1850 maxval = max(eggs+eggs.std_error) + 100;
|
|
1851 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, location, latitude,
|
|
1852 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error);
|
|
1853 # Turn off device driver to flush output.
|
|
1854 dev.off();
|
|
1855 } else if (life_stage == "Nymph") {
|
|
1856 for (life_stage_nymph in life_stages_nymph) {
|
|
1857 # Start PDF device driver.
|
|
1858 dev.new(width=20, height=30);
|
|
1859 file_path = get_file_path(life_stage, "nymph_pop.pdf", life_stage_nymph=life_stage_nymph)
|
|
1860 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1861 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1862 if (life_stage_nymph=="Total") {
|
|
1863 # Total nymph population size.
|
|
1864 group = total_nymphs;
|
|
1865 group_std_error = total_nymphs.std_error;
|
|
1866 } else if (life_stage_nymph=="Young") {
|
|
1867 # Young nymph population size.
|
|
1868 group = young_nymphs;
|
|
1869 group_std_error = young_nymphs.std_error;
|
|
1870 } else if (life_stage_nymph=="Old") {
|
|
1871 # Old nymph population size.
|
|
1872 group = old_nymphs;
|
|
1873 group_std_error = old_nymphs.std_error;
|
|
1874 }
|
|
1875 maxval = max(group+group_std_error) + 100;
|
|
1876 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, location, latitude,
|
|
1877 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=group, group_std_error=group_std_error,
|
|
1878 life_stages_nymph=life_stage_nymph);
|
|
1879 # Turn off device driver to flush output.
|
|
1880 dev.off();
|
|
1881 }
|
|
1882 } else if (life_stage == "Adult") {
|
|
1883 for (life_stage_adult in life_stages_adult) {
|
|
1884 # Start PDF device driver.
|
|
1885 dev.new(width=20, height=30);
|
|
1886 file_path = get_file_path(life_stage, "adult_pop.pdf", life_stage_adult=life_stage_adult)
|
|
1887 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1888 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1889 if (life_stage_adult=="Total") {
|
|
1890 # Total adult population size.
|
|
1891 group = total_adults;
|
|
1892 group_std_error = total_adults.std_error
|
|
1893 } else if (life_stage_adult=="Pre-vittelogenic") {
|
|
1894 # Pre-vittelogenic adult population size.
|
|
1895 group = previttelogenic_adults;
|
|
1896 group_std_error = previttelogenic_adults.std_error
|
|
1897 } else if (life_stage_adult=="Vittelogenic") {
|
|
1898 # Vittelogenic adult population size.
|
|
1899 group = vittelogenic_adults;
|
|
1900 group_std_error = vittelogenic_adults.std_error
|
|
1901 } else if (life_stage_adult=="Diapausing") {
|
|
1902 # Diapausing adult population size.
|
|
1903 group = diapausing_adults;
|
|
1904 group_std_error = diapausing_adults.std_error
|
|
1905 }
|
|
1906 maxval = max(group+group_std_error) + 100;
|
|
1907 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, location, latitude,
|
|
1908 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=group, group_std_error=group_std_error,
|
|
1909 life_stages_adult=life_stage_adult);
|
|
1910 # Turn off device driver to flush output.
|
|
1911 dev.off();
|
|
1912 }
|
|
1913 } else if (life_stage == "Total") {
|
|
1914 # Start PDF device driver.
|
|
1915 dev.new(width=20, height=30);
|
|
1916 file_path = get_file_path(life_stage, "total_pop.pdf")
|
|
1917 pdf(file=file_path, width=20, height=30, bg="white");
|
|
1918 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
|
|
1919 # Total population size.
|
|
1920 maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100;
|
|
1921 render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, location, latitude,
|
|
1922 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=total_adults, group_std_error=total_adults.std_error,
|
|
1923 group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs, group3_std_error=eggs.std_error);
|
|
1924 # Turn off device driver to flush output.
|
|
1925 dev.off();
|
|
1926 }
|
|
1927 }
|
|
1928 }
|