comparison insect_phenology_model.R @ 41:f4d683709b7f draft

Uploaded
author greg
date Wed, 11 Apr 2018 13:26:56 -0400
parents d8e6304dc5e4
children fd3c00392fce
comparison
equal deleted inserted replaced
40:d8e6304dc5e4 41:f4d683709b7f
360 temperature_data_frame = read.csv(file=input_ytd, header=T, strip.white=TRUE, stringsAsFactors=FALSE, sep=","); 360 temperature_data_frame = read.csv(file=input_ytd, header=T, strip.white=TRUE, stringsAsFactors=FALSE, sep=",");
361 # Set the temperature_data_frame column names for access. 361 # Set the temperature_data_frame column names for access.
362 colnames(temperature_data_frame) = c("LATITUDE", "LONGITUDE", "DATE", "DOY", "TMIN", "TMAX"); 362 colnames(temperature_data_frame) = c("LATITUDE", "LONGITUDE", "DATE", "DOY", "TMIN", "TMAX");
363 # Get the start date. 363 # Get the start date.
364 start_date = temperature_data_frame$DATE[1]; 364 start_date = temperature_data_frame$DATE[1];
365 end_date = temperature_data_frame$DATE[num_days_ytd];
365 # See if we're in a leap year. 366 # See if we're in a leap year.
366 is_leap_year = is_leap_year(start_date); 367 is_leap_year = is_leap_year(start_date);
367 # Get the number of days in the year. 368 # Get the number of days in the year.
368 total_days = get_total_days(is_leap_year); 369 total_days = get_total_days(is_leap_year);
369 # Extract the year from the start date. 370 # Extract the year from the start date.
401 for (i in first_normals_append_row:total_days) { 402 for (i in first_normals_append_row:total_days) {
402 temperature_data_frame[i,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i); 403 temperature_data_frame[i,] = get_next_normals_row(norm_data_frame, year, is_leap_year, i);
403 } 404 }
404 # Add a column containing the daylight length for each day. 405 # Add a column containing the daylight length for each day.
405 temperature_data_frame = add_daylight_length(temperature_data_frame, total_days); 406 temperature_data_frame = add_daylight_length(temperature_data_frame, total_days);
406 return(list(temperature_data_frame, start_date, start_doy_ytd, end_doy_ytd, is_leap_year, total_days)); 407 return(list(temperature_data_frame, start_date, end_date, start_doy_ytd, end_doy_ytd, is_leap_year, total_days));
407 } 408 }
408 409
409 render_chart = function(ticks, date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval, 410 render_chart = function(ticks, date_labels, chart_type, plot_std_error, insect, location, latitude, start_date, end_date, days, maxval,
410 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL, 411 replications, life_stage, group, group_std_error, group2=NULL, group2_std_error=NULL, group3=NULL, group3_std_error=NULL,
411 life_stages_adult=NULL, life_stages_nymph=NULL) { 412 life_stages_adult=NULL, life_stages_nymph=NULL) {
502 # Parse the inputs. 503 # Parse the inputs.
503 data_list = parse_input_data(opt$input_ytd, opt$input_norm, opt$num_days_ytd); 504 data_list = parse_input_data(opt$input_ytd, opt$input_norm, opt$num_days_ytd);
504 temperature_data_frame = data_list[[1]]; 505 temperature_data_frame = data_list[[1]];
505 # Information needed for plots. 506 # Information needed for plots.
506 start_date = data_list[[2]]; 507 start_date = data_list[[2]];
507 end_date = temperature_data_frame$DATE[opt$num_days_ytd]; 508 end_date = data_list[[3]];
508 start_doy_ytd = data_list[[3]]; 509 start_doy_ytd = data_list[[4]];
509 end_doy_ytd = data_list[[4]]; 510 end_doy_ytd = data_list[[5]];
510 is_leap_year = data_list[[5]]; 511 is_leap_year = data_list[[6]];
511 total_days = data_list[[6]]; 512 total_days = data_list[[7]];
512 total_days_vector = c(1:total_days); 513 total_days_vector = c(1:total_days);
513 514
514 # Create copies of the temperature data for generations P, F1 and F2 if we're plotting generations separately. 515 # Create copies of the temperature data for generations P, F1 and F2 if we're plotting generations separately.
515 if (plot_generations_separately) { 516 if (plot_generations_separately) {
516 temperature_data_frame_P = data.frame(temperature_data_frame); 517 temperature_data_frame_P = data.frame(temperature_data_frame);