Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 82:0c807f99a816 draft
Uploaded
author | greg |
---|---|
date | Tue, 14 Nov 2017 15:00:21 -0500 |
parents | 5729eb737082 |
children | 8f5c05be4efe |
comparison
equal
deleted
inserted
replaced
81:5729eb737082 | 82:0c807f99a816 |
---|---|
30 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=",") |
31 if (dim(temperature_data_frame)[2] == 6) { | 31 if (dim(temperature_data_frame)[2] == 6) { |
32 # The input data has the following 6 columns: | 32 # The input data has the following 6 columns: |
33 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX | 33 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX |
34 # Add a column containing the daylight length for each day. | 34 # Add a column containing the daylight length for each day. |
35 temperature_data_frame <- add_daylight_length(latitude, temperature_data_frame, num_rows) | 35 temperature_data_frame <- add_daylight_length(temperature_data_frame, num_rows) |
36 } | 36 } |
37 # Return the temperature_data_frame. | 37 # Return the temperature_data_frame. |
38 temperature_data_frame | 38 temperature_data_frame |
39 } | 39 } |
40 | 40 |
41 add_daylight_length = function(latitude, temperature_data_frame, num_days) { | 41 add_daylight_length = function(temperature_data_frame, num_rows) { |
42 # Return a vector of daylight length (photoperido profile) for | 42 # Return a vector of daylight length (photoperido profile) for |
43 # the number of days specified in the input temperature data | 43 # the number of days specified in the input temperature data |
44 # (from Forsythe 1995). | 44 # (from Forsythe 1995). |
45 p = 0.8333 | 45 p = 0.8333 |
46 latitude <- temperature_data_frame[1, 1] | |
46 daylight_length_vector <- NULL | 47 daylight_length_vector <- NULL |
47 for (i in 1:num_days) { | 48 for (i in 1:num_rows) { |
48 # Get the day of the year from the current row | 49 # Get the day of the year from the current row |
49 # of the temperature data for computation. | 50 # of the temperature data for computation. |
50 doy <- temperature_data_frame[i, 4] | 51 doy <- temperature_data_frame[i, 4] |
51 theta <- 0.2163108 + 2 * atan(0.9671396 * tan(0.00860 * (doy - 186))) | 52 theta <- 0.2163108 + 2 * atan(0.9671396 * tan(0.00860 * (doy - 186))) |
52 phi <- asin(0.39795 * cos(theta)) | 53 phi <- asin(0.39795 * cos(theta)) |
199 return = mort.prob | 200 return = mort.prob |
200 return | 201 return |
201 } | 202 } |
202 | 203 |
203 temperature_data_frame <- parse_input_data(opt$input, opt$num_days) | 204 temperature_data_frame <- parse_input_data(opt$input, opt$num_days) |
204 print(temperature_data_frame) | |
205 latitude <- temperature_data_frame[1, 1] | 205 latitude <- temperature_data_frame[1, 1] |
206 | 206 |
207 cat("Number of days: ", opt$num_days, "\n") | 207 cat("Number of days: ", opt$num_days, "\n") |
208 | 208 |
209 # Initialize matrix for results from all replications. | 209 # Initialize matrix for results from all replications. |