Skip to content

Commit d8d252f

Browse files
Merge pull request #832 from ldecicco-USGS/continuous
Continuous
2 parents 0d998c4 + 23f4f14 commit d8d252f

38 files changed

+664
-378
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Authors@R: c(
2525
email = "[email protected]",
2626
comment=c(ORCID = "0000-0003-2521-5043")),
2727
person("Lee", "Stanish", role="ctb",
28-
email = "[email protected]",
2928
comment=c(ORCID = "0000-0002-9775-6861")),
3029
person("Joeseph", "Zemmels", role="ctb",
3130
email = "[email protected]",

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export(readWQPqw)
4646
export(readWQPsummary)
4747
export(read_USGS_samples)
4848
export(read_waterdata)
49+
export(read_waterdata_continuous)
4950
export(read_waterdata_daily)
5051
export(read_waterdata_field_measurements)
5152
export(read_waterdata_latest_continuous)

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
dataRetrieval 2.7.22
22
===================
33
* Added read_waterdata_latest_daily to access latest daily USGS water data.
4+
* Added read_waterdata_continuous to access continuous USGS water data.
45
* Added state_name and hydrologic_unit_code to read_waterdata_ts_meta
6+
* Removed daily_id from read_waterdata_daily output. Currently it
7+
is not stable over time.
58

69
dataRetrieval 2.7.21
710
===================

R/AAA.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ pkg.env <- new.env()
88

99
services <- c("server", "daily", "time-series-metadata",
1010
"monitoring-locations", "latest-continuous",
11-
"field-measurements", "latest-daily")
11+
"field-measurements", "latest-daily",
12+
"continuous")
1213
collections <- c("parameter-codes", "agency-codes", "altitude-datums", "aquifer-codes",
1314
"aquifer-types", "coordinate-accuracy-codes", "coordinate-datum-codes",
1415
"coordinate-method-codes", "medium-codes",

R/construct_api_requests.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ construct_api_requests <- function(service,
6868
if(!is.na(max_results)){
6969
get_list[["limit"]] <- max_results
7070
} else {
71-
get_list[["limit"]] <- 10000
71+
get_list[["limit"]] <- 50000
7272
}
7373
} else {
7474
if(!is.na(max_results)){

R/readNWISunit.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ readNWISuv <- function(siteNumbers, parameterCd, startDate = "", endDate = "", t
9191
service <- "iv_recent"
9292
}
9393

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.")
97+
98+
9499
url <- constructNWISURL(siteNumbers,
95100
parameterCd,
96101
startDate,
@@ -360,7 +365,10 @@ readNWISmeas <- function(siteNumbers,
360365
expanded = FALSE,
361366
convertType = TRUE) {
362367

363-
message(new_nwis_message())
368+
.Deprecated(new = "read_waterdata_field_measurements",
369+
package = "dataRetrieval",
370+
msg = "NWIS servers are slated for decommission. Please begin to migrate to read_waterdata_field_measurements.")
371+
364372
# Doesn't seem to be a WaterML1 format option
365373
url <- constructNWISURL(
366374
siteNumbers = siteNumbers,

R/read_waterdata_continuous.R

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#' Get Continuous USGS Water Data
2+
#'
3+
#' @description `r get_description("continuous")`
4+
#'
5+
#' Currently, the services only allow up to 3 years of data to be requested with
6+
#' a single request. If no "time" is specified, the service will return the
7+
#' last single year of data. If this is a bottleneck, please check back
8+
#' for new direct download functions that are expected to be available sometime
9+
#' in 2026.
10+
#'
11+
#' @export
12+
#' @param monitoring_location_id `r get_params("continuous")$monitoring_location_id`
13+
#' @param parameter_code `r get_params("continuous")$parameter_code`
14+
#' @param time `r get_params("continuous")$time`
15+
#' @param value `r get_params("continuous")$value`
16+
#' @param unit_of_measure `r get_params("continuous")$unit_of_measure`
17+
#' @param approval_status `r get_params("continuous")$approval_status`
18+
#' @param last_modified `r get_params("continuous")$last_modified`
19+
#' @param time_series_id `r get_params("continuous")$time_series_id`
20+
#' @param qualifier `r get_params("continuous")$qualifier`
21+
#' @param statistic_id `r get_params("continuous")$statistic_id`. Note that
22+
#' for continuous data, the statistic_id is almost universally 00011.
23+
#' Requesting anything else will most-likely cause a timeout.
24+
#' @param properties A vector of requested columns to be returned from the query.
25+
#' Available options are:
26+
#' `r schema <- check_OGC_requests(endpoint = "continuous", type = "schema"); paste(names(schema$properties)[!names(schema$properties) %in% c("id", "internal_id")], collapse = ", ")`
27+
#' @param limit The optional limit parameter is used to control the subset of the
28+
#' selected features that should be returned in each page. The maximum allowable
29+
#' limit is 50000. It may be beneficial to set this number lower if your internet
30+
#' connection is spotty. The default (`NA`) will set the limit to the maximum
31+
#' allowable limit for the service.
32+
#' @param max_results The optional maximum number of rows to return. This value
33+
#' must be less than the requested limit.
34+
#' @param convertType logical, defaults to `TRUE`. If `TRUE`, the function
35+
#' will convert the data to dates and qualifier to string vector, and sepcifically
36+
#' order the returning data frame by time and monitoring_location_id.
37+
#' @examplesIf is_dataRetrieval_user()
38+
#'
39+
#' \donttest{
40+
#' site <- "USGS-451605097071701"
41+
#' pcode <- "72019"
42+
#'
43+
#' uv_data_trim <- read_waterdata_continuous(monitoring_location_id = site,
44+
#' parameter_code = pcode,
45+
#' properties = c("value",
46+
#' "time"))
47+
#'
48+
#' uv_data <- read_waterdata_continuous(monitoring_location_id = site,
49+
#' parameter_code = pcode,
50+
#' time = "P2D")
51+
#'
52+
#'
53+
#' # Only return data that has been modified in last 7 days
54+
#' multi_site2 <- read_waterdata_continuous(monitoring_location_id = c("USGS-451605097071701",
55+
#' "USGS-14181500"),
56+
#' parameter_code = c("00060", "72019"),
57+
#' last_modified = "P7D")
58+
#'
59+
#' }
60+
read_waterdata_continuous <- function(monitoring_location_id = NA_character_,
61+
parameter_code = NA_character_,
62+
properties = NA_character_,
63+
time_series_id = NA_character_,
64+
approval_status = NA_character_,
65+
unit_of_measure = NA_character_,
66+
qualifier = NA_character_,
67+
statistic_id = NA_character_,
68+
value = NA,
69+
last_modified = NA_character_,
70+
time = NA_character_,
71+
limit = NA,
72+
max_results = NA,
73+
convertType = TRUE){
74+
75+
service <- "continuous"
76+
output_id <- "continuous_id"
77+
78+
args <- mget(names(formals()))
79+
args[["skipGeometry"]] <- TRUE
80+
81+
if(!is.na(statistic_id) & !all(statistic_id == "00011")){
82+
warning("With few if any exceptions, statistic_id is always 00011 for continuous data, and requesting other statistic ids will likely return no data.")
83+
}
84+
85+
return_list <- get_ogc_data(args,
86+
output_id,
87+
service)
88+
89+
if(convertType){
90+
return_list <- order_results(return_list, properties)
91+
return_list <- return_list[, names(return_list)[names(return_list)!= output_id]]
92+
if("time_series_id" %in% names(return_list)){
93+
return_list <- return_list[, c( names(return_list)[names(return_list)!= "time_series_id"],
94+
"time_series_id")]
95+
}
96+
}
97+
98+
return(return_list)
99+
}
100+
101+
order_results <- function(return_list, properties){
102+
103+
if(all(is.na(properties)) |
104+
all(c("time", "monitoring_location_id") %in% properties)){
105+
return_list <- return_list[order(return_list$time,
106+
return_list$monitoring_location_id), ]
107+
} else if ("time" %in% properties) {
108+
return_list <- return_list[order(return_list$time), ]
109+
}
110+
111+
return(return_list)
112+
}
113+

R/read_waterdata_daily.R

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
#' @param last_modified `r get_params("daily")$last_modified`
1414
#' @param time_series_id `r get_params("daily")$time_series_id`
1515
#' @param qualifier `r get_params("daily")$qualifier`
16-
#' @param daily_id `r get_params("daily")$id`
1716
#' @param properties A vector of requested columns to be returned from the query.
1817
#' Available options are:
19-
#' `r schema <- check_OGC_requests(endpoint = "daily", type = "schema"); paste(names(schema$properties), collapse = ", ")`
18+
#' `r schema <- check_OGC_requests(endpoint = "daily", type = "schema"); paste(names(schema$properties)[!names(schema$properties) %in% c("id")], collapse = ", ")`
2019
#' @param bbox Only features that have a geometry that intersects the bounding
2120
#' box are selected.The bounding box is provided as four or six numbers, depending
2221
#' on whether the coordinate reference system includes a vertical axis (height or
@@ -25,7 +24,7 @@
2524
#' Southern-most latitude, Eastern-most longitude, Northern-most longitude).
2625
#' @param limit The optional limit parameter is used to control the subset of the
2726
#' selected features that should be returned in each page. The maximum allowable
28-
#' limit is 10000. It may be beneficial to set this number lower if your internet
27+
#' limit is 50000. It may be beneficial to set this number lower if your internet
2928
#' connection is spotty. The default (`NA`) will set the limit to the maximum
3029
#' allowable limit for the service.
3130
#' @param max_results The optional maximum number of rows to return. This value
@@ -39,7 +38,6 @@
3938
#'
4039
#' \donttest{
4140
#' site <- "USGS-02238500"
42-
#' pcode <- "00060"
4341
#' dv_data_sf <- read_waterdata_daily(monitoring_location_id = site,
4442
#' parameter_code = "00060",
4543
#' time = c("2021-01-01", "2022-01-01"))
@@ -50,8 +48,7 @@
5048
#'
5149
#' dv_data_trim <- read_waterdata_daily(monitoring_location_id = site,
5250
#' parameter_code = "00060",
53-
#' properties = c("monitoring_location_id",
54-
#' "value",
51+
#' properties = c("value",
5552
#' "time"),
5653
#' time = c("2021-01-01", "2022-01-01"))
5754
#'
@@ -71,22 +68,21 @@
7168
#'
7269
#' }
7370
read_waterdata_daily <- function(monitoring_location_id = NA_character_,
74-
parameter_code = NA_character_,
75-
statistic_id = NA_character_,
76-
properties = NA_character_,
77-
time_series_id = NA_character_,
78-
daily_id = NA_character_,
79-
approval_status = NA_character_,
80-
unit_of_measure = NA_character_,
81-
qualifier = NA_character_,
82-
value = NA,
83-
last_modified = NA_character_,
84-
skipGeometry = NA,
85-
time = NA_character_,
86-
bbox = NA,
87-
limit = NA,
88-
max_results = NA,
89-
convertType = TRUE){
71+
parameter_code = NA_character_,
72+
statistic_id = NA_character_,
73+
properties = NA_character_,
74+
time_series_id = NA_character_,
75+
approval_status = NA_character_,
76+
unit_of_measure = NA_character_,
77+
qualifier = NA_character_,
78+
value = NA,
79+
last_modified = NA_character_,
80+
skipGeometry = NA,
81+
time = NA_character_,
82+
bbox = NA,
83+
limit = NA,
84+
max_results = NA,
85+
convertType = TRUE){
9086

9187
service <- "daily"
9288
output_id <- "daily_id"
@@ -96,7 +92,14 @@ read_waterdata_daily <- function(monitoring_location_id = NA_character_,
9692
output_id,
9793
service)
9894

99-
return_list <- return_list[order(return_list$time, return_list$monitoring_location_id), ]
95+
if(convertType){
96+
return_list <- order_results(return_list, properties)
97+
return_list <- return_list[,names(return_list)[names(return_list)!= output_id]]
98+
if("time_series_id" %in% names(return_list)){
99+
return_list <- return_list[, c( names(return_list)[names(return_list)!= "time_series_id"],
100+
"time_series_id")]
101+
}
102+
}
100103

101104
return(return_list)
102105
}

R/read_waterdata_field_measurements.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' @param measuring_agency `r get_params("field-measurements")$measuring_agency`
1919
#' @param properties A vector of requested columns to be returned from the query.
2020
#' Available options are:
21-
#' `r schema <- check_OGC_requests(endpoint = "field-measurements", type = "schema"); paste(names(schema$properties), collapse = ", ")`
21+
#' `r schema <- check_OGC_requests(endpoint = "field-measurements", type = "schema"); paste(names(schema$properties)[!names(schema$properties) %in% c("id")], collapse = ", ")`
2222
#' @param bbox Only features that have a geometry that intersects the bounding
2323
#' box are selected.The bounding box is provided as four or six numbers, depending
2424
#' on whether the coordinate reference system includes a vertical axis (height or
@@ -27,7 +27,7 @@
2727
#' Southern-most latitude, Eastern-most longitude, Northern-most longitude).
2828
#' @param limit The optional limit parameter is used to control the subset of the
2929
#' selected features that should be returned in each page. The maximum allowable
30-
#' limit is 10000. It may be beneficial to set this number lower if your internet
30+
#' limit is 50000. It may be beneficial to set this number lower if your internet
3131
#' connection is spotty. The default (`NA`) will set the limit to the maximum
3232
#' allowable limit for the service.
3333
#' @param max_results The optional maximum number of rows to return. This value
@@ -99,7 +99,14 @@ read_waterdata_field_measurements <- function(monitoring_location_id = NA_charac
9999
output_id,
100100
service)
101101

102-
return_list <- return_list[order(return_list$time, return_list$monitoring_location_id), ]
102+
if(convertType){
103+
return_list <- order_results(return_list, properties)
104+
return_list <- return_list[,names(return_list)[names(return_list)!= output_id]]
105+
if("field_visit_id" %in% names(return_list)){
106+
return_list <- return_list[, c( names(return_list)[names(return_list)!= "field_visit_id"],
107+
"field_visit_id")]
108+
}
109+
}
103110

104111
return(return_list)
105112
}

R/read_waterdata_latest_continuous.R

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
#' @export
66
#' @param monitoring_location_id `r get_params("latest-continuous")$monitoring_location_id`
77
#' @param parameter_code `r get_params("latest-continuous")$parameter_code`
8-
#' @param statistic_id `r get_params("latest-continuous")$statistic_id`
98
#' @param time `r get_params("latest-continuous")$time`
109
#' @param value `r get_params("latest-continuous")$value`
1110
#' @param unit_of_measure `r get_params("latest-continuous")$unit_of_measure`
1211
#' @param approval_status `r get_params("latest-continuous")$approval_status`
1312
#' @param last_modified `r get_params("latest-continuous")$last_modified`
1413
#' @param time_series_id `r get_params("latest-continuous")$time_series_id`
1514
#' @param qualifier `r get_params("latest-continuous")$qualifier`
16-
#' @param latest_continuous_id `r get_params("latest-continuous")$id`
15+
#' @param statistic_id `r get_params("latest-continuous")$statistic_id`. Note that
16+
#' for continuous data, the statistic_id is almost universally 00011.
17+
#' Requesting anything else will most-likely cause a timeout.
1718
#' @param properties A vector of requested columns to be returned from the query.
1819
#' Available options are:
19-
#' `r schema <- check_OGC_requests(endpoint = "latest-continuous", type = "schema"); paste(names(schema$properties), collapse = ", ")`
20+
#' `r schema <- check_OGC_requests(endpoint = "latest-continuous", type = "schema"); paste(names(schema$properties)[!names(schema$properties) %in% c("id")], collapse = ", ")`
2021
#' @param bbox Only features that have a geometry that intersects the bounding
2122
#' box are selected.The bounding box is provided as four or six numbers, depending
2223
#' on whether the coordinate reference system includes a vertical axis (height or
@@ -25,7 +26,7 @@
2526
#' Southern-most latitude, Eastern-most longitude, Northern-most longitude).
2627
#' @param limit The optional limit parameter is used to control the subset of the
2728
#' selected features that should be returned in each page. The maximum allowable
28-
#' limit is 10000. It may be beneficial to set this number lower if your internet
29+
#' limit is 50000. It may be beneficial to set this number lower if your internet
2930
#' connection is spotty. The default (`NA`) will set the limit to the maximum
3031
#' allowable limit for the service.
3132
#' @param max_results The optional maximum number of rows to return. This value
@@ -74,7 +75,6 @@ read_waterdata_latest_continuous <- function(monitoring_location_id = NA_charact
7475
statistic_id = NA_character_,
7576
properties = NA_character_,
7677
time_series_id = NA_character_,
77-
latest_continuous_id = NA_character_,
7878
approval_status = NA_character_,
7979
unit_of_measure = NA_character_,
8080
qualifier = NA_character_,
@@ -95,7 +95,14 @@ read_waterdata_latest_continuous <- function(monitoring_location_id = NA_charact
9595
output_id,
9696
service)
9797

98-
return_list <- return_list[order(return_list$time, return_list$monitoring_location_id), ]
98+
if(convertType){
99+
return_list <- order_results(return_list, properties)
100+
return_list <- return_list[, names(return_list)[names(return_list)!= output_id]]
101+
if("time_series_id" %in% names(return_list)){
102+
return_list <- return_list[, c( names(return_list)[names(return_list)!= "time_series_id"],
103+
"time_series_id")]
104+
}
105+
}
99106

100107
return(return_list)
101108
}

0 commit comments

Comments
 (0)