Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 74:9843894544a8 draft
Uploaded
author | greg |
---|---|
date | Tue, 14 Nov 2017 13:57:23 -0500 |
parents | 9bc7ab4da9e7 |
children | 392980f72514 |
comparison
equal
deleted
inserted
replaced
73:9bc7ab4da9e7 | 74:9843894544a8 |
---|---|
26 args <- parse_args(parser, positional_arguments=TRUE) | 26 args <- parse_args(parser, positional_arguments=TRUE) |
27 opt <- args$options | 27 opt <- args$options |
28 | 28 |
29 parse_input_data = function(input_file, num_rows, num_columns) { | 29 parse_input_data = function(input_file, num_rows, num_columns) { |
30 # Read in the input temperature datafile into a data frame. | 30 # 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=",") | |
31 if (num_rows == 6) { | 32 if (num_rows == 6) { |
32 # The input data has the following 6 columns: | 33 # The input data has the following 6 columns: |
33 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX | 34 # LATITUDE, LONGITUDE, DATE, DOY, TMIN, TMAX |
34 temperature_data_frame <- read.csv(file=input_file, header=T, strip.white=TRUE, sep=",") | |
35 # Add a column containing the daylight length for each day. | 35 # Add a column containing the daylight length for each day. |
36 temperature_data_frame <- add_daylight_length(latitude, temperature_data_frame, opt$num_days) | 36 temperature_data_frame <- add_daylight_length(latitude, temperature_data_frame, num_days) |
37 temperature_data_frame | 37 } |
38 } | 38 # Return the temperature_data_frame. |
39 temperature_data_frame | |
39 } | 40 } |
40 | 41 |
41 add_daylight_length = function(latitude, temperature_data_frame, num_days) { | 42 add_daylight_length = function(latitude, temperature_data_frame, num_days) { |
42 # Return a vector of daylight length (photoperido profile) for | 43 # Return a vector of daylight length (photoperido profile) for |
43 # the number of days specified in the input temperature data | 44 # the number of days specified in the input temperature data |
53 # Compute the length of daylight for the day of the year. | 54 # Compute the length of daylight for the day of the year. |
54 daylight_length_vector[i] <- 24 - (24 / pi * acos((sin(p * pi / 180) + sin(latitude * pi / 180) * sin(phi)) / (cos(latitude * pi / 180) * cos(phi)))) | 55 daylight_length_vector[i] <- 24 - (24 / pi * acos((sin(p * pi / 180) + sin(latitude * pi / 180) * sin(phi)) / (cos(latitude * pi / 180) * cos(phi)))) |
55 } | 56 } |
56 # Append daylight_length_vector as a new column to temperature_data_frame. | 57 # Append daylight_length_vector as a new column to temperature_data_frame. |
57 temperature_data_frame[, 7] <- daylight_length_vector | 58 temperature_data_frame[, 7] <- daylight_length_vector |
58 # Return the altered temperature_data_frame. | 59 # Return the temperature_data_frame. |
59 temperature_data_frame | 60 temperature_data_frame |
60 } | 61 } |
61 | 62 |
62 get_temperature_at_hour = function(latitude, temperature_data_frame, row, num_days) { | 63 get_temperature_at_hour = function(latitude, temperature_data_frame, row, num_days) { |
63 # Base development threshold for Brown Marmolated Stink Bug | 64 # Base development threshold for Brown Marmolated Stink Bug |
198 } | 199 } |
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_rows, opt$num_columns) | 204 temperature_data_frame <- parse_input_data(opt$input, opt$num_days, opt$num_columns) |
204 latitude <- temperature_data_frame[1, 1] | 205 latitude <- temperature_data_frame[1, 1] |
205 | 206 |
206 cat("Number of days: ", opt$num_days, "\n") | 207 cat("Number of days: ", opt$num_days, "\n") |
207 | 208 |
208 # Initialize matrix for results from all replications. | 209 # Initialize matrix for results from all replications. |