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.0.7 #122

Merged
merged 9 commits into from
Aug 30, 2024
Merged

1.0.7 #122

Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ vignettes/download_functions.Rmd
vignettes/epa_download.Rmd
vignettes/protected_datasets.Rmd
inst/extdata/air.2m
inst/extdata/nasa/token.txt
LICENSE.md
20 changes: 16 additions & 4 deletions 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 in R
Version: 1.0.3
Title: Accessing and Analyzing Large-Scale Environmental Data
Version: 1.0.6
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 All @@ -13,7 +13,18 @@ Maintainer: Kyle Messier <[email protected]>
Description: Functions are designed to facilitate access to and utility with large scale, publicly available environmental data in R. The package contains functions for downloading raw data files from web URLs (download_data()), processing the raw data files into clean spatial objects (process_covariates()), and extracting values from the spatial data objects at point and polygon locations (calc_covariates()). These functions call a series of source-specific functions which are tailored to each data sources/datasets particular URL structure, data format, and spatial/temporal resolution. The functions are tested, versioned, and open source and open access. For calc_sedc() method details, see Messier, Akita, and Serre (2012) <doi:10.1021/es203152a>.
Depends: R (>= 4.1.0)
Imports: dplyr, sf, sftime, stats, terra, methods, data.table, httr, rvest, exactextractr, utils, stringi, testthat (>= 3.0.0), parallelly, stars, future, future.apply, tidyr, rlang, nhdplusTools, archive, collapse, Rdpack
Suggests: covr, withr, knitr, rmarkdown, lwgeom, FNN, doRNG, devtools, stringr, tigris
Suggests:
covr,
withr,
knitr,
rmarkdown,
lwgeom,
FNN,
doRNG,
devtools,
stringr,
tigris,
spelling
RdMacros: Rdpack
Encoding: UTF-8
VignetteBuilder: knitr, rmarkdown
Expand All @@ -22,5 +33,6 @@ RoxygenNote: 7.3.2
Config/Needs/website: tidyverse/tidytemplate
Config/testhat/edition: 3
License: MIT + file LICENSE
URL: https://github.com/NIEHS/amadeus
URL: https://niehs.github.io/amadeus/
BugReports: https://github.com/NIEHS/amadeus/issues
Language: en-US
52 changes: 46 additions & 6 deletions R/calculate_covariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#' @return Calculated covariates as a data.frame or SpatVector object
#' @author Insang Song
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_covariates(
Expand Down Expand Up @@ -106,12 +108,14 @@ calc_covariates <-
...
)
}, error = function(e) {
print(e)
print(args(what_to_run))
stop(
paste0(
"Please refer to the argument list and the error message above ",
"to rectify the error.\n"
e,
"\n",
paste0(deparse(args(what_to_run)), collapse = "\n"),
"\n",
"Please refer to the argument list and ",
"the error message above to rectify the error.\n"
)
)
})
Expand Down Expand Up @@ -150,6 +154,8 @@ calc_covariates <-
#' @importFrom terra merge
#' @importFrom methods is
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_koppen_geiger(
Expand Down Expand Up @@ -307,6 +313,8 @@ calc_koppen_geiger <-
#' @importFrom future.apply future_Map
#' @importFrom collapse rowbind
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_nlcd(
Expand Down Expand Up @@ -471,6 +479,8 @@ calc_nlcd <- function(from,
#' @importFrom terra extract
#' @importFrom data.table year
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_ecoregion(
Expand Down Expand Up @@ -598,10 +608,12 @@ calc_ecoregion <-
#' @importFrom sf st_as_sf
#' @importFrom sf st_drop_geometry
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' locs <- data.frame(lon = -78.8277, lat = 35.95013, id = "001")
#' calc_modis_daily(
#' from = mod06l2_warp,
#' from = mod06l2_warp, # dervied from process_modis() example
#' locs = locs,
#' locs_id = "id",
#' radius = 0,
Expand Down Expand Up @@ -812,6 +824,8 @@ calc_modis_daily <- function(
#' @importFrom future.apply future_lapply
#' @importFrom parallelly availableWorkers
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' locs <- data.frame(lon = -78.8277, lat = 35.95013, id = "001")
#' locs <- terra::vect(locs, geom = c("lon", "lat"), crs = "EPSG:4326")
Expand Down Expand Up @@ -1026,6 +1040,8 @@ process_modis_swath, or process_blackmarble.")
#' @importFrom data.table month
#' @importFrom data.table as.data.table
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_temporal_dummies(
Expand Down Expand Up @@ -1308,6 +1324,8 @@ The result may not be accurate.\n",
#' @importFrom dplyr ungroup
#' @importFrom dplyr summarize
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_tri(
Expand Down Expand Up @@ -1397,10 +1415,12 @@ calc_tri <- function(
#' @importFrom terra project
#' @importFrom terra intersect
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_nei(
#' from = nei, # derived from process_nei example,
#' from = nei, # derived from process_nei example
#' locs = loc,
#' locs_id = "id"
#' )
Expand Down Expand Up @@ -1459,6 +1479,8 @@ calc_nei <- function(
#' @importFrom dplyr all_of
#' @importFrom stats setNames
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_hms(
Expand Down Expand Up @@ -1692,6 +1714,8 @@ calc_hms <- function(
#' @importFrom terra nlyr
#' @importFrom terra crs
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_gmted(
Expand Down Expand Up @@ -1813,6 +1837,8 @@ calc_gmted <- function(
#' @importFrom terra nlyr
#' @importFrom terra crs
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_narr(
Expand Down Expand Up @@ -1906,6 +1932,8 @@ calc_narr <- function(
#' @importFrom terra nlyr
#' @importFrom terra crs
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_geos(
Expand Down Expand Up @@ -1983,6 +2011,8 @@ calc_geos <- function(
#' @return a data.frame or SpatVector object
#' @importFrom methods is
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_sedac_population(
Expand Down Expand Up @@ -2098,6 +2128,8 @@ calc_sedac_population <- function(
#' @importFrom terra linearUnits
#' @importFrom methods is
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_sedac_groads(
Expand Down Expand Up @@ -2212,6 +2244,8 @@ calc_sedac_groads <- function(
#' @importFrom terra nlyr
#' @importFrom terra crs
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_merra2(
Expand Down Expand Up @@ -2301,6 +2335,8 @@ calc_merra2 <- function(
#' @importFrom terra nlyr
#' @importFrom terra crs
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_gridmet(
Expand Down Expand Up @@ -2386,6 +2422,8 @@ calc_gridmet <- function(
#' @importFrom terra nlyr
#' @importFrom terra crs
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' calc_terraclimate(
Expand Down Expand Up @@ -2469,6 +2507,8 @@ calc_terraclimate <- function(
#' @importFrom dplyr lag
#' @importFrom dplyr select
#' @examples
#' ## NOTE: Example is wrapped in `\dontrun{}` as function requires a large
#' ## amount of data which is not included in the package.
#' \dontrun{
#' loc <- data.frame(id = "001", lon = -78.90, lat = 35.97)
#' terracliamte_covar <- calc_terraclimate(
Expand Down
29 changes: 18 additions & 11 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,16 @@ download_data <-
)
},
error = function(e) {
print(e)
print(args(what_to_run))
stop(paste0("Please refer to the argument list and ",
"the error message above to rectify the error.\n"))
stop(
paste0(
e,
"\n",
paste0(deparse(args(what_to_run)), collapse = "\n"),
"\n",
"Please refer to the argument list and ",
"the error message above to rectify the error.\n"
)
)
}
)
}
Expand Down Expand Up @@ -1016,7 +1022,7 @@ download_merra2 <- function(
identifiers_df <- as.data.frame(identifiers)
colnames(identifiers_df) <- c("collection_id", "estd_name", "DOI")
if (!all(collection %in% identifiers_df$collection_id)) {
print(identifiers_df)
message(identifiers_df)
stop(paste0("Requested collection is not recognized.\n
Please refer to the table above to find a proper collection.\n"))
}
Expand Down Expand Up @@ -2181,15 +2187,17 @@ download_koppen_geiger <- function(
#'
#' \insertRef{article_roman2018vnp46}{amadeus}
#' @examples
#' \dontrun{
#' ## NOTE: Examples are wrapped in `/dontrun{}` to avoid sharing sensitive
#' ## NASA EarthData tokden information.
#' # example with MOD09GA product
#' download_modis(
#' product = "MOD09GA",
#' version = "61",
#' horizontal_tiles = c(8, 8),
#' vertical_tiles = c(4, 4),
#' date = c("2024-01-01", "2024-01-01"),
#' nasa_earth_data_token =
#' system.file("extdata", "nasa", "token.txt", package = "amadeus"),
#' nasa_earth_data_token = "./pathtotoken/token.txt",
#' directory_to_save = tempdir(),
#' acknowledgement = TRUE,
#' download = FALSE, # NOTE: download skipped for examples,
Expand All @@ -2207,8 +2215,7 @@ download_koppen_geiger <- function(
#' "extdata", "nasa", "LAADS_query.2024-08-02T12_49.csv",
#' package = "amadeus"
#' ),
#' nasa_earth_data_token =
#' system.file("extdata", "nasa", "token.txt", package = "amadeus"),
#' nasa_earth_data_token = "./pathtotoken/token.txt",
#' directory_to_save = tempdir(),
#' acknowledgement = TRUE,
#' download = FALSE, # NOTE: download skipped for examples,
Expand All @@ -2221,13 +2228,13 @@ download_koppen_geiger <- function(
#' horizontal_tiles = c(8, 8),
#' vertical_tiles = c(4, 4),
#' date = c("2024-01-01", "2024-01-01"),
#' nasa_earth_data_token =
#' system.file("extdata", "nasa", "token.txt", package = "amadeus"),
#' nasa_earth_data_token = "./pathtotoken/token.txt",
#' directory_to_save = tempdir(),
#' acknowledgement = TRUE,
#' download = FALSE, # NOTE: download skipped for examples,
#' remove_command = TRUE
#' )
#' }
# nolint end
#' @export
download_modis <- function(
Expand Down
Loading
Loading