Repository 'insect_phenology_model'
hg clone https://eddie.galaxyproject.org/repos/greg/insect_phenology_model

Changeset 99:51045fde125e (2017-12-04)
Previous changeset 98:d33a401c0153 (2017-12-04) Next changeset 100:52114847afff (2017-12-04)
Commit message:
Uploaded
modified:
insect_phenology_model.R
b
diff -r d33a401c0153 -r 51045fde125e insect_phenology_model.R
--- a/insect_phenology_model.R Mon Dec 04 11:54:10 2017 -0500
+++ b/insect_phenology_model.R Mon Dec 04 13:04:11 2017 -0500
[
b'@@ -217,7 +217,7 @@\n g2.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications)\n g0a.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications)\n g1a.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications)\n-g2a.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications)\n+F2_adults.replications <- matrix(rep(0, opt$num_days*opt$replications), ncol=opt$replications)\n \n # Loop through replications.\n for (N.replications in 1:opt$replications) {\n@@ -467,13 +467,13 @@\n                 }\n             } # Else if it is still alive.\n         } # End of the individual bug loop.\n-        # Find how many died.\n+        # Find the number of deaths.\n         num_insects.death <- length(death.vector)\n         if (num_insects.death > 0) {\n+      # Remove record of dead.\n             vector.matrix <- vector.matrix[-death.vector, ]\n         }\n-        # Remove record of dead.\n-        # Find how many new born.\n+        # Find the number of births.\n         num_insects.newborn <- length(birth.vector[,1])\n         vector.matrix <- rbind(vector.matrix, birth.vector)\n         # Update population size for the next day.\n@@ -481,38 +481,29 @@\n \n         # Aggregate results by day.\n         tot.pop <- c(tot.pop, num_insects)\n-        # Egg.\n-        sum_eggs <- sum(vector.matrix[,2] == 0)\n-        # Young nymph.\n-        sum_young_nymphs <- sum(vector.matrix[,2] == 1)\n-        # Old nymph.\n-        sum_old_nymphs <- sum(vector.matrix[,2] == 2)\n-        # Previtellogenic.\n-        sum_previtellogenic <- sum(vector.matrix[,2] == 3)\n-        # Vitellogenic.\n-        sum_vitellogenic <- sum(vector.matrix[,2] == 4)\n-        # Diapausing.\n-        sum_diapausing <- sum(vector.matrix[,2] == 5)\n-        # Overwintering adult.\n-        sum_overwintering_adults <- sum(vector.matrix[,1] == 0)\n-        # First generation.\n-        sum_first_generation <- sum(vector.matrix[,1] == 1)\n-        # Second generation.\n-        sum_second_generation <- sum(vector.matrix[,1] == 2)\n-        # Sum of all adults.\n+\n+        # All adults population size.\n         num_insects.adult <- sum(vector.matrix[,2] == 3) + sum(vector.matrix[,2] == 4) + sum(vector.matrix[,2] == 5)\n \n-        # Population sizes.\n-        gen0.pop[row] <- sum_overwintering_adults\n-        gen1.pop[row] <- sum_first_generation\n-        gen2.pop[row] <- sum_second_generation\n+        # Overwintering adult population size.\n+        gen0.pop[row] <- sum(vector.matrix[,1] == 0)\n+        # First generation population size.\n+        gen1.pop[row] <- sum(vector.matrix[,1] == 1)\n+        # Second generation population size.\n+        gen2.pop[row] <- sum(vector.matrix[,1] == 2)\n \n-        S0[row] <- sum_eggs\n-        S1[row] <- sum_young_nymphs\n-        S2[row] <- sum_old_nymphs\n-        S3[row] <- sum_previtellogenic\n-        S4[row] <- sum_vitellogenic\n-        S5[row] <- sum_diapausing\n+        # Egg population size.\n+        S0[row] <- sum(vector.matrix[,2] == 0)\n+        # Young nymph population size.\n+        S1[row] <- sum(vector.matrix[,2] == 1)\n+        # Old nymph population size.\n+        S2[row] <- sum(vector.matrix[,2] == 2)\n+        # Previtellogenic population size.\n+        S3[row] <- sum(vector.matrix[,2] == 3)\n+        # Vitellogenic population size.\n+        S4[row] <- sum(vector.matrix[,2] == 4)\n+        # Diapausing population size.\n+        S5[row] <- sum(vector.matrix[,2] == 5)\n \n         g0.adult[row] <- sum(vector.matrix[,1] == 0)\n         g1.adult[row] <- sum((vector.matrix[,1] == 1 & vector.matrix[,2] == 3) | (vector.matrix[,1] == 1 & vector.matrix[,2] == 4) | (vector.matrix[,1] == 1 & vector.matrix[,2] == 5))\n@@ -541,34 +532,34 @@\n     g2.replications[,N.replications] <- gen2.pop\n     g0a.replications[,N.replications] <- g0.adult\n     g1a.replications[,N.replications] <- g1.adult\n-    g2a.replications[,N.replications] <- g2.adult\n+    F2_adults.replications[,N.replications] <- g2.a'..b'ations)\n+eggs.std_error <- apply(S0.replications, 1, sd) / sqrt(opt$replications)\n # Standard error value for P.\n g0.std_error <- apply(g0.replications, 1, sd) / sqrt(opt$replications)\n # Standard error for F1.\n@@ -580,7 +571,7 @@\n # Standard error for F1 adult.\n g1a.std_error <- apply(g1a.replications, 1, sd) / sqrt(opt$replications)\n # Standard error for F2 adult.\n-g2a.std_error <- apply(g2a.replications, 1, sd) / sqrt(opt$replications)\n+F2_adults.std_error <- apply(F2_adults.replications, 1, sd) / sqrt(opt$replications)\n \n dev.new(width=20, height=30)\n \n@@ -597,25 +588,25 @@\n \n # Subfigure 1: population size by life stage\n title <- paste(opt$insect, ": Total pop. by life stage :", opt$location, ": Lat:", latitude, ":", start_date, "-", end_date, sep=" ")\n-plot(day.all, adult_mean, main=title, type="l", ylim=c(0, max(egg_mean + egg_mean.std_error, nymph_mean + nymph_mean.std_error, adult_mean + adult_mean.std_error)), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3)\n+plot(day.all, adults, main=title, type="l", ylim=c(0, max(eggs + eggs.std_error, nymphs + nymphs.std_error, adults + adults.std_error)), axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3)\n # Young and old nymphs.\n-lines(day.all, nymph_mean, lwd=2, lty=1, col=2)\n+lines(day.all, nymphs, lwd=2, lty=1, col=2)\n # Eggs\n-lines(day.all, egg_mean, lwd=2, lty=1, col=4)\n+lines(day.all, eggs, lwd=2, lty=1, col=4)\n axis(1, at=c(1:12) * 30 - 15, cex.axis=3, labels=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))\n axis(2, cex.axis=3)\n legend("topleft", c("Egg", "Nymph", "Adult"), lty=c(1, 1, 1), col=c(4, 2, 1), cex=3)\n if (opt$std_error_plot == 1) {\n     # Add Standard error lines to plot\n     # Standard error for adults\n-    lines (day.all, adult_mean+adult_mean.std_error, lty=2)\n-    lines (day.all, adult_mean-adult_mean.std_error, lty=2)\n+    lines (day.all, adults+adults.std_error, lty=2)\n+    lines (day.all, adults-adults.std_error, lty=2)\n     # Standard error for nymphs\n-    lines (day.all, nymph_mean+nymph_mean.std_error, col=2, lty=2)\n-    lines (day.all, nymph_mean-nymph_mean.std_error, col=2, lty=2)\n+    lines (day.all, nymphs+nymphs.std_error, col=2, lty=2)\n+    lines (day.all, nymphs-nymphs.std_error, col=2, lty=2)\n     # Standard error for eggs\n-    lines (day.all, egg_mean+egg_mean.std_error, col=4, lty=2)\n-    lines (day.all, egg_mean-egg_mean.std_error, col=4, lty=2)\n+    lines (day.all, eggs+eggs.std_error, col=4, lty=2)\n+    lines (day.all, eggs-eggs.std_error, col=4, lty=2)\n }\n \n # Subfigure 2: population size by generation\n@@ -641,9 +632,9 @@\n \n # Subfigure 3: adult population size by generation\n title <- paste(opt$insect, ": Adult pop. by generation :", opt$location, ": Lat:", latitude, ":", start_date, "-", end_date, sep=" ")\n-plot(day.all, g0a, ylim=c(0, max(F2_adult_mean) + 100), main=title, type="l", axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3)\n+plot(day.all, g0a, ylim=c(0, max(F2_adults) + 100), main=title, type="l", axes=F, lwd=2, xlab="", ylab="", cex=3, cex.lab=3, cex.axis=3, cex.main=3)\n lines(day.all, g1a, lwd = 2, lty = 1, col=2)\n-lines(day.all, F2_adult_mean, lwd = 2, lty = 1, col=4)\n+lines(day.all, F2_adults, lwd = 2, lty = 1, col=4)\n axis(1, at=c(1:12) * 30 - 15, cex.axis=3, labels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))\n axis(2, cex.axis=3)\n legend("topleft", c("P", "F1", "F2"), lty=c(1, 1, 1), col=c(1, 2, 4), cex=3)\n@@ -656,8 +647,8 @@\n     lines (day.all, g1a+g1a.std_error, col=2, lty=2)\n     lines (day.all, g1a-g1a.std_error, col=2, lty=2)\n     # Standard error for eggs\n-    lines (day.all, F2_adult_mean+g2a.std_error, col=4, lty=2)\n-    lines (day.all, F2_adult_mean-g2a.std_error, col=4, lty=2)\n+    lines (day.all, F2_adults+F2_adults.std_error, col=4, lty=2)\n+    lines (day.all, F2_adults-F2_adults.std_error, col=4, lty=2)\n }\n \n # Turn off device driver to flush output.\n'