Mercurial > repos > greg > insect_phenology_model
comparison insect_phenology_model.R @ 119:833f70d9001d draft
Uploaded
author | greg |
---|---|
date | Tue, 29 May 2018 14:31:39 -0400 |
parents | 9c998fd06628 |
children | 635b6dc6b268 |
comparison
equal
deleted
inserted
replaced
118:e0bd1edbd8e4 | 119:833f70d9001d |
---|---|
61 # Append vector vec as a new column to data_frame. | 61 # Append vector vec as a new column to data_frame. |
62 data_frame[,num_columns+1] = vec; | 62 data_frame[,num_columns+1] = vec; |
63 # Reset the column names with the additional column for later access. | 63 # Reset the column names with the additional column for later access. |
64 colnames(data_frame) = append(current_column_names, new_column_name); | 64 colnames(data_frame) = append(current_column_names, new_column_name); |
65 return(data_frame); | 65 return(data_frame); |
66 } | |
67 | |
68 extract_date_interval_rows = function(df, start_date, end_date) { | |
69 date_interval_rows = df[df$DATE >= start_date & sf$DATE <= end_date]; | |
70 return(date_interval_rows); | |
66 } | 71 } |
67 | 72 |
68 get_file_path = function(life_stage, base_name, life_stage_nymph=NULL, life_stage_adult=NULL) { | 73 get_file_path = function(life_stage, base_name, life_stage_nymph=NULL, life_stage_adult=NULL) { |
69 if (!is.null(life_stage_nymph)) { | 74 if (!is.null(life_stage_nymph)) { |
70 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph); | 75 lsi = get_life_stage_index(life_stage, life_stage_nymph=life_stage_nymph); |
396 # Get the start date. | 401 # Get the start date. |
397 start_date = temperature_data_frame$DATE[1]; | 402 start_date = temperature_data_frame$DATE[1]; |
398 end_date = temperature_data_frame$DATE[num_days]; | 403 end_date = temperature_data_frame$DATE[num_days]; |
399 } else { | 404 } else { |
400 # Extract the custom date interval from temperature_data_frame. | 405 # Extract the custom date interval from temperature_data_frame. |
401 temperature_data_frame = temperature_data_frame[date %between% c(start_date, end_date)] | 406 temperature_data_frame = extract_date_interval_rows(temperature_data_frame, start_date, end_date); |
402 } | 407 } |
403 # Extract the year from the start date. | 408 # Extract the year from the start date. |
404 date_str = format(start_date); | 409 date_str = format(start_date); |
405 date_str_items = strsplit(date_str, "-")[[1]]; | 410 date_str_items = strsplit(date_str, "-")[[1]]; |
406 year = date_str_items[1]; | 411 year = date_str_items[1]; |
424 if (is.null(start_date) && is.null(end_date)) { | 429 if (is.null(start_date) && is.null(end_date)) { |
425 # Get the number of days in the year. | 430 # Get the number of days in the year. |
426 total_days = get_total_days(is_leap_year); | 431 total_days = get_total_days(is_leap_year); |
427 } else { | 432 } else { |
428 # Extract the custom date interval from norm_data_frame. | 433 # Extract the custom date interval from norm_data_frame. |
429 norm_data_frame = norm_data_frame[date %between% c(start_date, end_date)] | 434 norm_data_frame = extract_date_interval_rows(norm_data_frame, start_date, end_date); |
430 # Use the pre-determined num_days for total_days. | 435 # Use the pre-determined num_days for total_days. |
431 total_days = num_days | 436 total_days = num_days |
432 } | 437 } |
433 # Set the location to be the station name if the user elected no to enter it. | 438 # Set the location to be the station name if the user elected no to enter it. |
434 if (is.null(location) | length(location)==0) { | 439 if (is.null(location) | length(location)==0) { |