Skip to content

Instantly share code, notes, and snippets.

@cboettig
Last active March 4, 2021 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cboettig/ff00f8c95e5763d1db0b1c80272ed5ad to your computer and use it in GitHub Desktop.
Save cboettig/ff00f8c95e5763d1db0b1c80272ed5ad to your computer and use it in GitHub Desktop.
library(tidync)
library(aws.s3)
download_noaa <- function(siteID,
interval = "6hr",
date = Sys.Date()-2,
cycle = "00",
dir = file.path(neon_dir(), "noaa")){
dir.create(dir, FALSE, TRUE)
prefix <- paste("noaa", paste0("NOAAGEFS_", interval),
siteID, date, cycle, sep="/")
object <- aws.s3::get_bucket("drivers",
prefix = prefix,
region = "data",
base_url = "ecoforecast.org")
#data <- purrr::map_chr(object, ~ .x$Key)
for(i in seq_along(object)){
aws.s3::save_object(object[[i]],
bucket = "drivers",
file = file.path(dir, object[[i]]$Key),
region = "data",
base_url = "ecoforecast.org")
}
}
stack_noaa <- function(dir = neon_dir()) {
files <- list.files(file.path(dir, "noaa"), pattern = "[.]nc",
recursive = TRUE, full.names = TRUE)
out <- purrr::map_dfr(files, function(x){
tidync::hyper_tibble(tidync::tidync(x))
}, .id = "file")
## Add metadata from filename as column...
out
}
############ and we're ready to go:
download_noaa("ABBY")
df <- stack_noaa()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment