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

0.1.2 #28

Merged
merged 11 commits into from
Feb 29, 2024
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: amadeus
Title: AMADEUS: A Mechanism/Machine for Data, Environments, and User Setup
Version: 0.1.1
Version: 0.1.2
Authors@R: c(
person("Kyle", "Messier", , "kyle.messier@nih.gov", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9508-9623")),
person("Mitchell", "Manware", role = c("aut", "ctb"), comment = c(ORCID = "0009-0003-6440-6106")),
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export(download_aqs_data)
export(download_data)
export(download_ecoregion_data)
export(download_epa_certificate)
export(download_geos_cf_data)
export(download_geos_data)
export(download_gmted_data)
export(download_hms_data)
export(download_koppen_geiger_data)
Expand Down
60 changes: 28 additions & 32 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' Please refer to:
#' * \link{download_aqs_data}: "aqs", "AQS"
#' * \link{download_ecoregion_data}: "ecoregion"
#' * \link{download_geos_cf_data}: "geos"
#' * \link{download_geos_data}: "geos"
#' * \link{download_gmted_data}: "gmted", "GMTED"
#' * \link{download_koppen_geiger_data}: "koppen", "koppengeiger"
#' * \link{download_merra2_data}: "merra2", "merra", "MERRA", "MERRA2"
Expand Down Expand Up @@ -49,7 +49,7 @@ download_data <-
what_to_run <- switch(dataset_name,
aqs = download_aqs_data,
ecoregion = download_ecoregion_data,
geos = download_geos_cf_data,
geos = download_geos_data,
gmted = download_gmted_data,
koppen = download_koppen_geiger_data,
koppengeiger = download_koppen_geiger_data,
Expand Down Expand Up @@ -144,7 +144,7 @@ download_aqs_data <-
data_download_acknowledgement =
data_download_acknowledgement
)
#### 2. check for null parameteres
#### 2. check for null parameters
check_for_null_parameters(mget(ls()))
#### 3. directory setup
directory_to_download <- download_sanitize_path(directory_to_download)
Expand Down Expand Up @@ -370,25 +370,23 @@ download_ecoregion_data <- function(
#### 14. remove download command
download_remove_command(commands_txt = commands_txt,
remove = remove_command)
if (download) {
#### 15. unzip files
download_unzip(
file_name = download_name,
directory_to_unzip = directory_to_save,
unzip = unzip
)
#### 16. remove zip files
download_remove_zips(
remove = remove_zip,
download_name = download_name
)
}
#### 15. unzip files
download_unzip(
file_name = download_name,
directory_to_unzip = directory_to_save,
unzip = unzip
)
#### 16. remove zip files
download_remove_zips(
remove = remove_zip,
download_name = download_name
)
}

# nolint start
#' Download atmospheric composition data from the NASA Global Earth Observing System (GEOS) model.
#' @description
#' The \code{download_goes_cf_data()} function accesses and downloads various
#' The \code{download_geos_data()} function accesses and downloads various
#' atmospheric composition collections from the [NASA Global Earth Observing System (GEOS) model](https://gmao.gsfc.nasa.gov/GEOS_systems/).
# nolint end
#' @param date_start character(1). length of 10. Start date for downloading
Expand All @@ -409,7 +407,7 @@ download_ecoregion_data <- function(
#' @author Mitchell Manware, Insang Song
#' @return NULL;
#' @export
download_geos_cf_data <- function(
download_geos_data <- function(
date_start = "2023-09-01",
date_end = "2023-09-01",
collection =
Expand Down Expand Up @@ -643,24 +641,22 @@ download_gmted_data <- function(
download = download,
system_command = system_command
)
#### 18. Remove command file
#### 17. Remove command file
download_remove_command(
commands_txt = commands_txt,
remove = remove_command
)
if (download) {
#### 17. end if unzip == FALSE
download_unzip(
file_name = download_name,
directory_to_unzip = directory_to_save,
unzip = unzip
)
#### 19. remove zip files
download_remove_zips(
remove = remove_zip,
download_name = download_name
)
}
#### 18. end if unzip == FALSE
download_unzip(
file_name = download_name,
directory_to_unzip = directory_to_save,
unzip = unzip
)
#### 19. remove zip files
download_remove_zips(
remove = remove_zip,
download_name = download_name
)
}

# nolint start
Expand Down
2 changes: 1 addition & 1 deletion R/download_test_support.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#' Check if sample of download URLs have HTTP Status 200
#' @param url Download URL to be checked.
#' @param method httr method to obtain URL (`"HEAD"`` or `"GET"`)
#' @param method httr method to obtain URL (`"HEAD"` or `"GET"`)
#' @author Insang Song; Mitchell Manware
#' @importFrom httr HEAD
#' @importFrom httr GET
Expand Down
20 changes: 12 additions & 8 deletions R/process.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#' - [`process_nlcd`]: `"nlcd"`, `"NLCD"`
#' - [`process_tri`]: `"tri"`, `"TRI"`
#' - [`process_nei`]: `"nei"`, `"NEI`
#' - [`process_geos`]: `"geos"`
#' - [`process_gmted`]: `"gmted"`, `"GMTED"`
#' - [`process_aqs`]: `"aqs"`, `"AQS"`
#' - [`process_hms`]: `"hms"`, `"HMS"`, `"smoke"`
Expand Down Expand Up @@ -76,8 +77,12 @@ process_covariates <-
}, error = function(e) {
print(e)
print(args(what_to_run))
stop("Please refer to the argument list and
the error message above to rectify the error.\n")
stop(
paste0(
"Please refer to the argument list and the error message above to ",
"rectify the error.\n"
)
)
})

return(res_covariate)
Expand Down Expand Up @@ -618,7 +623,7 @@ process_nlcd <-
#' @export
process_ecoregion <-
function(
path = "./input/data/ecoregions/raw/us_eco_l3_state_boundaries.shp"
path = NULL
) {
ecoreg <- terra::vect(path)
ecoreg <- ecoreg[, grepl("^(L2_KEY|L3_KEY)", names(ecoreg))]
Expand Down Expand Up @@ -655,8 +660,7 @@ process_conformity <-
locs_epsg <- locs$crs_dt
} else {
if (!all(keyword %in% names(locs))) {
stop("locs should be stdt or
have 'lon', 'lat', (and 'time') fields.\n")
stop("locs should be stdt or have 'lon', 'lat', (and 'time') fields.\n")
}
if (!methods::is(locs, "SpatVector")) {
if (methods::is(locs, "sf")) {
Expand Down Expand Up @@ -1318,7 +1322,7 @@ process_gmted <- function(
process_narr <- function(
date = c("2023-09-01", "2023-09-01"),
variable = NULL,
path = "../../data/covariates/narr/") {
path = NULL) {
#### directory setup
path <- download_sanitize_path(path)
#### check for variable
Expand Down Expand Up @@ -1453,7 +1457,7 @@ process_narr <- function(
}

#' Import and clean GEOS-CF data downloaded with
#' `download_geos_cf_data` or `download_data(dataset_name = "geos")`. Function
#' `download_geos_data` or `download_data(dataset_name = "geos")`. Function
#' returns a SpatRast object containing the user-defined variables of interest.
#' Layer names indicate the variable, pressure level, date (YYYYMMDD), and, if
#' applicable, the hour (HHMMSS).
Expand All @@ -1474,7 +1478,7 @@ process_narr <- function(
process_geos <-
function(date = c("2018-01-01", "2018-01-01"),
variable = NULL,
path = "../../data/covariates/geos_cf/") {
path = NULL) {
#### directory setup
path <- download_sanitize_path(path)
#### check for variable
Expand Down
2 changes: 1 addition & 1 deletion man/check_url_status.Rd

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

2 changes: 1 addition & 1 deletion man/download_data.Rd

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

8 changes: 4 additions & 4 deletions man/download_geos_cf_data.Rd → man/download_geos_data.Rd

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

1 change: 1 addition & 0 deletions man/process_covariates.Rd

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

4 changes: 1 addition & 3 deletions man/process_ecoregion.Rd

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

6 changes: 3 additions & 3 deletions man/process_geos.Rd

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

2 changes: 1 addition & 1 deletion man/process_narr.Rd

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

16 changes: 16 additions & 0 deletions tests/testthat/test-calculate_covariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ testthat::test_that("calc_dummies works well", {

})

testthat::test_that("calc_temporal_dummies errors.", {
withr::local_package("terra")
ncp <- data.frame(lon = -78.8277, lat = 35.95013)
ncp$site_id <- "3799900018810101"
testthat::expect_error(
calc_temporal_dummies(
ncp
)
)
testthat::expect_error(
calc_temporal_dummies(
terra::vect(ncp)
)
)
})

testthat::test_that("calc_ecoregion works well", {
withr::local_package("terra")
withr::local_package("sf")
Expand Down
Loading