-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement n_hours_per_met_file #102
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
feee7b1
num hours per met file
jmineau 944e688
only call find_met_files twice if met_subgrid is enabled
jmineau e93e780
implement met_hours using n_hours_per_met_file
jmineau f6128a9
call unique on request and output
jmineau da53c9d
add n_hours_per_met_file param to stilt_cli
jmineau a92d9fd
n_hours_per_met_file guidance
jmineau 6ab0091
Merge branch 'main' into foward_met_files
John-C-Lin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,42 +1,61 @@ | ||
#' find_met_files searches for meteorological data files | ||
#' @author Ben Fasoli | ||
#' @author Ben Fasoli & James Mineau | ||
#' | ||
#' 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, met_file_format, n_hours, met_path) { | ||
find_met_files <- function(t_start, n_hours, n_hours_per_met_file, | ||
met_file_format, met_path) { | ||
require(dplyr) | ||
|
||
|
||
ts <- as.POSIXct(t_start, tz = 'UTC') | ||
is_backward <- n_hours < 0 | ||
|
||
# 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) %>% | ||
jmineau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
range() %>% | ||
(function(x) seq(x[1], x[2], by = 'hour')) %>% | ||
strftime(tz = 'UTC', format = met_file_format) | ||
|
||
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 | ||
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]) | ||
|
||
unique(available[idx]) # Available files that match the request | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding guidance about how to know what value to set, since ARL met files can be a bit of a black box to users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had any experience with ARL met files other than the HRRR archive that Lin Group keeps on CHPC. @tartanrunner25 do you have any suggestions for user guidance on determining the number of hours in an ARL met file?