Skip to content

Commit

Permalink
#351 change from sf crop fxn to dplyr filtering for arc2 fxn
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Jun 1, 2020
1 parent 2179546 commit b2f85d6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Description: Client for many 'NOAA' data sources including the 'NCDC' climate
for 'NOAA' sea ice data, the 'NOAA' severe weather inventory, 'NOAA' Historical
Observing 'Metadata' Repository ('HOMR') data, 'NOAA' storm data via 'IBTrACS',
tornado data via the 'NOAA' storm prediction center, and more.
Version: 0.9.6.97
Version: 0.9.6.98
License: MIT + file LICENSE
Encoding: UTF-8
Language: en-US
Expand Down
15 changes: 3 additions & 12 deletions R/arc2.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#' @param date (character/date) one or more dates of the form YYYY-MM-DD
#' @param box (numeric) vector of length 4, of the form
#' `xmin, ymin, xmax, ymax`. optional. If not given, no spatial filtering
#' is done. If given, we use `sf::st_crop()` on a combined set of all dates,
#' is done. If given, we use `dplyr::filter()` on a combined set of all dates,
#' then split the output into tibbles by date
#' @param ... curl options passed on to [crul::verb-GET]
#' @references docs:
#' <ftp://ftp.cpc.ncep.noaa.gov/fews/fewsdata/africa/arc2/ARC2_readme.txt>
#' @note See [arc2_cache] for managing cached files
#' @section box parameter:
#' The `box` parameter filters the arc2 data to a bounding box you supply.
#' The function that does the cropping to the bounding box is `sf::st_crop`.
#' The function that does the cropping to the bounding box is `dplyr::filter`.
#' You can do any filtering you want on your own if you do not supply
#' `box` and then use whatever tools you want to filter the data by
#' lat/lon, date, precip values.
Expand Down Expand Up @@ -52,22 +52,13 @@ arc2 <- function(date, box = NULL, ...) {
res <- stats::setNames(res, vapply(dates, asdate, ""))
return(res)
}
check4pkg("sf")
assert(box, "numeric")
tmpdf <- dplyr::bind_rows(res)
filter_split(tmpdf, box)
}

filter_split <- function(x, box) {
z <- sf::st_as_sf(x, coords = c("lon", "lat"), crs = 4326)
cropped <- sf::st_crop(z, box)
cd <- data.frame(sf::st_coordinates(cropped))
df <- tibble::tibble(
date = cropped$date,
lon = cd$X,
lat = cd$Y,
precip = cropped$precip
)
df <- dplyr::filter(x, dplyr::between(lon, 9, 10), dplyr::between(lat, 4, 5))
split(df, df$date)
}

Expand Down
4 changes: 2 additions & 2 deletions man/arc2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b2f85d6

Please sign in to comment.