Skip to content
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

1.1.1 #129

Merged
merged 4 commits into from
Oct 8, 2024
Merged

1.1.1 #129

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: amadeus
Title: Accessing and Analyzing Large-Scale Environmental Data
Version: 1.1.0
Version: 1.1.1
Authors@R: c(
person(given = "Mitchell", family = "Manware", role = c("aut", "ctb"), comment = c(ORCID = "0009-0003-6440-6106")),
person(given = "Insang", family = "Song", role = c("aut", "ctb"), comment = c(ORCID = "0000-0001-8732-3256")),
Expand Down
41 changes: 34 additions & 7 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ download_koppen_geiger <- function(
#' @return
#' * For \code{hash = FALSE}, NULL
#' * For \code{hash = TRUE}, an \code{rlang::hash_file} character.
#' * HDF (.hdf) files will be stored in
#' * HDF (.hdf) files will be stored in year/day_of_year sub-directories within
#' \code{directory_to_save}.
#' @importFrom Rdpack reprompt
#' @references
Expand Down Expand Up @@ -2493,17 +2493,27 @@ download_modis <- function(
nasa_earth_data_token,
"\" -O ",
directory_to_save,
splitter,
download_name,
"\n"
)

#### filter commands to non-existing files
download_command <- download_command[
which(
!file.exists(paste0(directory_to_save, download_name))
!file.exists(paste0(directory_to_save, splitter, download_name))
)
]

new_dirs <- unique(
sprintf("%s%s", directory_to_save, splitter)
)

lapply(
new_dirs,
function(x) dir.create(x, recursive = TRUE, showWarnings = FALSE)
)

# avoid any possible errors by removing existing command files
download_sink(commands_txt)
#### cat command only if file does not already exist
Expand All @@ -2517,7 +2527,7 @@ download_modis <- function(
)

message("Requests were processed.\n")
return(NULL)
return(download_hash(hash, directory_to_save))
}


Expand Down Expand Up @@ -2597,21 +2607,38 @@ download_modis <- function(
filelist,
value = TRUE
)
download_url <- sprintf("%s%s", ladsurl, filelist_sub)

download_name <- sapply(
strsplit(download_url, paste0("/", day, "/")), `[`, 2
strsplit(filelist_sub, paste0("/", day, "/")), `[`, 2
)

dir_str_julian <-
lapply(download_name, function(x) strsplit(x, ".A")[[1]][3])

dir_substr <- paste0(
substr(dir_str_julian, 1, 4), "/",
substr(dir_str_julian, 5, 7), "/"
)

new_dirs <- unique(
sprintf("%s%s", directory_to_save, dir_substr)
)

lapply(
new_dirs,
function(x) dir.create(x, recursive = TRUE, showWarnings = FALSE)
)

# Main wget run
download_command <- paste0(
"wget -e robots=off -np -R .html,.tmp ",
"-nH --cut-dirs=3 \"",
download_url,
filelist_sub,
"\" --header \"Authorization: Bearer ",
nasa_earth_data_token,
"\" -O ",
directory_to_save,
dir_substr,
download_name,
"\n"
)
Expand All @@ -2620,7 +2647,7 @@ download_modis <- function(
download_command <- download_command[
which(
!file.exists(
paste0(directory_to_save, download_name)
paste0(directory_to_save, dir_substr, download_name)
)
)
]
Expand Down
2 changes: 1 addition & 1 deletion man/download_modis.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-terraclimate.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ testthat::test_that("download_terraclimate (single year)", {
# function parameters
year <- 2019
variables <- "Precipitation"
directory_to_save <- paste0(tempdir(), "/terracclimate/")
directory_to_save <- paste0(tempdir(), "/terraclimate/")
# run download function
download_data(dataset_name = "terraclimate",
year = year,
Expand Down
Loading