changeset 22:cd4d17bf3b9e draft

Uploaded
author greg
date Thu, 09 Nov 2017 08:09:12 -0500
parents a61f74f6d165
children 7fb723bc93b4
files insect_phenology_model.R
diffstat 1 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/insect_phenology_model.R	Thu Nov 09 08:08:59 2017 -0500
+++ b/insect_phenology_model.R	Thu Nov 09 08:09:12 2017 -0500
@@ -6,7 +6,6 @@
     make_option(c("-a", "--adult_mort"), action="store", dest="adult_mort", type="integer", help="Adjustment rate for adult mortality"),
     make_option(c("-b", "--adult_accum"), action="store", dest="adult_accum", type="integer", help="Adjustment of DD accumulation (old nymph->adult)"),
     make_option(c("-c", "--egg_mort"), action="store", dest="egg_mort", type="integer", help="Adjustment rate for egg mortality"),
-    make_option(c("-d", "--latitude"), action="store", dest="latitude", type="double", help="Latitude of selected location"),
     make_option(c("-e", "--location"), action="store", dest="location", help="Selected location"),
     make_option(c("-f", "--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"),
     make_option(c("-i", "--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"),
@@ -18,8 +17,7 @@
     make_option(c("-q", "--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"),
     make_option(c("-s", "--replications"), action="store", dest="replications", type="integer", help="Number of replications"),
     make_option(c("-t", "--se_plot"), action="store", dest="se_plot", help="Plot SE"),
-    make_option(c("-u", "--year"), action="store", dest="year", type="integer", help="Starting year"),
-    make_option(c("-v", "--temperature_dataset"), action="store", dest="temperature_dataset", help="Temperature data for selected location"),
+    make_option(c("-v", "--input"), action="store", dest="input", help="Temperature data for selected location"),
     make_option(c("-y", "--young_nymph_accum"), action="store", dest="young_nymph_accum", type="integer", help="Adjustment of DD accumulation (egg->young nymph)")
 )
 
@@ -27,17 +25,17 @@
 args <- parse_args(parser, positional_arguments=TRUE)
 opt <- args$options
 
-data.input=function(loc, year, temperature.dataset)
+get_temperature_file_path=function(loc, temperature_data)
 {
     expdata <- matrix(rep(0, opt$num_days * 3), nrow=opt$num_days)
-    namedat <- paste(loc,  year, ".Rdat", sep="")
-    temp.data <- read.csv(file=temperature.dataset, header=T)
-
     expdata[,1] <- c(1:opt$num_days)
     # Minimum
-    expdata[,2] <- temp.data[c(1:opt$num_days), 3]
+    expdata[,2] <- temperature_data[c(1:opt$num_days), 3]
     # Maximum
-    expdata[,3] <- temp.data[c(1:opt$num_days), 2]
+    expdata[,3] <- temperature_data[c(1:opt$num_days), 2]
+    date <- temperature_data[1, 3]
+    year <- substr(date, 1, 4)
+    namedat <- paste(loc,  year, ".Rdat", sep="")
     save(expdata, file=namedat)
     namedat
 }
@@ -211,8 +209,10 @@
 cat("(young nymph->old nymph): ", opt$old_nymph_accum, "\n")
 cat("(old nymph->adult): ", opt$adult_accum, "\n")
 
-# Read in the input temperature datafile
-temperature_file_path <- data.input(opt$location, opt$year, opt$temperature_dataset)
+# Read in the input temperature datafile into a Data Frame object.
+temperature_data <= temp.data <- read.csv(file=opt$input, header=T, sep=",")
+temperature_file_path <- get_temperature_file_path(opt$location, temperature_data)
+latitude <- temperature_data[1, 1]
 
 # Initialize matrix for results from all replications
 S0.rep <- S1.rep <- S2.rep <- S3.rep <- S4.rep <- S5.rep <- matrix(rep(0, opt$num_days * opt$replications), ncol = opt$replications)
@@ -230,7 +230,7 @@
     # complete matrix for the population
     vec.mat <- t(matrix(vec.mat, nrow=5))
     # complete photoperiod profile in a year, requires daylength function
-    ph.p <- daylength(opt$latitude, opt$num_days)
+    ph.p <- daylength(latitude, opt$num_days)
 
     # time series of population size
     tot.pop <- NULL
@@ -246,11 +246,11 @@
     # start tick
     ptm <- proc.time()
 
-    # all the days
+    # All the days included in the input temperature dataset.
     for (day in 1:opt$num_days) {
         # photoperiod in the day
         photoperiod <- ph.p[day]
-        temp.profile <- hourtemp(opt$latitude, day, temperature_file_path, opt$num_days)
+        temp.profile <- hourtemp(latitude, day, temperature_file_path, opt$num_days)
         mean.temp <- temp.profile[1]
         dd.temp <- temp.profile[2]
         dd.day[day] <- dd.temp
@@ -265,7 +265,7 @@
             vec.ind <- vec.mat[i,]
             # first of all, still alive?  
             # adjustment for late season mortality rate
-            if (opt$latitude < 40.0) {
+            if (latitude < 40.0) {
                 post.mort <- 1
                 day.kill <- 300
             }