-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "implement n_hours_per_met_file (#102)"
This reverts commit 0b81580.
- Loading branch information
1 parent
0b81580
commit 34fb920
Showing
5 changed files
with
31 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,42 @@ | ||
#' find_met_files searches for meteorological data files | ||
#' @author Ben Fasoli & James Mineau | ||
#' @author Ben Fasoli | ||
#' | ||
#' Searches for available meteorological files matching the given strftime | ||
#' compatible file naming convention | ||
#' | ||
#' @param t_start time of simulation start | ||
#' @param n_hours number of hours to run each simulation; negative indicates | ||
#' backward in time | ||
#' @param n_hours_per_met_file number of hours of meteorological data in each | ||
#' met file | ||
#' @param met_file_format grep compatible file naming convention to identify | ||
#' meteorological data files necessary for the timing of the simulation | ||
#' indicated by \code{t_start} and \code{n_hours} | ||
#' @param n_hours number of hours to run each simulation; negative indicates | ||
#' backward in time | ||
#' @param met_path directory to find meteorological data | ||
#' | ||
#' @import dplyr | ||
#' @export | ||
|
||
find_met_files <- function(t_start, n_hours, n_hours_per_met_file, | ||
met_file_format, met_path) { | ||
find_met_files <- function(t_start, met_file_format, n_hours, met_path) { | ||
require(dplyr) | ||
|
||
ts <- as.POSIXct(t_start, tz = 'UTC') | ||
|
||
is_backward <- n_hours < 0 | ||
met_bracket <- n_hours_per_met_file - 1 # ts can be in the middle of a met file | ||
|
||
# Generate the hours to search for | ||
if (is_backward) { | ||
met_hours <- seq( | ||
ts - as.difftime(abs(n_hours) + met_bracket, units = 'hours'), | ||
ts, | ||
by = 3600 | ||
) | ||
} else { | ||
met_hours <- seq( | ||
ts - as.difftime(met_bracket, units = 'hours'), | ||
ts + as.difftime(n_hours, units = 'hours'), | ||
by = 3600 | ||
) | ||
} | ||
|
||
# Format the request and remove duplicates | ||
request <- met_hours %>% | ||
strftime(tz = 'UTC', format = met_file_format) %>% | ||
unique() | ||
|
||
# Find the available files | ||
|
||
# TODO: implement n_hours_per_met_file to better determine file names at | ||
# varying time resolutions | ||
request <- as.POSIXct(t_start, tz='UTC') %>% | ||
c(. + c(1, -1, n_hours, is_backward * (n_hours - 5)) * 3600) %>% | ||
range() %>% | ||
(function(x) seq(x[1], x[2], by = 'hour')) %>% | ||
strftime(tz = 'UTC', format = met_file_format) | ||
|
||
available <- dir(met_path, full.names = T, recursive = T) | ||
available <- available[!grepl('.lock', available)] | ||
|
||
# Find the files that match the request | ||
|
||
idx <- do.call(c, lapply(request, function(pattern) { | ||
grep(pattern = pattern, x = available) | ||
})) | ||
|
||
if (any(idx < 1)) | ||
return() | ||
|
||
unique(available[idx]) # Available files that match the request | ||
unique(available[idx]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters