comparison insect_phenology_model.R @ 16:309954bbe999 draft

Uploaded
author greg
date Tue, 06 Mar 2018 08:26:42 -0500
parents dd86ee185113
children f5ecff4800f2
comparison
equal deleted inserted replaced
15:dd86ee185113 16:309954bbe999
9 make_option(c("--input"), action="store", dest="input", help="Temperature data for selected location"), 9 make_option(c("--input"), action="store", dest="input", help="Temperature data for selected location"),
10 make_option(c("--insect"), action="store", dest="insect", help="Insect name"), 10 make_option(c("--insect"), action="store", dest="insect", help="Insect name"),
11 make_option(c("--insects_per_replication"), action="store", dest="insects_per_replication", type="integer", help="Number of insects with which to start each replication"), 11 make_option(c("--insects_per_replication"), action="store", dest="insects_per_replication", type="integer", help="Number of insects with which to start each replication"),
12 make_option(c("--life_stages"), action="store", dest="life_stages", help="Selected life stages for plotting"), 12 make_option(c("--life_stages"), action="store", dest="life_stages", help="Selected life stages for plotting"),
13 make_option(c("--life_stages_adult"), action="store", dest="life_stages_adult", default=NULL, help="Adult life stages for plotting"), 13 make_option(c("--life_stages_adult"), action="store", dest="life_stages_adult", default=NULL, help="Adult life stages for plotting"),
14 make_option(c("--life_stage_nymph"), action="store", dest="life_stage_nymph", default=NULL, help="Nymph life stages for plotting"), 14 make_option(c("--life_stages_nymph"), action="store", dest="life_stages_nymph", default=NULL, help="Nymph life stages for plotting"),
15 make_option(c("--location"), action="store", dest="location", help="Selected location"), 15 make_option(c("--location"), action="store", dest="location", help="Selected location"),
16 make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"), 16 make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"),
17 make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"), 17 make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"),
18 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"), 18 make_option(c("--nymph_mortality"), action="store", dest="nymph_mortality", type="integer", help="Adjustment rate for nymph mortality"),
19 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"), 19 make_option(c("--old_nymph_accumulation"), action="store", dest="old_nymph_accumulation", type="integer", help="Adjustment of degree-days accumulation (young nymph->old nymph)"),
217 } 217 }
218 218
219 219
220 render_chart = function(date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval, 220 render_chart = function(date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval,
221 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL, 221 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL,
222 life_stages_adult=NULL, life_stage_nymph=NULL) { 222 life_stages_adult=NULL, life_stages_nymph=NULL) {
223 if (chart_type=="pop_size_by_life_stage") { 223 if (chart_type=="pop_size_by_life_stage") {
224 if (life_stage=="Total") { 224 if (life_stage=="Total") {
225 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); 225 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
226 legend_text = c("Egg", "Nymph", "Adult"); 226 legend_text = c("Egg", "Nymph", "Adult");
227 columns = c(4, 2, 1); 227 columns = c(4, 2, 1);
246 if (life_stage=="Egg") { 246 if (life_stage=="Egg") {
247 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); 247 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
248 legend_text = c(life_stage); 248 legend_text = c(life_stage);
249 columns = c(4); 249 columns = c(4);
250 } else if (life_stage=="Nymph") { 250 } else if (life_stage=="Nymph") {
251 stage = paste(life_stage_nymph, "Nymph Pop :", sep=" "); 251 stage = paste(life_stages_nymph, "Nymph Pop :", sep=" ");
252 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); 252 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
253 legend_text = c(paste(life_stage_nymph, life_stage, sep=" ")); 253 legend_text = c(paste(life_stages_nymph, life_stage, sep=" "));
254 columns = c(2); 254 columns = c(2);
255 } else if (life_stage=="Adult") { 255 } else if (life_stage=="Adult") {
256 stage = paste(life_stages_adult, "Adult Pop", sep=" "); 256 stage = paste(life_stages_adult, "Adult Pop", sep=" ");
257 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); 257 title = paste(insect, ": Reps", replications, ":", stage, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
258 legend_text = c(paste(life_stages_adult, life_stage, sep=" ")); 258 legend_text = c(paste(life_stages_adult, life_stage, sep=" "));
272 if (life_stage=="Total") { 272 if (life_stage=="Total") {
273 title_str = ": Total Pop by Gen :"; 273 title_str = ": Total Pop by Gen :";
274 } else if (life_stage=="Egg") { 274 } else if (life_stage=="Egg") {
275 title_str = ": Egg Pop by Gen :"; 275 title_str = ": Egg Pop by Gen :";
276 } else if (life_stage=="Nymph") { 276 } else if (life_stage=="Nymph") {
277 title_str = paste(":", life_stage_nymph, "Nymph Pop by Gen", ":", sep=" "); 277 title_str = paste(":", life_stages_nymph, "Nymph Pop by Gen", ":", sep=" ");
278 } else if (life_stage=="Adult") { 278 } else if (life_stage=="Adult") {
279 title_str = paste(":", life_stages_adult, "Adult Pop by Gen", ":", sep=" "); 279 title_str = paste(":", life_stages_adult, "Adult Pop by Gen", ":", sep=" ");
280 } 280 }
281 title = paste(insect, ": Reps", replications, title_str, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); 281 title = paste(insect, ": Reps", replications, title_str, location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" ");
282 legend_text = c("P", "F1", "F2"); 282 legend_text = c("P", "F1", "F2");
325 process_adults = FALSE; 325 process_adults = FALSE;
326 for (life_stage in life_stages) { 326 for (life_stage in life_stages) {
327 if (life_stage=="Total") { 327 if (life_stage=="Total") {
328 process_eggs = TRUE; 328 process_eggs = TRUE;
329 process_nymphs = TRUE; 329 process_nymphs = TRUE;
330 life_stage_nymph = "Total";
331 process_adults = TRUE; 330 process_adults = TRUE;
332 life_stages_adult = "Total";
333 } else if (life_stage=="Egg") { 331 } else if (life_stage=="Egg") {
334 process_eggs = TRUE; 332 process_eggs = TRUE;
335 } else if (life_stage=="Nymph") { 333 } else if (life_stage=="Nymph") {
336 process_nymphs = TRUE; 334 process_nymphs = TRUE;
337 life_stage_nymph = opt$life_stage_nymph;
338 } else if (life_stage=="Adult") { 335 } else if (life_stage=="Adult") {
339 process_adults = TRUE; 336 process_adults = TRUE;
340 life_stages_adult = opt$life_stages_adult; 337 }
341 } 338 }
342 } 339 if (process_adults) {
343 340 # Split life_stages_adult into a list of strings for plots.
341 life_stages_adult_str = as.character(opt$life_stages_adult);
342 life_stages_adult = strsplit(life_stages_adult_str, ",")[[1]];
343 }
344 if (process_nymphs) {
345 # Split life_stages_nymph into a list of strings for plots.
346 life_stages_nymph_str = as.character(opt$life_stages_nymph);
347 life_stages_nymph = strsplit(life_stages_nymph_str, ",")[[1]];
348 }
344 # Initialize matrices. 349 # Initialize matrices.
345 if (process_eggs) { 350 if (process_eggs) {
346 Eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); 351 Eggs.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications);
347 } 352 }
348 if (process_nymphs) { 353 if (process_nymphs) {
806 # Standard error for eggs. 811 # Standard error for eggs.
807 eggs.std_error = apply(Eggs.replications, 1, sd) / sqrt(opt$replications); 812 eggs.std_error = apply(Eggs.replications, 1, sd) / sqrt(opt$replications);
808 } 813 }
809 if (process_nymphs) { 814 if (process_nymphs) {
810 # Calculate nymph populations for selected life stage. 815 # Calculate nymph populations for selected life stage.
811 if (life_stage_nymph=="Total") { 816 for (life_stage_nymph in life_stages_nymph) {
812 # Mean value for all nymphs. 817 if (life_stages_nymph=="Total") {
813 nymphs = apply((YoungNymphs.replications+OldNymphs.replications), 1, mean); 818 # Mean value for all nymphs.
814 # Standard error for all nymphs. 819 total_nymphs = apply((YoungNymphs.replications+OldNymphs.replications), 1, mean);
815 nymphs.std_error = apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd); 820 # Standard error for all nymphs.
816 } else if (life_stage_nymph=="Young") { 821 total_nymphs.std_error = apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd);
817 # Mean value for young nymphs. 822 } else if (life_stages_nymph=="Young") {
818 nymphs = apply(YoungNymphs.replications, 1, mean); 823 # Mean value for young nymphs.
819 # Standard error for young nymphs. 824 young_nymphs = apply(YoungNymphs.replications, 1, mean);
820 nymphs.std_error = apply(YoungNymphs.replications / sqrt(opt$replications), 1, sd); 825 # Standard error for young nymphs.
821 } else if (life_stage_nymph=="Old") { 826 young_nymphs.std_error = apply(YoungNymphs.replications / sqrt(opt$replications), 1, sd);
822 # Mean value for old nymphs. 827 } else if (life_stages_nymph=="Old") {
823 nymphs = apply(OldNymphs.replications, 1, mean); 828 # Mean value for old nymphs.
824 # Standard error for old nymphs. 829 old_nymphs = apply(OldNymphs.replications, 1, mean);
825 nymphs.std_error = apply(OldNymphs.replications / sqrt(opt$replications), 1, sd); 830 # Standard error for old nymphs.
831 old_nymphs.std_error = apply(OldNymphs.replications / sqrt(opt$replications), 1, sd);
832 }
826 } 833 }
827 } 834 }
828 if (process_adults) { 835 if (process_adults) {
829 # Calculate adult populations for selected life stage. 836 # Calculate adult populations for selected life stage.
830 if (life_stages_adult=="Total") { 837 for (life_stage_adult in life_stages_adult) {
831 # Mean value for all adults. 838 if (life_stages_adult=="Total") {
832 adults = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, mean); 839 # Mean value for all adults.
833 # Standard error for all adults. 840 total_adults = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, mean);
834 adults.std_error = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications); 841 # Standard error for all adults.
835 } else if (life_stages_adult == "Pre-vittelogenic") { 842 total_adults.std_error = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications);
836 # Mean value for previtellogenic adults. 843 } else if (life_stages_adult == "Pre-vittelogenic") {
837 adults = apply(Previtellogenic.replications, 1, mean); 844 # Mean value for previtellogenic adults.
838 # Standard error for previtellogenic adults. 845 previttelogenic_adults = apply(Previtellogenic.replications, 1, mean);
839 adults.std_error = apply(Previtellogenic.replications, 1, sd) / sqrt(opt$replications); 846 # Standard error for previtellogenic adults.
840 } else if (life_stages_adult == "Vittelogenic") { 847 previttelogenic_adults.std_error = apply(Previtellogenic.replications, 1, sd) / sqrt(opt$replications);
841 # Mean value for vitellogenic adults. 848 } else if (life_stages_adult == "Vittelogenic") {
842 adults = apply(Vitellogenic.replications, 1, mean); 849 # Mean value for vitellogenic adults.
843 # Standard error for vitellogenic adults. 850 vittelogenic_adults = apply(Vitellogenic.replications, 1, mean);
844 adults.std_error = apply(Vitellogenic.replications, 1, sd) / sqrt(opt$replications); 851 # Standard error for vitellogenic adults.
845 } else if (life_stages_adult == "Diapausing") { 852 vittelogenic_adults.std_error = apply(Vitellogenic.replications, 1, sd) / sqrt(opt$replications);
846 # Mean value for vitellogenic adults. 853 } else if (life_stages_adult == "Diapausing") {
847 adults = apply(Diapausing.replications, 1, mean); 854 # Mean value for vitellogenic adults.
848 # Standard error for vitellogenic adults. 855 diapausing_adults = apply(Diapausing.replications, 1, mean);
849 adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications); 856 # Standard error for vitellogenic adults.
857 diapausing_adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications);
858 }
850 } 859 }
851 } 860 }
852 861
853 if (plot_generations_separately) { 862 if (plot_generations_separately) {
854 # Mean value for P which is Parental, or overwintered adults. 863 # Mean value for P which is Parental, or overwintered adults.
929 opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs, 938 opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error, group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs,
930 group3_std_error=F2_eggs.std_error); 939 group3_std_error=F2_eggs.std_error);
931 # Turn off device driver to flush output. 940 # Turn off device driver to flush output.
932 dev.off(); 941 dev.off();
933 } else if (life_stage == "Nymph") { 942 } else if (life_stage == "Nymph") {
934 # Start PDF device driver. 943 for (life_stage_nymph in life_stages_nymph) {
935 dev.new(width=20, height=30); 944 # Start PDF device driver.
936 file_name = paste(tolower(life_stage_nymph), "nymph_pop_by_generation.pdf", sep="_"); 945 dev.new(width=20, height=30);
937 file_path = paste(output_dir, file_name, sep="/"); 946 file_name = paste(tolower(life_stage_nymph), "nymph_pop_by_generation.pdf", sep="_");
938 pdf(file=file_path, width=20, height=30, bg="white"); 947 file_path = paste(output_dir, file_name, sep="/");
939 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); 948 pdf(file=file_path, width=20, height=30, bg="white");
940 # Nymph population size by generation. 949 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
941 maxval = max(F2_nymphs) + 100; 950 # Nymph population size by generation.
942 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, 951 maxval = max(F2_nymphs) + 100;
943 opt$replications, life_stage, group=P_nymphs, group_std_error=P_nymphs.std_error, group2=F1_nymphs, group2_std_error=F1_nymphs.std_error, 952 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
944 group3=F2_nymphs, group3_std_error=F2_nymphs.std_error, life_stage_nymph=life_stage_nymph); 953 opt$replications, life_stage, group=P_nymphs, group_std_error=P_nymphs.std_error, group2=F1_nymphs, group2_std_error=F1_nymphs.std_error,
945 # Turn off device driver to flush output. 954 group3=F2_nymphs, group3_std_error=F2_nymphs.std_error, life_stages_nymph=life_stage_nymph);
946 dev.off(); 955 # Turn off device driver to flush output.
956 dev.off();
957 }
947 } else if (life_stage == "Adult") { 958 } else if (life_stage == "Adult") {
948 # Start PDF device driver. 959 for (life_stage_adult in life_stages_adult) {
949 dev.new(width=20, height=30); 960 # Start PDF device driver.
950 file_name = paste(tolower(life_stages_adult), "adult_pop_by_generation.pdf", sep="_"); 961 dev.new(width=20, height=30);
951 file_path = paste(output_dir, file_name, sep="/"); 962 file_name = paste(tolower(life_stage_adult), "adult_pop_by_generation.pdf", sep="_");
952 pdf(file=file_path, width=20, height=30, bg="white"); 963 file_path = paste(output_dir, file_name, sep="/");
953 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); 964 pdf(file=file_path, width=20, height=30, bg="white");
954 # Adult population size by generation. 965 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
955 maxval = max(F2_adults) + 100; 966 # Adult population size by generation.
956 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, 967 maxval = max(F2_adults) + 100;
957 opt$replications, life_stage, group=P_adults, group_std_error=P_adults.std_error, group2=F1_adults, group2_std_error=F1_adults.std_error, 968 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
958 group3=F2_adults, group3_std_error=F2_adults.std_error, life_stages_adult=life_stages_adult); 969 opt$replications, life_stage, group=P_adults, group_std_error=P_adults.std_error, group2=F1_adults, group2_std_error=F1_adults.std_error,
959 # Turn off device driver to flush output. 970 group3=F2_adults, group3_std_error=F2_adults.std_error, life_stages_adult=life_stage_adult);
960 dev.off(); 971 # Turn off device driver to flush output.
972 dev.off();
973 }
961 } else if (life_stage == "Total") { 974 } else if (life_stage == "Total") {
962 # Start PDF device driver. 975 # Start PDF device driver.
963 dev.new(width=20, height=30); 976 dev.new(width=20, height=30);
964 file_path = paste(output_dir, "total_pop_by_generation.pdf", sep="/"); 977 file_path = paste(output_dir, "total_pop_by_generation.pdf", sep="/");
965 pdf(file=file_path, width=20, height=30, bg="white"); 978 pdf(file=file_path, width=20, height=30, bg="white");
985 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, 998 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
986 opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error); 999 opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error);
987 # Turn off device driver to flush output. 1000 # Turn off device driver to flush output.
988 dev.off(); 1001 dev.off();
989 } else if (life_stage == "Nymph") { 1002 } else if (life_stage == "Nymph") {
990 # Start PDF device driver. 1003 for (life_stage_nymph in life_stages_nymph) {
991 dev.new(width=20, height=30); 1004 # Start PDF device driver.
992 file_name = paste(tolower(life_stage_nymph), "nymph_pop.pdf", sep="_"); 1005 dev.new(width=20, height=30);
993 file_path = paste(output_dir, file_name, sep="/"); 1006 file_name = paste(tolower(life_stage_nymph), "nymph_pop.pdf", sep="_");
994 pdf(file=file_path, width=20, height=30, bg="white"); 1007 file_path = paste(output_dir, file_name, sep="/");
995 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); 1008 pdf(file=file_path, width=20, height=30, bg="white");
996 # Nymph population size. 1009 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
997 maxval = max(nymphs+nymphs.std_error); 1010 if (life_stage_nymph=="Total") {
998 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, 1011 # Total nymph population size.
999 opt$replications, life_stage, group=nymphs, group_std_error=nymphs.std_error, life_stage_nymph=life_stage_nymph); 1012 group = total_nymphs;
1000 # Turn off device driver to flush output. 1013 group_std_error = total_nymphs.std_error;
1001 dev.off(); 1014 } else if (life_stage_nymph=="Young") {
1015 # Young nymph population size.
1016 group = young_nymphs;
1017 group_std_error = young_nymphs.std_error;
1018 } else if (life_stage_nymph=="Old") {
1019 # Old nymph population size.
1020 group = old_nymphs;
1021 group_std_error = old_nymphs.std_error;
1022 }
1023 maxval = max(group+group.std_error);
1024 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
1025 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_nymph=life_stage_nymph);
1026 # Turn off device driver to flush output.
1027 dev.off();
1028 }
1002 } else if (life_stage == "Adult") { 1029 } else if (life_stage == "Adult") {
1003 # Start PDF device driver. 1030 for (life_stage_adult in life_stages_adult) {
1004 dev.new(width=20, height=30); 1031 # Start PDF device driver.
1005 file_name = paste(tolower(life_stages_adult), "adult_pop.pdf", sep="_"); 1032 dev.new(width=20, height=30);
1006 file_path = paste(output_dir, file_name, sep="/"); 1033 file_name = paste(tolower(life_stages_adult), "adult_pop.pdf", sep="_");
1007 pdf(file=file_path, width=20, height=30, bg="white"); 1034 file_path = paste(output_dir, file_name, sep="/");
1008 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); 1035 pdf(file=file_path, width=20, height=30, bg="white");
1009 # Adult population size. 1036 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
1010 maxval = max(adults+adults.std_error); 1037 if (life_stage_adult=="Total") {
1011 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, 1038 # Total adult population size.
1012 opt$replications, life_stage, group=adults, group_std_error=adults.std_error, life_stages_adult=life_stages_adult); 1039 group = total_adults;
1013 # Turn off device driver to flush output. 1040 group_std_error = total_adults.std_error
1014 dev.off(); 1041 } else if (life_stage_adult=="Pre-vittelogenic") {
1042 # Pre-vittelogenic adult population size.
1043 group = previttelogenic_adults;
1044 group_std_error = previttelogenic_adults.std_error
1045 } else if (life_stage_adult=="Vittelogenic") {
1046 # Vittelogenic adult population size.
1047 group = vittelogenic_adults;
1048 group_std_error = vittelogenic_adults.std_error
1049 } else if (life_stage_adult=="Diapausing") {
1050 # Diapausing adult population size.
1051 group = diapausing_adults;
1052 group_std_error = diapausing_adults.std_error
1053 }
1054 maxval = max(group+group_std_error);
1055 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
1056 opt$replications, life_stage, group=group, group_std_error=group_std_error, life_stages_adult=life_stage_adult);
1057 # Turn off device driver to flush output.
1058 dev.off();
1059 }
1015 } else if (life_stage == "Total") { 1060 } else if (life_stage == "Total") {
1016 # Start PDF device driver. 1061 # Start PDF device driver.
1017 dev.new(width=20, height=30); 1062 dev.new(width=20, height=30);
1018 file_path = paste(output_dir, "total_pop.pdf", sep="/"); 1063 file_path = paste(output_dir, "total_pop.pdf", sep="/");
1019 pdf(file=file_path, width=20, height=30, bg="white"); 1064 pdf(file=file_path, width=20, height=30, bg="white");
1020 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); 1065 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
1021 # Total population size. 1066 # Total population size.
1022 maxval = max(eggs+eggs.std_error, nymphs+nymphs.std_error, adults+adults.std_error); 1067 maxval = max(eggs+eggs.std_error, nymphs+nymphs.std_error, adults+adults.std_error);
1023 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, 1068 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval,
1024 opt$replications, life_stage, group=adults, group_std_error=adults.std_error, group2=nymphs, group2_std_error=nymphs.std_error, group3=eggs, 1069 opt$replications, life_stage, group=total_adults, group_std_error=total_adults.std_error, group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs,
1025 group3_std_error=eggs.std_error); 1070 group3_std_error=eggs.std_error);
1026 # Turn off device driver to flush output. 1071 # Turn off device driver to flush output.
1027 dev.off(); 1072 dev.off();
1028 } 1073 }
1029 } 1074 }