Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 18:f5ecff4800f2 draft
Uploaded
author | greg |
---|---|
date | Tue, 06 Mar 2018 13:39:14 -0500 |
parents | 309954bbe999 |
children | 3c6e94e477cb |
comparison
equal
deleted
inserted
replaced
17:6f31ade9a0f4 | 18:f5ecff4800f2 |
---|---|
51 temperature_data_frame[, num_columns+1] = daylight_length_vector; | 51 temperature_data_frame[, num_columns+1] = daylight_length_vector; |
52 return(temperature_data_frame); | 52 return(temperature_data_frame); |
53 } | 53 } |
54 | 54 |
55 dev.egg = function(temperature) { | 55 dev.egg = function(temperature) { |
56 # This function is not used, but was | |
57 # in the original, so keep it for now. | |
56 dev.rate = -0.9843 * temperature + 33.438; | 58 dev.rate = -0.9843 * temperature + 33.438; |
57 return(dev.rate); | 59 return(dev.rate); |
58 } | 60 } |
59 | 61 |
60 dev.emerg = function(temperature) { | 62 dev.emerg = function(temperature) { |
63 # This function is not used, but was | |
64 # in the original, so keep it for now. | |
61 emerg.rate = -0.5332 * temperature + 24.147; | 65 emerg.rate = -0.5332 * temperature + 24.147; |
62 return(emerg.rate); | 66 return(emerg.rate); |
63 } | 67 } |
64 | 68 |
65 dev.old = function(temperature) { | 69 dev.old = function(temperature) { |
70 # This function is not used, but was | |
71 # in the original, so keep it for now. | |
66 n34 = -0.6119 * temperature + 17.602; | 72 n34 = -0.6119 * temperature + 17.602; |
67 n45 = -0.4408 * temperature + 19.036; | 73 n45 = -0.4408 * temperature + 19.036; |
68 dev.rate = mean(n34 + n45); | 74 dev.rate = mean(n34 + n45); |
69 return(dev.rate); | 75 return(dev.rate); |
70 } | 76 } |
71 | 77 |
72 dev.young = function(temperature) { | 78 dev.young = function(temperature) { |
79 # This function is not used, but was | |
80 # in the original, so keep it for now. | |
73 n12 = -0.3728 * temperature + 14.68; | 81 n12 = -0.3728 * temperature + 14.68; |
74 n23 = -0.6119 * temperature + 25.249; | 82 n23 = -0.6119 * temperature + 25.249; |
75 dev.rate = mean(n12 + n23); | 83 dev.rate = mean(n12 + n23); |
76 return(dev.rate); | 84 return(dev.rate); |
77 } | 85 } |
91 month_labels[length(month_labels)+1] = month_label; | 99 month_labels[length(month_labels)+1] = month_label; |
92 current_month_label = month_label; | 100 current_month_label = month_label; |
93 } | 101 } |
94 } | 102 } |
95 return(c(unlist(month_labels))); | 103 return(c(unlist(month_labels))); |
104 } | |
105 | |
106 get_life_stage_index = function(life_stage, life_stage_nymph=NULL, life_stage_adult=NULL) { | |
107 # Name collection elements so that they | |
108 # are displayed in logical order. | |
109 if (life_stage=="Egg") { | |
110 lsi = "01"; | |
111 } else if (life_stage=="Nymph") { | |
112 if (life_stage_nymph=="Young") { | |
113 lsi = "02"; | |
114 } else if (life_stage_nymph=="Old") { | |
115 lsi = "03"; | |
116 } else if (life_stage_nymph=="Total") { | |
117 lsi="04"; | |
118 } | |
119 } else if (life_stage=="Adult") { | |
120 if (life_stage_adult=="Pre-vittelogenic") { | |
121 lsi = "05"; | |
122 } else if (life_stage_adult=="Vittelogenic") { | |
123 lsi = "06"; | |
124 } else if (life_stage_adult=="Diapausing") { | |
125 lsi = "07"; | |
126 } else if (life_stage_adult=="Total") { | |
127 lsi = "08"; | |
128 } | |
129 } else if (life_stage=="Total") { | |
130 lsi = "09"; | |
131 } | |
132 return(lsi); | |
96 } | 133 } |
97 | 134 |
98 get_temperature_at_hour = function(latitude, temperature_data_frame, row, num_days) { | 135 get_temperature_at_hour = function(latitude, temperature_data_frame, row, num_days) { |
99 # Base development threshold for Brown Marmorated Stink Bug | 136 # Base development threshold for Brown Marmorated Stink Bug |
100 # insect phenology model. | 137 # insect phenology model. |
216 return(temperature_data_frame); | 253 return(temperature_data_frame); |
217 } | 254 } |
218 | 255 |
219 | 256 |
220 render_chart = function(date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval, | 257 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, | 258 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_stages_nymph=NULL) { | 259 life_stages_adult=NULL, life_stages_nymph=NULL) { |
223 if (chart_type=="pop_size_by_life_stage") { | 260 if (chart_type=="pop_size_by_life_stage") { |
224 if (life_stage=="Total") { | 261 if (life_stage=="Total") { |
225 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); | 262 title = paste(insect, ": Reps", replications, ":", life_stage, "Pop :", location, ": Lat", latitude, ":", start_date, "-", end_date, sep=" "); |
226 legend_text = c("Egg", "Nymph", "Adult"); | 263 legend_text = c("Egg", "Nymph", "Adult"); |
227 columns = c(4, 2, 1); | 264 columns = c(4, 2, 1); |
387 } | 424 } |
388 # Total population. | 425 # Total population. |
389 population.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); | 426 population.replications = matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications); |
390 | 427 |
391 # Process replications. | 428 # Process replications. |
392 for (N.replications in 1:opt$replications) { | 429 for (current_replication in 1:opt$replications) { |
393 # Start with the user-defined number of insects per replication. | 430 # Start with the user-defined number of insects per replication. |
394 num_insects = opt$insects_per_replication; | 431 num_insects = opt$insects_per_replication; |
395 # Generation, Stage, degree-days, T, Diapause. | 432 # Generation, Stage, degree-days, T, Diapause. |
396 vector.ini = c(0, 3, 0, 0, 0); | 433 vector.ini = c(0, 3, 0, 0, 0); |
397 # Replicate to create a matrix where the columns are | 434 # Replicate to create a matrix where the columns are |
472 if (vector.individual[2] == 0) { | 509 if (vector.individual[2] == 0) { |
473 # Egg. | 510 # Egg. |
474 death.probability = opt$egg_mortality * mortality.egg(mean.temp); | 511 death.probability = opt$egg_mortality * mortality.egg(mean.temp); |
475 } | 512 } |
476 else if (vector.individual[2] == 1 | vector.individual[2] == 2) { | 513 else if (vector.individual[2] == 1 | vector.individual[2] == 2) { |
514 # Nymph. | |
477 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp); | 515 death.probability = opt$nymph_mortality * mortality.nymph(mean.temp); |
478 } | 516 } |
479 else if (vector.individual[2] == 3 | vector.individual[2] == 4 | vector.individual[2] == 5) { | 517 else if (vector.individual[2] == 3 | vector.individual[2] == 4 | vector.individual[2] == 5) { |
480 # Adult. | 518 # Adult. |
481 if (doy < day.kill) { | 519 if (doy < day.kill) { |
709 # size, column 1 (Generation) must be 2. | 747 # size, column 1 (Generation) must be 2. |
710 second_generation.population[row] = sum(vector.matrix[,1]==2); | 748 second_generation.population[row] = sum(vector.matrix[,1]==2); |
711 | 749 |
712 if (plot_generations_separately) { | 750 if (plot_generations_separately) { |
713 if (process_eggs) { | 751 if (process_eggs) { |
714 # For egg life stage of generation F1 population size, | 752 # For egg life stage of generation P population size, |
715 # column 1 (generation) is 0 and column 2 (Stage) is 0. | 753 # column 1 (generation) is 0 and column 2 (Stage) is 0. |
716 P.egg[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==0); | 754 P.egg[row] = sum(vector.matrix[,1]==0 & vector.matrix[,2]==0); |
717 # For egg life stage of generation F1 population size, | 755 # For egg life stage of generation F1 population size, |
718 # column 1 (generation) is 1 and column 2 (Stage) is 0. | 756 # column 1 (generation) is 1 and column 2 (Stage) is 0. |
719 F1.egg[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==0); | 757 F1.egg[row] = sum(vector.matrix[,1]==1 & vector.matrix[,2]==0); |
720 # For egg life stage of generation F2 population size, | 758 # For egg life stage of generation F2 population size, |
721 # column 1 (generation) is 2 and column 2 (Stage) is 0. | 759 # column 1 (generation) is 2 and column 2 (Stage) is 0. |
722 F2.egg[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==0); | 760 F2.egg[row] = sum(vector.matrix[,1]==2 & vector.matrix[,2]==0); |
723 } | 761 } |
724 if (process_nymphs) { | 762 if (process_nymphs) { |
725 # For nymph life stage of generation F1 population | 763 # For nymph life stage of generation P population |
726 # size, one of the following combinations is required: | 764 # size, one of the following combinations is required: |
727 # - column 1 (Generation) is 0 and column 2 (Stage) is 1 (Young nymph) | 765 # - column 1 (Generation) is 0 and column 2 (Stage) is 1 (Young nymph) |
728 # - column 1 (Generation) is 0 and column 2 (Stage) is 2 (Old nymph) | 766 # - column 1 (Generation) is 0 and column 2 (Stage) is 2 (Old nymph) |
729 P.nymph[row] = sum((vector.matrix[,1]==0 & vector.matrix[,2]==1) | (vector.matrix[,1]==0 & vector.matrix[,2]==2)); | 767 P.nymph[row] = sum((vector.matrix[,1]==0 & vector.matrix[,2]==1) | (vector.matrix[,1]==0 & vector.matrix[,2]==2)); |
730 # For nymph life stage of generation F1 population | 768 # For nymph life stage of generation F1 population |
763 | 801 |
764 averages.cum = cumsum(averages.day); | 802 averages.cum = cumsum(averages.day); |
765 | 803 |
766 # Define the output values. | 804 # Define the output values. |
767 if (process_eggs) { | 805 if (process_eggs) { |
768 Eggs.replications[,N.replications] = Eggs; | 806 Eggs.replications[,current_replication] = Eggs; |
769 } | 807 } |
770 if (process_nymphs) { | 808 if (process_nymphs) { |
771 YoungNymphs.replications[,N.replications] = YoungNymphs; | 809 YoungNymphs.replications[,current_replication] = YoungNymphs; |
772 OldNymphs.replications[,N.replications] = OldNymphs; | 810 OldNymphs.replications[,current_replication] = OldNymphs; |
773 } | 811 } |
774 if (process_adults) { | 812 if (process_adults) { |
775 Previtellogenic.replications[,N.replications] = Previtellogenic; | 813 Previtellogenic.replications[,current_replication] = Previtellogenic; |
776 Vitellogenic.replications[,N.replications] = Vitellogenic; | 814 Vitellogenic.replications[,current_replication] = Vitellogenic; |
777 Diapausing.replications[,N.replications] = Diapausing; | 815 Diapausing.replications[,current_replication] = Diapausing; |
778 } | 816 } |
779 newborn.replications[,N.replications] = N.newborn; | 817 newborn.replications[,current_replication] = N.newborn; |
780 adult.replications[,N.replications] = N.adult; | 818 adult.replications[,current_replication] = N.adult; |
781 death.replications[,N.replications] = N.death; | 819 death.replications[,current_replication] = N.death; |
782 if (plot_generations_separately) { | 820 if (plot_generations_separately) { |
783 # P is Parental, or overwintered adults. | 821 # P is Parental, or overwintered adults. |
784 P.replications[,N.replications] = overwintering_adult.population; | 822 P.replications[,current_replication] = overwintering_adult.population; |
785 # F1 is the first field-produced generation. | 823 # F1 is the first field-produced generation. |
786 F1.replications[,N.replications] = first_generation.population; | 824 F1.replications[,current_replication] = first_generation.population; |
787 # F2 is the second field-produced generation. | 825 # F2 is the second field-produced generation. |
788 F2.replications[,N.replications] = second_generation.population; | 826 F2.replications[,current_replication] = second_generation.population; |
789 if (process_eggs) { | 827 if (process_eggs) { |
790 P_eggs.replications[,N.replications] = P.egg; | 828 P_eggs.replications[,current_replication] = P.egg; |
791 F1_eggs.replications[,N.replications] = F1.egg; | 829 F1_eggs.replications[,current_replication] = F1.egg; |
792 F2_eggs.replications[,N.replications] = F2.egg; | 830 F2_eggs.replications[,current_replication] = F2.egg; |
793 } | 831 } |
794 if (process_nymphs) { | 832 if (process_nymphs) { |
795 P_nymphs.replications[,N.replications] = P.nymph; | 833 P_nymphs.replications[,current_replication] = P.nymph; |
796 F1_nymphs.replications[,N.replications] = F1.nymph; | 834 F1_nymphs.replications[,current_replication] = F1.nymph; |
797 F2_nymphs.replications[,N.replications] = F2.nymph; | 835 F2_nymphs.replications[,current_replication] = F2.nymph; |
798 } | 836 } |
799 if (process_adults) { | 837 if (process_adults) { |
800 P_adults.replications[,N.replications] = P.adult; | 838 P_adults.replications[,current_replication] = P.adult; |
801 F1_adults.replications[,N.replications] = F1.adult; | 839 F1_adults.replications[,current_replication] = F1.adult; |
802 F2_adults.replications[,N.replications] = F2.adult; | 840 F2_adults.replications[,current_replication] = F2.adult; |
803 } | 841 } |
804 } | 842 } |
805 population.replications[,N.replications] = total.population; | 843 population.replications[,current_replication] = total.population; |
844 # End processing replications. | |
806 } | 845 } |
807 | 846 |
808 if (process_eggs) { | 847 if (process_eggs) { |
809 # Mean value for eggs. | 848 # Mean value for eggs. |
810 eggs = apply(Eggs.replications, 1, mean); | 849 eggs = apply(Eggs.replications, 1, mean); |
812 eggs.std_error = apply(Eggs.replications, 1, sd) / sqrt(opt$replications); | 851 eggs.std_error = apply(Eggs.replications, 1, sd) / sqrt(opt$replications); |
813 } | 852 } |
814 if (process_nymphs) { | 853 if (process_nymphs) { |
815 # Calculate nymph populations for selected life stage. | 854 # Calculate nymph populations for selected life stage. |
816 for (life_stage_nymph in life_stages_nymph) { | 855 for (life_stage_nymph in life_stages_nymph) { |
817 if (life_stages_nymph=="Total") { | 856 if (life_stage_nymph=="Total") { |
818 # Mean value for all nymphs. | 857 # Mean value for all nymphs. |
819 total_nymphs = apply((YoungNymphs.replications+OldNymphs.replications), 1, mean); | 858 total_nymphs = apply((YoungNymphs.replications+OldNymphs.replications), 1, mean); |
820 # Standard error for all nymphs. | 859 # Standard error for all nymphs. |
821 total_nymphs.std_error = apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd); | 860 total_nymphs.std_error = apply((YoungNymphs.replications+OldNymphs.replications) / sqrt(opt$replications), 1, sd); |
822 } else if (life_stages_nymph=="Young") { | 861 } else if (life_stage_nymph=="Young") { |
823 # Mean value for young nymphs. | 862 # Mean value for young nymphs. |
824 young_nymphs = apply(YoungNymphs.replications, 1, mean); | 863 young_nymphs = apply(YoungNymphs.replications, 1, mean); |
825 # Standard error for young nymphs. | 864 # Standard error for young nymphs. |
826 young_nymphs.std_error = apply(YoungNymphs.replications / sqrt(opt$replications), 1, sd); | 865 young_nymphs.std_error = apply(YoungNymphs.replications / sqrt(opt$replications), 1, sd); |
827 } else if (life_stages_nymph=="Old") { | 866 } else if (life_stage_nymph=="Old") { |
828 # Mean value for old nymphs. | 867 # Mean value for old nymphs. |
829 old_nymphs = apply(OldNymphs.replications, 1, mean); | 868 old_nymphs = apply(OldNymphs.replications, 1, mean); |
830 # Standard error for old nymphs. | 869 # Standard error for old nymphs. |
831 old_nymphs.std_error = apply(OldNymphs.replications / sqrt(opt$replications), 1, sd); | 870 old_nymphs.std_error = apply(OldNymphs.replications / sqrt(opt$replications), 1, sd); |
832 } | 871 } |
833 } | 872 } |
834 } | 873 } |
835 if (process_adults) { | 874 if (process_adults) { |
836 # Calculate adult populations for selected life stage. | 875 # Calculate adult populations for selected life stage. |
837 for (life_stage_adult in life_stages_adult) { | 876 for (life_stage_adult in life_stages_adult) { |
838 if (life_stages_adult=="Total") { | 877 if (life_stage_adult=="Total") { |
839 # Mean value for all adults. | 878 # Mean value for all adults. |
840 total_adults = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, mean); | 879 total_adults = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, mean); |
841 # Standard error for all adults. | 880 # Standard error for all adults. |
842 total_adults.std_error = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications); | 881 total_adults.std_error = apply((Previtellogenic.replications+Vitellogenic.replications+Diapausing.replications), 1, sd) / sqrt(opt$replications); |
843 } else if (life_stages_adult == "Pre-vittelogenic") { | 882 } else if (life_stage_adult == "Pre-vittelogenic") { |
844 # Mean value for previtellogenic adults. | 883 # Mean value for previtellogenic adults. |
845 previttelogenic_adults = apply(Previtellogenic.replications, 1, mean); | 884 previttelogenic_adults = apply(Previtellogenic.replications, 1, mean); |
846 # Standard error for previtellogenic adults. | 885 # Standard error for previtellogenic adults. |
847 previttelogenic_adults.std_error = apply(Previtellogenic.replications, 1, sd) / sqrt(opt$replications); | 886 previttelogenic_adults.std_error = apply(Previtellogenic.replications, 1, sd) / sqrt(opt$replications); |
848 } else if (life_stages_adult == "Vittelogenic") { | 887 } else if (life_stage_adult == "Vittelogenic") { |
849 # Mean value for vitellogenic adults. | 888 # Mean value for vitellogenic adults. |
850 vittelogenic_adults = apply(Vitellogenic.replications, 1, mean); | 889 vittelogenic_adults = apply(Vitellogenic.replications, 1, mean); |
851 # Standard error for vitellogenic adults. | 890 # Standard error for vitellogenic adults. |
852 vittelogenic_adults.std_error = apply(Vitellogenic.replications, 1, sd) / sqrt(opt$replications); | 891 vittelogenic_adults.std_error = apply(Vitellogenic.replications, 1, sd) / sqrt(opt$replications); |
853 } else if (life_stages_adult == "Diapausing") { | 892 } else if (life_stage_adult == "Diapausing") { |
854 # Mean value for vitellogenic adults. | 893 # Mean value for vitellogenic adults. |
855 diapausing_adults = apply(Diapausing.replications, 1, mean); | 894 diapausing_adults = apply(Diapausing.replications, 1, mean); |
856 # Standard error for vitellogenic adults. | 895 # Standard error for vitellogenic adults. |
857 diapausing_adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications); | 896 diapausing_adults.std_error = apply(Diapausing.replications, 1, sd) / sqrt(opt$replications); |
858 } | 897 } |
927 if (plot_generations_separately) { | 966 if (plot_generations_separately) { |
928 for (life_stage in life_stages) { | 967 for (life_stage in life_stages) { |
929 if (life_stage == "Egg") { | 968 if (life_stage == "Egg") { |
930 # Start PDF device driver. | 969 # Start PDF device driver. |
931 dev.new(width=20, height=30); | 970 dev.new(width=20, height=30); |
932 file_path = paste(output_dir, "egg_pop_by_generation.pdf", sep="/"); | 971 lsi = get_life_stage_index(life_stage); |
972 file_name = paste(lsi, "egg_pop_by_generation.pdf", sep="_"); | |
973 file_path = paste(output_dir, file_name, sep="/"); | |
933 pdf(file=file_path, width=20, height=30, bg="white"); | 974 pdf(file=file_path, width=20, height=30, bg="white"); |
934 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 975 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
935 # Egg population size by generation. | 976 # Egg population size by generation. |
936 maxval = max(F2_eggs) + 100; | 977 maxval = max(P_eggs+F1_eggs+F2_eggs) + 100; |
937 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 978 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
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, | 979 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, |
939 group3_std_error=F2_eggs.std_error); | 980 group3_std_error=F2_eggs.std_error); |
940 # Turn off device driver to flush output. | 981 # Turn off device driver to flush output. |
941 dev.off(); | 982 dev.off(); |
942 } else if (life_stage == "Nymph") { | 983 } else if (life_stage == "Nymph") { |
943 for (life_stage_nymph in life_stages_nymph) { | 984 for (life_stage_nymph in life_stages_nymph) { |
944 # Start PDF device driver. | 985 # Start PDF device driver. |
945 dev.new(width=20, height=30); | 986 dev.new(width=20, height=30); |
946 file_name = paste(tolower(life_stage_nymph), "nymph_pop_by_generation.pdf", sep="_"); | 987 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph); |
988 file_name = paste(lsi, tolower(life_stage_nymph), "nymph_pop_by_generation.pdf", sep="_"); | |
947 file_path = paste(output_dir, file_name, sep="/"); | 989 file_path = paste(output_dir, file_name, sep="/"); |
948 pdf(file=file_path, width=20, height=30, bg="white"); | 990 pdf(file=file_path, width=20, height=30, bg="white"); |
949 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 991 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
950 # Nymph population size by generation. | 992 # Nymph population size by generation. |
951 maxval = max(F2_nymphs) + 100; | 993 maxval = max(P_nymphs+F1_nymphs+F2_nymphs) + 100; |
952 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 994 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
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, | 995 opt$replications, life_stage, group=P_nymphs, group_std_error=P_nymphs.std_error, group2=F1_nymphs, group2_std_error=F1_nymphs.std_error, |
954 group3=F2_nymphs, group3_std_error=F2_nymphs.std_error, life_stages_nymph=life_stage_nymph); | 996 group3=F2_nymphs, group3_std_error=F2_nymphs.std_error, life_stages_nymph=life_stage_nymph); |
955 # Turn off device driver to flush output. | 997 # Turn off device driver to flush output. |
956 dev.off(); | 998 dev.off(); |
957 } | 999 } |
958 } else if (life_stage == "Adult") { | 1000 } else if (life_stage == "Adult") { |
959 for (life_stage_adult in life_stages_adult) { | 1001 for (life_stage_adult in life_stages_adult) { |
960 # Start PDF device driver. | 1002 # Start PDF device driver. |
961 dev.new(width=20, height=30); | 1003 dev.new(width=20, height=30); |
962 file_name = paste(tolower(life_stage_adult), "adult_pop_by_generation.pdf", sep="_"); | 1004 lsi = get_life_stage_index(life_stage, life_stage_adult=life_stage_adult); |
1005 file_name = paste(lsi, tolower(life_stage_adult), "adult_pop_by_generation.pdf", sep="_"); | |
963 file_path = paste(output_dir, file_name, sep="/"); | 1006 file_path = paste(output_dir, file_name, sep="/"); |
964 pdf(file=file_path, width=20, height=30, bg="white"); | 1007 pdf(file=file_path, width=20, height=30, bg="white"); |
965 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1008 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
966 # Adult population size by generation. | 1009 # Adult population size by generation. |
967 maxval = max(F2_adults) + 100; | 1010 maxval = max(P_adults+F1_adults+F2_adults) + 100; |
968 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1011 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
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, | 1012 opt$replications, life_stage, group=P_adults, group_std_error=P_adults.std_error, group2=F1_adults, group2_std_error=F1_adults.std_error, |
970 group3=F2_adults, group3_std_error=F2_adults.std_error, life_stages_adult=life_stage_adult); | 1013 group3=F2_adults, group3_std_error=F2_adults.std_error, life_stages_adult=life_stage_adult); |
971 # Turn off device driver to flush output. | 1014 # Turn off device driver to flush output. |
972 dev.off(); | 1015 dev.off(); |
973 } | 1016 } |
974 } else if (life_stage == "Total") { | 1017 } else if (life_stage == "Total") { |
975 # Start PDF device driver. | 1018 # Start PDF device driver. |
1019 # Name collection elements so that they | |
1020 # are displayed in logical order. | |
976 dev.new(width=20, height=30); | 1021 dev.new(width=20, height=30); |
977 file_path = paste(output_dir, "total_pop_by_generation.pdf", sep="/"); | 1022 lsi = get_life_stage_index(life_stage); |
1023 file_name = paste(lsi, "total_pop_by_generation.pdf", sep="_"); | |
1024 file_path = paste(output_dir, file_name, sep="/"); | |
978 pdf(file=file_path, width=20, height=30, bg="white"); | 1025 pdf(file=file_path, width=20, height=30, bg="white"); |
979 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1026 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
980 # Total population size by generation. | 1027 # Total population size by generation. |
981 maxval = max(F2); | 1028 maxval = max(P+F1+F2) + 100; |
982 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, | 1029 render_chart(date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
983 opt$replications, life_stage, group=P, group_std_error=P.std_error, group2=F1, group2_std_error=F1.std_error, group3=F2, group3_std_error=F2.std_error); | 1030 opt$replications, life_stage, group=P, group_std_error=P.std_error, group2=F1, group2_std_error=F1.std_error, group3=F2, group3_std_error=F2.std_error); |
984 # Turn off device driver to flush output. | 1031 # Turn off device driver to flush output. |
985 dev.off(); | 1032 dev.off(); |
986 } | 1033 } |
988 } else { | 1035 } else { |
989 for (life_stage in life_stages) { | 1036 for (life_stage in life_stages) { |
990 if (life_stage == "Egg") { | 1037 if (life_stage == "Egg") { |
991 # Start PDF device driver. | 1038 # Start PDF device driver. |
992 dev.new(width=20, height=30); | 1039 dev.new(width=20, height=30); |
993 file_path = paste(output_dir, "egg_pop.pdf", sep="/"); | 1040 lsi = get_life_stage_index(life_stage); |
1041 file_name = paste(lsi, "egg_pop.pdf", sep="_"); | |
1042 file_path = paste(output_dir, file_name, sep="/"); | |
994 pdf(file=file_path, width=20, height=30, bg="white"); | 1043 pdf(file=file_path, width=20, height=30, bg="white"); |
995 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1044 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
996 # Egg population size. | 1045 # Egg population size. |
997 maxval = max(eggs+eggs.std_error); | 1046 maxval = max(eggs+eggs.std_error) + 100; |
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, | 1047 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
999 opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error); | 1048 opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error); |
1000 # Turn off device driver to flush output. | 1049 # Turn off device driver to flush output. |
1001 dev.off(); | 1050 dev.off(); |
1002 } else if (life_stage == "Nymph") { | 1051 } else if (life_stage == "Nymph") { |
1003 for (life_stage_nymph in life_stages_nymph) { | 1052 for (life_stage_nymph in life_stages_nymph) { |
1004 # Start PDF device driver. | 1053 # Start PDF device driver. |
1005 dev.new(width=20, height=30); | 1054 dev.new(width=20, height=30); |
1006 file_name = paste(tolower(life_stage_nymph), "nymph_pop.pdf", sep="_"); | 1055 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph); |
1056 file_name = paste(lsi, tolower(life_stage_nymph), "nymph_pop.pdf", sep="_"); | |
1007 file_path = paste(output_dir, file_name, sep="/"); | 1057 file_path = paste(output_dir, file_name, sep="/"); |
1008 pdf(file=file_path, width=20, height=30, bg="white"); | 1058 pdf(file=file_path, width=20, height=30, bg="white"); |
1009 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1059 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1010 if (life_stage_nymph=="Total") { | 1060 if (life_stage_nymph=="Total") { |
1011 # Total nymph population size. | 1061 # Total nymph population size. |
1018 } else if (life_stage_nymph=="Old") { | 1068 } else if (life_stage_nymph=="Old") { |
1019 # Old nymph population size. | 1069 # Old nymph population size. |
1020 group = old_nymphs; | 1070 group = old_nymphs; |
1021 group_std_error = old_nymphs.std_error; | 1071 group_std_error = old_nymphs.std_error; |
1022 } | 1072 } |
1023 maxval = max(group+group.std_error); | 1073 maxval = max(group+group_std_error) + 100; |
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, | 1074 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); | 1075 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. | 1076 # Turn off device driver to flush output. |
1027 dev.off(); | 1077 dev.off(); |
1028 } | 1078 } |
1029 } else if (life_stage == "Adult") { | 1079 } else if (life_stage == "Adult") { |
1030 for (life_stage_adult in life_stages_adult) { | 1080 for (life_stage_adult in life_stages_adult) { |
1031 # Start PDF device driver. | 1081 # Start PDF device driver. |
1032 dev.new(width=20, height=30); | 1082 dev.new(width=20, height=30); |
1033 file_name = paste(tolower(life_stages_adult), "adult_pop.pdf", sep="_"); | 1083 lsi = get_life_stage_index(life_stage, life_stage_adult=life_stage_adult); |
1084 file_name = paste(lsi, tolower(life_stage_adult), "adult_pop.pdf", sep="_"); | |
1034 file_path = paste(output_dir, file_name, sep="/"); | 1085 file_path = paste(output_dir, file_name, sep="/"); |
1035 pdf(file=file_path, width=20, height=30, bg="white"); | 1086 pdf(file=file_path, width=20, height=30, bg="white"); |
1036 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1087 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1037 if (life_stage_adult=="Total") { | 1088 if (life_stage_adult=="Total") { |
1038 # Total adult population size. | 1089 # Total adult population size. |
1049 } else if (life_stage_adult=="Diapausing") { | 1100 } else if (life_stage_adult=="Diapausing") { |
1050 # Diapausing adult population size. | 1101 # Diapausing adult population size. |
1051 group = diapausing_adults; | 1102 group = diapausing_adults; |
1052 group_std_error = diapausing_adults.std_error | 1103 group_std_error = diapausing_adults.std_error |
1053 } | 1104 } |
1054 maxval = max(group+group_std_error); | 1105 maxval = max(group+group_std_error) + 100; |
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, | 1106 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); | 1107 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. | 1108 # Turn off device driver to flush output. |
1058 dev.off(); | 1109 dev.off(); |
1059 } | 1110 } |
1060 } else if (life_stage == "Total") { | 1111 } else if (life_stage == "Total") { |
1061 # Start PDF device driver. | 1112 # Start PDF device driver. |
1062 dev.new(width=20, height=30); | 1113 dev.new(width=20, height=30); |
1063 file_path = paste(output_dir, "total_pop.pdf", sep="/"); | 1114 lsi = get_life_stage_index(life_stage); |
1115 file_name = paste(lsi, "total_pop.pdf", sep="_"); | |
1116 file_path = paste(output_dir, file_name, sep="/"); | |
1064 pdf(file=file_path, width=20, height=30, bg="white"); | 1117 pdf(file=file_path, width=20, height=30, bg="white"); |
1065 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); | 1118 par(mar=c(5, 6, 4, 4), mfrow=c(3, 1)); |
1066 # Total population size. | 1119 # Total population size. |
1067 maxval = max(eggs+eggs.std_error, nymphs+nymphs.std_error, adults+adults.std_error); | 1120 maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100; |
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, | 1121 render_chart(date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude, start_date, end_date, days, maxval, |
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, | 1122 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, |
1070 group3_std_error=eggs.std_error); | 1123 group3_std_error=eggs.std_error); |
1071 # Turn off device driver to flush output. | 1124 # Turn off device driver to flush output. |
1072 dev.off(); | 1125 dev.off(); |