Repository 'insect_phenology_model'
hg clone https://eddie.galaxyproject.org/repos/greg/insect_phenology_model

Changeset 123:e69e30d853fb (2018-05-31)
Previous changeset 122:8946ddb9d72c (2018-05-31) Next changeset 124:534658644efe (2018-06-01)
Commit message:
Uploaded
modified:
insect_phenology_model.R
b
diff -r 8946ddb9d72c -r e69e30d853fb insect_phenology_model.R
--- a/insect_phenology_model.R Thu May 31 13:09:32 2018 -0400
+++ b/insect_phenology_model.R Thu May 31 14:08:46 2018 -0400
[
b'@@ -269,10 +269,10 @@\n     }\n }\n \n-get_x_axis_ticks_and_labels = function(temperature_data_frame, prepend_end_doy_norm, append_start_doy_norm, restricted_date_interval) {\n+get_x_axis_ticks_and_labels = function(temperature_data_frame, prepend_end_doy_norm, append_start_doy_norm, date_interval) {\n     # Generate a list of ticks and labels for plotting the\n     # x axis.  There are several scenarios that affect this.\n-    # 1. If restricted_date_interval is TRUE:\n+    # 1. If date_interval is TRUE:\n     #    a.\n     if (prepend_end_doy_norm > 0) {\n         prepend_end_norm_row = which(temperature_data_frame$DOY==prepend_end_doy_norm);\n@@ -330,7 +330,7 @@\n             }\n             tick_index = get_tick_index(i, last_tick, ticks, month_labels)\n             if (!is.null(tick_index)) {\n-                if (restricted_date_interval) {\n+                if (date_interval) {\n                     # Add a tick for every day.\n                     ticks[tick_index] = i;\n                     # Add a blank month label so it is not displayed.\n@@ -412,9 +412,9 @@\n     if (is.null(start_date) && is.null(end_date)) {\n         # We\'re processing the entire year, possibly merging\n         # data from input_norm with data from input_ytd.\n-        restricted_date_interval = FALSE;\n+        date_interval = FALSE;\n     } else {\n-        restricted_date_interval = TRUE;\n+        date_interval = TRUE;\n         # Get the DOY for start_date and end_date.\n         start_date_doy = strftime(start_date, format="%j");\n         end_date_doy = strftime(end_date, format="%j");\n@@ -432,7 +432,7 @@\n         temperature_data_frame = read.csv(file=input_ytd, header=T, strip.white=TRUE, stringsAsFactors=FALSE, sep=",");\n         # Set the temperature_data_frame column names for access.\n         colnames(temperature_data_frame) = c("LATITUDE", "LONGITUDE", "DATE", "DOY", "TMIN", "TMAX");\n-        if (restricted_date_interval) {\n+        if (date_interval) {\n             # We\'re plotting a date interval.\n             start_date_ytd_row = which(temperature_data_frame$DATE==start_date);\n             if (start_date_ytd_row > 0) {\n@@ -448,30 +448,39 @@\n                 end_doy_ytd = as.integer(temperature_data_frame$DOY[end_date_ytd_row]);\n             }\n             date_str = start_date;\n+            # Extract the year from the start date.\n+            date_str_items = strsplit(date_str, "-")[[1]];\n+            year = date_str_items[1];\n         } else {\n             # We\'re plotting an entire year.\n             # Get the number of days contained in temperature_data_frame.\n             num_rows = dim(temperature_data_frame)[1];\n             # Get the start date and end date from temperature_data_frame.\n             start_date_ytd_row = 1;\n+            # Temporarily set start_date to get the year.\n             start_date = temperature_data_frame$DATE[1];\n             end_date_ytd_row = num_rows;\n             end_date = temperature_data_frame$DATE[num_rows];\n             date_str = format(start_date);\n+            # Extract the year from the start date.\n+            date_str_items = strsplit(date_str, "-")[[1]];\n+            # Get the year.\n+            year = date_str_items[1];\n+            # Properly set the start_date to be Jan 1 of the year.\n+            start_date = paste(year, "01", "01", sep="-");\n+            # Properly set the end_date to be Dec 31 of the year.\n+            end_date = paste(year, "12", "31", sep="-");\n             # Save the first DOY to later check if start_date is Jan 1.\n             start_doy_ytd = as.integer(temperature_data_frame$DOY[1]);\n             end_doy_ytd = as.integer(temperature_data_frame$DOY[num_rows]);\n         }\n-        # Extract the year from the start date.\n-        date_str_items = strsplit(date_str, "-")[[1]];\n-        year = date_str_items[1];\n     } else {\n         # We\'re processing only the 30 year normals data, so create an empty\n         # data frame for containing temperature data after it is converted\n         # fr'..b'row were set above.\n             if (start_date_ytd_row > 0 & end_date_ytd_row > 0) {\n                 # The date interval is contained within the input_ytd\n@@ -604,16 +613,15 @@\n                 # Define the next row for the year-to-date data from the 30 year normals data.\n                 append_start_doy_norm = end_doy_ytd + 1;\n                 first_norm_row = which(norm_data_frame$DOY == append_start_doy_norm);\n-                last_norm_row = which(norm_data_frame$DOY == total_days);\n                 # Append the 30 year normals data to the year-to-date data.\n-                for (i in first_norm_row:last_norm_row) {\n+                for (i in first_norm_row:total_days) {\n                     temperature_data_frame[i,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i);\n                 }\n             }\n         }\n     } else {\n         # We\'re processing only the 30 year normals data.\n-        if (restricted_date_interval) {\n+        if (date_interval) {\n             # Populate temperature_data_frame from norm_data_frame.\n             temperature_data_frame = from_30_year_normals(temperature_data_frame, norm_data_frame, start_date_doy, end_date_doy);\n         } else {\n@@ -726,19 +734,7 @@\n     return(valid_date);\n }\n \n-# Parse the inputs.\n-data_list = parse_input_data(opt$input_ytd, opt$input_norm, opt$location, opt$start_date, opt$end_date);\n-temperature_data_frame = data_list[[1]];\n-# Information needed for plots, some of these values are\n-# being reset here since in some case they were set above.\n-start_date = data_list[[2]];\n-end_date = data_list[[3]];\n-prepend_end_doy_norm = data_list[[4]];\n-append_start_doy_norm = data_list[[5]];\n-is_leap_year = data_list[[6]];\n-location = data_list[[7]];\n-\n-if (is.null(input_ytd)) {\n+if (is.null(opt$input_ytd)) {\n     processing_year_to_date_data = FALSE;\n } else {\n     processing_year_to_date_data = TRUE;\n@@ -751,7 +747,7 @@\n }\n if (is.null(opt$start_date) && is.null(opt$end_date)) {\n     # We\'re plotting an entire year.\n-    restricted_date_interval = FALSE;\n+    date_interval = FALSE;\n     # Display the total number of days in the Galaxy history item blurb.\n     if (processing_year_to_date_data) {\n         cat("Number of days year-to-date: ", opt$num_days_ytd, "\\n");\n@@ -768,7 +764,7 @@\n     # Galaxy should soon include support for a date selector\n     # at which point this tool should be enhanced to use it.\n     # Validate start_date.\n-    restricted_date_interval = TRUE;\n+    date_interval = TRUE;\n     # Calaculate the number of days in the date interval rather\n     # than using the number of rows in the input temperature data.\n     start_date = validate_date(opt$start_date);\n@@ -787,6 +783,17 @@\n     # Display the total number of days in the Galaxy history item blurb.\n     cat("Number of days in date interval: ", num_days, "\\n");\n }\n+# Parse the inputs.\n+data_list = parse_input_data(opt$input_ytd, opt$input_norm, opt$location, opt$start_date, opt$end_date);\n+temperature_data_frame = data_list[[1]];\n+# Information needed for plots, some of these values are\n+# being reset here since in some case they were set above.\n+start_date = data_list[[2]];\n+end_date = data_list[[3]];\n+prepend_end_doy_norm = data_list[[4]];\n+append_start_doy_norm = data_list[[5]];\n+is_leap_year = data_list[[6]];\n+location = data_list[[7]];\n \n # Create copies of the temperature data for generations P, F1 and F2 if we\'re plotting generations separately.\n if (plot_generations_separately) {\n@@ -796,7 +803,7 @@\n }\n \n # Get the ticks date labels for plots.\n-ticks_and_labels = get_x_axis_ticks_and_labels(temperature_data_frame, prepend_end_doy_norm, append_start_doy_norm, restricted_date_interval);\n+ticks_and_labels = get_x_axis_ticks_and_labels(temperature_data_frame, prepend_end_doy_norm, append_start_doy_norm, date_interval);\n ticks = c(unlist(ticks_and_labels[1]));\n date_labels = c(unlist(ticks_and_labels[2]));\n # All latitude values are the same, so get the value for plots from the first row.\n'