annotate extract_ipm_date_interval.R @ 5:d62034b36200 draft default tip

Uploaded
author greg
date Thu, 09 Aug 2018 10:15:32 -0400
parents 8b068f78e7fd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1868b7913590 Uploaded
greg
parents:
diff changeset
1 #!/usr/bin/env Rscript
1868b7913590 Uploaded
greg
parents:
diff changeset
2
1868b7913590 Uploaded
greg
parents:
diff changeset
3 suppressPackageStartupMessages(library("data.table"))
1868b7913590 Uploaded
greg
parents:
diff changeset
4 suppressPackageStartupMessages(library("hash"))
1868b7913590 Uploaded
greg
parents:
diff changeset
5 suppressPackageStartupMessages(library("optparse"))
1868b7913590 Uploaded
greg
parents:
diff changeset
6
1868b7913590 Uploaded
greg
parents:
diff changeset
7 option_list <- list(
1868b7913590 Uploaded
greg
parents:
diff changeset
8 make_option(c("--input_data_dir"), action="store", dest="input_data_dir", help="Directory containing .csv outputs from insect_phenology_model"),
1868b7913590 Uploaded
greg
parents:
diff changeset
9 make_option(c("--end_date"), action="store", dest="end_date", help="End date for date interval"),
1868b7913590 Uploaded
greg
parents:
diff changeset
10 make_option(c("--start_date"), action="store", dest="start_date", help="Start date for date interval"),
1868b7913590 Uploaded
greg
parents:
diff changeset
11 make_option(c("--script_dir"), action="store", dest="script_dir", help="R script source directory"),
1868b7913590 Uploaded
greg
parents:
diff changeset
12 make_option(c("--tool_parameters"), action="store", dest="tool_parameters", help="Users defined parameters for executing the insect_phenology_model inputs")
1868b7913590 Uploaded
greg
parents:
diff changeset
13 )
1868b7913590 Uploaded
greg
parents:
diff changeset
14
1868b7913590 Uploaded
greg
parents:
diff changeset
15 parser <- OptionParser(usage="%prog [options] file", option_list=option_list);
1868b7913590 Uploaded
greg
parents:
diff changeset
16 args <- parse_args(parser, positional_arguments=TRUE);
1868b7913590 Uploaded
greg
parents:
diff changeset
17 opt <- args$options;
1868b7913590 Uploaded
greg
parents:
diff changeset
18
1868b7913590 Uploaded
greg
parents:
diff changeset
19 get_new_temperature_data_frame = function(input_data_file) {
1868b7913590 Uploaded
greg
parents:
diff changeset
20 # Read a csv file to produce a data frame
1868b7913590 Uploaded
greg
parents:
diff changeset
21 # consisting of the data which was produced
1868b7913590 Uploaded
greg
parents:
diff changeset
22 # by the insect_phenology_model tool.
1868b7913590 Uploaded
greg
parents:
diff changeset
23 temperature_data_frame = read.csv(file=input_data_file, header=T, strip.white=TRUE, stringsAsFactors=FALSE, sep=",");
1868b7913590 Uploaded
greg
parents:
diff changeset
24 return(temperature_data_frame);
1868b7913590 Uploaded
greg
parents:
diff changeset
25 }
1868b7913590 Uploaded
greg
parents:
diff changeset
26
1868b7913590 Uploaded
greg
parents:
diff changeset
27 parse_tool_parameters = function(tool_parameters) {
1868b7913590 Uploaded
greg
parents:
diff changeset
28 # Parse the tool parameters that were used to produce
1868b7913590 Uploaded
greg
parents:
diff changeset
29 # the input datasets found in input_data_dir. These
1868b7913590 Uploaded
greg
parents:
diff changeset
30 # datasets were produced by the insect_phenology_model
1868b7913590 Uploaded
greg
parents:
diff changeset
31 # tool.
1868b7913590 Uploaded
greg
parents:
diff changeset
32 raw_params = sub("^__SeP__", "", tool_parameters);
1868b7913590 Uploaded
greg
parents:
diff changeset
33 raw_param_items = strsplit(raw_params, "__SeP__")[[1]];
1868b7913590 Uploaded
greg
parents:
diff changeset
34 keys = raw_param_items[c(T, F)];
1868b7913590 Uploaded
greg
parents:
diff changeset
35 values = raw_param_items[c(F, T)];
1868b7913590 Uploaded
greg
parents:
diff changeset
36 num_keys_and_vals = length(keys);
1868b7913590 Uploaded
greg
parents:
diff changeset
37 for (i in 1:num_keys_and_vals) {
1868b7913590 Uploaded
greg
parents:
diff changeset
38 values[i] = restore_text(values[[i]]);
1868b7913590 Uploaded
greg
parents:
diff changeset
39 }
1868b7913590 Uploaded
greg
parents:
diff changeset
40 for (i in 1:num_keys_and_vals) {
1868b7913590 Uploaded
greg
parents:
diff changeset
41 key = keys[i];
1868b7913590 Uploaded
greg
parents:
diff changeset
42 if (endsWith(key, "cond")) {
1868b7913590 Uploaded
greg
parents:
diff changeset
43 value = values[i];
1868b7913590 Uploaded
greg
parents:
diff changeset
44 # Galaxy passes some input job parameters as json-like strings
1868b7913590 Uploaded
greg
parents:
diff changeset
45 # for complex objects like conditionals, so we should see if
1868b7913590 Uploaded
greg
parents:
diff changeset
46 # we can re-implement this using r-jsonlite if possible. An
1868b7913590 Uploaded
greg
parents:
diff changeset
47 # exception is currently thrown when we do this:
1868b7913590 Uploaded
greg
parents:
diff changeset
48 # params_hash = fromJSON(opt$tool_parameters);
1868b7913590 Uploaded
greg
parents:
diff changeset
49 # Error: lexical error: invalid char in json text.
1868b7913590 Uploaded
greg
parents:
diff changeset
50 # __SeP__adult_mortality__SeP____
1868b7913590 Uploaded
greg
parents:
diff changeset
51 # (right here) ------^
1868b7913590 Uploaded
greg
parents:
diff changeset
52 # Here is an example complex object parameter value, in
1868b7913590 Uploaded
greg
parents:
diff changeset
53 # this case the parameter name is plot_nymph_life_stage_cond.
1868b7913590 Uploaded
greg
parents:
diff changeset
54 # {"life_stages_nymph": ["Total"], "__current_case__": 0, "plot_nymph_life_stage": "yes"}
1868b7913590 Uploaded
greg
parents:
diff changeset
55 # This code is somewhat brittle, so a better approach is
1868b7913590 Uploaded
greg
parents:
diff changeset
56 # warranted if possible.
1868b7913590 Uploaded
greg
parents:
diff changeset
57 if (key == "merge_ytd_temperature_data_cond") {
1868b7913590 Uploaded
greg
parents:
diff changeset
58 val = grep("yes", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
59 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
60 # Get the location.
1868b7913590 Uploaded
greg
parents:
diff changeset
61 items = strsplit(value, "\"location\": ")[[1]];
1868b7913590 Uploaded
greg
parents:
diff changeset
62 location_str = items[2];
1868b7913590 Uploaded
greg
parents:
diff changeset
63 val = grep("\",", location_str);
1868b7913590 Uploaded
greg
parents:
diff changeset
64 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
65 items = strsplit(location_str, "\",")[[1]];
1868b7913590 Uploaded
greg
parents:
diff changeset
66 location = items[1];
1868b7913590 Uploaded
greg
parents:
diff changeset
67 } else {
1868b7913590 Uploaded
greg
parents:
diff changeset
68 location = items[1];
1868b7913590 Uploaded
greg
parents:
diff changeset
69 }
1868b7913590 Uploaded
greg
parents:
diff changeset
70 if (location == "\"") {
1868b7913590 Uploaded
greg
parents:
diff changeset
71 location = "";
1868b7913590 Uploaded
greg
parents:
diff changeset
72 }
1868b7913590 Uploaded
greg
parents:
diff changeset
73 keys[i] = "location";
1868b7913590 Uploaded
greg
parents:
diff changeset
74 values[i] = location;
1868b7913590 Uploaded
greg
parents:
diff changeset
75 }
1868b7913590 Uploaded
greg
parents:
diff changeset
76 } else if (key =="plot_nymph_life_stage_cond") {
1868b7913590 Uploaded
greg
parents:
diff changeset
77 val = grep("yes", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
78 if (length(val)==0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
79 keys[i] = "plot_nymph_life_stage";
1868b7913590 Uploaded
greg
parents:
diff changeset
80 values[i] = "no";
1868b7913590 Uploaded
greg
parents:
diff changeset
81 } else {
1868b7913590 Uploaded
greg
parents:
diff changeset
82 # Get the value for "life_stages_nymph".
1868b7913590 Uploaded
greg
parents:
diff changeset
83 items = strsplit(value, "\"life_stages_nymph\": ")[[1]];
1868b7913590 Uploaded
greg
parents:
diff changeset
84 life_stages_nymph_str = items[2];
1868b7913590 Uploaded
greg
parents:
diff changeset
85 if (grep("],", life_stages_nymph_str)[[1]] > 0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
86 items = strsplit(life_stages_nymph_str, "],")[[1]];
1868b7913590 Uploaded
greg
parents:
diff changeset
87 life_stages_nymph_str = items[1];
1868b7913590 Uploaded
greg
parents:
diff changeset
88 #life_stages_nymph_str = sub("^\\[", "", life_stages_nymph_str);
1868b7913590 Uploaded
greg
parents:
diff changeset
89 num_curent_keys = length(keys);
1868b7913590 Uploaded
greg
parents:
diff changeset
90 keys[num_curent_keys+1] = "life_stages_nymph";
1868b7913590 Uploaded
greg
parents:
diff changeset
91 values[num_curent_keys+1] = life_stages_nymph_str;
1868b7913590 Uploaded
greg
parents:
diff changeset
92 }
1868b7913590 Uploaded
greg
parents:
diff changeset
93 keys[i] = "plot_nymph_life_stage";
1868b7913590 Uploaded
greg
parents:
diff changeset
94 values[i] = "yes";
1868b7913590 Uploaded
greg
parents:
diff changeset
95 }
1868b7913590 Uploaded
greg
parents:
diff changeset
96 } else if (key =="plot_adult_life_stage_cond") {
1868b7913590 Uploaded
greg
parents:
diff changeset
97 val = grep("yes", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
98 # The value of val is an integer if the pattern is not found.
1868b7913590 Uploaded
greg
parents:
diff changeset
99 if (length(val)==0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
100 keys[i] = "plot_adult_life_stage";
1868b7913590 Uploaded
greg
parents:
diff changeset
101 values[i] = "no";
1868b7913590 Uploaded
greg
parents:
diff changeset
102 } else {
1868b7913590 Uploaded
greg
parents:
diff changeset
103 # Get the value for "life_stages_adult".
1868b7913590 Uploaded
greg
parents:
diff changeset
104 items = strsplit(value, "\"life_stages_adult\": ")[[1]];
1868b7913590 Uploaded
greg
parents:
diff changeset
105 life_stages_adult_str = items[2];
1868b7913590 Uploaded
greg
parents:
diff changeset
106 if (grep("],", life_stages_adult_str)[[1]] > 0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
107 items = strsplit(life_stages_adult_str, "],")[[1]];
1868b7913590 Uploaded
greg
parents:
diff changeset
108 life_stages_adult_str = items[1];
1868b7913590 Uploaded
greg
parents:
diff changeset
109 #life_stages_adult_str = sub("^\\[", "", life_stages_adult_str);
1868b7913590 Uploaded
greg
parents:
diff changeset
110 num_curent_keys = length(keys);
1868b7913590 Uploaded
greg
parents:
diff changeset
111 keys[num_curent_keys+1] = "life_stages_adult";
1868b7913590 Uploaded
greg
parents:
diff changeset
112 values[num_curent_keys+1] = life_stages_adult_str;
1868b7913590 Uploaded
greg
parents:
diff changeset
113 }
1868b7913590 Uploaded
greg
parents:
diff changeset
114 keys[i] = "plot_adult_life_stage";
1868b7913590 Uploaded
greg
parents:
diff changeset
115 values[i] = "yes";
1868b7913590 Uploaded
greg
parents:
diff changeset
116 }
1868b7913590 Uploaded
greg
parents:
diff changeset
117 }
1868b7913590 Uploaded
greg
parents:
diff changeset
118 }
1868b7913590 Uploaded
greg
parents:
diff changeset
119 }
1868b7913590 Uploaded
greg
parents:
diff changeset
120 # Strip all double qu0tes from values.
1868b7913590 Uploaded
greg
parents:
diff changeset
121 for (i in 1:length(values)) {
1868b7913590 Uploaded
greg
parents:
diff changeset
122 value = values[i];
1868b7913590 Uploaded
greg
parents:
diff changeset
123 value = gsub("\"", "", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
124 values[i] = value;
1868b7913590 Uploaded
greg
parents:
diff changeset
125 }
1868b7913590 Uploaded
greg
parents:
diff changeset
126 return(hash(keys, values));
1868b7913590 Uploaded
greg
parents:
diff changeset
127 }
1868b7913590 Uploaded
greg
parents:
diff changeset
128
1868b7913590 Uploaded
greg
parents:
diff changeset
129 prepare_plot = function(life_stage, file_path, maxval, ticks, date_labels, chart_type, plot_std_error, insect, location,
1868b7913590 Uploaded
greg
parents:
diff changeset
130 latitude, start_date, end_date, total_days_vector, replications, group, group_std_error, group2, group2_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
131 group3, group3_std_error, sub_life_stage=NULL) {
1868b7913590 Uploaded
greg
parents:
diff changeset
132 # Start PDF device driver.
1868b7913590 Uploaded
greg
parents:
diff changeset
133 dev.new(width=20, height=30);
1868b7913590 Uploaded
greg
parents:
diff changeset
134 pdf(file=file_path, width=20, height=30, bg="white");
1868b7913590 Uploaded
greg
parents:
diff changeset
135 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
1868b7913590 Uploaded
greg
parents:
diff changeset
136 render_chart(ticks, date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date,
1868b7913590 Uploaded
greg
parents:
diff changeset
137 total_days_vector, maxval, replications, life_stage, group=group, group_std_error=group_std_error, group2=group2,
1868b7913590 Uploaded
greg
parents:
diff changeset
138 group2_std_error=group2_std_error, group3=group3, group3_std_error=group3_std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
139 # Turn off device driver to flush output.
1868b7913590 Uploaded
greg
parents:
diff changeset
140 dev.off();
1868b7913590 Uploaded
greg
parents:
diff changeset
141 }
1868b7913590 Uploaded
greg
parents:
diff changeset
142
1868b7913590 Uploaded
greg
parents:
diff changeset
143 restore_text = function(text) {
1868b7913590 Uploaded
greg
parents:
diff changeset
144 # Un-escape characters that are escaped by the
1868b7913590 Uploaded
greg
parents:
diff changeset
145 # Galaxy tool parameter handlers.
1868b7913590 Uploaded
greg
parents:
diff changeset
146 if (is.null(text) || length(text) == 0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
147 return(text);
1868b7913590 Uploaded
greg
parents:
diff changeset
148 }
1868b7913590 Uploaded
greg
parents:
diff changeset
149 chars = list(">", "<", "'", '"', "[", "]", "{", "}", "@", "\n", "\r", "\t", "#");
1868b7913590 Uploaded
greg
parents:
diff changeset
150 mapped_chars = list("__gt__", "__lt__", "__sq__", "__dq__", "__ob__", "__cb__",
1868b7913590 Uploaded
greg
parents:
diff changeset
151 "__oc__", "__cc__", "__at__", "__cn__", "__cr__", "__tc__", "__pd__");
1868b7913590 Uploaded
greg
parents:
diff changeset
152 for (i in 1:length(mapped_chars)) {
1868b7913590 Uploaded
greg
parents:
diff changeset
153 char = chars[[i]];
1868b7913590 Uploaded
greg
parents:
diff changeset
154 mapped_char = mapped_chars[[i]];
1868b7913590 Uploaded
greg
parents:
diff changeset
155 text = gsub(mapped_char, char, text);
1868b7913590 Uploaded
greg
parents:
diff changeset
156 }
1868b7913590 Uploaded
greg
parents:
diff changeset
157 return(text);
1868b7913590 Uploaded
greg
parents:
diff changeset
158 }
1868b7913590 Uploaded
greg
parents:
diff changeset
159
1868b7913590 Uploaded
greg
parents:
diff changeset
160 # Import the shared utility functions.
1868b7913590 Uploaded
greg
parents:
diff changeset
161 utils_path <- paste(opt$script_dir, "utils.R", sep="/");
1868b7913590 Uploaded
greg
parents:
diff changeset
162 source(utils_path);
1868b7913590 Uploaded
greg
parents:
diff changeset
163
1868b7913590 Uploaded
greg
parents:
diff changeset
164 params_hash = parse_tool_parameters(opt$tool_parameters);
1868b7913590 Uploaded
greg
parents:
diff changeset
165
1868b7913590 Uploaded
greg
parents:
diff changeset
166 # Determine the data we need to generate for plotting.
1868b7913590 Uploaded
greg
parents:
diff changeset
167 if (params_hash$plot_generations_separately == "yes") {
1868b7913590 Uploaded
greg
parents:
diff changeset
168 plot_generations_separately = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
169 } else {
1868b7913590 Uploaded
greg
parents:
diff changeset
170 plot_generations_separately = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
171 }
1868b7913590 Uploaded
greg
parents:
diff changeset
172 if (params_hash$plot_std_error == "yes") {
1868b7913590 Uploaded
greg
parents:
diff changeset
173 plot_std_error = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
174 } else {
1868b7913590 Uploaded
greg
parents:
diff changeset
175 plot_std_error = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
176 }
1868b7913590 Uploaded
greg
parents:
diff changeset
177 process_eggs = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
178 process_nymphs = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
179 process_young_nymphs = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
180 process_old_nymphs = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
181 process_total_nymphs = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
182 process_adults = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
183 process_previttelogenic_adults = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
184 process_vittelogenic_adults = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
185 process_diapausing_adults = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
186 process_total_adults = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
187 if (params_hash$plot_egg_life_stage == "yes") {
1868b7913590 Uploaded
greg
parents:
diff changeset
188 process_eggs = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
189 }
1868b7913590 Uploaded
greg
parents:
diff changeset
190 if (params_hash$plot_nymph_life_stage == "yes") {
1868b7913590 Uploaded
greg
parents:
diff changeset
191 process_nymphs = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
192 # Get the selected life stages.
1868b7913590 Uploaded
greg
parents:
diff changeset
193 value = params_hash$life_stages_nymph;
1868b7913590 Uploaded
greg
parents:
diff changeset
194 val = grep("Young", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
195 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
196 process_young_nymphs = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
197 }
1868b7913590 Uploaded
greg
parents:
diff changeset
198 val = grep("Old", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
199 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
200 process_old_nymphs = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
201 }
1868b7913590 Uploaded
greg
parents:
diff changeset
202 val = grep("Total", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
203 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
204 process_total_nymphs = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
205 }
1868b7913590 Uploaded
greg
parents:
diff changeset
206 }
1868b7913590 Uploaded
greg
parents:
diff changeset
207 if (params_hash$plot_adult_life_stage == "yes") {
1868b7913590 Uploaded
greg
parents:
diff changeset
208 process_adults = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
209 # Get the selected life stages.
1868b7913590 Uploaded
greg
parents:
diff changeset
210 value = params_hash$life_stages_adult;
1868b7913590 Uploaded
greg
parents:
diff changeset
211 val = grep("Pre-vittelogenic", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
212 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
213 process_previttelogenic_adults = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
214 }
1868b7913590 Uploaded
greg
parents:
diff changeset
215 val = grep("Vittelogenic", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
216 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
217 process_vittelogenic_adults = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
218 }
1868b7913590 Uploaded
greg
parents:
diff changeset
219 val = grep("Diapausing", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
220 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
221 process_diapausing_adults = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
222 }
1868b7913590 Uploaded
greg
parents:
diff changeset
223 val = grep("Total", value);
1868b7913590 Uploaded
greg
parents:
diff changeset
224 if (length(val)>0) {
1868b7913590 Uploaded
greg
parents:
diff changeset
225 process_total_adults = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
226 }
1868b7913590 Uploaded
greg
parents:
diff changeset
227 }
1868b7913590 Uploaded
greg
parents:
diff changeset
228
1868b7913590 Uploaded
greg
parents:
diff changeset
229 if (params_hash$plot_egg_life_stage == "yes" & params_hash$plot_nymph_life_stage == "yes" & params_hash$plot_adult_life_stage == "yes") {
1868b7913590 Uploaded
greg
parents:
diff changeset
230 process_total = TRUE;
1868b7913590 Uploaded
greg
parents:
diff changeset
231 } else {
1868b7913590 Uploaded
greg
parents:
diff changeset
232 process_total = FALSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
233 }
1868b7913590 Uploaded
greg
parents:
diff changeset
234
1868b7913590 Uploaded
greg
parents:
diff changeset
235
1868b7913590 Uploaded
greg
parents:
diff changeset
236 # FIXME: currently custom date fields are free text, but
1868b7913590 Uploaded
greg
parents:
diff changeset
237 # Galaxy should soon include support for a date selector
1868b7913590 Uploaded
greg
parents:
diff changeset
238 # at which point this tool should be enhanced to use it.
1868b7913590 Uploaded
greg
parents:
diff changeset
239 # Validate start_date.
1868b7913590 Uploaded
greg
parents:
diff changeset
240 start_date = format(opt$start_date);
1868b7913590 Uploaded
greg
parents:
diff changeset
241 end_date = format(opt$end_date);
1868b7913590 Uploaded
greg
parents:
diff changeset
242
1868b7913590 Uploaded
greg
parents:
diff changeset
243 # Calaculate the number of days in the date interval.
1868b7913590 Uploaded
greg
parents:
diff changeset
244 start_date = validate_date(start_date);
1868b7913590 Uploaded
greg
parents:
diff changeset
245 # Validate end_date.
1868b7913590 Uploaded
greg
parents:
diff changeset
246 end_date = validate_date(end_date);
1868b7913590 Uploaded
greg
parents:
diff changeset
247 if (start_date >= end_date) {
3
8b068f78e7fd Uploaded
greg
parents: 1
diff changeset
248 stop_err("The start date must be between 1 and 50 days before the end date.\n");
0
1868b7913590 Uploaded
greg
parents:
diff changeset
249 }
1868b7913590 Uploaded
greg
parents:
diff changeset
250 # Calculate the number of days in the date interval.
1868b7913590 Uploaded
greg
parents:
diff changeset
251 num_days = difftime(end_date, start_date, units=c("days"));
1868b7913590 Uploaded
greg
parents:
diff changeset
252 # Add 1 to the number of days to make the dates inclusive. For
1868b7913590 Uploaded
greg
parents:
diff changeset
253 # example, if the user enters a date range of 2018-01-01 to
1868b7913590 Uploaded
greg
parents:
diff changeset
254 # 2018-01-31, they likely expect the end date to be included.
1868b7913590 Uploaded
greg
parents:
diff changeset
255 num_days = num_days + 1;
1868b7913590 Uploaded
greg
parents:
diff changeset
256 if (num_days > 50) {
1868b7913590 Uploaded
greg
parents:
diff changeset
257 # We need to restrict date intervals since
1868b7913590 Uploaded
greg
parents:
diff changeset
258 # plots render tick marks for each day.
1868b7913590 Uploaded
greg
parents:
diff changeset
259 stop_err("Date intervals for plotting cannot exceed 50 days.");
1868b7913590 Uploaded
greg
parents:
diff changeset
260 }
1868b7913590 Uploaded
greg
parents:
diff changeset
261 # Display the total number of days in the Galaxy history item blurb.
1868b7913590 Uploaded
greg
parents:
diff changeset
262 cat("Number of days in date interval: ", num_days, "\n");
1868b7913590 Uploaded
greg
parents:
diff changeset
263
1868b7913590 Uploaded
greg
parents:
diff changeset
264 # Create the csv data files consisting of the date interval.
1868b7913590 Uploaded
greg
parents:
diff changeset
265 input_data_files = list.files(path=opt$input_data_dir, full.names=TRUE);
1868b7913590 Uploaded
greg
parents:
diff changeset
266 for (input_data_file in input_data_files) {
1868b7913590 Uploaded
greg
parents:
diff changeset
267 file_name = basename(input_data_file);
1868b7913590 Uploaded
greg
parents:
diff changeset
268 temperature_data_frame = get_new_temperature_data_frame(input_data_file);
1868b7913590 Uploaded
greg
parents:
diff changeset
269 start_date_row = which(temperature_data_frame$DATE==start_date);
1868b7913590 Uploaded
greg
parents:
diff changeset
270 end_date_row = which(temperature_data_frame$DATE==end_date);
3
8b068f78e7fd Uploaded
greg
parents: 1
diff changeset
271 if (length(start_date_row)==0 | length(end_date_row)==0) {
8b068f78e7fd Uploaded
greg
parents: 1
diff changeset
272 stop_err("Invalid date interval, make sure the start and end dates are both contained within the selected input data files.\n");
8b068f78e7fd Uploaded
greg
parents: 1
diff changeset
273 }
0
1868b7913590 Uploaded
greg
parents:
diff changeset
274 # Extract the date interval.
1868b7913590 Uploaded
greg
parents:
diff changeset
275 temperature_data_frame = temperature_data_frame[start_date_row:end_date_row,];
1868b7913590 Uploaded
greg
parents:
diff changeset
276 # Save the date interval data into an output file
1868b7913590 Uploaded
greg
parents:
diff changeset
277 # named the same as the input.
1868b7913590 Uploaded
greg
parents:
diff changeset
278 file_path = paste("output_data_dir", file_name, sep="/");
1868b7913590 Uploaded
greg
parents:
diff changeset
279 write.csv(temperature_data_frame, file=file_path, row.names=F);
1868b7913590 Uploaded
greg
parents:
diff changeset
280 }
1868b7913590 Uploaded
greg
parents:
diff changeset
281
1868b7913590 Uploaded
greg
parents:
diff changeset
282 # Extract the vectors needed for plots from the input data files
1868b7913590 Uploaded
greg
parents:
diff changeset
283 # produced by the insect_phenology_model tool.
1868b7913590 Uploaded
greg
parents:
diff changeset
284 total_days_vector = NULL;
1868b7913590 Uploaded
greg
parents:
diff changeset
285 ticks_and_labels = NULL;
1868b7913590 Uploaded
greg
parents:
diff changeset
286 latitude = NULL;
1868b7913590 Uploaded
greg
parents:
diff changeset
287 input_data_files = list.files(path="output_data_dir", full.names=TRUE);
1868b7913590 Uploaded
greg
parents:
diff changeset
288 for (input_data_file in input_data_files) {
1868b7913590 Uploaded
greg
parents:
diff changeset
289 file_name = basename(input_data_file);
1868b7913590 Uploaded
greg
parents:
diff changeset
290 temperature_data_frame = get_new_temperature_data_frame(input_data_file);
1868b7913590 Uploaded
greg
parents:
diff changeset
291 # Initialize the total_days_vector for later plotting.
1868b7913590 Uploaded
greg
parents:
diff changeset
292 if (is.null(total_days_vector)) {
1868b7913590 Uploaded
greg
parents:
diff changeset
293 total_days_vector = c(1:dim(temperature_data_frame)[1]);
1868b7913590 Uploaded
greg
parents:
diff changeset
294 }
1868b7913590 Uploaded
greg
parents:
diff changeset
295 if (is.null(ticks_and_labels)) {
1868b7913590 Uploaded
greg
parents:
diff changeset
296 # Get the ticks date labels for later plotting
1868b7913590 Uploaded
greg
parents:
diff changeset
297 ticks_and_labels = get_x_axis_ticks_and_labels(temperature_data_frame, date_interval=TRUE);
1868b7913590 Uploaded
greg
parents:
diff changeset
298 ticks = c(unlist(ticks_and_labels[1]));
1868b7913590 Uploaded
greg
parents:
diff changeset
299 date_labels = c(unlist(ticks_and_labels[2]));
1868b7913590 Uploaded
greg
parents:
diff changeset
300 }
1868b7913590 Uploaded
greg
parents:
diff changeset
301 if (is.null(latitude)) {
1868b7913590 Uploaded
greg
parents:
diff changeset
302 # Get the latitude for later plotting.
1868b7913590 Uploaded
greg
parents:
diff changeset
303 latitude = temperature_data_frame$LATITUDE[1];
1868b7913590 Uploaded
greg
parents:
diff changeset
304 }
1868b7913590 Uploaded
greg
parents:
diff changeset
305
1868b7913590 Uploaded
greg
parents:
diff changeset
306 if (file_name == "04_combined_generations.csv") {
1868b7913590 Uploaded
greg
parents:
diff changeset
307 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
308 eggs = temperature_data_frame$EGG;
1868b7913590 Uploaded
greg
parents:
diff changeset
309 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
310 eggs.std_error = temperature_data_frame$EGGSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
311 }
1868b7913590 Uploaded
greg
parents:
diff changeset
312 }
1868b7913590 Uploaded
greg
parents:
diff changeset
313 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
314 young_nymphs = temperature_data_frame$YOUNGNYMPH;
1868b7913590 Uploaded
greg
parents:
diff changeset
315 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
316 young_nymphs.std_error = temperature_data_frame$YOUNGNYMPHSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
317 }
1868b7913590 Uploaded
greg
parents:
diff changeset
318 }
1868b7913590 Uploaded
greg
parents:
diff changeset
319 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
320 old_nymphs = temperature_data_frame$OLDNYMPH;
1868b7913590 Uploaded
greg
parents:
diff changeset
321 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
322 old_nymphs.std_error = temperature_data_frame$OLDNYMPHSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
323 }
1868b7913590 Uploaded
greg
parents:
diff changeset
324 }
1868b7913590 Uploaded
greg
parents:
diff changeset
325 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
326 total_nymphs = temperature_data_frame$TOTALNYMPH;
1868b7913590 Uploaded
greg
parents:
diff changeset
327 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
328 total_nymphs.std_error = temperature_data_frame$TOTALNYMPHSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
329 }
1868b7913590 Uploaded
greg
parents:
diff changeset
330 }
1868b7913590 Uploaded
greg
parents:
diff changeset
331 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
332 previttelogenic_adults = temperature_data_frame$PRE.VITADULT;
1868b7913590 Uploaded
greg
parents:
diff changeset
333 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
334 previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULTSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
335 }
1868b7913590 Uploaded
greg
parents:
diff changeset
336 }
1868b7913590 Uploaded
greg
parents:
diff changeset
337 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
338 vittelogenic_adults = temperature_data_frame$VITADULT;
1868b7913590 Uploaded
greg
parents:
diff changeset
339 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
340 vittelogenic_adults.std_error = temperature_data_frame$VITADULTSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
341 }
1868b7913590 Uploaded
greg
parents:
diff changeset
342 }
1868b7913590 Uploaded
greg
parents:
diff changeset
343 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
344 diapausing_adults = temperature_data_frame$DIAPAUSINGADULT;
1868b7913590 Uploaded
greg
parents:
diff changeset
345 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
346 diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULTSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
347 }
1868b7913590 Uploaded
greg
parents:
diff changeset
348 }
1868b7913590 Uploaded
greg
parents:
diff changeset
349 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
350 total_adults = temperature_data_frame$TOTALADULT;
1868b7913590 Uploaded
greg
parents:
diff changeset
351 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
352 total_adults.std_error = temperature_data_frame$TOTALADULTSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
353 }
1868b7913590 Uploaded
greg
parents:
diff changeset
354 }
1868b7913590 Uploaded
greg
parents:
diff changeset
355 } else if (file_name == "01_generation_P.csv") {
1868b7913590 Uploaded
greg
parents:
diff changeset
356 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
357 P_eggs = temperature_data_frame$EGG.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
358 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
359 P_eggs.std_error = temperature_data_frame$EGG.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
360 }
1868b7913590 Uploaded
greg
parents:
diff changeset
361 }
1868b7913590 Uploaded
greg
parents:
diff changeset
362 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
363 P_young_nymphs = temperature_data_frame$YOUNGNYMPH.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
364 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
365 P_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
366 }
1868b7913590 Uploaded
greg
parents:
diff changeset
367 }
1868b7913590 Uploaded
greg
parents:
diff changeset
368 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
369 P_old_nymphs = temperature_data_frame$OLDNYMPH.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
370 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
371 P_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
372 }
1868b7913590 Uploaded
greg
parents:
diff changeset
373 }
1868b7913590 Uploaded
greg
parents:
diff changeset
374 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
375 P_total_nymphs = temperature_data_frame$TOTALNYMPH.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
376 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
377 P_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
378 }
1868b7913590 Uploaded
greg
parents:
diff changeset
379 }
1868b7913590 Uploaded
greg
parents:
diff changeset
380 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
381 P_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
382 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
383 P_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
384 }
1868b7913590 Uploaded
greg
parents:
diff changeset
385 }
1868b7913590 Uploaded
greg
parents:
diff changeset
386 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
387 P_vittelogenic_adults = temperature_data_frame$VITADULT.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
388 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
389 P_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
390 }
1868b7913590 Uploaded
greg
parents:
diff changeset
391 }
1868b7913590 Uploaded
greg
parents:
diff changeset
392 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
393 P_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
394 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
395 P_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
396 }
1868b7913590 Uploaded
greg
parents:
diff changeset
397 }
1868b7913590 Uploaded
greg
parents:
diff changeset
398 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
399 P_total_adults = temperature_data_frame$TOTALADULT.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
400 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
401 P_total_adults.std_error = temperature_data_frame$TOTALADULT.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
402 }
1868b7913590 Uploaded
greg
parents:
diff changeset
403 }
1
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
404 if (process_total) {
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
405 P_all_total = temperature_data_frame$ALL.TOTAL.P;
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
406 if (plot_std_error) {
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
407 P_all_total.std_error = temperature_data_frame$ALL.TOTAL.P.SE;
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
408 }
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
409 }
0
1868b7913590 Uploaded
greg
parents:
diff changeset
410 } else if (file_name == "02_generation_F1.csv") {
1868b7913590 Uploaded
greg
parents:
diff changeset
411 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
412 F1_eggs = temperature_data_frame$EGG.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
413 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
414 F1_eggs.std_error = temperature_data_frame$EGG.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
415 }
1868b7913590 Uploaded
greg
parents:
diff changeset
416 }
1868b7913590 Uploaded
greg
parents:
diff changeset
417 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
418 F1_young_nymphs = temperature_data_frame$YOUNGNYMPH.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
419 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
420 F1_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
421 }
1868b7913590 Uploaded
greg
parents:
diff changeset
422 }
1868b7913590 Uploaded
greg
parents:
diff changeset
423 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
424 F1_old_nymphs = temperature_data_frame$OLDNYMPH.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
425 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
426 F1_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
427 }
1868b7913590 Uploaded
greg
parents:
diff changeset
428 }
1868b7913590 Uploaded
greg
parents:
diff changeset
429 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
430 F1_total_nymphs = temperature_data_frame$TOTALNYMPH.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
431 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
432 F1_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
433 }
1868b7913590 Uploaded
greg
parents:
diff changeset
434 }
1868b7913590 Uploaded
greg
parents:
diff changeset
435 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
436 F1_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
437 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
438 F1_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
439 }
1868b7913590 Uploaded
greg
parents:
diff changeset
440 }
1868b7913590 Uploaded
greg
parents:
diff changeset
441 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
442 F1_vittelogenic_adults = temperature_data_frame$VITADULT.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
443 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
444 F1_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
445 }
1868b7913590 Uploaded
greg
parents:
diff changeset
446 }
1868b7913590 Uploaded
greg
parents:
diff changeset
447 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
448 F1_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
449 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
450 F1_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
451 }
1868b7913590 Uploaded
greg
parents:
diff changeset
452 }
1868b7913590 Uploaded
greg
parents:
diff changeset
453 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
454 F1_total_adults = temperature_data_frame$TOTALADULT.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
455 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
456 F1_total_adults.std_error = temperature_data_frame$TOTALADULT.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
457 }
1868b7913590 Uploaded
greg
parents:
diff changeset
458 }
1
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
459 if (process_total) {
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
460 F1_all_total = temperature_data_frame$ALL.TOTAL.F1;
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
461 if (plot_std_error) {
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
462 F1_all_total.std_error = temperature_data_frame$ALL.TOTAL.F1.SE;
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
463 }
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
464 }
0
1868b7913590 Uploaded
greg
parents:
diff changeset
465 } else if (file_name == "03_generation_F2.csv") {
1868b7913590 Uploaded
greg
parents:
diff changeset
466 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
467 F2_eggs = temperature_data_frame$EGG.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
468 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
469 F2_eggs.std_error = temperature_data_frame$EGG.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
470 }
1868b7913590 Uploaded
greg
parents:
diff changeset
471 }
1868b7913590 Uploaded
greg
parents:
diff changeset
472 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
473 F2_young_nymphs = temperature_data_frame$YOUNGNYMPH.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
474 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
475 F2_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
476 }
1868b7913590 Uploaded
greg
parents:
diff changeset
477 }
1868b7913590 Uploaded
greg
parents:
diff changeset
478 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
479 F2_old_nymphs = temperature_data_frame$OLDNYMPH.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
480 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
481 F2_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
482 }
1868b7913590 Uploaded
greg
parents:
diff changeset
483 }
1868b7913590 Uploaded
greg
parents:
diff changeset
484 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
485 F2_total_nymphs = temperature_data_frame$TOTALNYMPH.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
486 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
487 F2_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
488 }
1868b7913590 Uploaded
greg
parents:
diff changeset
489 }
1868b7913590 Uploaded
greg
parents:
diff changeset
490 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
491 F2_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
492 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
493 F2_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
494 }
1868b7913590 Uploaded
greg
parents:
diff changeset
495 }
1868b7913590 Uploaded
greg
parents:
diff changeset
496 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
497 F2_vittelogenic_adults = temperature_data_frame$VITADULT.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
498 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
499 F2_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
500 }
1868b7913590 Uploaded
greg
parents:
diff changeset
501 }
1868b7913590 Uploaded
greg
parents:
diff changeset
502 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
503 F2_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
504 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
505 F2_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
506 }
1868b7913590 Uploaded
greg
parents:
diff changeset
507 }
1868b7913590 Uploaded
greg
parents:
diff changeset
508 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
509 F2_total_adults = temperature_data_frame$TOTALADULT.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
510 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
511 F2_total_adults.std_error = temperature_data_frame$TOTALADULT.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
512 }
1868b7913590 Uploaded
greg
parents:
diff changeset
513 }
1
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
514 if (process_total) {
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
515 F2_all_total = temperature_data_frame$ALL.TOTAL.F2;
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
516 if (plot_std_error) {
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
517 F2_all_total.std_error = temperature_data_frame$ALL.TOTAL.F2.SE;
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
518 }
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
519 }
0
1868b7913590 Uploaded
greg
parents:
diff changeset
520 }
1868b7913590 Uploaded
greg
parents:
diff changeset
521 }
1868b7913590 Uploaded
greg
parents:
diff changeset
522
1868b7913590 Uploaded
greg
parents:
diff changeset
523 # Create the pdf plot files based on the date interval.
1868b7913590 Uploaded
greg
parents:
diff changeset
524 if (plot_generations_separately) {
1868b7913590 Uploaded
greg
parents:
diff changeset
525 chart_type = "pop_size_by_generation";
1868b7913590 Uploaded
greg
parents:
diff changeset
526 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
527 # Total population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
528 life_stage = "Egg";
1868b7913590 Uploaded
greg
parents:
diff changeset
529 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf")
1868b7913590 Uploaded
greg
parents:
diff changeset
530 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
531 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
532 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
533 params_hash$replications, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs,
1868b7913590 Uploaded
greg
parents:
diff changeset
534 group2_std_error=F1_eggs.std_error, group3=F2_eggs, group3_std_error=F2_eggs.std_error);
1868b7913590 Uploaded
greg
parents:
diff changeset
535 }
1868b7913590 Uploaded
greg
parents:
diff changeset
536 if (process_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
537 life_stage = "Nymph";
1868b7913590 Uploaded
greg
parents:
diff changeset
538 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
539 # Young nymph population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
540 sub_life_stage = "Young";
1868b7913590 Uploaded
greg
parents:
diff changeset
541 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
542 maxval = max(P_young_nymphs+F1_young_nymphs+F2_young_nymphs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
543 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
544 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
545 params_hash$replications, group=P_young_nymphs, group_std_error=P_young_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
546 group2=F1_young_nymphs, group2_std_error=F1_young_nymphs.std_error, group3=F2_young_nymphs,
1868b7913590 Uploaded
greg
parents:
diff changeset
547 group3_std_error=F2_young_nymphs.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
548 }
1868b7913590 Uploaded
greg
parents:
diff changeset
549 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
550 # Old nymph population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
551 sub_life_stage = "Old";
1868b7913590 Uploaded
greg
parents:
diff changeset
552 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
553 maxval = max(P_old_nymphs+F1_old_nymphs+F2_old_nymphs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
554 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
555 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
556 params_hash$replications, group=P_old_nymphs, group_std_error=P_old_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
557 group2=F1_old_nymphs, group2_std_error=F1_old_nymphs.std_error, group3=F2_old_nymphs,
1868b7913590 Uploaded
greg
parents:
diff changeset
558 group3_std_error=F2_old_nymphs.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
559 }
1868b7913590 Uploaded
greg
parents:
diff changeset
560 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
561 # Total nymph population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
562 sub_life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
563 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
564 maxval = max(P_total_nymphs+F1_total_nymphs+F2_total_nymphs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
565 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
566 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
567 params_hash$replications, group=P_total_nymphs, group_std_error=P_total_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
568 group2=F1_total_nymphs, group2_std_error=F1_total_nymphs.std_error, group3=F2_total_nymphs,
1868b7913590 Uploaded
greg
parents:
diff changeset
569 group3_std_error=F2_total_nymphs.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
570 }
1868b7913590 Uploaded
greg
parents:
diff changeset
571 }
1868b7913590 Uploaded
greg
parents:
diff changeset
572 if (process_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
573 life_stage = "Adult";
1868b7913590 Uploaded
greg
parents:
diff changeset
574 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
575 # Pre-vittelogenic adult population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
576 sub_life_stage = "Pre-vittelogenic";
1868b7913590 Uploaded
greg
parents:
diff changeset
577 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
578 maxval = max(P_previttelogenic_adults+F1_previttelogenic_adults+F2_previttelogenic_adults) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
579 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
580 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
581 params_hash$replications, group=P_previttelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
582 group_std_error=P_previttelogenic_adults.std_error, group2=F1_previttelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
583 group2_std_error=F1_previttelogenic_adults.std_error, group3=F2_previttelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
584 group3_std_error=F2_previttelogenic_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
585 }
1868b7913590 Uploaded
greg
parents:
diff changeset
586 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
587 # Vittelogenic adult population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
588 sub_life_stage = "Vittelogenic";
1868b7913590 Uploaded
greg
parents:
diff changeset
589 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
590 maxval = max(P_vittelogenic_adults+F1_vittelogenic_adults+F2_vittelogenic_adults) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
591 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
592 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
593 params_hash$replications, group=P_vittelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
594 group_std_error=P_vittelogenic_adults.std_error, group2=F1_vittelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
595 group2_std_error=F1_vittelogenic_adults.std_error, group3=F2_vittelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
596 group3_std_error=F2_vittelogenic_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
597 }
1868b7913590 Uploaded
greg
parents:
diff changeset
598 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
599 # Diapausing adult population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
600 sub_life_stage = "Diapausing";
1868b7913590 Uploaded
greg
parents:
diff changeset
601 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
602 maxval = max(P_diapausing_adults+F1_diapausing_adults+F2_diapausing_adults) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
603 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
604 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
605 params_hash$replications, group=P_diapausing_adults, group_std_error=P_diapausing_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
606 group2=F1_diapausing_adults, group2_std_error=F1_diapausing_adults.std_error, group3=F2_diapausing_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
607 group3_std_error=F2_diapausing_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
608 }
1868b7913590 Uploaded
greg
parents:
diff changeset
609 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
610 # Total adult population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
611 sub_life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
612 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
613 maxval = max(P_total_adults+F1_total_adults+F2_total_adults) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
614 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
615 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
616 params_hash$replications, group=P_total_adults, group_std_error=P_total_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
617 group2=F1_total_adults, group2_std_error=F1_total_adults.std_error, group3=F2_total_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
618 group3_std_error=F2_total_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
619 }
1868b7913590 Uploaded
greg
parents:
diff changeset
620 }
1868b7913590 Uploaded
greg
parents:
diff changeset
621 if (process_total) {
1868b7913590 Uploaded
greg
parents:
diff changeset
622 life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
623 # Total population size for egg, nymph and adult by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
624 file_path = get_file_path(life_stage, "total_pop_by_generation.pdf")
1868b7913590 Uploaded
greg
parents:
diff changeset
625 maxval = max(total_adults+eggs+total_nymphs) + 100;
1
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
626 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
627 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
628 params_hash$replications, group=P_all_total, group_std_error=P_all_total.std_error, group2=F1_all_total,
459b422e5df6 Uploaded
greg
parents: 0
diff changeset
629 group2_std_error=F1_all_total.std_error, group3=F2_all_total, group3_std_error=F2_all_total.std_error);
0
1868b7913590 Uploaded
greg
parents:
diff changeset
630 }
1868b7913590 Uploaded
greg
parents:
diff changeset
631 } else {
1868b7913590 Uploaded
greg
parents:
diff changeset
632 chart_type = "pop_size_by_life_stage";
1868b7913590 Uploaded
greg
parents:
diff changeset
633 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
634 # Egg population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
635 life_stage = "Egg";
1868b7913590 Uploaded
greg
parents:
diff changeset
636 file_path = get_file_path(life_stage, "egg_pop.pdf")
1868b7913590 Uploaded
greg
parents:
diff changeset
637 maxval = max(eggs+eggs.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
638 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
639 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
640 params_hash$replications, group=eggs, group_std_error=eggs.std_error);
1868b7913590 Uploaded
greg
parents:
diff changeset
641 }
1868b7913590 Uploaded
greg
parents:
diff changeset
642 if (process_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
643 life_stage = "Nymph";
1868b7913590 Uploaded
greg
parents:
diff changeset
644 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
645 # Young nymph population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
646 sub_life_stage = "Young";
1868b7913590 Uploaded
greg
parents:
diff changeset
647 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
648 maxval = max(young_nymphs+young_nymphs.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
649 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
650 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
651 params_hash$replications, group=young_nymphs, group_std_error=young_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
652 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
653 }
1868b7913590 Uploaded
greg
parents:
diff changeset
654 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
655 # Old nymph population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
656 sub_life_stage = "Old";
1868b7913590 Uploaded
greg
parents:
diff changeset
657 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
658 maxval = max(old_nymphs+old_nymphs.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
659 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
660 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
661 params_hash$replications, group=old_nymphs, group_std_error=old_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
662 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
663 }
1868b7913590 Uploaded
greg
parents:
diff changeset
664 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
665 # Total nymph population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
666 sub_life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
667 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
668 maxval = max(total_nymphs+total_nymphs.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
669 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
670 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
671 params_hash$replications, group=total_nymphs, group_std_error=total_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
672 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
673 }
1868b7913590 Uploaded
greg
parents:
diff changeset
674 }
1868b7913590 Uploaded
greg
parents:
diff changeset
675 if (process_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
676 life_stage = "Adult";
1868b7913590 Uploaded
greg
parents:
diff changeset
677 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
678 # Pre-vittelogenic adult population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
679 sub_life_stage = "Pre-vittelogenic";
1868b7913590 Uploaded
greg
parents:
diff changeset
680 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
681 maxval = max(previttelogenic_adults+previttelogenic_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
682 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
683 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
684 params_hash$replications, group=previttelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
685 group_std_error=previttelogenic_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
686 }
1868b7913590 Uploaded
greg
parents:
diff changeset
687 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
688 # Vittelogenic adult population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
689 sub_life_stage = "Vittelogenic";
1868b7913590 Uploaded
greg
parents:
diff changeset
690 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
691 maxval = max(vittelogenic_adults+vittelogenic_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
692 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
693 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
694 params_hash$replications, group=vittelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
695 group_std_error=vittelogenic_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
696 }
1868b7913590 Uploaded
greg
parents:
diff changeset
697 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
698 # Diapausing adult population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
699 sub_life_stage = "Diapausing";
1868b7913590 Uploaded
greg
parents:
diff changeset
700 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
701 maxval = max(diapausing_adults+diapausing_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
702 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
703 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
704 params_hash$replications, group=diapausing_adults, group_std_error=diapausing_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
705 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
706 }
1868b7913590 Uploaded
greg
parents:
diff changeset
707 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
708 # Total adult population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
709 sub_life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
710 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
711 maxval = max(total_adults+total_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
712 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
713 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
714 params_hash$replications, group=total_adults, group_std_error=total_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
715 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
716 }
1868b7913590 Uploaded
greg
parents:
diff changeset
717 }
1868b7913590 Uploaded
greg
parents:
diff changeset
718 if (process_total) {
1868b7913590 Uploaded
greg
parents:
diff changeset
719 # Total population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
720 life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
721 file_path = get_file_path(life_stage, "total_pop.pdf")
1868b7913590 Uploaded
greg
parents:
diff changeset
722 maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
723 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
724 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
725 params_hash$replications, group=total_adults, group_std_error=total_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
726 group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs, group3_std_error=eggs.std_error);
1868b7913590 Uploaded
greg
parents:
diff changeset
727 }
1868b7913590 Uploaded
greg
parents:
diff changeset
728 }
1868b7913590 Uploaded
greg
parents:
diff changeset
729