Learn R Programming

dataRetrieval (version 2.7.11)

readNWISdata: General Data Import from NWIS

Description

Returns data from the NWIS web service. Arguments to the function should be based on https://waterservices.usgs.gov service calls. See examples below for ideas of constructing queries.

Usage

readNWISdata(..., asDateTime = TRUE, convertType = TRUE, tz = "UTC")

Arguments

see https://waterservices.usgs.gov/rest/Site-Service.html for a complete list of options. A list of arguments can also be supplied. One important argument to include is 'service'. Possible values are "iv" (for instantaneous), "iv_recent" (for instantaneous values within the last 120 days), "dv" (for daily values), "gwlevels" (for groundwater levels), "site" (for site service), "qw" (water-quality),"measurement", and "stat" (for statistics service). Note: "qw" and "measurement" calls go to: https://nwis.waterdata.usgs.gov/usa/nwis for data requests, and use different call requests schemes. The statistics service has a limited selection of arguments (see https://waterservices.usgs.gov/rest/Statistics-Service-Test-Tool.html).

asDateTime

logical, if TRUE returns date and time as POSIXct, if FALSE, Date

convertType

logical, defaults to TRUE. If TRUE, the function will convert the data to dates, datetimes, numerics based on a standard algorithm. If false, everything is returned as a character

tz

character to set timezone attribute of dateTime. Default is "UTC", and converts the date times to UTC, properly accounting for daylight savings times based on the data's provided tz_cd column. Possible values to provide are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles", "America/Anchorage", as well as the following which do not use daylight savings time: "America/Honolulu", "America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla". See also OlsonNames() for more information on time zones.

Value

A data frame with the following columns:

Name Type Description
agency character The NWIS code for the agency reporting the data
site character The USGS site number
dateTime POSIXct The date and time (if applicable) of the measurement, converted to UTC for unit value data. R only allows one time zone attribute per column. For unit data spanning a time zone change, converting the data to UTC solves this problem. For daily data, the time zone attribute is the time zone of the first returned measurement.
tz_cd character The time zone code for dateTime column
code character Any codes that qualify the corresponding value
value numeric The numeric value for the parameter

Note that code and value are repeated for the parameters requested. The names are of the form X_D_P_S, where X is literal, D is an option description of the parameter, P is the parameter code, and S is the statistic code (if applicable).

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

Name Type Description
url character The url used to generate the data
siteInfo data.frame A data frame containing information on the requested sites
variableInfo data.frame A data frame containing information on the requested parameters
statisticInfo data.frame A data frame containing information on the requested statistics on the data
queryTime POSIXct The time the data was returned

See Also

renameNWISColumns, importWaterML1, importRDB1

Examples

Run this code
# NOT RUN {
# Examples not run for time considerations

dataTemp <- readNWISdata(stateCd="OH",parameterCd="00010", service="dv")
instFlow <- readNWISdata(sites="05114000", service="iv", 
                   parameterCd="00060", 
                   startDate="2014-05-01T00:00Z",endDate="2014-05-01T12:00Z")
                                                   
instFlowCDT <- readNWISdata(sites="05114000", service="iv", 
                   parameterCd="00060", 
                   startDate="2014-05-01T00:00",endDate="2014-05-01T12:00",
                   tz="America/Chicago")

#Empty:
multiSite <- readNWISdata(sites=c("04025000","04072150"), service="iv", 
                           parameterCd="00010")
#Not empty:
multiSite <- readNWISdata(sites=c("04025500","040263491"), 
                           service="iv", parameterCd="00060")
bBoxEx <- readNWISdata(bBox=c(-83,36.5,-81,38.5), parameterCd="00010")

startDate <- as.Date("2013-10-01")
endDate <- as.Date("2014-09-30")
waterYear <- readNWISdata(bBox=c(-83,36.5,-82.5,36.75), parameterCd="00010", 
                  service="dv", startDate=startDate, endDate=endDate)
siteInfo <- readNWISdata(stateCd="WI", parameterCd="00010",
                  hasDataTypeCd="iv", service="site")
temp <- readNWISdata(bBox=c(-83,36.5,-82.5,36.75), parameterCd="00010", service="site", 
                   seriesCatalogOutput=TRUE)
wiGWL <- readNWISdata(stateCd = "WI", service = "gwlevels")
meas <- readNWISdata(state_cd = "WI", service = "measurements",
                     format = "rdb_expanded")

waterYearStat <- readNWISdata(site = c("01646500"), 
                              service = "stat",
                              statReportType="annual",
                              statYearType = "water",
                              missingData = "on")
monthlyStat <- readNWISdata(site=c("01646500"),
                            service="stat",
                            statReportType="monthly")  
                                                             
dailyStat <- readNWISdata(site = c("01646500"),
                          service = "stat",
                          statReportType = "daily",
                          statType = c("p25","p50","p75","min","max"),
                          parameterCd = "00060")

arg.list <- list(site = "03111548",
                 statReportType = "daily",
                 statType = c("p25","p50","p75","min","max"),
                 parameterCd = "00060")
allDailyStats_2 <- readNWISdata(arg.list, service="stat")

#' # use county names to get data
dailyStaffordVA <- readNWISdata(stateCd = "Virginia",
                                countyCd="Stafford",
                                parameterCd = "00060",
                                startDate = "2015-01-01",
                                endDate = "2015-01-30")
va_counties <- c("51001","51003","51005","51007","51009","51011","51013","51015")
va_counties_data <- readNWISdata(startDate = "2015-01-01", endDate = "2015-12-31", 
parameterCd = "00060", countycode = va_counties)
 
site_id <- '01594440'
rating_curve <- readNWISdata(service = "rating", site_no = site_id, file_type="base")
all_sites_base <- readNWISdata(service = "rating", file_type="base")
all_sites_core <- readNWISdata(service = "rating", file_type="corr")
all_sites_exsa <- readNWISdata(service = "rating", file_type="exsa")
all_sites_24hrs <- readNWISdata(service = "rating", file_type="exsa", period = 24)
                      
peak_data <- readNWISdata(service = "peak", 
                          site_no = c("01594440","040851325"),
                          range_selection = "data_range")


# }

Run the code above in your browser using DataLab