Last active
March 4, 2021 01:17
-
-
Save cboettig/ff00f8c95e5763d1db0b1c80272ed5ad to your computer and use it in GitHub Desktop.
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
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