Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,4 @@ export(TADA_ViewATTAINS)
export(TADA_ViewColorPalette)
export(TADA_addPoints)
export(TADA_addPolys)
export(TADA_getNWIS)
importFrom(magrittr,"%>%")
6 changes: 2 additions & 4 deletions R/ContinuousDataFunctions.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' TADA_listNWIS
#' TADA_listNWIS (DRAFT - UNDER ACTIVE DEVELOPMENT)
#'
#' List USGS continuous monitoring sites with available daily statistics
#'
Expand Down Expand Up @@ -396,7 +396,7 @@ TADA_listNWIS <- function(aoi_sf = "null", statecode = "null", siteid = "null")
}


#' Retrieve and tidy daily values from NWIS
#' Retrieve and tidy daily values from NWIS (DRAFT - UNDER ACTIVE DEVELOPMENT)
#'
#' This function interfaces with the USGS National Water Information System (NWIS) to
#' retrieve daily values (DV) water quality data using the TADA (Tools for Automated
Expand All @@ -423,8 +423,6 @@ TADA_listNWIS <- function(aoi_sf = "null", statecode = "null", siteid = "null")
#' should be provided. The function will stop if none or more than one are provided.
#' Moreover, all sf features must be under 118,078 square miles (roughly the area of Nevada).
#'
#' @export
#'
#' @examples
#' \dontrun{
#' # Example 1: Query by area of interest
Expand Down
4 changes: 2 additions & 2 deletions R/Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,9 @@ TADA_FindNearbySites <- function(.data, dist_buffer = 100,
nhd.catch <- near.dfs %>%
purrr::map(~ .x %>%
fetchNHD(resolution = nhd_res))

# remove any fetchNHD dfs that do not contain any data (to prevent bind rows error)
nhd.catch.filt <- purrr::keep(nhd.catch, ~nrow(.) > 0)
nhd.catch.filt <- purrr::keep(nhd.catch, ~ nrow(.) > 0)

# create one df from all fetchNHD data
nhd.catch.all <- dplyr::bind_rows(nhd.catch.filt)
Expand Down
228 changes: 228 additions & 0 deletions R/dev/Draft/ContinuousDataIntegration.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
---
title: "Continuous Data Integration"
format: html
editor: visual
author: "TADA Team"
date: "`r Sys.Date()`"
output:
rmarkdown::html_vignette:
toc: true
fig_caption: yes
fig_height: 8
fig_width: 8
vignette: >
%\VignetteEncoding{UTF-8}
%\VignetteIndexEntry{Continuous Data Integration}
%\VignetteEngine{knitr::rmarkdown}
description: An example workflow integrating USGS continuous data with WQP data.
editor_options:
chunk_output_type: console
markdown:
wrap: 72
---

## Welcome!

Thank you for your interest in Tools for Automated Data Analysis (TADA).
TADA is an open-source tool set built in the R programming language.
This [RMarkdown](https://bookdown.org/yihui/rmarkdown/) document walks
users through how to download the TADA R package from GitHub, access and
parameterize several important functions, and create basic
visualizations with a sample data set.

**Note: TADA is still under development. New functionality is added
weekly, and sometimes we need to make bug fixes in response to tester
and user feedback. We appreciate your feedback, patience, and interest
in these helpful tools.**

**If you are interested in contributing to TADA development, more
information is available at:**

[**Contributing**](https://usepa.github.io/EPATADA/articles/CONTRIBUTING.html)

**We welcome collaboration with external partners.**

## Install and load packages

First, install and load the remotes package specifying the repo. This is
needed before installing TADA because it is only available on GitHub.

```{r install_remotes, results = 'hide'}
install.packages("remotes",
repos = "http://cran.us.r-project.org"
)
library(remotes)
```

Next, install and load TADA using the remotes package. TADA R Package
dependencies will also be downloaded automatically from CRAN with the
TADA install. You may be prompted in the console to update dependency
packages that have more recent versions available. If you see this
prompt, it is recommended to update all of them (enter 1 into the
console).

```{r install_TADA, eval = F, results = 'hide'}
remotes::install_github("USEPA/EPATADA",
ref = "develop",
dependencies = TRUE
)
```

```{r dev_install, results = 'hide', include = F}
remotes::install_github("USEPA/EPATADA",
ref = "develop",
dependencies = TRUE
)
```

Finally, use the **library()** function to load the TADA R Package into
your R session.

```{r, results = 'hide'}
library(EPATADA)
```

## Help pages

All EPATADA R package functions have their own individual help pages,
listed in the Package index on the
[Reference](https://usepa.github.io/EPATADA/reference/index.html) tab of
the GitHub website. Users can also access the help page for a given
function in R or RStudio using the following format (example below):
`?[name of TADA function]`

```{r help_pages, eval = F}
# Access help page for TADA_DataRetrieval
?TADA_DataRetrieval
```

# USGS National Water Information System (NWIS) Functions

TADA provides functions to access continuous daily USGS National Water
Information System (NWIS) data. These functions allow you to query and
retrieve continuous daily-value data from USGS water monitoring
locations.

### `TADA_listNWIS()`

This function retrieves all available daily data from USGS National
Water Information System (NWIS) based on different queries: an area of
interest (i.e., an sf object), states, or specific sites.

The function returns a spatial sf object containing site information and
available parameters. If no data is found, it returns an empty sf object
with the appropriate column structure.

#### Using `TADA_listNWIS()`

Let's retrieve information about available NWIS data by a state, then
visualize that information:

```{r}
# Example: Query by state
ri_sites <- TADA_listNWIS(statecode = "RI")

ri_summary <- ri_sites %>%
dplyr::group_by(site_no) %>%
dplyr::summarize(
parameters = paste(unique(parameter), collapse = "; "),
parameter_codes = paste(unique(parameter_code), collapse = "; ")
)

leaflet::leaflet() %>%
leaflet::addProviderTiles("Esri.WorldTopoMap",
group = "World topo",
options = leaflet::providerTileOptions(
updateWhenZooming = FALSE,
updateWhenIdle = TRUE
)
) %>%
leaflet::clearShapes() %>%
leaflet.extras::addResetMapButton() %>%
leaflet::addLegend(
position = "bottomright",
colors = "black",
labels = "NWIS Monitoring Location(s)",
opacity = 1
) %>%
leaflet::addCircleMarkers(
data = ri_summary,
color = "grey", fillColor = "black",
fillOpacity = 0.8, stroke = TRUE, weight = 1.5, radius = 6,
popup = paste0(
"Site Number: ",
ri_summary$site_no,
"<br> Parameters: ",
ri_summary$parameters,
"<br> Parameter codes: ",
ri_summary$parameter_codes
)
)
```

We can also query by specific USGS monitoring sites:

```{r}
site_nums <- c("11530500", "11532500") # Two sites in Northern California
sites_info <- TADA_listNWIS(siteid = site_nums)
```

Lastly, we can query NWIS sites by a user-supplied sf object:

```{r}
cherokee_sf <- sf::st_read("inst/extdata/OKTribe.shp") %>%
dplyr::filter(NAME == "Cherokee")

cherokee_nwis <- TADA_listNWIS(aoi_sf = cherokee_sf)
```

### `TADA_getNWIS()`

This function retrieves and tidy-formats daily values from NWIS. It
interfaces with the USGS National Water Information System to retrieve
daily value (DV) water data. Like `TADA_listNWIS()`, users can query
data based on an area of interest (i.e., an sf object), statecode, or
specific sites.

Additionally, users must specify the parameter codes and statistics they
want to download and a date range. A list of all available parameters
can be found at:
[https://help.waterdata.usgs.gov/parameter_cd?group_cd=%](https://help.waterdata.usgs.gov/parameter_cd?group_cd=%){.uri}
and a list of all statistics codes can be found at:
<https://help.waterdata.usgs.gov/stat_code>

#### Using `TADA_getNWIS()`

With TADA_getNWIS(), users can retrieve time series data available from
USGS sites by specifying the desired locations (using site identifiers,
spatial feature (sf) objects, or states - similar to `TADA_listNWIS()`),
parameter codes, statistics codes, and a time period. Let's retrieve
mean (stat code 00003) water temperature data (parameter code 00010)
being collected in the sf object above for January 2022:

```{r}
# Example: Retrieve water temperature data within a specified area of interest:
temperature_data <- TADA_getNWIS(
aoi_sf = cherokee_sf, # could also use arguments `statecode` or `siteid`
parameter_codes = "00010", # water temperature in Celsius
stat_codes = "00003", # mean daily value
start_date = "2022-01-01",
end_date = "2022-01-31"
)

# Let's visualize the discharge data
temperature_data %>%
dplyr::mutate(
NWIS.date = as.Date(NWIS.date),
NWIS.value = as.numeric(NWIS.value)
) %>%
ggplot2::ggplot(ggplot2::aes(x = NWIS.date, y = NWIS.value, color = NWIS.site_no)) +
ggplot2::geom_line() +
ggplot2::labs(
title = "Daily Water Temperature at Selected USGS Sites",
x = "Date",
y = "Water Temperature (Celsius)",
color = "Site Number"
) +
ggplot2::theme_minimal()
```
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Welcome to EPATADA: Tools for Automated Data Analysis!
## EPATADA: Tools for Automated Data Analysis!

[![](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)

Expand All @@ -24,28 +24,40 @@ Tools for Automated Data Analysis, or TADA, is being developed to help States, T

## Installation

You must first have R and R Studio installed to use the TADA R Package (see instructions below if needed). Our team is actively developing TADA, therefore we highly recommend that you update the TADA R Package and all of its dependency libraries each time you use the package. You can install and/or update the [TADA R Package](https://github.com/USEPA/EPATADA) and all dependencies by running:
You must first have R and R Studio installed to use the TADA R Package (see instructions below if needed). Our team is actively developing TADA, therefore we highly recommend that you update the TADA R Package and all of its dependency libraries each time you use the package. You can install and/or update the TADA R Package and all dependencies by running:

```{r}
if(!"remotes"%in%installed.packages()){
install.packages("remotes")
}

library(remotes)

remotes::install_github("USEPA/EPATADA", ref = "develop", dependencies = TRUE, force = TRUE)

library(EPATADA)
```

The TADA R Shiny application can be run [on the web](https://rconnect-public.epa.gov/TADAShiny/) (R and R Studio install not required), or within R Studio. We recommend running it within R Studio if possible to avoid time out issues and to make sure you have the most up to data version (web version is on a slightly lagged update schedule). Run the following code within R Studio to install or update and run the most recent version of the [TADA R Shiny](https://github.com/USEPA/TADAShiny) application:
The TADA R Shiny application can be run [on the web](https://rconnect-public.epa.gov/TADAShiny/) (R and R Studio install not required), or within R Studio. We recommend running it within R Studio if possible to avoid time out issues (especially when working with large datasets) and to make sure you are using the most up to date version. The web version of the application is on a slightly lagged update schedule. Run the following code within R Studio to install or update and run the most recent version of the [TADA R Shiny](https://github.com/USEPA/TADAShiny) application:

```{r}
if(!"remotes"%in%installed.packages()){
install.packages("remotes")
}

library(remotes)

remotes::install_github("USEPA/TADAShiny", ref = "develop", dependencies = TRUE, force = TRUE)

TADAShiny::run_app()
library(TADAShiny)

run_app()
```

## Run Web Version

Alternatively, you can run the public web version of the TADAShiny application (<https://rconnect-public.epa.gov/TADAShiny/>). Beware that this version is not the most up to date and we recommend running the app from R studio instead if possible.

### Recommended Citation:

```
Expand Down
Loading