changeset 45:315c5e1bc44a draft

Uploaded
author greg
date Mon, 23 Apr 2018 10:19:06 -0400
parents c61d3d9d44db
children 0791cca1fc5c
files insect_phenology_model.R
diffstat 1 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/insect_phenology_model.R	Mon Apr 23 10:18:59 2018 -0400
+++ b/insect_phenology_model.R	Mon Apr 23 10:19:06 2018 -0400
@@ -13,7 +13,7 @@
     make_option(c("--life_stages"), action="store", dest="life_stages", help="Selected life stages for plotting"),
     make_option(c("--life_stages_adult"), action="store", dest="life_stages_adult", default=NULL, help="Adult life stages for plotting"),
     make_option(c("--life_stages_nymph"), action="store", dest="life_stages_nymph", default=NULL, help="Nymph life stages for plotting"),
-    make_option(c("--location"), action="store", dest="location", help="Selected location"),
+    make_option(c("--location"), action="store", dest="location", default=NULL, help="Selected location"),
     make_option(c("--min_clutch_size"), action="store", dest="min_clutch_size", type="integer", help="Adjustment of minimum clutch size"),
     make_option(c("--max_clutch_size"), action="store", dest="max_clutch_size", type="integer", help="Adjustment of maximum clutch size"),
     make_option(c("--num_days_ytd"), action="store", dest="num_days_ytd", default=NULL, type="integer", help="Total number of days in the year-to-date temperature dataset"),
@@ -353,7 +353,7 @@
     return(mortality.probability);
 }
 
-parse_input_data = function(input_ytd, input_norm, num_days_ytd) {
+parse_input_data = function(input_ytd, input_norm, num_days_ytd, location) {
     if (is.null(input_ytd)) {
         # We're analysing only the 30 year normals data, so create an empty
         # data frame for containing temperature data after it is converted
@@ -401,6 +401,10 @@
     if (!is_leap_year) {
         norm_data_frame = norm_data_frame[-c(60),];
     }
+    # Set the location to be the station name if the user elected no to enter it.
+    if (is.null(location)) {
+        location = norm_data_frame$NAME[1];
+    }
     if (is.null(input_ytd)) {
         # Convert the 30 year normals data to the year-to-date format.
         for (i in 1:total_days) {
@@ -428,7 +432,7 @@
     }
     # Add a column containing the daylight length for each day.
     temperature_data_frame = add_daylight_length(temperature_data_frame, total_days);
-    return(list(temperature_data_frame, start_date, end_date, start_doy_ytd, end_doy_ytd, is_leap_year, total_days));
+    return(list(temperature_data_frame, start_date, end_date, start_doy_ytd, end_doy_ytd, is_leap_year, total_days, location));
 }
 
 render_chart = function(ticks, date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval,
@@ -525,7 +529,7 @@
 cat("Year-to-date number of days: ", opt$num_days_ytd, "\n");
 
 # Parse the inputs.
-data_list = parse_input_data(opt$input_ytd, opt$input_norm, opt$num_days_ytd);
+data_list = parse_input_data(opt$input_ytd, opt$input_norm, opt$num_days_ytd, opt$location);
 temperature_data_frame = data_list[[1]];
 # Information needed for plots.
 start_date = data_list[[2]];
@@ -535,6 +539,7 @@
 is_leap_year = data_list[[6]];
 total_days = data_list[[7]];
 total_days_vector = c(1:total_days);
+location =  data_list[[8]];
 
 # Create copies of the temperature data for generations P, F1 and F2 if we're plotting generations separately.
 if (plot_generations_separately) {
@@ -1464,7 +1469,7 @@
             par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
             # Egg population size by generation.
             maxval = max(P_eggs+F1_eggs+F2_eggs) + 100;
-            render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude,
+            render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, location, latitude,
                 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=P_eggs, group_std_error=P_eggs.std_error,
                 group2=F1_eggs, group2_std_error=F1_eggs.std_error, group3=F2_eggs, group3_std_error=F2_eggs.std_error);
             # Turn off device driver to flush output.
@@ -1504,7 +1509,7 @@
                     group3 = F2_total_nymphs;
                     group3_std_error = F2_total_nymphs.std_error;
                 }
-                render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude,
+                render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, location, latitude,
                     start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=group, group_std_error=group_std_error,
                     group2=group2, group2_std_error=group2_std_error, group3=group3, group3_std_error=group3_std_error, life_stages_nymph=life_stage_nymph);
                 # Turn off device driver to flush output.
@@ -1554,7 +1559,7 @@
                     group3 = F2_total_adults;
                     group3_std_error = F2_total_adults.std_error;
                 }
-                render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude,
+                render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, location, latitude,
                     start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=group, group_std_error=group_std_error,
                     group2=group2, group2_std_error=group2_std_error, group3=group3, group3_std_error=group3_std_error, life_stages_adult=life_stage_adult);
                 # Turn off device driver to flush output.
@@ -1570,7 +1575,7 @@
             par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
             # Total population size by generation.
             maxval = max(P+F1+F2) + 100;
-            render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, opt$location, latitude,
+            render_chart(ticks, date_labels, "pop_size_by_generation", opt$plot_std_error, opt$insect, location, latitude,
                 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=P, group_std_error=P.std_error,
                 group2=F1, group2_std_error=F1.std_error, group3=F2, group3_std_error=F2.std_error);
             # Turn off device driver to flush output.
@@ -1587,7 +1592,7 @@
             par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
             # Egg population size.
             maxval = max(eggs+eggs.std_error) + 100;
-            render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude,
+            render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, location, latitude,
                 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=eggs, group_std_error=eggs.std_error);
             # Turn off device driver to flush output.
             dev.off();
@@ -1612,7 +1617,7 @@
                     group_std_error = old_nymphs.std_error;
                 }
                 maxval = max(group+group_std_error) + 100;
-                render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude,
+                render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, location, latitude,
                     start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=group, group_std_error=group_std_error,
                     life_stages_nymph=life_stage_nymph);
                 # Turn off device driver to flush output.
@@ -1643,7 +1648,7 @@
                     group_std_error = diapausing_adults.std_error
                 }
                 maxval = max(group+group_std_error) + 100;
-                render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude,
+                render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, location, latitude,
                     start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=group, group_std_error=group_std_error,
                     life_stages_adult=life_stage_adult);
                 # Turn off device driver to flush output.
@@ -1657,7 +1662,7 @@
             par(mar=c(5, 6, 4, 4), mfrow=c(3, 1));
             # Total population size.
             maxval = max(eggs+eggs.std_error, total_nymphs+total_nymphs.std_error, total_adults+total_adults.std_error) + 100;
-            render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, opt$location, latitude,
+            render_chart(ticks, date_labels, "pop_size_by_life_stage", opt$plot_std_error, opt$insect, location, latitude,
                 start_date, end_date, total_days_vector, maxval, opt$replications, life_stage, group=total_adults, group_std_error=total_adults.std_error,
                 group2=total_nymphs, group2_std_error=total_nymphs.std_error, group3=eggs, group3_std_error=eggs.std_error);
             # Turn off device driver to flush output.