Skip to content

Commit 43e569a

Browse files
Merge pull request #848 from ldecicco-USGS/develop
Add flexibility to read_waterdata_metadata
2 parents 0413abf + f2bcdaf commit 43e569a

39 files changed

+270
-405
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export(create_WQP_bib)
1717
export(findNLDI)
1818
export(getWebServiceData)
1919
export(get_nldi_sources)
20+
export(get_ogc_params)
2021
export(importNGWMN)
2122
export(importRDB1)
2223
export(importWQP)

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ encouraged to migrate to the "read_waterdata_metadata" functions.
1111
recommended because it will silently cut off data after 50,000 rows.
1212
* Removed max_results argument. Was confusing and redundant with the combination
1313
of no_paging and limit.
14+
* Increase the flexibility of read_waterdata_metadata to match other OGC functions.
1415
* NLDI to use agency code prefixes and should no longer be stripping the "USGS-" off the site ides.
16+
* Add deprecate message to readNWISuse function as data services have been retired.
1517

1618
dataRetrieval 2.7.21
1719
===================

R/AAA.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ pkg.env <- new.env()
1616
"hydrologic-unit-codes", "states",
1717
"national-aquifer-codes", "reliability-codes", "site-types", "statistic-codes",
1818
"topographic-codes", "time-zone-codes")
19+
names(collections) <- c("parameter_code", "agency_code", "altitude_datum", "aquifer_code",
20+
"aquifer_type", "coordinate_accuracy_code", "coordinate_datum_code",
21+
"coordinate_method_code", "medium_code", "county",
22+
"hydrologic_unit_code", "state",
23+
"national_aquifer_code", "reliability_code", "site_types", "statistic_code",
24+
"topographic_code", "time_zone_code")
1925

2026
pkg.env$api_endpoints <- services
2127
pkg.env$metadata <- collections

R/construct_api_requests.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ construct_api_requests <- function(service,
5353
"computation_period_identifier",
5454
"computation_identifier")
5555

56-
if(service %in% c("monitoring-locations", #"parameter-codes",
56+
if(service %in% c("monitoring-locations", "parameter-codes",
5757
"time-series-metadata")){
5858
comma_params <- c(comma_params, "id")
5959
}

R/get_ogc_documentation.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,22 @@ get_collection <- function(){
5252
return(query_ret)
5353
}
5454

55-
#' Create parameter descriptions dynamically
55+
#' Get parameter descriptions
5656
#'
57-
#' This function populates the parameter descriptions.
57+
#' This function returns a list of properties available from an endpoint. When
58+
#' available, it will also contain a description.
5859
#'
59-
#' @param service Character, can be any of the endpoints
60+
#' @param service Character, can be any of the USGS Waterdata API endpoints or collections.
6061
#' @return list
61-
#' @noRd
62+
#' @export
6263
#' @examplesIf is_dataRetrieval_user()
6364
#'
6465
#' \donttest{
65-
#' ml <- dataRetrieval:::get_params("monitoring-locations")
66+
#' ml <- dataRetrieval::get_ogc_params("monitoring-locations")
6667
#' ml$national_aquifer_code
6768
#' }
6869
#'
69-
get_params <- function(service){
70+
get_ogc_params <- function(service){
7071

7172
check_queryables_req <- base_url() |>
7273
httr2::req_url_path_append("collections") |>

R/readNWISpCode.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#' USGS Parameter Data Retrieval
22
#'
33
#' Imports data from NWIS about measured parameter based on user-supplied parameter code or codes.
4-
#' This function gets the data from here: <https://nwis.waterdata.usgs.gov/nwis/pmcodes>
54
#'
65
#' @param parameterCd character of USGS parameter codes (or multiple parameter codes).
76
#' These are 5 digit number codes. To get a complete list of all current parameter

R/readNWISunit.R

Lines changed: 16 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
#' Instantaneous value data retrieval from USGS (NWIS)
22
#'
3-
#' Imports data from NWIS web service. This function gets the data from here:
4-
#' <https://waterservices.usgs.gov/docs/instantaneous-values/instantaneous-values-details/>
5-
#' Inputs to this function are just USGS site ids, USGS parameter codes,
3+
#' Imports data from NWIS web service.
4+
#' Inputs to this function are USGS site ids, USGS parameter codes,
65
#' and start and end date. For a more complex query, use [readNWISdata()],
76
#' including an arguement service="uv".
87
#' Not all parameter codes are available for all data.
98
#' Use the function [whatNWISdata()] to discover what data
109
#' is available for a USGS site. The column data_type_cd with the values "uv"
1110
#' returned from [whatNWISdata()]) are available from this service.
1211
#'
13-
#' More information on the web service can be found here:
14-
#' <https://waterservices.usgs.gov/test-tools>, choosing the
15-
#' "Instantaneous Value Service".
1612
#'
1713
#' @param siteNumbers character USGS site number (or multiple sites). This is usually an 8 digit number
1814
#' @param parameterCd character USGS parameter code. This is usually an 5 digit number.
1915
#' @param startDate character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
2016
#' retrieval for the earliest possible record. Simple date arguments are specified in local time.
21-
#' See more information here: <https://waterservices.usgs.gov/docs/instantaneous-values/>.
2217
#' @param endDate character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
2318
#' retrieval for the latest possible record. Simple date arguments are specified in local time.
24-
#' See more information here: <https://waterservices.usgs.gov/docs/instantaneous-values/>.
2519
#' @param tz character to set timezone attribute of dateTime. Default is "UTC", and converts the
26-
#' date times to UTC, properly accounting for daylight savings times based on the data's provided tz_cd column.
20+
#' date times to UTC, properly accounting for daylight savings times based on the data provided tz_cd column.
2721
#' Possible values to provide are "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles",
2822
#' "America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu",
2923
#' "America/Jamaica", "America/Managua", "America/Phoenix", and "America/Metlakatla". See also `OlsonNames()`
@@ -91,9 +85,9 @@ readNWISuv <- function(siteNumbers, parameterCd, startDate = "", endDate = "", t
9185
service <- "iv_recent"
9286
}
9387

94-
# .Deprecated(new = "read_waterdata_continuous",
95-
# package = "dataRetrieval",
96-
# msg = "NWIS servers are slated for decommission. Please begin to migrate to read_waterdata_continuous.")
88+
.Deprecated(new = "read_waterdata_continuous",
89+
package = "dataRetrieval",
90+
msg = "NWIS servers are slated for decommission. Please begin to migrate to read_waterdata_continuous.")
9791

9892

9993
url <- constructNWISURL(siteNumbers,
@@ -111,8 +105,8 @@ readNWISuv <- function(siteNumbers, parameterCd, startDate = "", endDate = "", t
111105

112106
#' Peak flow data from USGS (NWIS)
113107
#'
114-
#' Reads peak flow from NWISweb. Data is retrieved from
115-
#' <https://waterdata.usgs.gov/nwis>.
108+
#' Reads peak flow from NWISweb.
109+
#'
116110
#' In some cases, the specific date of the peak data is not know. This function
117111
#' will default to
118112
#' converting complete dates to a "Date" object, and converting incomplete dates to
@@ -233,7 +227,6 @@ readNWISpeak <- function(siteNumbers,
233227
#' Rating table for an active USGS streamgage retrieval
234228
#'
235229
#' Reads current rating table for an active USGS streamgage from NWISweb.
236-
#' Data is retrieved from <https://waterdata.usgs.gov/nwis>.
237230
#'
238231
#' @param siteNumber character USGS site number. This is usually an 8 digit number
239232
#' @param type character can be "base", "corr", or "exsa"
@@ -304,8 +297,7 @@ readNWISrating <- function(siteNumber, type = "base", convertType = TRUE) {
304297

305298
#' Surface-water measurement data retrieval from USGS (NWIS)
306299
#'
307-
#' Reads surface-water measurement data from NWISweb. Data is retrieved from <https://waterdata.usgs.gov/nwis>.
308-
#' See <https://waterdata.usgs.gov/usa/nwis/sw> for details about surface water.
300+
#' Reads surface-water measurement data from NWISweb.
309301
#'
310302
#' @param siteNumbers character USGS site number (or multiple sites). This is usually an 8 digit number
311303
#' @param startDate character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
@@ -334,9 +326,6 @@ readNWISrating <- function(siteNumber, type = "base", convertType = TRUE) {
334326
#' tz_cd \tab character \tab The time zone code for the measurement_dt column \cr
335327
#' }
336328
#'
337-
#' See <https://waterdata.usgs.gov/usa/nwis/sw> for details about surface water, and
338-
#' <https://waterdata.usgs.gov/nwis/help?output_formats_help>
339-
#' for help on the columns and codes.
340329
#'
341330
#' There are also several useful attributes attached to the data frame:
342331
#' \tabular{lll}{
@@ -438,8 +427,7 @@ readNWISmeas <- function(siteNumbers,
438427

439428
#' Groundwater level measurements retrieval from USGS (NWIS)
440429
#'
441-
#' Imports groundwater level data from NWIS web service. This function gets the data from here:
442-
#' <https://waterservices.usgs.gov/docs/groundwater-levels/groundwater-levels-details/>
430+
#' Imports groundwater level data from NWIS web service.
443431
#' Inputs to this function are just USGS site ids, USGS parameter codes,
444432
#' and start and end date. For a more complex query, use [readNWISdata()],
445433
#' including an argument service="gwlevels".
@@ -448,16 +436,7 @@ readNWISmeas <- function(siteNumbers,
448436
#' is available for a USGS site. The column data_type_cd with the values "gw"
449437
#' returned from [whatNWISdata()]) are available from this service.
450438
#'
451-
#' More information on the web service can be found here:
452-
#' <https://waterservices.usgs.gov/test-tools>, choosing the
453-
#' "Groundwater Levels Value Service".
454-
#'
455439
#'
456-
#' Mixed date/times come back from the service
457-
#' depending on the year that the data was collected. See <https://waterdata.usgs.gov/usa/nwis/gw>
458-
#' for details about groundwater. By default the returned dates are converted to date objects, unless convertType
459-
#' is specified as FALSE. Sites with non-standard date formats (i.e. lacking a day) can be affected (see examples).
460-
#' See <https://waterservices.usgs.gov/docs/groundwater-levels/> for more information.
461440
#'
462441
#' @param siteNumbers character USGS site number (or multiple sites). This is usually an 8 digit number
463442
#' @param startDate character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
@@ -569,7 +548,6 @@ readNWISgwl <- function(siteNumbers,
569548
#' Site statistics retrieval from USGS (NWIS)
570549
#'
571550
#' Retrieves site statistics from the USGS Statistics Web Service beta.
572-
#' See <https://waterservices.usgs.gov/docs/statistics/> for more information.
573551
#'
574552
#' @param siteNumbers character USGS site number (or multiple sites). This is usually an 8 digit number.
575553
#' @param parameterCd character USGS parameter code. This is usually a 5 digit number.
@@ -593,9 +571,7 @@ readNWISgwl <- function(siteNumbers,
593571
#' for water years. Monthly and yearly
594572
#' provide statistics for each month and year within the range indivually.
595573
#' @param statType character type(s) of statistics to output for daily values.
596-
#' Default is mean, which is the only
597-
#' option for monthly and yearly report types. See the statistics service documentation
598-
#' at <https://waterservices.usgs.gov/docs/statistics/> for a full list of codes.
574+
#' Default is mean, which is the only option for monthly and yearly report types.
599575
#' @return A data frame with the following columns:
600576
#' \tabular{lll}{
601577
#' Name \tab Type \tab Description \cr
@@ -679,9 +655,7 @@ readNWISstat <- function(siteNumbers, parameterCd, startDate = "", endDate = "",
679655

680656
#' Water use data retrieval from USGS (NWIS)
681657
#'
682-
#' Retrieves water use data from USGS Water Use Data for the Nation. See
683-
#' <https://waterdata.usgs.gov/nwis/wu> for
684-
#' more information. All available use categories for the supplied arguments are retrieved.
658+
#' Retrieves water use data from USGS Water Use Data for the Nation.
685659
#'
686660
#' @param stateCd could be character (full name, abbreviation, id), or numeric (id).
687661
#' Only one is accepted per query.
@@ -711,81 +685,17 @@ readNWISstat <- function(siteNumbers, parameterCd, startDate = "", endDate = "",
711685
#' County and state fields will be included as appropriate.
712686
#'
713687
#' @export
714-
#' @examplesIf is_dataRetrieval_user()
715-
#' \donttest{
716-
#' # All data for a county
717-
#' allegheny <- readNWISuse(stateCd = "Pennsylvania", countyCd = "Allegheny")
718-
#'
719-
#' # Data for an entire state for certain years
720-
#' ohio <- readNWISuse(years = c(2000, 2005, 2010), stateCd = "OH", countyCd = NULL)
721-
#'
722-
#' # Data for an entire state, county by county
723-
#' pr <- readNWISuse(years = c(2000, 2005, 2010), stateCd = "PR", countyCd = "ALL")
724-
#'
725-
#' # All national-scale data, transforming data frame to named columns from named rows
726-
#' national <- readNWISuse(stateCd = NULL, countyCd = NULL, transform = TRUE)
727-
#'
728-
#' # Washington, DC data
729-
#' dc <- readNWISuse(stateCd = "DC", countyCd = NULL)
730-
#'
731-
#' # data for multiple counties, with different input formatting
732-
#' paData <- readNWISuse(stateCd = "42", countyCd = c("Allegheny County", "BUTLER", 1, "031"))
733-
#'
734-
#' # retrieving two specific categories for an entire state
735-
#' ks <- readNWISuse(stateCd = "KS", countyCd = NULL, categories = c("IT", "LI"))
736-
#' }
737688
readNWISuse <- function(stateCd,
738689
countyCd,
739690
years = "ALL",
740691
categories = "ALL",
741692
convertType = TRUE,
742693
transform = FALSE) {
743-
message(new_nwis_message())
744-
countyID <- NULL
745-
countyCd <- countyCd[countyCd != ""]
746-
747-
if (exists("countyCd") && !is.null(countyCd)) {
748-
if (!any(toupper(countyCd) == "ALL")) {
749-
for (c in countyCd) {
750-
code <- countyCdLookup(state = stateCd, county = c, outputType = "id")
751-
countyID <- c(countyID, code)
752-
}
753-
} else {
754-
countyID <- toupper(countyID)
755-
}
756-
}
757-
758-
years <- .capitalALL(years)
759-
categories <- .capitalALL(categories)
760-
761-
url <- constructUseURL(
762-
years = years,
763-
stateCd = stateCd,
764-
countyCd = countyID,
765-
categories = categories
766-
)
767-
returned_data <- importRDB1(
768-
obs_url = url,
769-
convertType = convertType
770-
)
694+
.Deprecated(new = "read_waterdata_use_data in development",
695+
package = "dataRetrieval",
696+
msg = "NWIS servers for water use have been decommission. New functions are being developed.")
697+
return(NULL)
771698

772-
# for total country data arriving in named rows
773-
if (transform) {
774-
cmmnt <- comment(returned_data)
775-
returned_data <- t(returned_data)
776-
colnames(returned_data) <- returned_data[1, ]
777-
returned_data <- as.data.frame(returned_data[-1, ], stringsAsFactors = FALSE)
778-
returned_data <- cbind(
779-
Year = as.integer(substr(rownames(returned_data), 2, 5)),
780-
returned_data
781-
)
782-
rownames(returned_data) <- NULL
783-
comment(returned_data) <- cmmnt
784-
if (!all(is.null(stateCd)) && all(nchar(stateCd) != 0)) {
785-
warning("transform = TRUE is only intended for national data")
786-
}
787-
}
788-
return(returned_data)
789699
}
790700

791701
.capitalALL <- function(input) {

R/read_waterdata_continuous.R

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111
#' Geometry output is not supported in the continuous data API endpoint.
1212
#'
1313
#' @export
14-
#' @param monitoring_location_id `r get_params("continuous")$monitoring_location_id`
14+
#' @param monitoring_location_id `r get_ogc_params("continuous")$monitoring_location_id`
1515
#' Multiple monitoring_location_ids can be requested as a character vector.
16-
#' @param parameter_code `r get_params("continuous")$parameter_code`
16+
#' @param parameter_code `r get_ogc_params("continuous")$parameter_code`
1717
#' Multiple parameter_codes can be requested as a character vector.
18-
#' @param time `r get_params("continuous")$time`.
18+
#' @param time `r get_ogc_params("continuous")$time`.
1919
#' You can also use a vector of length 2: the first value being the starting date,
2020
#' the second value being the ending date. NA's within the vector indicate a
2121
#' half-bound date. For example, c("2024-01-01", NA) will return all data starting
2222
#' at 2024-01-01.
23-
#' @param value `r get_params("continuous")$value`
24-
#' @param unit_of_measure `r get_params("continuous")$unit_of_measure`
25-
#' @param approval_status `r get_params("continuous")$approval_status`
26-
#' @param last_modified `r get_params("continuous")$last_modified`
27-
#' @param time_series_id `r get_params("continuous")$time_series_id`
23+
#' @param value `r get_ogc_params("continuous")$value`
24+
#' @param unit_of_measure `r get_ogc_params("continuous")$unit_of_measure`
25+
#' @param approval_status `r get_ogc_params("continuous")$approval_status`
26+
#' @param last_modified `r get_ogc_params("continuous")$last_modified`
27+
#' @param time_series_id `r get_ogc_params("continuous")$time_series_id`
2828
#' Multiple time_series_ids can be requested as a character vector.
29-
#' @param qualifier `r get_params("continuous")$qualifier`
29+
#' @param qualifier `r get_ogc_params("continuous")$qualifier`
3030
#' @param properties A vector of requested columns to be returned from the query.
3131
#' Available options are:
3232
#' `r dataRetrieval:::get_properties_for_docs("continuous", "continuous_id")`.

R/read_waterdata_daily.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
#' @description `r get_description("daily")`
44
#'
55
#' @export
6-
#' @param monitoring_location_id `r get_params("daily")$monitoring_location_id`
6+
#' @param monitoring_location_id `r get_ogc_params("daily")$monitoring_location_id`
77
#' Multiple monitoring_location_ids can be requested as a character vector.
8-
#' @param parameter_code `r get_params("daily")$parameter_code`
8+
#' @param parameter_code `r get_ogc_params("daily")$parameter_code`
99
#' Multiple parameter_codes can be requested as a character vector.
10-
#' @param statistic_id `r get_params("daily")$statistic_id`
10+
#' @param statistic_id `r get_ogc_params("daily")$statistic_id`
1111
#' Multiple statistic_ids can be requested as a character vector.
12-
#' @param time `r get_params("daily")$time`
12+
#' @param time `r get_ogc_params("daily")$time`
1313
#' You can also use a vector of length 2: the first value being the starting date,
1414
#' the second value being the ending date. NA's within the vector indicate a
1515
#' half-bound date. For example, c("2024-01-01", NA) will return all data starting
1616
#' at 2024-01-01.
17-
#' @param value `r get_params("daily")$value`
18-
#' @param unit_of_measure `r get_params("daily")$unit_of_measure`
19-
#' @param approval_status `r get_params("daily")$approval_status`
20-
#' @param last_modified `r get_params("daily")$last_modified`
21-
#' @param time_series_id `r get_params("daily")$time_series_id`
17+
#' @param value `r get_ogc_params("daily")$value`
18+
#' @param unit_of_measure `r get_ogc_params("daily")$unit_of_measure`
19+
#' @param approval_status `r get_ogc_params("daily")$approval_status`
20+
#' @param last_modified `r get_ogc_params("daily")$last_modified`
21+
#' @param time_series_id `r get_ogc_params("daily")$time_series_id`
2222
#' Multiple time_series_ids can be requested as a character vector.
23-
#' @param qualifier `r get_params("daily")$qualifier`
23+
#' @param qualifier `r get_ogc_params("daily")$qualifier`
2424
#' @param properties A vector of requested columns to be returned from the query.
2525
#' Available options are:
2626
#' `r dataRetrieval:::get_properties_for_docs("daily", "daily_id")`.

0 commit comments

Comments
 (0)