You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/daily_data_statistics.Rmd
+13-15Lines changed: 13 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,9 @@ editor_options:
12
12
```{r, include = FALSE}
13
13
knitr::opts_chunk$set(
14
14
collapse = TRUE,
15
-
comment = "#>"
15
+
comment = "#>",
16
+
message = FALSE,
17
+
warning = FALSE
16
18
)
17
19
18
20
library(dataRetrieval)
@@ -40,7 +42,7 @@ Day-of-year and month-of-year statistics aggregate observations for the same cal
40
42
Consider the output below, where we request day-of-year discharge averages for January 1 and January 2.
41
43
Note that the `start_date` and `end_date` are set in `month-year` format to describe the day-of-year range.
42
44
43
-
```{r, message=FALSE, warning=FALSE}
45
+
```{r}
44
46
jan_por_mean <-
45
47
read_waterdata_stats_por(
46
48
monitoring_location_id = site1,
@@ -67,10 +69,10 @@ Let's now look at an example that illustrates the benefits of the statistics API
67
69
In the example below, we pull all day-of-year discharge percentiles for our site.
68
70
Keep in mind that doing so *without* the statistics API would require us to download the **entire** daily period of record for this site and hand-compute these percentiles ourselves, a time- and resource-intensive process indeed.
69
71
70
-
For demonstration, we filter the output to the January 1 day-of-year percentiles, which include a set of percentiles commonly used on WDFN webpages (e.g., [Wisconsin water conditions](https://waterdata.usgs.gov/state/wisconsin/)).
72
+
For demonstration, we filter the output to the January 1 day-of-year percentiles, which include a set of percentiles commonly used on the Water Data for the Nation (WDFN) webpages (e.g., [Wisconsin water conditions](https://waterdata.usgs.gov/state/wisconsin/)).
71
73
72
74
73
-
```{r, message=FALSE, warning=FALSE}
75
+
```{r}
74
76
full_por_percentiles <-
75
77
read_waterdata_stats_por(
76
78
monitoring_location_id = site1,
@@ -91,7 +93,7 @@ full_por_percentiles |>
91
93
After a bit of data manipulation, we can then visualize the percentiles as "ribbons" on a plot.
92
94
Each ribbon spans between two percentiles returned by the /statistics API (e.g., minimum to 5th, 5th to 10th, etc).
93
95
94
-
```{r, message=FALSE, warning=FALSE}
96
+
```{r}
95
97
doy_perc_bands <-
96
98
full_por_percentiles |>
97
99
sf::st_drop_geometry() |>
@@ -150,7 +152,7 @@ ggplot(data = doy_perc_bands,
150
152
151
153
Finally, let's overlay daily mean data onto the plot:
As <https://waterdata.usgs.gov/monitoring-location/USGS-02037500/statistical-graphs/>
221
+
As also seen on the WDFN pages:<https://waterdata.usgs.gov/monitoring-location/USGS-02037500/statistical-graphs/>
220
222
221
223
222
224
## Fetching monthly and annual statistics within a date range
@@ -225,7 +227,7 @@ Unlike day- or month-of-year statistics, which summarize typical seasonal condit
225
227
Consider the example below where we fetch the average discharge value for the month of January, 2024.
226
228
Notice that the `start_date` and `end_date` arguments are given in `YYYY-MM-DD` format.
227
229
228
-
```{r, message=FALSE, warning=FALSE}
230
+
```{r}
229
231
jan_daterange_mean <-
230
232
read_waterdata_stats_daterange(
231
233
monitoring_location_id = site1,
@@ -238,15 +240,11 @@ jan_daterange_mean <-
238
240
jan_daterange_mean
239
241
```
240
242
241
-
Instead of `time_of_year` and `time_of_year_type` columns, this output contains `start_date`, `end_date`, and `interval_type` columns representing the daterange over which the average was calculated.
242
-
The first row shows the average January, 2024 discharge was about 112 cubic feet per second.
243
-
We again have extra rows: the second row contains the **calendar** year 2024 average and the third contains the **water** year 2024 average.
243
+
Instead of `time_of_year` and `time_of_year_type` columns, this output contains `start_date`, `end_date`, and `interval_type` columns representing the daterange over which the average was calculated. The first row shows the average January, 2024 discharge was about 112 cubic feet per second. We again have extra rows: the second row contains the **calendar** year 2024 average and the third contains the **water** year 2024 average.
244
244
245
-
Annual statistics will be returned for any calendar/water years than intersect with the specified date range.
246
-
Consider the example below, where the `start_date` to `end_date` range is only 93 days yet happens to intersect with calendar **and** water years 2023 and 2024.
247
-
We see this reflected in output containing monthly averages for September, 2023 through January, 2024 as well as 2023 and 2024 calendar and water year averages.
245
+
Annual statistics will be returned for any calendar/water years than intersect with the specified date range. Consider the example below, where the `start_date` to `end_date` range is only 93 days yet happens to intersect with calendar **and** water years 2023 and 2024. We see this reflected in output containing monthly averages for September, 2023 through January, 2024 as well as 2023 and 2024 calendar and water year averages.
0 commit comments