-
Notifications
You must be signed in to change notification settings - Fork 1
add nexrad source functionality #177
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d34c345
added nexrad to sources in get_vpts
iskandari c398060
added get_vpts_nexrad helper function and associated test
iskandari 1531b52
added nexrad to generic get_vpts_coverage file
iskandari dc161c1
added separate getRad.nexrad_vpts_data_url as the processed data URL …
iskandari 4250dce
changed to getRad.nexrad_vpts_data_url
iskandari d299ff4
added nexrad test to generic test-get_vpts_coverage file
iskandari 8085e44
added specific test-get_vpts_coverage_nexrad test
iskandari 483630a
regenerated docs
iskandari 54c79a1
change get-vpts_nexrad to only read daily not to gunzip
iskandari dc82da0
added coverage functionality to get_vpts_nexrad
iskandari 152d606
test against check_odim_nexrad_scalar()
iskandari 62ddfef
test against check_odim_nexrad_scalar()
iskandari 0a9397a
lowercase what is in function argument, not the file
iskandari c2f5772
create small test coverage tibble as opposed to downloading entire co…
iskandari c7fc531
formatted modified files with styler
iskandari 0690ec8
Apply air formatting
iskandari c5b4d80
regenerated docs
iskandari 85f0548
removed nexrad_stations.rda; removed nexrad form vpts_coverage vignette
iskandari 82f1494
added newline at end of test-get_pvol_ee
iskandari f308a39
update vignette to also include birdcast dataset, also use svg output…
21f10b7
Ensure radar is taken from environment (was attempting to many downlo…
9d211f2
make sure proper call is used for errors
f18b7ef
Update R/get_vpts_nexrad.R
bart1 2187bc2
import .env and update documentation
18e3ce0
add news item
c96a961
Fix swedish test, seems that old data is not removed if no recent dat…
d0db93e
Change documentation from internal to noRd
bart1 a517ee9
run document
e499b78
rename to birdcast
1d74343
Merge branch 'main' into feature/source_birdcast_archive
34b7e91
fix coverage test
3f3b2be
fix test
c8c3afa
Avoid progress bars that cannot be silenced
77c614e
failures would be good to show to keep an eye on trends
73f8bf1
updated documentation
c899780
Merge pull request #186 from aloftdata/main
bart1 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #' Get VPTS file coverage from the public BirdCast NEXRAD archive | ||
| #' | ||
| #' Gets the VPTS file coverage from the public BirdCast NEXRAD archive. This is | ||
| #' derived from a coverage file at | ||
| #' <`r file.path(getOption("getRad.nexrad_vpts_data_url"), "coverage.csv")`>. By | ||
| #' default this file is cached for 6 hours. | ||
| #' | ||
| #' @param call A call used for error messaging. | ||
| #' @inheritParams req_cache_getrad | ||
| #' @return A data frame of the coverage file in the NEXRAD VPTS archive. | ||
| #' @noRd | ||
| #' @examplesIf interactive() | ||
| #' get_vpts_coverage_nexrad() | ||
| get_vpts_coverage_nexrad <- function( | ||
| use_cache = TRUE, | ||
| ..., | ||
| call = rlang::caller_env() | ||
| ) { | ||
| nexrad_vpts_data_url <- getOption("getRad.nexrad_vpts_data_url") | ||
|
|
||
| coverage_raw <- | ||
| httr2::request(nexrad_vpts_data_url) |> | ||
| httr2::req_url_path_append("coverage.csv") |> | ||
| req_user_agent_getrad() |> | ||
| req_retry_getrad() |> | ||
| req_cache_getrad(use_cache = use_cache) |> | ||
| httr2::req_progress(type = "down") |> | ||
| httr2::req_perform(error_call = call) |> | ||
| httr2::resp_body_raw() | ||
|
|
||
| coverage <- | ||
| vroom::vroom( | ||
| coverage_raw, | ||
| progress = FALSE, | ||
| show_col_types = FALSE | ||
| ) |> | ||
| dplyr::mutate( | ||
| source = string_extract(.data$directory, "^[^/]+"), | ||
| radar = string_extract(.data$directory, "(?<=daily\\/)[A-Z0-9]{4}"), | ||
| date = as.Date( | ||
| string_extract( | ||
| .data$directory, | ||
| "[0-9]{4}\\/[0-9]{2}\\/[0-9]{2}$" | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| return(coverage) | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #' Get VPTS data from the public BirdCast NEXRAD archive | ||
| #' | ||
| #' Gets VPTS data from the public BirdCast NEXRAD archive. | ||
| #' | ||
| #' @details | ||
| #' By default, data are retrieved from the public BirdCast S3 archive at | ||
| #' `https://birdcastdata.s3.amazonaws.com/nexrad/daily`. | ||
| #' | ||
| #' The expected path format is: | ||
| #' `"{radar}/{year}/{radar}_vpts_{year}{month}{day}.csv"`. | ||
| #' | ||
| #' @section Inner working: | ||
| #' - Checks that the requested radar is present in the NEXRAD coverage file. | ||
| #' - Checks that data exist for the requested radar/date combination. | ||
| #' - Constructs the S3 paths for the daily VPTS files from the coverage file. | ||
| #' - Performs parallel HTTP requests to fetch the VPTS CSV data. | ||
| #' - Parses the response bodies with the shared VPTS column classes. | ||
| #' - Uses uppercase NEXRAD radar codes for archive paths. | ||
| #' - Adds a column with the radar source. | ||
| #' | ||
| #' @param radar NEXRAD radar code. | ||
| #' @param rounded_interval Interval to fetch data for, rounded to nearest day. | ||
| #' @param coverage A data frame containing the coverage of the BirdCast NEXRAD | ||
| #' archive. If not provided, it will be fetched via the internet. | ||
| #' @return A tibble with VPTS data. | ||
| #' @keywords internal | ||
| get_vpts_nexrad <- function( | ||
| radar, | ||
| rounded_interval, | ||
| coverage = get_vpts_coverage_nexrad() | ||
| ) { | ||
| radar <- toupper(radar) | ||
|
|
||
| # Check that only one radar is provided. | ||
| check_odim_nexrad_scalar(radar) | ||
|
|
||
| # Check if the requested radar is present in the coverage. | ||
| if (!all(radar %in% coverage$radar)) { | ||
| missing_radar <- radar[!radar %in% coverage$radar] | ||
|
|
||
| cli::cli_abort( | ||
| "Can't find radar {.val {missing_radar}} in the NEXRAD coverage file | ||
| (see {.fun get_vpts_coverage}).", | ||
| missing_radar = missing_radar, | ||
| class = "getRad_error_nexrad_radar_not_found" | ||
| ) | ||
| } | ||
|
|
||
| # Check if the requested radar/date combination is present in the coverage. | ||
| filtered_coverage <- dplyr::filter( | ||
| coverage, | ||
| .data$radar %in% radar, | ||
| .data$date %within% rounded_interval | ||
| ) | ||
|
|
||
| if (nrow(filtered_coverage) == 0) { | ||
| cli::cli_abort( | ||
| "Can't find any data for the requested radar(s) and date(s).", | ||
| class = "getRad_error_date_not_found" | ||
| ) | ||
| } | ||
|
|
||
| # Convert the selected coverage rows into paths on the BirdCast NEXRAD archive. | ||
| s3_paths <- filtered_coverage |> | ||
| dplyr::mutate( | ||
| path = glue::glue( | ||
| "{radar}/{year}/{radar}_vpts_{year}{month}{day}.csv", | ||
| radar = .data$radar, | ||
| year = lubridate::year(.data$date), | ||
| month = sprintf("%02d", lubridate::month(.data$date)), | ||
| day = sprintf("%02d", lubridate::day(.data$date)) | ||
| ) | ||
| ) |> | ||
| dplyr::pull(.data$path) | ||
|
|
||
| # Read the VPTS CSV files. | ||
| nexrad_data_url <- "https://birdcastdata.s3.amazonaws.com/nexrad/daily" | ||
| radar_out <- tolower(radar) | ||
|
|
||
| out <- paste(nexrad_data_url, s3_paths, sep = "/") |> | ||
| read_vpts_from_url() |> | ||
| purrr::keep(.p = ~ as.logical(nrow(.x))) |> | ||
| purrr::list_rbind() | ||
|
|
||
| out$radar <- radar_out | ||
| out$source <- "nexrad" | ||
|
|
||
| out | ||
| } | ||
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.