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