Skip to content
Merged

Ngwmn #904

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
758533b
getting ready for NGWMN
ldecicco-USGS Mar 5, 2026
98a441d
gah
ldecicco-USGS Mar 9, 2026
3379d61
get all functions ready
ldecicco-USGS Mar 9, 2026
9ee4770
Get upstream data
ldecicco-USGS Mar 11, 2026
7d51660
from upstream
ldecicco-USGS Apr 20, 2026
72b2aa2
Updates from develop
ldecicco-USGS Apr 29, 2026
e32db79
Merge branch 'develop' of https://code.usgs.gov/water/dataRetrieval i…
ldecicco-USGS May 7, 2026
f45e702
upstream updates
ldecicco-USGS May 19, 2026
8f3ac58
Merge branch 'develop' of https://code.usgs.gov/water/dataRetrieval i…
ldecicco-USGS May 19, 2026
c881609
Merge branch 'main' of github.com:DOI-USGS/dataRetrieval into ngwmn
ldecicco-USGS Jun 2, 2026
c2947ba
some updates from API
ldecicco-USGS Jun 2, 2026
a125abf
updates from APIs
ldecicco-USGS Jun 2, 2026
977d870
rebuilding docs
ldecicco-USGS Jun 2, 2026
aba54d7
remove old code
ldecicco-USGS Jun 2, 2026
424b6f9
Merge branch 'develop' of github.com:DOI-USGS/dataRetrieval into ngwmn
ldecicco-USGS Jun 11, 2026
f06fcf5
remove old examples, add new ones
ldecicco-USGS Jun 11, 2026
c8c6dbd
Update R/get_ogc_documentation.R
ldecicco-USGS Jun 16, 2026
4758026
Add check for required arguments
ldecicco-USGS Jun 16, 2026
77df23c
Merge branch 'ngwmn' of github.com:ldecicco-USGS/dataRetrieval into n…
ldecicco-USGS Jun 16, 2026
cacc4ed
fix na bug
ldecicco-USGS Jun 23, 2026
7f65eb9
Adding read_ngwmn function
ldecicco-USGS Jun 23, 2026
6c6a2f7
Add some tests
ldecicco-USGS Jun 23, 2026
0e79ee8
add more tests
ldecicco-USGS Jun 23, 2026
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,7 +1,7 @@
Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrology and Water Quality Data
Version: 2.7.25
Version: 2.7.25.9000
Authors@R: c(
person("Laura", "DeCicco", role = c("aut","cre"),
email = "ldecicco@usgs.gov",
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export(readWQPdata)
export(readWQPqw)
export(readWQPsummary)
export(read_USGS_samples)
export(read_ngwmn)
export(read_ngwmn_lithology)
export(read_ngwmn_providers)
export(read_ngwmn_sites)
export(read_ngwmn_water_level)
export(read_ngwmn_well_construction)
export(read_waterdata)
export(read_waterdata_channel)
export(read_waterdata_combined_meta)
Expand Down
16 changes: 8 additions & 8 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ return full period of record.

dataRetrieval 2.7.23
===================
* Added data.table to Imports

* Added read_waterdata_stats_por and read_waterdata_stats_daterange to access USGS daily data statistics.
* Updated vignettes, examples, and README to reflect new stats functions.
* Added tests for read_waterdata_stats functions
* Added read_waterdata_field_meta, read_waterdata_combine_meta, and read_waterdata_channel
* Added read_ngwmn_water_levels, read_ngwmn_sites, read_ngwmn_providers, read_ngwmn_well_construction, read_ngwmn_lithology
* Removed readNWISgwl, readNWISmeas, and readNGWMN as services have been turned off
* Added data.table to Imports
* Updated next_req_url to allow paging through /statistics API output
* Added deprecation message to readNWISstat function
* Specify "UTC" attribute for returned time
* Improved time documentation for waterdata functions
* Specify "UTC" attribute for returned time for waterdata functinos
* Added options("dataRetrieval.attach_request" = TRUE) as default to attach the
request object as an attribute to the returned data frames. Setting
options("dataRetrieval.attach_request" = FALSE) will return a data frame without
the request attribute
* Improved time documentation
* Improved error handling in WQP functions
* Added read_waterdata_field_meta, read_waterdata_combine_meta,
and read_waterdata_channel
* Removed readNWISgwl and readNWISmeas as services have been turned off
* Updated CQL2 templates to allow HUC queries specifically to use a wildcard
to get multiple inclusive HUCs.
* Add deprecation message to readNGWMN functions. read_ngwmn will be coming soon.



dataRetrieval 2.7.22
===================
* Added read_waterdata_latest_daily to access latest daily USGS water data.
Expand Down
1 change: 1 addition & 0 deletions R/AAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pkg.env <- new.env()
"time_zone_code"
)

num_cols <- c()
pkg.env$api_endpoints <- services
pkg.env$metadata <- collections
}
Expand Down
30 changes: 17 additions & 13 deletions R/construct_api_requests.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ construct_api_requests <- function(
output_id,
...,
bbox = NA,
base = "OGC",
convertType = getOption("dataRetrieval.convertType"),
no_paging = getOption("dataRetrieval.no_paging"),
chunk_size = getOption("dataRetrieval.site_chunk_size_data"),
Expand Down Expand Up @@ -92,13 +93,7 @@ construct_api_requests <- function(
}

single_params <- c(
"datetime",
"last_modified",
"begin",
"end",
"time",
"begin_utc",
"end_utc",
time_periods,
"limit",
"skipGeometry"
)
Expand Down Expand Up @@ -159,7 +154,7 @@ construct_api_requests <- function(

format_type <- ifelse(isTRUE(no_paging), "csv", "json")

baseURL <- setup_api(service, format = format_type)
baseURL <- setup_api(service, format = format_type, base = base)
baseURL <- explode_query(baseURL, POST = FALSE, get_list, multi = "comma")

if (all(!is.na(bbox))) {
Expand Down Expand Up @@ -235,16 +230,25 @@ construct_api_requests <- function(
#' Setup the request for the OGC API requests
#'
#' @noRd
#' @param base Character OGC or NGWMN
#' @return httr2 request
#' @examplesIf is_dataRetrieval_user()
#'
#' \donttest{
#' request <- dataRetrieval:::base_url()
#' request
#' }
base_url <- function() {
httr2::request("https://api.waterdata.usgs.gov/ogcapi/") |>
httr2::req_url_path_append(getOption("dataRetrieval.api_version"))
base_url <- function(base = "OGC") {
match.arg(base, c("OGC", "NGWMN"))

if (base == "OGC") {
baseURL <- httr2::request("https://api.waterdata.usgs.gov/ogcapi/") |>
httr2::req_url_path_append(getOption("dataRetrieval.api_version"))
} else {
baseURL <- httr2::request(
"https://api.waterdata.usgs.gov/ngwmn/ogcapi/"
)
}
}

#' Setup the request for a particular endpoint collection
Expand All @@ -257,8 +261,8 @@ base_url <- function() {
#' request <- dataRetrieval:::setup_api("daily")
#' request
#' }
setup_api <- function(service, format = "json") {
baseURL <- base_url() |>
setup_api <- function(service, format = "json", base = "OGC") {
baseURL <- base_url(base) |>
httr2::req_url_path_append("collections") |>
httr2::req_url_path_append(service, "items") |>
basic_request(format = format)
Expand Down
5 changes: 3 additions & 2 deletions R/dataRetrieval-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,15 @@ NULL
# "field-measurements", "latest-daily",
# "continuous", "field-measurements-metadata",
# "combined-metadata", "channel-measurements", "peaks")
#
#
# property_list <- list()
# for(service in services){
# property_list[[service]] <- dataRetrieval:::get_properties_for_docs(service)
# }
#
# num_cols <- c("value", "contributing_drainage_area", "drainage_area",
# "altitude_accuracy", "well_construction_depth",
# #"altitude_accuracy",
# "well_construction_depth",
# "hole_construction_depth", "channel_flow", "channel_width",
# "channel_area", "channel_velocity", "channel_location_distance")
#
Expand Down
20 changes: 17 additions & 3 deletions R/deal_with_empty.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#' as "daily", "monitoring-locations", "time-series-metadata"
#' @param skipGeometry A logical for whether to return geometry
#' @param convertType A logical for whether to convert value to numeric
#' @param base character, either "OGC" or "NGWMN" depending on data.
#'
#' @return data.frame
#' @noRd
Expand All @@ -25,18 +26,31 @@ deal_with_empty <- function(
service,
skipGeometry,
convertType,
no_paging = FALSE
no_paging = FALSE,
base = "OGC"
) {
if (nrow(return_list) == 0) {
if (all(is.na(properties))) {
schema <- check_OGC_requests(endpoint = service, type = "schema")
schema <- check_OGC_requests(
endpoint = service,
type = "schema",
base = base
)
properties <- names(schema$properties)
}
return_list <- data.frame(matrix(nrow = 0, ncol = length(properties)))
return_list <- lapply(return_list, as.character)
names(return_list) <- properties

single_params <- c("datetime", "last_modified", "begin", "end", "time")
single_params <- c(
"datetime",
"last_modified",
"begin",
"end",
"time",
"datetime",
"sample_time"
)

for (i in single_params) {
if (i %in% names(return_list)) {
Expand Down
24 changes: 15 additions & 9 deletions R/get_ogc_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @noRd
#' @return data.frame with attributes
get_ogc_data <- function(args, output_id, service) {
get_ogc_data <- function(args, output_id, service, base = "OGC") {
chunk_size <- args[["chunk_size"]]
args[["..."]] <- NULL

Expand All @@ -20,7 +20,12 @@ get_ogc_data <- function(args, output_id, service) {

rl <- lapply(ml_splits, function(x) {
args[["monitoring_location_id"]] <- x
get_ogc_data(args = args, output_id = output_id, service = service)
get_ogc_data(
args = args,
output_id = output_id,
service = service,
base = base
)
})

rl_filtered <- rl[
Expand All @@ -35,6 +40,7 @@ get_ogc_data <- function(args, output_id, service) {
} else {
args[["output_id"]] <- output_id
args[["service"]] <- service
args[["base"]] <- base

req <- do.call(construct_api_requests, args)

Expand All @@ -48,13 +54,13 @@ get_ogc_data <- function(args, output_id, service) {
return_list <- walk_pages(req)
}

return_list <- deal_with_empty(
return_list,
args[["properties"]],
service,
isTRUE(args[["skipGeometry"]]),
args[["convertType"]],
no_paging
return_list <- deal_with_empty(return_list = return_list,
properties = args[["properties"]],
service = service,
skipGeometry = isTRUE(args[["skipGeometry"]]),
convertType = args[["convertType"]],
no_paging = no_paging,
base = base
)

return_list <- rejigger_cols(return_list, args[["properties"]], output_id)
Expand Down
52 changes: 40 additions & 12 deletions R/get_ogc_documentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
#' This function populates the parameter descriptions.
#'
#' @param service Character, can be any of the endpoints
#' @param base Character, can be "OGC" or "NGWMN"
#' @return list
#' @noRd
#' @examplesIf is_dataRetrieval_user()
#'
#' \donttest{
#' ml_desc <- dataRetrieval:::get_description("monitoring-locations")
#' ml_desc
#'
#' wl_desc <- dataRetrieval:::get_description("waterLevelObs", base = "NGWMN")
#' wl_desc
#' }
#'
get_description <- function(service) {
query_ret <- get_collection()
get_description <- function(service, base = "OGC") {
query_ret <- get_collection(base)

tags <- query_ret[["tags"]]

Expand All @@ -36,8 +40,8 @@ get_description <- function(service) {
#' collection
#' }
#'
get_collection <- function() {
check_collections <- base_url() |>
get_collection <- function(base = "OGC") {
check_collections <- base_url(base = base) |>
httr2::req_url_path_append("openapi") |>
httr2::req_url_query(f = "html#/server/getCollections")

Expand All @@ -55,6 +59,7 @@ get_collection <- function() {
#' available, it will also contain a description.
#'
#' @param service Character, can be any of the USGS Waterdata API endpoints or collections.
#' @param base Either "OGC" for waterdata, or "NGWMN" for National Groundwater Monitoring Network.
#' @return list
#' @export
#' @examplesIf is_dataRetrieval_user()
Expand All @@ -64,8 +69,8 @@ get_collection <- function() {
#' ml$national_aquifer_code
#' }
#'
get_ogc_params <- function(service) {
check_queryables_req <- base_url() |>
get_ogc_params <- function(service, base = "OGC") {
check_queryables_req <- base_url(base) |>
httr2::req_url_path_append("collections") |>
httr2::req_url_path_append(service) |>
httr2::req_url_path_append("schema") |>
Expand All @@ -74,7 +79,13 @@ get_ogc_params <- function(service) {
query_ret <- httr2::req_perform(check_queryables_req) |>
httr2::resp_body_json()

params <- sapply(query_ret$properties, function(x) x[["description"]])
if (base == "OGC") {
params <- sapply(query_ret$properties, function(x) x[["description"]])
} else if (base == "NGWMN") {
params <- query_ret$properties
}

params
}


Expand All @@ -85,6 +96,7 @@ get_ogc_params <- function(service) {
#'
#' @param service Character, can be any of the endpoints
#' @param output_id Character, dataRetrieval output name
#' @param base Character, either "OGC" or "NGWMN"
#' @return list
#' @noRd
#' @examplesIf is_dataRetrieval_user()
Expand All @@ -93,10 +105,14 @@ get_ogc_params <- function(service) {
#' dataRetrieval:::get_properties_for_docs("monitoring-locations",
#' "monitoring_location_id")
#'
#' dataRetrieval:::get_properties_for_docs("waterLevelObs",
#' base = "NGWMN")
#'
#' }
#'
get_properties_for_docs <- function(service, output_id = NA) {
schema <- check_OGC_requests(endpoint = service, type = "schema")
get_properties_for_docs <- function(service, output_id = NA, base = "OGC") {
schema <- check_OGC_requests(endpoint = service, type = "schema", base = base)

properties <- names(schema$properties)
if (!is.na(output_id)) {
properties[properties == "id"] <- output_id
Expand All @@ -109,6 +125,7 @@ get_properties_for_docs <- function(service, output_id = NA) {
#'
#' @param endpoint Character, can be any existing collection
#' @param type Character, can be "queryables", "schema"
#' @param base Character, can be "OGC" or "NGWMN"
#' @export
#' @keywords internal
#' @return list
Expand All @@ -124,13 +141,24 @@ get_properties_for_docs <- function(service, output_id = NA) {
#' type = "queryables")
#' ts_meta_schema <- check_OGC_requests(endpoint = "time-series-metadata",
#' type = "schema")
#'
#' ngwml <- check_OGC_requests(endpoint = "waterLevelObs",
#' type = "schema",
#' base = "NGWMN")
#' }
check_OGC_requests <- function(endpoint = "daily", type = "queryables") {
check_OGC_requests <- function(
endpoint = "daily",
type = "queryables",
base = "OGC"
) {
match.arg(type, c("queryables", "schema"))
match.arg(base, c("OGC", "NGWMN"))

match.arg(endpoint, c(pkg.env$api_endpoints, pkg.env$metadata))
if (base == "OGC") {
match.arg(endpoint, c(pkg.env$api_endpoints, pkg.env$metadata))
}

req <- base_url() |>
req <- base_url(base) |>
httr2::req_url_path_append("collections") |>
httr2::req_url_path_append(endpoint) |>
httr2::req_url_path_append(type) |>
Expand Down
7 changes: 7 additions & 0 deletions R/importNGWMN_wml2.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
#' }
#'
importNGWMN <- function(input, asDateTime = FALSE, tz = "UTC") {

.Deprecated(
new = "read_ngwmn_water_level",
package = "dataRetrieval",
msg = "Updated NGWMN APIs will use read_ngwmn set of functions."
)

if (tz != "") {
tz <- match.arg(tz, OlsonNames())
} else {
Expand Down
Loading
Loading