Skip to content

Commit

Permalink
Merge pull request #637 from adokter/fix_download_pvolfiles
Browse files Browse the repository at this point in the history
skip day instead of abort when no data available (fix #636)
  • Loading branch information
adokter authored Oct 19, 2023
2 parents 0b765f4 + ae0b39a commit 7121339
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions R/download_pvolfiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,19 @@ download_pvolfiles <- function(date_min, date_max, radar,
if (nrow(bucket_df) == 0) {
# Check if date is correct
prefix_tmp <- paste(gsub("-", "/", dates[i_d]), sep = "/")
assertthat::assert_that(assertthat::not_empty(
msg <- assertthat::validate_that(assertthat::not_empty(
aws.s3::get_bucket_df(bucket = bucket, prefix = prefix_tmp, max = 1)
),
msg = paste0(
"No data availble on the ", dates[i_d],
". Please check data availability for this date."
)
)
assertthat::assert_that(assertthat::not_empty(
if(msg != TRUE){
warning(msg)
next
}
msg <- assertthat::validate_that(assertthat::not_empty(
aws.s3::get_bucket_df(bucket = bucket, prefix = prefix, max = 1)
),
msg = paste0(
Expand All @@ -114,6 +118,10 @@ download_pvolfiles <- function(date_min, date_max, radar,
" https://noaa-nexrad-level2.s3.amazonaws.com/index.html"
)
)
if(msg != TRUE){
warning(msg)
next
}
}

# filter bucket with exact date
Expand All @@ -130,12 +138,17 @@ download_pvolfiles <- function(date_min, date_max, radar,
# throw out occasional NA keys, see e.g. 2015/03/01/KEPZ/
bucket_df %>% dplyr::filter(!is.na(.data$Key)) -> bucket_df

assertthat::assert_that(nrow(bucket_df) > 0,
msg <- assertthat::validate_that(nrow(bucket_df) > 0,
msg = paste0(
"No data available for ", radar, " on the ", dates[i_d],
"within the selected datetime range. Check radar code and data availability on",
" https://noaa-nexrad-level2.s3.amazonaws.com/index.html"
))
if(msg != TRUE){
warning(msg)
next
}


# create progress bar
message(paste0("\nDownloading pvol for ", prefix))
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-download_pvolfiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test_that("date input for download_pvolfiles() ", {
regexp = "date_max is not greater or equal to date_min",
fixed = TRUE
)
expect_error(
expect_warning(
suppressMessages(
download_pvolfiles(
as.POSIXct("2046-10-02 20:00", tz = "UTC"),
Expand Down Expand Up @@ -117,7 +117,7 @@ test_that("Check radar code for download_pvolfiles() ", {
"radar is not of length 1",
fixed = TRUE
)
expect_error(
expect_warning(
suppressMessages(
download_pvolfiles(date_min, date_max, "ABCD", directory, overwrite)
),
Expand Down

0 comments on commit 7121339

Please sign in to comment.