comparison insect_phenology_model.R @ 80:b701a134d640 draft

Uploaded
author greg
date Tue, 14 Nov 2017 14:49:29 -0500
parents 8752f4363a85
children 5729eb737082
comparison
equal deleted inserted replaced
79:2448bca7eac6 80:b701a134d640
9 make_option(c("-e", "--location"), action="store", dest="location", help="Selected location"), 9 make_option(c("-e", "--location"), action="store", dest="location", help="Selected location"),
10 make_option(c("-f", "--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"), 10 make_option(c("-f", "--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"),
11 make_option(c("-i", "--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"), 11 make_option(c("-i", "--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"),
12 make_option(c("-j", "--nymph_mort"), action="store", dest="nymph_mort", type="integer", help="Adjustment rate for nymph mortality"), 12 make_option(c("-j", "--nymph_mort"), action="store", dest="nymph_mort", type="integer", help="Adjustment rate for nymph mortality"),
13 make_option(c("-k", "--old_nymph_accum"), action="store", dest="old_nymph_accum", type="integer", help="Adjustment of DD accumulation (young nymph->old nymph)"), 13 make_option(c("-k", "--old_nymph_accum"), action="store", dest="old_nymph_accum", type="integer", help="Adjustment of DD accumulation (young nymph->old nymph)"),
14 make_option(c("-m", "--num_columns"), action="store", dest="num_columns", type="integer", help="Total number of columns in the temperature dataset"),
15 make_option(c("-n", "--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"), 14 make_option(c("-n", "--num_days"), action="store", dest="num_days", type="integer", help="Total number of days in the temperature dataset"),
16 make_option(c("-o", "--output"), action="store", dest="output", help="Output dataset"), 15 make_option(c("-o", "--output"), action="store", dest="output", help="Output dataset"),
17 make_option(c("-p", "--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"), 16 make_option(c("-p", "--oviposition"), action="store", dest="oviposition", type="integer", help="Adjustment for oviposition rate"),
18 make_option(c("-q", "--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"), 17 make_option(c("-q", "--photoperiod"), action="store", dest="photoperiod", type="double", help="Critical photoperiod for diapause induction/termination"),
19 make_option(c("-s", "--replications"), action="store", dest="replications", type="integer", help="Number of replications"), 18 make_option(c("-s", "--replications"), action="store", dest="replications", type="integer", help="Number of replications"),
24 23
25 parser <- OptionParser(usage="%prog [options] file", option_list=option_list) 24 parser <- OptionParser(usage="%prog [options] file", option_list=option_list)
26 args <- parse_args(parser, positional_arguments=TRUE) 25 args <- parse_args(parser, positional_arguments=TRUE)
27 opt <- args$options 26 opt <- args$options
28 27
29 parse_input_data = function(input_file, num_rows, num_columns) { 28 parse_input_data = function(input_file, num_rows) {
30 # Read in the input temperature datafile into a data frame. 29 # Read in the input temperature datafile into a data frame.
31 temperature_data_frame <- read.csv(file=input_file, header=T, strip.white=TRUE, sep=",") 30 temperature_data_frame <- read.csv(file=input_file, header=T, strip.white=TRUE, sep=",")
32 if (num_columns == 6) { 31 if (ncol(temperature_data_frame) == 6) {
33 # The input data has the following 6 columns: 32 # The input data has the following 6 columns:
34 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX 33 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX
35 # Add a column containing the daylight length for each day. 34 # Add a column containing the daylight length for each day.
36 temperature_data_frame <- add_daylight_length(latitude, temperature_data_frame, num_rows) 35 temperature_data_frame <- add_daylight_length(latitude, temperature_data_frame, num_rows)
37 } 36 }
199 } 198 }
200 return = mort.prob 199 return = mort.prob
201 return 200 return
202 } 201 }
203 202
204 cat("Number of columns: ", opt$num_columns, "\n") 203 temperature_data_frame <- parse_input_data(opt$input, opt$num_days)
205
206 temperature_data_frame <- parse_input_data(opt$input, opt$num_days, opt$num_columns)
207 print(temperature_data_frame) 204 print(temperature_data_frame)
208 latitude <- temperature_data_frame[1, 1] 205 latitude <- temperature_data_frame[1, 1]
209 206
210 cat("Number of days: ", opt$num_days, "\n") 207 cat("Number of days: ", opt$num_days, "\n")
211 208