View source: R/extract_helpers.R
expand_by_hour | R Documentation |
This function is designed to facilitate the extraction of FVCOM predictions at times that are not integer hours (the temporal resolution at which predictions are made). To this end, this function expands a dataframe with non-integer hours to include both surrounding integer hours. The resultant dataframe can be passed extract
(outside of this function) to extract predictions for these integer hours. Predictions can then be interpolated to the non-integer hours of interest via shrink_by_hour
.
expand_by_hour(dat)
dat |
A dataframe that defines the FVCOM array date names, hours, layers (if applicable) and mesh cell IDs for which FVCOM predictions are desired (see |
The function returns a dataframe, as inputted, but in which any rows with a non-integer 'hour_dbl' value have been expanded into two rows, with the hour before and the hour after the non-integer hour respectively defined in a new column 'hour' (as required for extract
). A column 'order' is also added; this provides a unique identifier for each original row.
Edward Lavender
#### Define example data for which FVCOM predictions are desired # Times, including non integer hours timestamp <- as.POSIXct(c("2016-03-01 00:00:00", "2016-03-02 00:02:00", "2016-03-01 00:00:00")) dat <- data.frame(timestamp = timestamp) # Define columns required to extract FVCOM predictions (see fvcom.tbx::extract()) dat$hour_dbl <- lubridate::hour(dat$timestamp) + lubridate::minute(dat$timestamp)/60 + lubridate::second(dat$timestamp)/3600 dat$date_name <- date_name(dat$timestamp) dat$mesh_ID <- as.numeric(as.character(dat_mesh_around_nodes$ID))[1] #### Implement expand_by_hour() dat <- expand_by_hour(dat) # Now fvcom.tbx::extract() can be implemented to extract predictions # And then predictions at integer hours can be interpolated to the original timestamps.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.