Raw Data Import for USGS NWIS QW Data

Description

Imports data from NWIS web service. This function gets the data from here: http://nwis.waterdata.usgs.gov/nwis/qwdata A list of parameter codes can be found here: http://nwis.waterdata.usgs.gov/nwis/pmcodes/ A list of statistic codes can be found here: http://nwis.waterdata.usgs.gov/nwis/help/?read_file=stat&format=table

Usage

1
2
readNWISqw(siteNumbers, parameterCd, startDate = "", endDate = "",
  expanded = TRUE, reshape = FALSE, tz = "")

Arguments

siteNumbers

character of USGS site numbers. This is usually an 8 digit number

parameterCd

character that contains the code for a parameter group, or a character vector of 5-digit parameter codes. See Details.

startDate

character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the earliest possible record. Date arguments are always specified in local time.

endDate

character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates retrieval for the latest possible record. Date arguments are always specified in local time.

expanded

logical defaults to TRUE. If TRUE, retrieves additional information. Expanded data includes remark_cd (remark code), result_va (result value), val_qual_tx (result value qualifier code), meth_cd (method code), dqi_cd (data-quality indicator code), rpt_lev_va (reporting level), and rpt_lev_cd (reporting level type). If FALSE, only returns remark_cd (remark code) and result_va (result value). Expanded = FALSE will not give sufficient information for unbiased statistical analysis.

reshape

logical, reshape the expanded data. If TRUE, then return a wide data frame with all water-quality in a single row for each sample. If FALSE (default), then return a long data frame with each water-quality result in a single row. This argument is only applicable to expanded data. Data requested using expanded=FALSE is always returned in the wide format.

tz

character to set timezone attribute of output columns: startDateTime and endDateTime. Default is an empty quote, which converts the datetimes to UTC (properly accounting for daylight savings times). Possible values to provide are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles", "America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"

Details

Valid parameter code groups are "All," or group codes:

Code Description
INF Information
PHY Physical
INM Inorganics, Major, Metals (major cations)
INN Inorganics, Major, Non-metals (major anions)
NUT Nutrient
MBI Microbiological
BIO Biological
IMN Inorganics, Minor, Non-metals
IMM Inorganics, Minor, Metals
TOX Toxicity
OPE Organics, pesticide
OPC Organics, PCBs
OOT Organics, other
RAD Radiochemical
SED Sediment
POP Population/community

If more than one parameter group is requested, only sites that data for all requested groups are returned.

Value

A data frame with at least the following columns:

Name Type Description
agency_cd character The NWIS code for the agency reporting the data
site_no character The USGS site number
sample_dt Date The date the sample was collected
sample_tm character The reported sample collection time
startDateTime POSIXct Combining sample_dt and sample_tm, a date/time column is created, and converted into UTC (unless the tz argument specifies a different time zone)
endDateTime POSIXct If any sample_end_dt and sample_end_dt exist, this column is created similar to startDateTime

Further columns will be included depending on the requested output format (expanded = TRUE or FALSE).

There are also several useful attributes attached to the data frame:

Name Type Description
url character The url used to generate the data
queryTime POSIXct The time the data was returned
comment character Header comments from the RDB file
siteInfo data frame A data frame containing information on the requested sites
variableInfo data frame A data frame containing information on the requested parameters

See Also

readWQPdata, whatWQPsites, readWQPqw, constructNWISURL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
siteNumbers <- c('04024430','04024000')
startDate <- '2010-01-01'
endDate <- ''
parameterCd <- c('34247','30234','32104','34220')
## Not run: 
rawNWISqwData <- readNWISqw(siteNumbers,parameterCd,startDate,endDate)
rawNWISqwDataReshaped <- readNWISqw(siteNumbers,parameterCd,
          startDate,endDate,reshape=TRUE)
parameterCd <- "all"
rawNWISall <- readNWISqw(siteNumbers,parameterCd,
          startDate,endDate)
pgroup <- c("NUT")
rawNWISNutrients <- readNWISqw(siteNumbers,pgroup,
          startDate,endDate)
groups <- c("NUT","OPE")
rawNWISNutOpe <- readNWISqw(siteNumbers,groups,
          startDate,endDate) 
rawNWISOpe <- readNWISqw(siteNumbers,"OPE",
          startDate,endDate) 
         
## End(Not run) 

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.