comparison insect_phenology_model.R @ 143:7628ba67c7ff draft default tip

Uploaded
author greg
date Thu, 20 Dec 2018 09:11:29 -0500
parents b06b3881ecf0
children
comparison
equal deleted inserted replaced
142:b06b3881ecf0 143:7628ba67c7ff
321 parse_input_data = function(input_ytd, input_norm, location, start_date, end_date) { 321 parse_input_data = function(input_ytd, input_norm, location, start_date, end_date) {
322 # The end DOY for norm data prepended to ytd data. 322 # The end DOY for norm data prepended to ytd data.
323 prepend_end_doy_norm = 0; 323 prepend_end_doy_norm = 0;
324 # The start DOY for norm data appended to ytd data. 324 # The start DOY for norm data appended to ytd data.
325 append_start_doy_norm = 0; 325 append_start_doy_norm = 0;
326 cat("start_date: ", start_date, "\n");
327 cat("end_date: ", end_date, "\n");
328 if (is.null(start_date) && is.null(end_date)) { 326 if (is.null(start_date) && is.null(end_date)) {
329 # We're not dealing with a date interval. 327 # We're not dealing with a date interval.
330 date_interval = FALSE; 328 date_interval = FALSE;
331 if (is.null(input_ytd)) { 329 if (is.null(input_ytd)) {
332 # Base all dates on the current date since 30 year 330 # Base all dates on the current date since 30 year
338 year = get_year_from_date(start_date); 336 year = get_year_from_date(start_date);
339 # Get the DOY for start_date and end_date. 337 # Get the DOY for start_date and end_date.
340 start_date_doy = as.integer(strftime(start_date, format="%j")); 338 start_date_doy = as.integer(strftime(start_date, format="%j"));
341 end_date_doy = as.integer(strftime(end_date, format="%j")); 339 end_date_doy = as.integer(strftime(end_date, format="%j"));
342 } 340 }
343 cat("date_interval: ", date_interval, "\n");
344 if (is.null(input_ytd)) { 341 if (is.null(input_ytd)) {
345 # We're processing only the 30 year normals data. 342 # We're processing only the 30 year normals data.
346 processing_year_to_date_data = FALSE; 343 processing_year_to_date_data = FALSE;
347 if (is.null(start_date) && is.null(end_date)) { 344 if (is.null(start_date) && is.null(end_date)) {
348 # We're processing the entire year, so we can 345 # We're processing the entire year, so we can
376 start_date_ytd_row = 0; 373 start_date_ytd_row = 0;
377 start_date_norm_row = which(norm_data_frame$DOY==start_date_doy); 374 start_date_norm_row = which(norm_data_frame$DOY==start_date_doy);
378 } 375 }
379 end_date_ytd_row = which(temperature_data_frame$DATE==end_date); 376 end_date_ytd_row = which(temperature_data_frame$DATE==end_date);
380 if (length(end_date_ytd_row) > 0) { 377 if (length(end_date_ytd_row) > 0) {
381 cat("I'm here...\n");
382 end_date_ytd_row = end_date_ytd_row[1]; 378 end_date_ytd_row = end_date_ytd_row[1];
383 # The end date is contained within the input_ytd data. 379 # The end date is contained within the input_ytd data.
384 end_doy_ytd = as.integer(temperature_data_frame$DOY[end_date_ytd_row]); 380 end_doy_ytd = as.integer(temperature_data_frame$DOY[end_date_ytd_row]);
385 cat("end_doy_ytd: ", end_doy_ytd, "\n");
386 cat("end_date_ytd_row: ", end_date_ytd_row, "\n");
387 cat("start_date_ytd_row: ", start_date_ytd_row, "\n");
388 } else { 381 } else {
389 end_date_ytd_row = 0; 382 end_date_ytd_row = 0;
390 } 383 }
391 } else { 384 } else {
392 # We're plotting an entire year. 385 # We're plotting an entire year.
406 # Properly set the end_date to be Dec 31 of the year. 399 # Properly set the end_date to be Dec 31 of the year.
407 end_date = paste(year, "12", "31", sep="-"); 400 end_date = paste(year, "12", "31", sep="-");
408 # Save the first DOY to later check if start_date is Jan 1. 401 # Save the first DOY to later check if start_date is Jan 1.
409 start_doy_ytd = as.integer(temperature_data_frame$DOY[1]); 402 start_doy_ytd = as.integer(temperature_data_frame$DOY[1]);
410 end_doy_ytd = as.integer(temperature_data_frame$DOY[num_ytd_rows]); 403 end_doy_ytd = as.integer(temperature_data_frame$DOY[num_ytd_rows]);
411 cat("I'm here 2...\n");
412 cat("end_doy_ytd: ", end_doy_ytd, "\n");
413 cat("end_date_ytd_row: ", end_date_ytd_row, "\n");
414 cat("start_date_ytd_row: ", start_date_ytd_row, "\n");
415 } 404 }
416 } else { 405 } else {
417 # We're processing only the 30 year normals data, so create an empty 406 # We're processing only the 30 year normals data, so create an empty
418 # data frame for containing temperature data after it is converted 407 # data frame for containing temperature data after it is converted
419 # from the 30 year normals format to the year-to-date format. 408 # from the 30 year normals format to the year-to-date format.