Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
with:
extra-packages: any::covr, any::xml2
needs: coverage
cache-version: 2 # Increment this to bust the cache

- name: Test coverage
run: |
Expand Down
11 changes: 8 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: StreamCatTools
Type: Package
Title: 'StreamCatTools'
Version: 0.10.0
Version: 0.11.0
Authors@R: c(person(given = "Marc",
family = "Weber",
role = c("aut", "cre"),
Expand Down Expand Up @@ -52,7 +52,7 @@ Imports:
patchwork,
cowplot,
tigris,
ggplot2
ggplot2,
Suggests:
dplyr,
mapview,
Expand All @@ -67,7 +67,12 @@ Suggests:
stringr,
purrr,
lifecycle,
tidyselect
tidyselect,
DBI,
duckdb,
tictoc,
stats,
wk
Encoding: UTF-8
URL: https://usepa.github.io/StreamCatTools/, https://github.com/USEPA/StreamCatTools
BugReports: https://github.com/USEPA/StreamCatTools/issues
Expand Down
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export(lc_get_metric_names)
export(lc_get_nlcd)
export(lc_get_nni)
export(lc_get_params)
export(lc_nlcd)
export(lc_get_watershed)
export(lc_plotnni)
export(sc_fullname)
export(sc_get_comid)
Expand All @@ -16,7 +16,6 @@ export(sc_get_metric_names)
export(sc_get_nlcd)
export(sc_get_nni)
export(sc_get_params)
export(sc_nlcd)
export(sc_plotnni)
import(ggpattern)
import(ggplot2)
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# StreamCatTools 0.11.0

- Adds new `lc_get_watershed` function to return a lake watershed as an `sf`
feature for a LakeCat (NHDPlusV2 Waterbody) COMID from an S3-hosted,
HUC2-partitioned GeoParquet dataset
- Uses optional HUC2 query as well as retries, multi-threading and `duckdb`
to speed up retrieval of spatial data from AWS S3 bucket

# StreamCatTools 0.10.0

- Adds new functions `sc_get_nni()` and `lc_get_nni()` for ease of access to
Expand Down
99 changes: 44 additions & 55 deletions R/lc_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,21 @@ lc_get_data <- function(comid = NULL,
#' @param comid Return metric information for specific COMIDs
#' Syntax: comid=<comid1>,<comid2>
#'
#' @param state Return metric information for COMIDs within a specific state. Use a state's abbreviation to
#' query for a given state.
#' Syntax: state=<state1>,<state2>
#'
#' @param county Return metric information for COMIDs within a specific county.
#' Users must use the FIPS code, not county name, as a way to disambiguate counties.
#' Syntax: county=<county1>,<county1>
#'
#' @param region Return metric information for COMIDs within a specified hydroregion.
#' Syntax: region=<regionid1>,<regionid2>
#'
#' @param conus Return all COMIDs in the conterminous United States.
#' The default value is false.
#' Values: true|false
#'
#' @param showAreaSqKm Return the area in square kilometers of a given area of interest.
#' The default value is false.
#' Values: true|false
Expand All @@ -207,7 +222,7 @@ lc_get_data <- function(comid = NULL,
#' @examples
#' \dontrun{
#'
#' df <- lc_nlcd(comid='23783629', year='2019', aoi='ws') # Will show a deprecation warning
#' df <- lc_get_nlcd(comid='23783629', year='2019', aoi='ws') # Will show a deprecation warning
#'
#' df <- lc_get_nlcd(comid='23783629', year='2019', aoi='ws')
#'
Expand Down Expand Up @@ -294,31 +309,6 @@ lc_get_nlcd <- function(year = '2019',
return(final_df)
}

#' @rdname lc_get_nlcd
#' @export
#' @keywords internal
lc_nlcd <- function(year = '2019',
comid = NULL,
aoi = NULL,
showAreaSqKm = NULL,
showPctFull = NULL,
state = NULL,
county = NULL,
region = NULL,
conus = NULL,
countOnly = NULL) {
lifecycle::deprecate_warn("0.10.0", "lc_nlcd()", "lc_get_nlcd()")
lc_get_nlcd(year = '2019',
comid = NULL,
aoi = NULL,
showAreaSqKm = NULL,
showPctFull = NULL,
state = NULL,
county = NULL,
region = NULL,
conus = NULL,
countOnly = NULL)
}

#' @title Get NNI
#'
Expand Down Expand Up @@ -365,8 +355,8 @@ lc_nlcd <- function(year = '2019',
#' }

lc_get_nni <- function(year, aoi = NULL, comid = NULL,
showAreaSqKm = TRUE, showPctFull = NULL,
countOnly = NULL) {
showAreaSqKm = TRUE, showPctFull = NULL,
countOnly = NULL) {
# year must be a character string.
year_chr <- as.character(year)
# split multiple years supplied as a single string into
Expand Down Expand Up @@ -412,29 +402,29 @@ lc_get_nni <- function(year, aoi = NULL, comid = NULL,
)
# Vector of NNI metric names.
nni <- c(
'n_leg_',
'n_ags_',
'n_ff_',
'n_uf_',
'n_cf_',
'n_cr_',
'n_hw_',
'n_lw_',
'p_leg_',
'p_ags_',
'p_ff_',
'p_uf_',
'p_cr_',
'p_hw_',
'p_lw_'
)
'n_leg_',
'n_ags_',
'n_ff_',
'n_uf_',
'n_cf_',
'n_cr_',
'n_hw_',
'n_lw_',
'p_leg_',
'p_ags_',
'p_ff_',
'p_uf_',
'p_cr_',
'p_hw_',
'p_lw_'
)
# Add n_dep for available years
ndep_year_vec <- year_vec[!year_vec %in% c('1987', '1988', '1989')]
ndep_comb <- expand.grid('n_dep_', ndep_year_vec)
ndep_mets <- paste0(ndep_comb$Var1,
ndep_comb$Var2,
collapse = ",",
recycle0 = TRUE)
ndep_comb$Var2,
collapse = ",",
recycle0 = TRUE)
# Add p_dep for available years
pdep_year_vec <- year_vec[!year_vec %in% c('1987', '1988', '1989', '1990', '1991', '1992', '1993', '1994', '1995', '1996',
'2014', '2015', '2016', '2017')]
Expand All @@ -447,17 +437,17 @@ lc_get_nni <- function(year, aoi = NULL, comid = NULL,
ww_year_vec <- year_vec[year_vec %in% c('1988', '1990', '1992', '1996', '2000', '2004', '2008', '2012')]
ww_comb <- expand.grid(c('p_usgsww_', 'n_usgsww_'), ww_year_vec)
ww_mets <- paste0(ww_comb$Var1,
ww_comb$Var2,
collapse = ",",
recycle0 = TRUE)
ww_comb$Var2,
collapse = ",",
recycle0 = TRUE)
# Create a data frame of all NNI Metric and year combinations.
all_comb <- expand.grid(nni, year_vec)
# Concatenate the NLCD metric name with the supplied year(s) to create
# valid metric names to submit to the API.
nni_mets <- paste0(all_comb$Var1,
all_comb$Var2,
collapse = ",",
recycle0 = TRUE)
all_comb$Var2,
collapse = ",",
recycle0 = TRUE)
# Combine all NNI metrics
nni_mets_all <- paste0(nni_mets, ",", ndep_mets, ",", pdep_mets, ",", ww_mets)

Expand All @@ -472,5 +462,4 @@ lc_get_nni <- function(year, aoi = NULL, comid = NULL,
)
# End of function. Return a data frame.
return(final_df)
}

}
10 changes: 5 additions & 5 deletions R/lc_get_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ lc_get_params <- function(param = NULL) {
} else if(param == 'variable_info') {
params <- httr2::request('https://api.epa.gov/StreamCat/lakes/variable_info') |>
httr2::req_perform() |>
httr2::resp_body_string() |>
httr2::resp_body_raw() |>
readr::read_csv(show_col_types = FALSE) |>
dplyr::select(-UUID,-DATE_DOWNLOADED,-METADATA) |>
dplyr::rename(dataset=FINAL_TABLE,category=INDICATOR_CATEGORY,
Expand All @@ -57,14 +57,14 @@ lc_get_params <- function(param = NULL) {
} else if(param == 'categories'){
params <- httr2::request('https://api.epa.gov/StreamCat/lakes/variable_info') |>
httr2::req_perform() |>
httr2::resp_body_string() |>
httr2::resp_body_raw() |>
readr::read_csv(show_col_types = FALSE) |>
dplyr::select(INDICATOR_CATEGORY)
params <- sort(unique(params$INDICATOR_CATEGORY))
} else if(param == 'datasets'){
params <- httr2::request('https://api.epa.gov/StreamCat/lakes/variable_info') |>
httr2::req_perform() |>
httr2::resp_body_string() |>
httr2::resp_body_raw() |>
readr::read_csv(show_col_types = FALSE) |>
dplyr::select(DSNAME)
params <- sort(unique(params$DSNAME[!is.na(params$DSNAME)]))
Expand All @@ -80,7 +80,7 @@ lc_get_params <- function(param = NULL) {
} else if(param == 'county'){
params <- resp$county_options[[1]]
params$fips <- as.character(params$fips)
params <- params |> dplyr::select(-fips_str)
params <- params |> dplyr::select(-dplyr::any_of("fips_str"))
params$fips[nchar(params$fips) < 5] <- paste0('0',params$fips[nchar(params$fips) < 5])
params <- params[with(params,order(state,county_name)),]
}
Expand Down Expand Up @@ -168,7 +168,7 @@ lc_get_metric_names <- function(category = NULL,
resp <- tryCatch({
params <- httr2::request('https://api.epa.gov/StreamCat/lakes/variable_info') |>
httr2::req_perform() |>
httr2::resp_body_string() |>
httr2::resp_body_raw() |>
readr::read_csv(show_col_types = FALSE)
},error = function(e) {
message("An error occurred during req_perform(); the service may be down or function parameters may be mis-specified: ", e$message)
Expand Down
Loading
Loading