Example Module 2 Workflow
TADA Team
2025-09-02
Source:vignettes/ExampleMod2Workflow.Rmd
ExampleMod2Workflow.Rmd
Install and Load EPATADA Package
First, install and load the remotes package specifying the repo. This is needed before installing EPATADA because it is only available on GitHub (not CRAN).
install.packages("remotes",
repos = "http://cran.us.r-project.org"
)
library(remotes)
Next, install and load EPATADA using the remotes package. USGS’s dataRetrieval and other TADA R Package dependencies will also be downloaded automatically from CRAN with the TADA install. If desired, the development version of dataRetrieval can be downloaded directly from GitHub (un-comment).
remotes::install_github("USEPA/EPATADA",
ref = "develop",
dependencies = TRUE
)
# remotes::install_github("USGS-R/dataRetrieval", dependencies=TRUE)
Finally, use the library() function to load the TADA R Package into your R session.
Get WQP Monitoring Data in Montana Using TADA_DataRetrieval()
Get bacteria and pH data from Missoula County, Montana.
# get MT data
tada.MT <- TADA_DataRetrieval(
startDate = "2020-01-01",
endDate = "2022-12-31",
statecode = "MT",
characteristicName = c(
"Escherichia",
"Escherichia coli",
"pH"
),
county = "Missoula County",
ask = FALSE
)
# clean up data set (minimal)
tada.MT.clean <- tada.MT %>%
TADA_RunKeyFlagFunctions() %>%
TADA_SimpleCensoredMethods()
# remove intermediate objects
rm(tada.MT)
Create An Example User-Supplied ATTAINS Assessment Unit and WQP Monitoring Location Crosswalk
Get existing data from ATTAINS and subset a few rows to create an example user-supplied crosswalk for demonstration purposes.
Find Additional ATTAINS Assessment Unit and WQP Monitoring Location Matches Using TADA_CreateAUMLCrosswalk()
Run TADA_CreateAUMLCrosswalk which can incorporate any combination of:
(optional) user-supplied crosswalk,
crosswalk downloaded from ATTAINS, and
results from TADA_CreateATTAINSAUMLCrosswalk which leverages the ATTAINS catchments to join monitoring locations to assessment units via a geospatial join .
The assignments are prioritized in the order listed. Any WQP monitoring locations which remain unassigned after checking the user-supplied crosswalk will be subset and run with TADA_CreateATTAINSAUMLCrosswalk which will attempt to make additional ATTAINS assessment unit assignments.
To make this function run more efficiently, and because we already have assessment unit assignments for some monitoring locations from the user-supplied crosswalk and the crosswalk downloaded from ATTAINS, the ATTAINS catchment data from the geospatial service is not currently being returned for matches in the crosswalks supplied by users or imported from ATTAINS. We have plans to create additional functions/internal reference files to facilitate this returning the associated catchments in the future. Therefore, any catchment data available for mapping is currently from TADA_CreateATTAINSAUMLCrosswalk assessed WQP monitoring locations only.
# use TADA get attains to make AU assignments for unassigned MLs
MT.AUMLRef <- TADA_CreateAUMLCrosswalk(tada.MT.clean,
au_ref = user.supplied.cw,
org_id = "MTDEQ",
add_catch = FALSE,
batch_upload = TRUE
)
Generate a Map with TADA_ViewATTAINS
The TADA_ViewATTAINS() map function shows the results from all three different crosswalk sources (user supplied crosswalk, ATTAINS crosswalk, and ATTAINS catchments/geospatial join) using different color circle markers (not final colors, we are very open to suggestions). The source has also been added to the popup window.
TADA_ViewATTAINS(MT.AUMLRef)
Update crosswalk in ATTAINS using TADA_UpdateATTAINSAUMLCrosswalk
After making any necessary changes to the ATTAINS_batchupload data frame generated by TADA_CreateAUMLCrosswalk, run TADA_UpdateATTAINSAUMLCrosswalk to add new links to WQP site pages.
batch.upload.MT <- MT.AUMLRef$ATTAINS_batchupload %>%
TADA_UpdateATTAINSAUMLCrosswalk( # selected attains_replace = TRUE because all matches currently in ATTAINS are included in this new crosswalk
attains_replace = TRUE,
batch_upload = TRUE,
wqp_data_links = "add",
# ml ids have already been corrected if needed
update_mlid = FALSE,
org_id = "MTDEQ"
)
Assign uses to AUs with TADA_CreateUseAURef
After assigning ML sites to AU, we will use TADA_CreateUseAURef to assign uses to these AUs. First, convert the ML sites to AU reference table to the appropriate format for TADA workflow. We will also assign the NEW:EX_MDEQ_WQ_WQX assessment unit example to the water type “LAKE, FRESHWATER” for demonstration on how to auto_assign uses to a new AU that is not yet in ATTAINS nor has been assigned uses to it yet.
Final.MT.AUMLRef <- MT.AUMLRef$ATTAINS_batchupload %>%
TADA_UpdateATTAINSAUMLCrosswalk( # selected attains_replace = TRUE because all matches currently in ATTAINS are included in this new crosswalk
attains_replace = TRUE,
batch_upload = FALSE,
wqp_data_links = "add",
# ml ids have already been corrected if needed
update_mlid = FALSE,
org_id = "MTDEQ"
) %>%
dplyr::mutate(
ATTAINS.WaterType = dplyr::case_when(
ATTAINS.AssessmentUnitIdentifier == "NEW:EX_MDEQ_WQ_WQX" ~ "LAKE, FRESHWATER",
TRUE ~ ATTAINS.WaterType
)
)
Now, we can use Final.MT.AUMLRef as our sites to AU crosswalk and proceed with assigning uses for each unique AU. The assignment of uses to AU are prioritized as follows:
(optional) User supplied uses to AU crosswalk,
Import existing uses by AU from ATTAINS ExpertQuery.
MT.UseAURef <- TADA_CreateUseAURef(AUMLRef = Final.MT.AUMLRef, org_id = "MTDEQ")
Assign uses to new AUs based on water type with TADA_CreateWaterUseRef
For any new AU, users will need to determine how to assign uses to them.
- TADA has developed a function called TADA_CreateWaterUseRef which imports a crosswalk of existing uses by water type from ExpertQuery for a specified organization. It can be leveraged within TADA_CreateUseAURef to assign any new AU the applicable uses for that water type. Users may choose to edit the TADA_CreateWaterUseRef crosswalk if needed.
MT.UseAURef.WaterUseRef <- TADA_CreateUseAURef(
waterUseRef = TADA_CreateWaterUseRef(org_id = "MTDEQ"),
AUMLRef = Final.MT.AUMLRef,
org_id = "MTDEQ"
)
- Users may manually assign use names to any new AUs if desired rather than using TADA_CreateWaterUseRef. For example:
MT.UseAURef.manual <- MT.UseAURef %>%
dplyr::left_join(
data.frame(
ATTAINS.UseName = c("Aquatic Life", "Drinking Water"),
ATTAINS.AssessmentUnitIdentifier = c("NEW:EX_MDEQ_WQ_WQX", "NEW:EX_MDEQ_WQ_WQX")
),
by = ("ATTAINS.AssessmentUnitIdentifier")
) %>%
dplyr::mutate(ATTAINS.UseName = dplyr::coalesce(ATTAINS.UseName.x, ATTAINS.UseName.y)) %>%
dplyr::select(-ATTAINS.UseName.x, -ATTAINS.UseName.y)