annotate extract_ipm_date_interval.R @ 0:1868b7913590 draft

Uploaded
author greg
date Tue, 07 Aug 2018 13:05:10 -0400
parents
children 459b422e5df6
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) {
1868b7913590 Uploaded
greg
parents:
diff changeset
248 stop_err("The start date must be between 1 and 50 days before the end date when setting date intervals for plots.");
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);
1868b7913590 Uploaded
greg
parents:
diff changeset
271 # Extract the date interval.
1868b7913590 Uploaded
greg
parents:
diff changeset
272 temperature_data_frame = temperature_data_frame[start_date_row:end_date_row,];
1868b7913590 Uploaded
greg
parents:
diff changeset
273 # Save the date interval data into an output file
1868b7913590 Uploaded
greg
parents:
diff changeset
274 # named the same as the input.
1868b7913590 Uploaded
greg
parents:
diff changeset
275 file_path = paste("output_data_dir", file_name, sep="/");
1868b7913590 Uploaded
greg
parents:
diff changeset
276 write.csv(temperature_data_frame, file=file_path, row.names=F);
1868b7913590 Uploaded
greg
parents:
diff changeset
277 }
1868b7913590 Uploaded
greg
parents:
diff changeset
278
1868b7913590 Uploaded
greg
parents:
diff changeset
279 # Extract the vectors needed for plots from the input data files
1868b7913590 Uploaded
greg
parents:
diff changeset
280 # produced by the insect_phenology_model tool.
1868b7913590 Uploaded
greg
parents:
diff changeset
281 total_days_vector = NULL;
1868b7913590 Uploaded
greg
parents:
diff changeset
282 ticks_and_labels = NULL;
1868b7913590 Uploaded
greg
parents:
diff changeset
283 latitude = NULL;
1868b7913590 Uploaded
greg
parents:
diff changeset
284 input_data_files = list.files(path="output_data_dir", full.names=TRUE);
1868b7913590 Uploaded
greg
parents:
diff changeset
285 for (input_data_file in input_data_files) {
1868b7913590 Uploaded
greg
parents:
diff changeset
286 file_name = basename(input_data_file);
1868b7913590 Uploaded
greg
parents:
diff changeset
287 temperature_data_frame = get_new_temperature_data_frame(input_data_file);
1868b7913590 Uploaded
greg
parents:
diff changeset
288 # Initialize the total_days_vector for later plotting.
1868b7913590 Uploaded
greg
parents:
diff changeset
289 if (is.null(total_days_vector)) {
1868b7913590 Uploaded
greg
parents:
diff changeset
290 total_days_vector = c(1:dim(temperature_data_frame)[1]);
1868b7913590 Uploaded
greg
parents:
diff changeset
291 }
1868b7913590 Uploaded
greg
parents:
diff changeset
292 if (is.null(ticks_and_labels)) {
1868b7913590 Uploaded
greg
parents:
diff changeset
293 # Get the ticks date labels for later plotting
1868b7913590 Uploaded
greg
parents:
diff changeset
294 ticks_and_labels = get_x_axis_ticks_and_labels(temperature_data_frame, date_interval=TRUE);
1868b7913590 Uploaded
greg
parents:
diff changeset
295 ticks = c(unlist(ticks_and_labels[1]));
1868b7913590 Uploaded
greg
parents:
diff changeset
296 date_labels = c(unlist(ticks_and_labels[2]));
1868b7913590 Uploaded
greg
parents:
diff changeset
297 }
1868b7913590 Uploaded
greg
parents:
diff changeset
298 if (is.null(latitude)) {
1868b7913590 Uploaded
greg
parents:
diff changeset
299 # Get the latitude for later plotting.
1868b7913590 Uploaded
greg
parents:
diff changeset
300 latitude = temperature_data_frame$LATITUDE[1];
1868b7913590 Uploaded
greg
parents:
diff changeset
301 }
1868b7913590 Uploaded
greg
parents:
diff changeset
302
1868b7913590 Uploaded
greg
parents:
diff changeset
303 if (file_name == "04_combined_generations.csv") {
1868b7913590 Uploaded
greg
parents:
diff changeset
304 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
305 eggs = temperature_data_frame$EGG;
1868b7913590 Uploaded
greg
parents:
diff changeset
306 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
307 eggs.std_error = temperature_data_frame$EGGSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
308 }
1868b7913590 Uploaded
greg
parents:
diff changeset
309 }
1868b7913590 Uploaded
greg
parents:
diff changeset
310 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
311 young_nymphs = temperature_data_frame$YOUNGNYMPH;
1868b7913590 Uploaded
greg
parents:
diff changeset
312 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
313 young_nymphs.std_error = temperature_data_frame$YOUNGNYMPHSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
314 }
1868b7913590 Uploaded
greg
parents:
diff changeset
315 }
1868b7913590 Uploaded
greg
parents:
diff changeset
316 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
317 old_nymphs = temperature_data_frame$OLDNYMPH;
1868b7913590 Uploaded
greg
parents:
diff changeset
318 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
319 old_nymphs.std_error = temperature_data_frame$OLDNYMPHSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
320 }
1868b7913590 Uploaded
greg
parents:
diff changeset
321 }
1868b7913590 Uploaded
greg
parents:
diff changeset
322 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
323 total_nymphs = temperature_data_frame$TOTALNYMPH;
1868b7913590 Uploaded
greg
parents:
diff changeset
324 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
325 total_nymphs.std_error = temperature_data_frame$TOTALNYMPHSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
326 }
1868b7913590 Uploaded
greg
parents:
diff changeset
327 }
1868b7913590 Uploaded
greg
parents:
diff changeset
328 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
329 previttelogenic_adults = temperature_data_frame$PRE.VITADULT;
1868b7913590 Uploaded
greg
parents:
diff changeset
330 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
331 previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULTSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
332 }
1868b7913590 Uploaded
greg
parents:
diff changeset
333 }
1868b7913590 Uploaded
greg
parents:
diff changeset
334 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
335 vittelogenic_adults = temperature_data_frame$VITADULT;
1868b7913590 Uploaded
greg
parents:
diff changeset
336 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
337 vittelogenic_adults.std_error = temperature_data_frame$VITADULTSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
338 }
1868b7913590 Uploaded
greg
parents:
diff changeset
339 }
1868b7913590 Uploaded
greg
parents:
diff changeset
340 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
341 diapausing_adults = temperature_data_frame$DIAPAUSINGADULT;
1868b7913590 Uploaded
greg
parents:
diff changeset
342 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
343 diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULTSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
344 }
1868b7913590 Uploaded
greg
parents:
diff changeset
345 }
1868b7913590 Uploaded
greg
parents:
diff changeset
346 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
347 total_adults = temperature_data_frame$TOTALADULT;
1868b7913590 Uploaded
greg
parents:
diff changeset
348 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
349 total_adults.std_error = temperature_data_frame$TOTALADULTSE;
1868b7913590 Uploaded
greg
parents:
diff changeset
350 }
1868b7913590 Uploaded
greg
parents:
diff changeset
351 }
1868b7913590 Uploaded
greg
parents:
diff changeset
352 } else if (file_name == "01_generation_P.csv") {
1868b7913590 Uploaded
greg
parents:
diff changeset
353 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
354 P_eggs = temperature_data_frame$EGG.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
355 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
356 P_eggs.std_error = temperature_data_frame$EGG.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
357 }
1868b7913590 Uploaded
greg
parents:
diff changeset
358 }
1868b7913590 Uploaded
greg
parents:
diff changeset
359 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
360 P_young_nymphs = temperature_data_frame$YOUNGNYMPH.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
361 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
362 P_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
363 }
1868b7913590 Uploaded
greg
parents:
diff changeset
364 }
1868b7913590 Uploaded
greg
parents:
diff changeset
365 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
366 P_old_nymphs = temperature_data_frame$OLDNYMPH.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
367 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
368 P_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
369 }
1868b7913590 Uploaded
greg
parents:
diff changeset
370 }
1868b7913590 Uploaded
greg
parents:
diff changeset
371 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
372 P_total_nymphs = temperature_data_frame$TOTALNYMPH.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
373 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
374 P_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
375 }
1868b7913590 Uploaded
greg
parents:
diff changeset
376 }
1868b7913590 Uploaded
greg
parents:
diff changeset
377 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
378 P_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
379 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
380 P_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
381 }
1868b7913590 Uploaded
greg
parents:
diff changeset
382 }
1868b7913590 Uploaded
greg
parents:
diff changeset
383 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
384 P_vittelogenic_adults = temperature_data_frame$VITADULT.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
385 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
386 P_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
387 }
1868b7913590 Uploaded
greg
parents:
diff changeset
388 }
1868b7913590 Uploaded
greg
parents:
diff changeset
389 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
390 P_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
391 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
392 P_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
393 }
1868b7913590 Uploaded
greg
parents:
diff changeset
394 }
1868b7913590 Uploaded
greg
parents:
diff changeset
395 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
396 P_total_adults = temperature_data_frame$TOTALADULT.P;
1868b7913590 Uploaded
greg
parents:
diff changeset
397 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
398 P_total_adults.std_error = temperature_data_frame$TOTALADULT.P.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
399 }
1868b7913590 Uploaded
greg
parents:
diff changeset
400 }
1868b7913590 Uploaded
greg
parents:
diff changeset
401 } else if (file_name == "02_generation_F1.csv") {
1868b7913590 Uploaded
greg
parents:
diff changeset
402 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
403 F1_eggs = temperature_data_frame$EGG.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
404 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
405 F1_eggs.std_error = temperature_data_frame$EGG.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
406 }
1868b7913590 Uploaded
greg
parents:
diff changeset
407 }
1868b7913590 Uploaded
greg
parents:
diff changeset
408 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
409 F1_young_nymphs = temperature_data_frame$YOUNGNYMPH.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
410 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
411 F1_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
412 }
1868b7913590 Uploaded
greg
parents:
diff changeset
413 }
1868b7913590 Uploaded
greg
parents:
diff changeset
414 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
415 F1_old_nymphs = temperature_data_frame$OLDNYMPH.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
416 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
417 F1_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
418 }
1868b7913590 Uploaded
greg
parents:
diff changeset
419 }
1868b7913590 Uploaded
greg
parents:
diff changeset
420 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
421 F1_total_nymphs = temperature_data_frame$TOTALNYMPH.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
422 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
423 F1_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
424 }
1868b7913590 Uploaded
greg
parents:
diff changeset
425 }
1868b7913590 Uploaded
greg
parents:
diff changeset
426 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
427 F1_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
428 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
429 F1_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
430 }
1868b7913590 Uploaded
greg
parents:
diff changeset
431 }
1868b7913590 Uploaded
greg
parents:
diff changeset
432 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
433 F1_vittelogenic_adults = temperature_data_frame$VITADULT.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
434 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
435 F1_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
436 }
1868b7913590 Uploaded
greg
parents:
diff changeset
437 }
1868b7913590 Uploaded
greg
parents:
diff changeset
438 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
439 F1_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
440 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
441 F1_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
442 }
1868b7913590 Uploaded
greg
parents:
diff changeset
443 }
1868b7913590 Uploaded
greg
parents:
diff changeset
444 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
445 F1_total_adults = temperature_data_frame$TOTALADULT.F1;
1868b7913590 Uploaded
greg
parents:
diff changeset
446 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
447 F1_total_adults.std_error = temperature_data_frame$TOTALADULT.F1.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
448 }
1868b7913590 Uploaded
greg
parents:
diff changeset
449 }
1868b7913590 Uploaded
greg
parents:
diff changeset
450 } else if (file_name == "03_generation_F2.csv") {
1868b7913590 Uploaded
greg
parents:
diff changeset
451 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
452 F2_eggs = temperature_data_frame$EGG.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
453 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
454 F2_eggs.std_error = temperature_data_frame$EGG.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
455 }
1868b7913590 Uploaded
greg
parents:
diff changeset
456 }
1868b7913590 Uploaded
greg
parents:
diff changeset
457 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
458 F2_young_nymphs = temperature_data_frame$YOUNGNYMPH.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
459 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
460 F2_young_nymphs.std_error = temperature_data_frame$YOUNGNYMPH.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
461 }
1868b7913590 Uploaded
greg
parents:
diff changeset
462 }
1868b7913590 Uploaded
greg
parents:
diff changeset
463 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
464 F2_old_nymphs = temperature_data_frame$OLDNYMPH.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
465 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
466 F2_old_nymphs.std_error = temperature_data_frame$OLDNYMPH.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
467 }
1868b7913590 Uploaded
greg
parents:
diff changeset
468 }
1868b7913590 Uploaded
greg
parents:
diff changeset
469 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
470 F2_total_nymphs = temperature_data_frame$TOTALNYMPH.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
471 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
472 F2_total_nymphs.std_error = temperature_data_frame$TOTALNYMPH.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
473 }
1868b7913590 Uploaded
greg
parents:
diff changeset
474 }
1868b7913590 Uploaded
greg
parents:
diff changeset
475 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
476 F2_previttelogenic_adults = temperature_data_frame$PRE.VITADULT.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
477 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
478 F2_previttelogenic_adults.std_error = temperature_data_frame$PRE.VITADULT.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
479 }
1868b7913590 Uploaded
greg
parents:
diff changeset
480 }
1868b7913590 Uploaded
greg
parents:
diff changeset
481 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
482 F2_vittelogenic_adults = temperature_data_frame$VITADULT.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
483 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
484 F2_vittelogenic_adults.std_error = temperature_data_frame$VITADULT.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
485 }
1868b7913590 Uploaded
greg
parents:
diff changeset
486 }
1868b7913590 Uploaded
greg
parents:
diff changeset
487 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
488 F2_diapausing_adults = temperature_data_frame$DIAPAUSINGADULT.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
489 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
490 F2_diapausing_adults.std_error = temperature_data_frame$DIAPAUSINGADULT.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
491 }
1868b7913590 Uploaded
greg
parents:
diff changeset
492 }
1868b7913590 Uploaded
greg
parents:
diff changeset
493 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
494 F2_total_adults = temperature_data_frame$TOTALADULT.F2;
1868b7913590 Uploaded
greg
parents:
diff changeset
495 if (plot_std_error) {
1868b7913590 Uploaded
greg
parents:
diff changeset
496 F2_total_adults.std_error = temperature_data_frame$TOTALADULT.F2.SE;
1868b7913590 Uploaded
greg
parents:
diff changeset
497 }
1868b7913590 Uploaded
greg
parents:
diff changeset
498 }
1868b7913590 Uploaded
greg
parents:
diff changeset
499 }
1868b7913590 Uploaded
greg
parents:
diff changeset
500 }
1868b7913590 Uploaded
greg
parents:
diff changeset
501
1868b7913590 Uploaded
greg
parents:
diff changeset
502 # Create the pdf plot files based on the date interval.
1868b7913590 Uploaded
greg
parents:
diff changeset
503 if (plot_generations_separately) {
1868b7913590 Uploaded
greg
parents:
diff changeset
504 chart_type = "pop_size_by_generation";
1868b7913590 Uploaded
greg
parents:
diff changeset
505 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
506 # Total population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
507 life_stage = "Egg";
1868b7913590 Uploaded
greg
parents:
diff changeset
508 file_path = get_file_path(life_stage, "egg_pop_by_generation.pdf")
1868b7913590 Uploaded
greg
parents:
diff changeset
509 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
510 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
511 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
512 params_hash$replications, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs,
1868b7913590 Uploaded
greg
parents:
diff changeset
513 group2_std_error=F1_eggs.std_error, group3=F2_eggs, group3_std_error=F2_eggs.std_error);
1868b7913590 Uploaded
greg
parents:
diff changeset
514 }
1868b7913590 Uploaded
greg
parents:
diff changeset
515 if (process_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
516 life_stage = "Nymph";
1868b7913590 Uploaded
greg
parents:
diff changeset
517 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
518 # Young nymph population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
519 sub_life_stage = "Young";
1868b7913590 Uploaded
greg
parents:
diff changeset
520 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
521 maxval = max(P_young_nymphs+F1_young_nymphs+F2_young_nymphs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
522 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
523 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
524 params_hash$replications, group=P_young_nymphs, group_std_error=P_young_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
525 group2=F1_young_nymphs, group2_std_error=F1_young_nymphs.std_error, group3=F2_young_nymphs,
1868b7913590 Uploaded
greg
parents:
diff changeset
526 group3_std_error=F2_young_nymphs.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
527 }
1868b7913590 Uploaded
greg
parents:
diff changeset
528 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
529 # Old nymph population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
530 sub_life_stage = "Old";
1868b7913590 Uploaded
greg
parents:
diff changeset
531 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
532 maxval = max(P_old_nymphs+F1_old_nymphs+F2_old_nymphs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
533 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
534 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
535 params_hash$replications, group=P_old_nymphs, group_std_error=P_old_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
536 group2=F1_old_nymphs, group2_std_error=F1_old_nymphs.std_error, group3=F2_old_nymphs,
1868b7913590 Uploaded
greg
parents:
diff changeset
537 group3_std_error=F2_old_nymphs.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
538 }
1868b7913590 Uploaded
greg
parents:
diff changeset
539 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
540 # Total nymph population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
541 sub_life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
542 file_path = get_file_path(life_stage, "nymph_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
543 maxval = max(P_total_nymphs+F1_total_nymphs+F2_total_nymphs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
544 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
545 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
546 params_hash$replications, group=P_total_nymphs, group_std_error=P_total_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
547 group2=F1_total_nymphs, group2_std_error=F1_total_nymphs.std_error, group3=F2_total_nymphs,
1868b7913590 Uploaded
greg
parents:
diff changeset
548 group3_std_error=F2_total_nymphs.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
549 }
1868b7913590 Uploaded
greg
parents:
diff changeset
550 }
1868b7913590 Uploaded
greg
parents:
diff changeset
551 if (process_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
552 life_stage = "Adult";
1868b7913590 Uploaded
greg
parents:
diff changeset
553 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
554 # Pre-vittelogenic adult population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
555 sub_life_stage = "Pre-vittelogenic";
1868b7913590 Uploaded
greg
parents:
diff changeset
556 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
557 maxval = max(P_previttelogenic_adults+F1_previttelogenic_adults+F2_previttelogenic_adults) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
558 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
559 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
560 params_hash$replications, group=P_previttelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
561 group_std_error=P_previttelogenic_adults.std_error, group2=F1_previttelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
562 group2_std_error=F1_previttelogenic_adults.std_error, group3=F2_previttelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
563 group3_std_error=F2_previttelogenic_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
564 }
1868b7913590 Uploaded
greg
parents:
diff changeset
565 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
566 # Vittelogenic adult population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
567 sub_life_stage = "Vittelogenic";
1868b7913590 Uploaded
greg
parents:
diff changeset
568 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
569 maxval = max(P_vittelogenic_adults+F1_vittelogenic_adults+F2_vittelogenic_adults) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
570 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
571 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
572 params_hash$replications, group=P_vittelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
573 group_std_error=P_vittelogenic_adults.std_error, group2=F1_vittelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
574 group2_std_error=F1_vittelogenic_adults.std_error, group3=F2_vittelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
575 group3_std_error=F2_vittelogenic_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
576 }
1868b7913590 Uploaded
greg
parents:
diff changeset
577 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
578 # Diapausing adult population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
579 sub_life_stage = "Diapausing";
1868b7913590 Uploaded
greg
parents:
diff changeset
580 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
581 maxval = max(P_diapausing_adults+F1_diapausing_adults+F2_diapausing_adults) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
582 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
583 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
584 params_hash$replications, group=P_diapausing_adults, group_std_error=P_diapausing_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
585 group2=F1_diapausing_adults, group2_std_error=F1_diapausing_adults.std_error, group3=F2_diapausing_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
586 group3_std_error=F2_diapausing_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
587 }
1868b7913590 Uploaded
greg
parents:
diff changeset
588 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
589 # Total adult population size by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
590 sub_life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
591 file_path = get_file_path(life_stage, "adult_pop_by_generation.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
592 maxval = max(P_total_adults+F1_total_adults+F2_total_adults) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
593 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
594 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
595 params_hash$replications, group=P_total_adults, group_std_error=P_total_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
596 group2=F1_total_adults, group2_std_error=F1_total_adults.std_error, group3=F2_total_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
597 group3_std_error=F2_total_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
598 }
1868b7913590 Uploaded
greg
parents:
diff changeset
599 }
1868b7913590 Uploaded
greg
parents:
diff changeset
600 if (process_total) {
1868b7913590 Uploaded
greg
parents:
diff changeset
601 life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
602 # Total population size for egg, nymph and adult by generation.
1868b7913590 Uploaded
greg
parents:
diff changeset
603 file_path = get_file_path(life_stage, "total_pop_by_generation.pdf")
1868b7913590 Uploaded
greg
parents:
diff changeset
604 maxval = max(total_adults+eggs+total_nymphs) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
605 # P == total_adults
1868b7913590 Uploaded
greg
parents:
diff changeset
606 # P.std_error == total_adults.std_error
1868b7913590 Uploaded
greg
parents:
diff changeset
607 # F1 == eggs
1868b7913590 Uploaded
greg
parents:
diff changeset
608 # F1.std_error == eggs.std_error
1868b7913590 Uploaded
greg
parents:
diff changeset
609 # F2 == ???
1868b7913590 Uploaded
greg
parents:
diff changeset
610 # F2.std_error == ???
1868b7913590 Uploaded
greg
parents:
diff changeset
611 # FIXME: testing demonstrates that P and F1 are properly assigned
1868b7913590 Uploaded
greg
parents:
diff changeset
612 # above, but F2 cannot be determined. F2 should undoubtedly be
1868b7913590 Uploaded
greg
parents:
diff changeset
613 # total_nymphs, but the data is not the same bewteen the output
1868b7913590 Uploaded
greg
parents:
diff changeset
614 # from the insect_phenology_model tool and the date interval from
1868b7913590 Uploaded
greg
parents:
diff changeset
615 # this tool. We won't plot the total until we get time to figure
1868b7913590 Uploaded
greg
parents:
diff changeset
616 # this out.
1868b7913590 Uploaded
greg
parents:
diff changeset
617 #prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
618 # params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
619 # params_hash$replications, group=total_adults, group_std_error=total_adults.std_error, group2=eggs,
1868b7913590 Uploaded
greg
parents:
diff changeset
620 # group2_std_error=eggs.std_error, group3=total_nymphs, group3_std_error=total_nymphs.std_error);
1868b7913590 Uploaded
greg
parents:
diff changeset
621 }
1868b7913590 Uploaded
greg
parents:
diff changeset
622 } else {
1868b7913590 Uploaded
greg
parents:
diff changeset
623 chart_type = "pop_size_by_life_stage";
1868b7913590 Uploaded
greg
parents:
diff changeset
624 if (process_eggs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
625 # Egg population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
626 life_stage = "Egg";
1868b7913590 Uploaded
greg
parents:
diff changeset
627 file_path = get_file_path(life_stage, "egg_pop.pdf")
1868b7913590 Uploaded
greg
parents:
diff changeset
628 maxval = max(eggs+eggs.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
629 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
630 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
631 params_hash$replications, group=eggs, group_std_error=eggs.std_error);
1868b7913590 Uploaded
greg
parents:
diff changeset
632 }
1868b7913590 Uploaded
greg
parents:
diff changeset
633 if (process_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
634 life_stage = "Nymph";
1868b7913590 Uploaded
greg
parents:
diff changeset
635 if (process_young_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
636 # Young nymph population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
637 sub_life_stage = "Young";
1868b7913590 Uploaded
greg
parents:
diff changeset
638 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
639 maxval = max(young_nymphs+young_nymphs.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
640 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
641 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
642 params_hash$replications, group=young_nymphs, group_std_error=young_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
643 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
644 }
1868b7913590 Uploaded
greg
parents:
diff changeset
645 if (process_old_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
646 # Old nymph population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
647 sub_life_stage = "Old";
1868b7913590 Uploaded
greg
parents:
diff changeset
648 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
649 maxval = max(old_nymphs+old_nymphs.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
650 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
651 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
652 params_hash$replications, group=old_nymphs, group_std_error=old_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
653 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
654 }
1868b7913590 Uploaded
greg
parents:
diff changeset
655 if (process_total_nymphs) {
1868b7913590 Uploaded
greg
parents:
diff changeset
656 # Total nymph population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
657 sub_life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
658 file_path = get_file_path(life_stage, "nymph_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
659 maxval = max(total_nymphs+total_nymphs.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
660 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
661 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
662 params_hash$replications, group=total_nymphs, group_std_error=total_nymphs.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
663 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
664 }
1868b7913590 Uploaded
greg
parents:
diff changeset
665 }
1868b7913590 Uploaded
greg
parents:
diff changeset
666 if (process_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
667 life_stage = "Adult";
1868b7913590 Uploaded
greg
parents:
diff changeset
668 if (process_previttelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
669 # Pre-vittelogenic adult population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
670 sub_life_stage = "Pre-vittelogenic";
1868b7913590 Uploaded
greg
parents:
diff changeset
671 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
672 maxval = max(previttelogenic_adults+previttelogenic_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
673 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
674 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
675 params_hash$replications, group=previttelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
676 group_std_error=previttelogenic_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
677 }
1868b7913590 Uploaded
greg
parents:
diff changeset
678 if (process_vittelogenic_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
679 # Vittelogenic adult population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
680 sub_life_stage = "Vittelogenic";
1868b7913590 Uploaded
greg
parents:
diff changeset
681 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
682 maxval = max(vittelogenic_adults+vittelogenic_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
683 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
684 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
685 params_hash$replications, group=vittelogenic_adults,
1868b7913590 Uploaded
greg
parents:
diff changeset
686 group_std_error=vittelogenic_adults.std_error, sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
687 }
1868b7913590 Uploaded
greg
parents:
diff changeset
688 if (process_diapausing_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
689 # Diapausing adult population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
690 sub_life_stage = "Diapausing";
1868b7913590 Uploaded
greg
parents:
diff changeset
691 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
692 maxval = max(diapausing_adults+diapausing_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
693 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
694 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
695 params_hash$replications, group=diapausing_adults, group_std_error=diapausing_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
696 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
697 }
1868b7913590 Uploaded
greg
parents:
diff changeset
698 if (process_total_adults) {
1868b7913590 Uploaded
greg
parents:
diff changeset
699 # Total adult population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
700 sub_life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
701 file_path = get_file_path(life_stage, "adult_pop.pdf", sub_life_stage=sub_life_stage)
1868b7913590 Uploaded
greg
parents:
diff changeset
702 maxval = max(total_adults+total_adults.std_error) + 100;
1868b7913590 Uploaded
greg
parents:
diff changeset
703 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
704 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
705 params_hash$replications, group=total_adults, group_std_error=total_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
706 sub_life_stage=sub_life_stage);
1868b7913590 Uploaded
greg
parents:
diff changeset
707 }
1868b7913590 Uploaded
greg
parents:
diff changeset
708 }
1868b7913590 Uploaded
greg
parents:
diff changeset
709 if (process_total) {
1868b7913590 Uploaded
greg
parents:
diff changeset
710 # Total population size.
1868b7913590 Uploaded
greg
parents:
diff changeset
711 life_stage = "Total";
1868b7913590 Uploaded
greg
parents:
diff changeset
712 file_path = get_file_path(life_stage, "total_pop.pdf")
1868b7913590 Uploaded
greg
parents:
diff changeset
713 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
714 prepare_plot(life_stage, file_path, maxval, ticks, date_labels, chart_type, params_hash$plot_std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
715 params_hash$insect, params_hash$location, latitude, start_date, end_date, total_days_vector,
1868b7913590 Uploaded
greg
parents:
diff changeset
716 params_hash$replications, group=total_adults, group_std_error=total_adults.std_error,
1868b7913590 Uploaded
greg
parents:
diff changeset
717 group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs, group3_std_error=eggs.std_error);
1868b7913590 Uploaded
greg
parents:
diff changeset
718 }
1868b7913590 Uploaded
greg
parents:
diff changeset
719 }
1868b7913590 Uploaded
greg
parents:
diff changeset
720