Skip to contents

Retrieve data from Water Quality Portal (WQP) and generate a TADA-compatible dataframe. Note that the inputs (e.g. project, organization, siteType) with the exceptions of endDate and startDate match the web service call format from the online WQP GUI. endDate and startDate match the format suggested in USGS's dataRetrieval package (endDate = "YYYY-MM-DD"), which is a more familiar date format for R users than the WQP GUI's endDateHi = "MM-DD-YYYY".

Usage

TADA_DataRetrieval(
  startDate = "null",
  endDate = "null",
  countrycode = "null",
  countycode = "null",
  huc = "null",
  siteid = "null",
  siteType = "null",
  characteristicName = "null",
  characteristicType = "null",
  sampleMedia = "null",
  statecode = "null",
  organization = "null",
  project = "null",
  providers = "null",
  applyautoclean = TRUE
)

Arguments

startDate

Start Date string in the format YYYY-MM-DD, for example, "2020-01-01"

endDate

End Date string in the format YYYY-MM-DD, for example, "2020-01-01"

countrycode

Code that identifies a country or ocean (e.g. countrycode = "CA" for Canada, countrycode = "OA" for Atlantic Ocean). See https://www.waterqualitydata.us/Codes/countrycode for options.

countycode

FIPS county name. Note that a state code must also be supplied (e.g. statecode = "AL", countycode = "Chilton"). See https://www.waterqualitydata.us/Codes/countycode for options.

huc

A numeric code denoting a hydrologic unit. Example: "04030202". Different size hucs can be entered. See https://epa.maps.arcgis.com/home/item.html?id=796992f4588c401fabec7446ecc7a5a3 for a map with HUCS. Click on a HUC to find the associated code.

siteid

Unique monitoring location identifier.

siteType

Type of waterbody. See https://www.waterqualitydata.us/Codes/sitetype for options.

characteristicName

Name of parameter. See https://www.waterqualitydata.us/Codes/characteristicName for options.

characteristicType

Groups of environmental measurements/parameters. See https://www.waterqualitydata.us/Codes/characteristicType for options.

sampleMedia

Sampling substrate such as water, air, or sediment. See https://www.waterqualitydata.us/Codes/sampleMedia for options.

statecode

FIPS state alpha code that identifies a state (e.g. statecode = "DE" for Delaware). See https://www.waterqualitydata.us/Codes/statecode for options.

organization

A string of letters and/or numbers (some additional characters also possible) used to signify an organization with data in the Water Quality Portal. See https://www.waterqualitydata.us/Codes/organization for options.

project

A string of letters and/or numbers (some additional characters also possible) used to signify a project with data in the Water Quality Portal. See https://www.waterqualitydata.us/Codes/project for options.

providers

Leave blank to include all, or specify "STEWARDS", "STORET" (i.e., WQX), and/or "NWIS". See https://www.waterqualitydata.us/Codes/providers for options.

applyautoclean

Logical, defaults to TRUE. Applies TADA_AutoClean function on the returned data profile.

Value

TADA-compatible dataframe

Details

Multiple fields are queried together using AND logic, but multiple values within one field are queried together using OR logic. For example, within characteristicName, if you enter, c("pH", "Dissolved oxygen (DO)), the function will return all results that are "pH" OR "Dissolved oxygen (DO)". Similarly, if you enter c("VA", "IL"), the function will return results from Virginia OR Illinois. But the combo of these fields are ANDs: The function will return any pH and DO data from only Virginia or Illinois; the data must fit into one of the values from BOTH of the query fields. characteristicName and Characteristic Group also work as an AND, therefore the characteristicName must fall within the Characteristic Group when both are entered.

Users can reference the WQX domain tables to find allowable values for queries, e.g., reference the WQX domain table to find countycode and statecode: https://cdx.epa.gov/wqx/download/DomainValues/County_CSV.zip Alternatively, you can use the WQP services to find areas where data is available in the US: https://www.waterqualitydata.us/Codes/countycode

TADA_DataRetrieval automatically runs TADA_AutoClean on the incoming data frame. TADA_AutoClean is important for categorizing result value and detection limit data, as well as harmonizing key columns used in TADA. See ?TADA_AutoClean for more information.

Note: TADA_DataRetrieval (by leveraging dataRetrieval), automatically converts the date times to UTC. It also automatically converts the data to dates, datetimes, numerics based on a standard algorithm. See: ?dataRetrieval::readWQPdata

Examples

if (FALSE) { # \dontrun{
# example for WI
tada1 <- TADA_DataRetrieval(
  statecode = "WI", countycode = "Dane",
  characteristicName = "Phosphorus"
)

# example for UT
tada2 <- TADA_DataRetrieval(
  statecode = "UT",
  characteristicName = c("Ammonia", "Nitrate", "Nitrogen")
)

# example for SC
tada3 <- TADA_DataRetrieval(statecode = "SC", countycode = "Abbeville")

# example for CT
tada4 <- TADA_DataRetrieval(statecode = "CT", startDate = "2020-10-01")


# note that countycode queries require a statecode (see example below)
tada5 <- TADA_DataRetrieval(countycode = "US:02:020")

# example for NM
tada6 <- TADA_DataRetrieval(
  statecode = "NM",
  characteristicName = c(
    "Ammonia",
    "Nitrate",
    "Nitrogen"
  ),
  startDate = "2020-05-01"
)

# example for AK project
tada7 <- TADA_DataRetrieval(project = "Anchorage Bacteria 20-21")

# another example for AK
tada8 <- TADA_DataRetrieval(
  statecode = "AK",
  characteristicName = c(
    "Fecal Coliform",
    "Escherichia coli",
    "Enterococcus",
    "Ammonia",
    "Nitrate",
    "Nitrogen"
  ),
  startDate = "2018-05-01"
)

# example for tribes
# Download data for many of the ATTAINS participating tribes
# Note this query may take about a half hour to run
# https://www.itecmembers.org/attains/
# ATTAINS participating tribes also have tribal pages in EPA's
# How's My Waterway Application
# Example: https://mywaterway.epa.gov/tribe/SFNOES
#
# Sac & Fox Nation, Oklahoma "SFNOES_WQX"
# Citizen Potawatomi Nation, Oklahoma "CPNWATER"
# Delaware Nation, Oklahoma "DELAWARENATION"
# Hoopa Valley Tribe, California "HVTEPA_WQX"
# Otoe Missouria Tribe of Oklahoma "O_MTRIBE_WQX"
# Minnesota Chippewa Tribe, Minnesota (Fond du Lac Band) "FONDULAC_WQX"
# Pueblo of San Ildefonso, New Mexico "SANILDEFONSODECP"
# Pueblo of Santa Ana, New Mexico "PUEBLO_SANTAANA"
# Pueblo of Tesuque, New Mexico "PUEBLOOFTESUQUE"
# Red Lake Band of Chippewa Indians, Minnesota "REDLAKE_WQX"
# Seneca-Cayuga Nation "SCEQ"
# The Chickasaw Nation "CNENVSER"
# The Choctaw Nation of Oklahoma "CHOCNATWQX"
# Wyandotte Nation "WNENVDPT_WQX"
# Pueblo of Pojoaque "PUEBLO_POJOAQUE"

tada9 <- TADA_DataRetrieval(organization = c(
  "SFNOES_WQX",
  "CPNWATER",
  "DELAWARENATION",
  "HVTEPA_WQX",
  "O_MTRIBE_WQX",
  "FONDULAC_WQX",
  "SANILDEFONSODECP",
  "PUEBLO_SANTAANA",
  "PUEBLOOFTESUQUE",
  "REDLAKE_WQX",
  "SCEQ",
  "CNENVSER",
  "CHOCNATWQX",
  "WNENVDPT_WQX",
  "PUEBLO_POJOAQUE"
))

# query only NWIS data for a 10 year period in CT
tada10 <- TADA_DataRetrieval(
  startDate = "2013-01-01",
  endDate = "2022-12-31",
  sampleMedia = c("Water", "water"),
  statecode = "CT", # consider downloading only 1 state at a time
  providers = "NWIS",
  applyautoclean = FALSE
)

# query by country code (e.g. Canada, countrycode = "CA")
tada11 <- TADA_DataRetrieval(
  startDate = "2015-01-01",
  countrycode = "CA"
)
} # }