annotate insect_phenology_model.R @ 32:94afb3e484c3 draft

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