Skip to content

Commit 1df87c3

Browse files
committed
Update docs
1 parent 9472c9b commit 1df87c3

File tree

6 files changed

+76
-84
lines changed

6 files changed

+76
-84
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
56

67
dataRetrieval 2.7.21

tutorials/basic_slides_deck.qmd

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,9 @@ We're going walk through 3 retrievals:
437437

438438
* **Workflow 4**: Continuous Data
439439

440-
- Uses the NWIS web services
440+
- Uses the new USGS Water Data API
441441

442-
- Will be deprecated, this fall we'll have `read_waterdata_continuous`
442+
- Modern data access point going forward
443443

444444
* **Workflow 5**: Join Continuous and Discrete
445445

@@ -814,10 +814,6 @@ band_instruments |>
814814

815815
* Continuous data is the high-frequency sensor data.
816816

817-
* The function to get that data today is `readNWISuv`
818-
819-
* As NWIS gets deprecated, we expect to have `read_waterdata_continuous` soon
820-
821817
* We'll look at Suisun Bay a Van Sickle Island NR Pittsburg CA ("USGS-11455508"), with parameter code "99133" which is Nitrate plus Nitrite.
822818

823819
## Workflow 4: Continuous data for known site
@@ -828,15 +824,14 @@ band_instruments |>
828824

829825
```{r}
830826
#| results: markup
831-
site_id <- "11455508"
827+
site_id <- "USGS-11455508"
832828
p_code_rt <- "99133"
833829
start_date <- "2024-01-01"
834830
end_date <- "2024-06-01"
835831
836-
continuous_data <- readNWISuv(site_id,
837-
p_code_rt,
838-
start_date,
839-
end_date)
832+
continuous_data <- read_waterdata_continuous(monitoring_location_id = site_id,
833+
parameter_code = p_code_rt,
834+
time = c(start_date, end_date))
840835
841836
names(continuous_data)
842837
```
@@ -846,28 +841,26 @@ names(continuous_data)
846841
::: {.column width="30%"}
847842

848843
```
849-
[1] "agency_cd"
850-
[2] "site_no"
851-
[3] "dateTime"
852-
[4] "X_99133_00000"
853-
[5] "X_99133_00000_cd"
854-
[6] "tz_cd"
844+
[4] "time" "unit_of_measure" "parameter_code"
845+
[7] "statistic_id" "value" "approval_status"
846+
[10] "last_modified" "qualifier"
855847
```
856848
:::
857849

858850
::::
859851

860852
```
861-
GET: https://nwis.waterservices.usgs.gov/nwis/iv/?site=11455508&format=waterml%2C1.1&ParameterCd=99133&startDT=2024-01-01&endDT=2024-06-01
853+
Requesting:
854+
https://api.waterdata.usgs.gov/ogcapi/v0/collections/continuous/items?f=json&lang=en-US&skipGeometry=TRUE&limit=40000&monitoring_location_id=USGS-11455508&parameter_code=99133&time=2024-01-01T00%3A00%3A00Z%2F2024-06-01T00%3A00%3A00Z
862855
```
863856

864857
## Workflow 4: Inspect
865858

866859
```{r}
867860
#| output-location: column
868861
ggplot(data = continuous_data) +
869-
geom_point(aes(x = dateTime,
870-
y = X_99133_00000))
862+
geom_point(aes(x = time,
863+
y = value))
871864
```
872865

873866
## Workflow 5: Join Discrete and Continuous
@@ -901,7 +894,7 @@ discrete_data <- read_waterdata_samples(monitoringLocationIdentifier = "USGS-114
901894
#| code-line-numbers: "1|2-3|5|6|1-6"
902895
library(data.table)
903896
setDT(discrete_data)[, join_date := Activity_StartDateTime]
904-
setDT(continuous_data)[, join_date := dateTime]
897+
setDT(continuous_data)[, join_date := time]
905898
906899
closest_dt <- continuous_data[discrete_data, on = .(join_date), roll = "nearest"]
907900
closest_dt <- data.frame(closest_dt)
@@ -917,7 +910,7 @@ closest_dt <- data.frame(closest_dt)
917910
#| output-location: column
918911
ggplot(data = closest_dt) +
919912
geom_point(aes(x = Result_Measure,
920-
y = X_99133_00000)) +
913+
y = value)) +
921914
geom_abline() +
922915
expand_limits(x = 0, y = 0) +
923916
xlab("Discrete") +

tutorials/changes_slides_deck.qmd

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ Open Geospatial Consortium (OGC), a non-profit international organization that d
137137

138138
* [read_waterdata_field_measurements](https://doi-usgs.github.io/dataRetrieval/reference/read_waterdata_field_measurements.html) - Discrete hydrologic data (gage height, discharge, and readings of groundwater levels)
139139

140-
* [read_waterdata](https://doi-usgs.github.io/dataRetrieval/reference/read_waterdata.html) - Generalized function
140+
* [read_waterdata_continuous](https://doi-usgs.github.io/dataRetrieval/reference/read_waterdata_continuous.html) - Continuous data are collected via automated sensors installed at a monitoring location.
141+
142+
* [read_waterdata](https://doi-usgs.github.io/dataRetrieval/reference/read_waterdata.html) - Generalized function.
141143

142144
* [read_waterdata_metadata](https://doi-usgs.github.io/dataRetrieval/reference/read_waterdata_metadata.html) - Metadata
143145

@@ -622,6 +624,25 @@ leaflet(data = latest_dane_county_daily |>
622624
values = ~value)
623625
```
624626

627+
## read_waterdata_continuous
628+
629+
Replaces `readNWISuv`:
630+
631+
```{r}
632+
this_week <- read_waterdata_continuous(monitoring_location_id = c("USGS-05406457",
633+
"USGS-05427930"),
634+
parameter_code = c("00060", "00010"),
635+
time = "P7D")
636+
```
637+
638+
Currently only allows 3 years of data to be queried at once.
639+
640+
::: footer
641+
642+
:::
643+
644+
645+
625646
## read_waterdata
626647

627648
* This function is totally different!

vignettes/dataRetrieval.Rmd

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Table 1 describes the functions available in the `dataRetrieval` package.
6060
Functions <- c(
6161
"read_waterdata",
6262
"read_waterdata_daily",
63-
"readNWISuv",
63+
"read_waterdata_continuous",
6464
"readNWISrating",
6565
"read_waterdata_field_measurements",
6666
"readNWISpeak",
@@ -108,7 +108,8 @@ Description <- c(
108108
)
109109
Source <- c("USGS Water Data API",
110110
"USGS Water Data API",
111-
rep("NWIS",2),
111+
"USGS Water Data API",
112+
"NWIS",
112113
"USGS Water Data API",
113114
"NWIS",
114115
"USGS Water Data API",
@@ -352,32 +353,21 @@ Any data collected at regular time intervals (such as 15-minute or hourly) are k
352353
parameterCd <- "00060" # Discharge
353354
startDate <- "2012-05-12"
354355
endDate <- "2012-05-13"
355-
dischargeUnit <- readNWISuv(siteNumber, parameterCd, startDate, endDate)
356-
dischargeUnit <- renameNWISColumns(dischargeUnit)
356+
dischargeUnit <- read_waterdata_continuous(monitoring_location_id = siteNumber,
357+
parameter_code = parameterCd,
358+
time = c(startDate, endDate))
359+
357360
```
358361

359362
The retrieval produces a data frame that contains 96 rows (one for every 15 minute period in the day). They include all data collected from the `startDate` through the `endDate` (starting and ending with midnight locally-collected time). The dateTime column is converted to UTC (Coordinated Universal Time), so midnight EST will be 5 hours earlier in the dateTime column (the previous day, at 7pm).
360363

361-
To override the UTC timezone, specify a valid timezone in the tz argument. Default is "", which will keep the dateTime column in UTC. Other valid timezones are:
362364

363-
```
364-
America/New_York
365-
America/Chicago
366-
America/Denver
367-
America/Los_Angeles
368-
America/Anchorage
369-
America/Honolulu
370-
America/Jamaica
371-
America/Managua
372-
America/Phoenix
373-
America/Metlakatla
374-
```
375365

376-
Data are retrieved from [https://waterservices.usgs.gov/docs/instantaneous-values/](https://waterservices.usgs.gov/docs/instantaneous-values/). There are occasions where NWIS values are not reported as numbers, instead a common example is "Ice". Any value that cannot be converted to a number will be reported as NA in this package. Site information and measured parameter information is attached to the data frame as attributes. This is discussed further in [metadata](#embedded-metadata) section.
366+
Data are retrieved from <https://api.waterdata.usgs.gov/ogcapi/v0/>. Site information and measured parameter information is attached to the data frame as attributes. This is discussed further in [metadata](#embedded-metadata) section.
377367

378368
## Groundwater Level Data
379369

380-
Groundwater level measurements can be obtained with the `readNWISgwl` function. Information on the returned data can be found with the `comment` function, and attached attributes as described in the [metadata](#embedded-metadata) section.
370+
Groundwater level measurements can be obtained with the `read_waterdata_field_measurements` function.
381371

382372
```{r gwlexample, echo=TRUE, eval=FALSE}
383373
siteNumber <- "USGS-434400121275801"
@@ -411,7 +401,7 @@ attr(ratingData, "RATING")
411401

412402
These data are the discrete measurements of discharge that are made for the purpose of developing or revising the rating curve. Information on the returned data can be found with the `comment` function and attached attributes as described in the [metadata](#embedded-metadata) section.
413403

414-
Surface-water measurement data can be obtained with the `readNWISmeas` function.
404+
Surface-water measurement data can be obtained with the `read_waterdata_field_measurements`` function.
415405

416406
```{r surfexample, echo=TRUE, eval=FALSE}
417407
surfaceData <- read_waterdata_field_measurements(monitoring_location_id = "USGS-01594440")

vignettes/join_by_closest.Rmd

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ output:
99
vignette: >
1010
%\VignetteIndexEntry{Join by closest date}
1111
\usepackage[utf8]{inputenc}
12-
%\VignetteEngine{knitr::rmarkdown}
1312
%\VignetteDepends{dplyr}
13+
%\VignetteEngine{knitr::rmarkdown}
1414
editor_options:
1515
chunk_output_type: console
1616
---
@@ -40,7 +40,7 @@ Let's look at site "01646500", and a nearby site with a real-time nitrate-plus-n
4040
```{r getData}
4141
library(dataRetrieval)
4242
43-
site_uv <- "01646500"
43+
site_uv <- "USGS-01646500"
4444
site_qw <- "USGS-01646580"
4545
pcode_uv <- "99133"
4646
pcode_qw <- "00631"
@@ -50,31 +50,11 @@ qw_data <- readWQPqw(site_qw, pcode_qw,
5050
startDate = start_date,
5151
endDate = end_date)
5252
53-
uv_data <- readNWISuv(siteNumbers = site_uv,
54-
parameterCd = c(pcode_uv, "00060"),
55-
startDate = start_date,
56-
endDate = end_date)
57-
```
58-
59-
60-
The sensor data ("uv" data) at this particular site has 2 columns of data that are important. The first task is to combine those columns. This is rather unique to this particular site and probably won't need to be done generally.
61-
62-
```{r trimUVdata}
63-
library(dplyr)
64-
65-
uv_trim <- uv_data |>
66-
select(uv_date = dateTime,
67-
val1 = X_SUNA...Discontinued._99133_00000,
68-
val2 = X_SUNA_99133_00000,
69-
flow = X_00060_00000) |>
70-
mutate(val_uv = if_else(is.na(val1), val2, val1)) |>
71-
select(-val1, -val2)
72-
53+
uv_data <- read_waterdata_continuous(monitoring_location_id = site_uv,
54+
parameter_code = c(pcode_uv),
55+
time = c(start_date, end_date))
7356
```
7457

75-
```{r showuvTrim, echo=FALSE}
76-
knitr::kable(head(uv_trim))
77-
```
7858

7959
Next we'll clean up the discrete water quality "qw" data to make it easy to follow in this tutorial.
8060

@@ -98,9 +78,9 @@ library(data.table)
9878
9979
setDT(qw_trim)[, join_date := qw_date]
10080
101-
setDT(uv_trim)[, join_date := uv_date]
81+
setDT(uv_data)[, join_date := time]
10282
103-
closest_dt <- uv_trim[qw_trim, on = .(join_date), roll = "nearest"]
83+
closest_dt <- uv_data[qw_trim, on = .(join_date), roll = "nearest"]
10484
```
10585

10686
`closest_dt` is a `data.table` object. It similar to a data.frame, but not identical. We can convert it to a data.frame and then use `dplyr` commands. Note: the whole analysis can be done via `data.table`, but most examples in `dataRetrieval` have used `dplyr`, which is why we bring it back to data.frame. `dplyr` also has a `join_by(closest())` option, but it is more complicated because you can only specify the closeness in either the forward or backwards direction (and we want either direction).
@@ -109,9 +89,9 @@ We can calculate "delta_time" - the difference in time between the uv and qw dat
10989

11090
```{r}
11191
qw_closest <- data.frame(closest_dt) |>
112-
mutate(delta_time = difftime(qw_date, uv_date,
92+
mutate(delta_time = difftime(qw_date, time,
11393
units = "hours"),
114-
val_uv = if_else(abs(as.numeric(delta_time)) >= 24, NA, val_uv)) |>
94+
val_uv = if_else(abs(as.numeric(delta_time)) >= 24, NA, value)) |>
11595
select(-join_date)
11696
11797
```
@@ -134,21 +114,11 @@ ggplot(data = qw_closest) +
134114
135115
```
136116

137-
```{r}
138-
ggplot(data = qw_closest) +
139-
geom_point(aes(x = flow, y = val_qw)) +
140-
theme_bw() +
141-
xlab("Discharge") +
142-
ylab("Concentration") +
143-
scale_x_log10() +
144-
scale_y_log10()
145-
146-
```
147117

148118
```{r}
149119
ggplot() +
150-
geom_line(data = uv_trim,
151-
aes(x = uv_date, val_uv),
120+
geom_line(data = uv_data,
121+
aes(x = time, value),
152122
color = "lightgrey") +
153123
geom_point(data = qw_closest,
154124
aes(x = qw_date, y = val_qw),

vignettes/read_waterdata_functions.Rmd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,23 @@ ggplot(data = daily_modern) +
181181
182182
```
183183

184+
## Continuous
185+
186+
The `read_waterdata_continuous` function replaces the `readNWISuv` function.
187+
188+
`r dataRetrieval:::get_description("continuous")`
189+
190+
To access these services on a web browser, go to <https://api.waterdata.usgs.gov/ogcapi/v0/collections/continuous>.
191+
192+
```{r}
193+
sensor_data <- read_waterdata_continuous(monitoring_location_id = "USGS-01491000",
194+
parameter_code = c("00060", "00010"),
195+
statistic_id = "00003",
196+
time = c("2023-10-01", "2024-09-30"))
197+
```
198+
199+
Currently this service only allows up to 3 years of data to be requested at once. If no time is specified in the query, the latest year of data is returned.
200+
184201
## Field Measurements
185202

186203
The `read_waterdata_field_measurements` replaces both the `readNWISgwl` and `readNWISmeas` functions.

0 commit comments

Comments
 (0)