diff --git a/.Rbuildignore b/.Rbuildignore index 7ad0cd654..24ec5b01e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -69,3 +69,5 @@ vignettes/continuous_pr.Rmd vignettes/quick_slides.Rmd ^[.]?air[.]toml$ ^\.vscode$ +^\.positai$ +^\.claude$ diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 4491fc348..129542db0 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -46,19 +46,23 @@ jobs: any::pkgdown any::rcmdcheck any::DT - any::data.table any::dplyr any::tidyr any::ggplot2 - any::zoo any::sf any::patchwork - any::maps + any::reticulate any::leaflet any::readxl any::gridExtra local::. needs: website + - name: Setup Micromamba + uses: mamba-org/setup-micromamba@v1 + with: + environment-file: environment.yml + cache-environment: false + cache-downloads: false - name: Create public directory run: | mkdir public diff --git a/.gitignore b/.gitignore index 6debd82a7..0eade678e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ vignettes/*.R /.quarto/ **/*.quarto_ipynb +.positai diff --git a/R/readNWISunit.R b/R/readNWISunit.R index c5b4fbc62..ae117ea13 100644 --- a/R/readNWISunit.R +++ b/R/readNWISunit.R @@ -58,25 +58,10 @@ #' endDate <- "2014-10-10" #' \donttest{ #' -#' rawData <- readNWISuv(site_id, parameterCd, startDate, endDate) +#' #rawData <- readNWISuv(site_id, parameterCd, startDate, endDate) #' -#' rawData_today <- readNWISuv(site_id, parameterCd, Sys.Date(), Sys.Date()) +#' #rawData_today <- readNWISuv(site_id, parameterCd, Sys.Date(), Sys.Date()) #' -#' timeZoneChange <- readNWISuv( -#' c("04024430", "04024000"), parameterCd, -#' "2013-11-03", "2013-11-03" -#' ) -#' -#' centralTime <- readNWISuv(site_id, parameterCd, -#' "2014-10-10T12:00", "2014-10-10T23:59", -#' tz = "America/Chicago" -#' ) -#' -#' # Adding 'Z' to the time indicates to the web service to call the data with UTC time: -#' GMTdata <- readNWISuv( -#' site_id, parameterCd, -#' "2014-10-10T00:00Z", "2014-10-10T23:59Z" -#' ) #' } readNWISuv <- function( siteNumbers, @@ -352,28 +337,28 @@ readNWISrating <- function(siteNumber, type = "base", convertType = TRUE) { #' @export #' @examplesIf is_dataRetrieval_user() #' \donttest{ -#' x1 <- readNWISstat( -#' siteNumbers = c("02319394"), -#' parameterCd = c("00060"), -#' statReportType = "annual" -#' ) +#' # x1 <- readNWISstat( +#' # siteNumbers = c("02319394"), +#' # parameterCd = c("00060"), +#' # statReportType = "annual" +#' # ) #' #' # all the annual mean discharge data for two sites -#' x2 <- readNWISstat( -#' siteNumbers = c("02319394", "02171500"), -#' parameterCd = c("00010", "00060"), -#' statReportType = "annual" -#' ) +#' #x2 <- readNWISstat( +#' # siteNumbers = c("02319394", "02171500"), +#' # parameterCd = c("00010", "00060"), +#' # statReportType = "annual" +#' # ) #' #' # Request p25, p75, and mean values for temperature and discharge for the 2000s #' # Note that p25 and p75 were not available for temperature, and return NAs -#' x <- readNWISstat( -#' siteNumbers = c("02171500"), -#' parameterCd = c("00010", "00060"), -#' statReportType = "daily", -#' statType = c("mean", "median"), -#' startDate = "2000", endDate = "2010" -#' ) +#' #x <- readNWISstat( +#' # siteNumbers = c("02171500"), +#' # parameterCd = c("00010", "00060"), +#' # statReportType = "daily", +#' # statType = c("mean", "median"), +#' # startDate = "2000", endDate = "2010" +#' # ) #' } readNWISstat <- function( siteNumbers, diff --git a/R/readWQPdata.R b/R/readWQPdata.R index 92d70b67b..3f65c6263 100644 --- a/R/readWQPdata.R +++ b/R/readWQPdata.R @@ -86,47 +86,47 @@ #' \donttest{ #' #' # Legacy: -#' nameToUse <- "pH" -#' pHData <- readWQPdata(siteid = "USGS-04024315", -#' characteristicName = nameToUse) -#' ncol(pHData) -#' attr(pHData, "siteInfo") -#' attr(pHData, "queryTime") -#' attr(pHData, "url") +#' #nameToUse <- "pH" +#' #pHData <- readWQPdata(siteid = "USGS-04024315", +#' # characteristicName = nameToUse) +#' #ncol(pHData) +#' #attr(pHData, "siteInfo") +#' #attr(pHData, "queryTime") +#' #attr(pHData, "url") #' #' # WQX3: -#' pHData_wqx3 <- readWQPdata(siteid = "USGS-04024315", -#' characteristicName = nameToUse, -#' service = "ResultWQX3", -#' dataProfile = "basicPhysChem") -#' attr(pHData_wqx3, "url") +#' #pHData_wqx3 <- readWQPdata(siteid = "USGS-04024315", +#' # characteristicName = nameToUse, +#' # service = "ResultWQX3", +#' # dataProfile = "basicPhysChem") +#' # attr(pHData_wqx3, "url") #' #' # More examples: #' # querying by county -#' DeWitt <- readWQPdata( -#' statecode = "Illinois", -#' countycode = "DeWitt", -#' characteristicName = "Nitrogen" -#' ) +#' #DeWitt <- readWQPdata( +#' # statecode = "Illinois", +#' # countycode = "DeWitt", +#' # characteristicName = "Nitrogen" +#' # ) #' -#' attr(DeWitt, "url") +#' #attr(DeWitt, "url") #' -#' DeWitt_wqx3 <- readWQPdata( -#' statecode = "Illinois", -#' countycode = "DeWitt", -#' characteristicName = "Nitrogen", -#' service = "ResultWQX3", -#' dataProfile = "basicPhysChem", -#' ignore_attributes = TRUE) +#' #DeWitt_wqx3 <- readWQPdata( +#' # statecode = "Illinois", +#' # countycode = "DeWitt", +#' # characteristicName = "Nitrogen", +#' # service = "ResultWQX3", +#' # dataProfile = "basicPhysChem", +#' # ignore_attributes = TRUE) #' -#' attr(DeWitt_wqx3, "url") +#' #attr(DeWitt_wqx3, "url") #' #' # Data profile: "Sampling Activity" -#' activity <- readWQPdata( -#' siteid = "USGS-04024315", -#' service = "Activity" -#' ) -#' attr(activity, "url") +#' #activity <- readWQPdata( +#' # siteid = "USGS-04024315", +#' # service = "Activity" +#' #) +#' #attr(activity, "url") #' #' # activity_wqx3 <- readWQPdata( #' # siteid = "USGS-04024315", @@ -134,14 +134,14 @@ #' # ) #' # attr(activity_wqx3, "url") #' -#' Dane_activity <- readWQPdata( -#' statecode = "Wisconsin", -#' countycode = "Dane", -#' startDateLo = "2023-01-01", -#' startDateHi = "2023-12-31", -#' service = "Activity" -#' ) -#' attr(Dane_activity, "url") +#' #Dane_activity <- readWQPdata( +#' # statecode = "Wisconsin", +#' # countycode = "Dane", +#' # startDateLo = "2023-01-01", +#' # startDateHi = "2023-12-31", +#' # service = "Activity" +#' # ) +#' #attr(Dane_activity, "url") #' #' # Dane_activity_wqx3 <- readWQPdata( #' # statecode = "Wisconsin", @@ -157,47 +157,47 @@ #' #' #' # Data profiles: "Organization Data" -#' org_data <- readWQPdata( -#' statecode = "WI", -#' countycode = "Dane", -#' service = "Organization" -#' ) +#' #org_data <- readWQPdata( +#' # statecode = "WI", +#' # countycode = "Dane", +#' # service = "Organization" +#' # ) #' #' # Data profiles: "Project Data" -#' project_data <- readWQPdata( -#' statecode = "WI", -#' countycode = "Dane", -#' service = "Project" -#' ) +#' #project_data <- readWQPdata( +#' # statecode = "WI", +#' # countycode = "Dane", +#' # service = "Project" +#' # ) #' #' # Data profiles: "Project Monitoring Location Weighting Data" -#' proj_mlwd <- readWQPdata( -#' statecode = "WI", -#' countycode = "Dane", -#' service = "ProjectMonitoringLocationWeighting" -#' ) +#' #proj_mlwd <- readWQPdata( +#' # statecode = "WI", +#' # countycode = "Dane", +#' # service = "ProjectMonitoringLocationWeighting" +#' # ) #' #' # Data profiles: "Sample Results (physical/chemical metadata)" -#' samp_data <- readWQPdata( -#' siteid = "USGS-04024315", -#' dataProfile = "resultPhysChem", -#' service = "Result" -#' ) +#' # samp_data <- readWQPdata( +#' # siteid = "USGS-04024315", +#' # dataProfile = "resultPhysChem", +#' # service = "Result" +#' # ) #' #' # Data profiles: "Sample Results (biological metadata)" -#' samp_bio <- readWQPdata( -#' siteid = "USGS-04024315", -#' dataProfile = "biological", -#' service = "Result" -#' ) +#' #samp_bio <- readWQPdata( +#' # siteid = "USGS-04024315", +#' # dataProfile = "biological", +#' # service = "Result" +#' # ) #' #' #' # Data profiles: "Sample Results (narrow)" -#' samp_narrow <- readWQPdata( -#' siteid = "USGS-04024315", -#' service = "Result", -#' dataProfile = "narrowResult" -#' ) +#' # samp_narrow <- readWQPdata( +#' # siteid = "USGS-04024315", +#' # service = "Result", +#' # dataProfile = "narrowResult" +#' # ) #' #' # samp_narrow_wqx3 <- readWQPdata( #' # siteid = "USGS-04024315", @@ -207,38 +207,38 @@ #' #' #' # Data profiles: "Sampling Activity" -#' samp_activity <- readWQPdata( -#' siteid = "USGS-04024315", -#' dataProfile = "activityAll", -#' service = "Activity" -#' ) +#' #samp_activity <- readWQPdata( +#' # siteid = "USGS-04024315", +#' # dataProfile = "activityAll", +#' # service = "Activity" +#' # ) #' #' # Data profile: "Sampling Activity Metrics" -#' act_metrics <- readWQPdata( -#' statecode = "WI", -#' countycode = "Dane", -#' service = "ActivityMetric" -#' ) +#' # act_metrics <- readWQPdata( +#' # statecode = "WI", +#' # countycode = "Dane", +#' # service = "ActivityMetric" +#' # ) #' #' # Data profile: "Result Detection Quantitation Limit Data" -#' dl_data <- readWQPdata( -#' siteid = "USGS-04024315", -#' service = "ResultDetectionQuantitationLimit" -#' ) +#' # dl_data <- readWQPdata( +#' # siteid = "USGS-04024315", +#' # service = "ResultDetectionQuantitationLimit" +#' # ) #' #' # other options: -#' Phosphorus <- readWQPdata( -#' statecode = "WI", countycode = "Dane", -#' characteristicName = "Phosphorus", -#' startDateLo = "2023-01-01", -#' ignore_attributes = TRUE, -#' convertType = FALSE -#' ) -#' -#' rawPHsites_legacy <- readWQPdata(siteid = c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), -#' characteristicName = "pH", -#' service = "Result", -#' dataProfile = "narrowResult" ) +#' # Phosphorus <- readWQPdata( +#' # statecode = "WI", countycode = "Dane", +#' # characteristicName = "Phosphorus", +#' # startDateLo = "2023-01-01", +#' # ignore_attributes = TRUE, +#' # convertType = FALSE +#' # ) +#' +#' #rawPHsites_legacy <- readWQPdata(siteid = c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), +#' # characteristicName = "pH", +#' # service = "Result", +#' # dataProfile = "narrowResult" ) #' #' # rawPHsites <- readWQPdata(siteid = c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), #' # characteristicName = "pH", @@ -416,12 +416,12 @@ create_WQP_attributes <- function(retval, ...) { #' #' @examplesIf is_dataRetrieval_user() #' \donttest{ -#' rawPcode <- readWQPqw("USGS-01594440", "01075", -#' ignore_attributes = TRUE, legacy = FALSE) -#' headerInfo <- attr(rawPcode, "headerInfo") -#' wqp_request_id <- headerInfo$`wqp-request-id` -#' count_info <- wqp_check_status(wqp_request_id) -#' count_info[["dataProviders"]] +#' #rawPcode <- readWQPqw("USGS-01594440", "01075", +#' # ignore_attributes = TRUE, legacy = FALSE) +#' # headerInfo <- attr(rawPcode, "headerInfo") +#' #wqp_request_id <- headerInfo$`wqp-request-id` +#' #count_info <- wqp_check_status(wqp_request_id) +#' #count_info[["dataProviders"]] #' } wqp_check_status <- function(wqp_request_id) { id_url <- paste0(pkg.env[["status"]], wqp_request_id) diff --git a/R/readWQPqw.R b/R/readWQPqw.R index 0762b4418..92d5403b4 100644 --- a/R/readWQPqw.R +++ b/R/readWQPqw.R @@ -51,28 +51,28 @@ #' and [importWQP()] #' @examplesIf is_dataRetrieval_user() #' \donttest{ -#' rawPcode <- readWQPqw("USGS-01594440", "01075", "", "") +#' #rawPcode <- readWQPqw("USGS-01594440", "01075", "", "") #' -#' attr(rawPcode, "siteInfo") -#' attr(rawPcode, "queryTime") -#' attr(rawPcode, "url") +#' #attr(rawPcode, "siteInfo") +#' #attr(rawPcode, "queryTime") +#' #attr(rawPcode, "url") #' -#' rawCharacteristicName <- readWQPqw("WIDNR_WQX-10032762", "Specific conductance", "", "") -#' pHsites_legacy <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), -#' "pH", "", "") -#' ncol(pHsites_legacy) -#' attr(pHsites_legacy, "url") +#' #rawCharacteristicName <- readWQPqw("WIDNR_WQX-10032762", "Specific conductance", "", "") +#' #pHsites_legacy <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), +#' # "pH", "", "") +#' #ncol(pHsites_legacy) +#' #attr(pHsites_legacy, "url") #' #' # pHsites_modern <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), #' # "pH", "", "", legacy = FALSE) #' # ncol(pHsites_modern) #' # attr(pHsites_modern, "url") #' -#' nwisEx <- readWQPqw("USGS-04024000", c("34247", "30234", "32104", "34220"), "", "2022-12-20") +#' # nwisEx <- readWQPqw("USGS-04024000", c("34247", "30234", "32104", "34220"), "", "2022-12-20") #' -#' DO <- readWQPqw(siteNumbers = "USGS-05288705", -#' parameterCd = "00300", -#' convertType = FALSE) +#' # DO <- readWQPqw(siteNumbers = "USGS-05288705", +#' # parameterCd = "00300", +#' # convertType = FALSE) #' } readWQPqw <- function( siteNumbers, diff --git a/R/whatWQPdata.R b/R/whatWQPdata.R index 48e576030..98e1e9988 100644 --- a/R/whatWQPdata.R +++ b/R/whatWQPdata.R @@ -6,14 +6,14 @@ #' @examples #' \donttest{ #' -#' site1 <- whatWQPsamples(siteid = "USGS-01594440") +#' #site1 <- whatWQPsamples(siteid = "USGS-01594440") #' -#' type <- "Stream" +#' #type <- "Stream" #' -#' sites <- whatWQPsamples(countycode = "US:55:025", siteType = type) +#' #sites <- whatWQPsamples(countycode = "US:55:025", siteType = type) #' -#' lakeSites_samples <- whatWQPsamples(siteType = "Lake, Reservoir, Impoundment", -#' countycode = "US:55:025") +#' #lakeSites_samples <- whatWQPsamples(siteType = "Lake, Reservoir, Impoundment", +#' # countycode = "US:55:025") #' } whatWQPsamples <- function(..., convertType = TRUE, legacy = TRUE) { values <- readWQPdots(..., legacy = legacy) @@ -81,11 +81,11 @@ whatWQPsamples <- function(..., convertType = TRUE, legacy = TRUE) { #' @examples #' \donttest{ #' -#' type <- "Stream" +#' #type <- "Stream" #' -#' sites <- whatWQPmetrics(countycode = "US:55:025", siteType = type) -#' lakeSites_metrics <- whatWQPmetrics(siteType = "Lake, Reservoir, Impoundment", -#' countycode = "US:55:025") +#' #sites <- whatWQPmetrics(countycode = "US:55:025", siteType = type) +#' #lakeSites_metrics <- whatWQPmetrics(siteType = "Lake, Reservoir, Impoundment", +#' # countycode = "US:55:025") #' } whatWQPmetrics <- function(..., convertType = TRUE) { values <- readWQPdots(..., legacy = TRUE) @@ -182,20 +182,20 @@ whatWQPmetrics <- function(..., convertType = TRUE) { #' @seealso whatWQPsites readWQPsummary readWQPdata #' @examplesIf is_dataRetrieval_user() #' \donttest{ -#' site1 <- whatWQPdata(siteid = "USGS-01594440") +#' #site1 <- whatWQPdata(siteid = "USGS-01594440") #' -#' type <- "Stream" -#' sites <- whatWQPdata(countycode = "US:55:025", siteType = type) +#' #type <- "Stream" +#' #sites <- whatWQPdata(countycode = "US:55:025", siteType = type) #' -#' lakeSites <- whatWQPdata(siteType = "Lake, Reservoir, Impoundment", -#' countycode = "US:55:025") -#' lakeSites_chars <- whatWQPdata( -#' siteType = "Lake, Reservoir, Impoundment", -#' countycode = "US:55:025", convertType = FALSE) +#' #lakeSites <- whatWQPdata(siteType = "Lake, Reservoir, Impoundment", +#' # countycode = "US:55:025") +#' #lakeSites_chars <- whatWQPdata( +#' # siteType = "Lake, Reservoir, Impoundment", +#' # countycode = "US:55:025", convertType = FALSE) #' #' -#' bbox <- c(-86.9736, 34.4883, -86.6135, 34.6562) -#' what_bb <- whatWQPdata(bBox = bbox) +#' #bbox <- c(-86.9736, 34.4883, -86.6135, 34.6562) +#' #what_bb <- whatWQPdata(bBox = bbox) #' } whatWQPdata <- function(..., convertType = TRUE) { args <- convertLists(...) diff --git a/R/whatWQPsites.R b/R/whatWQPsites.R index f18677309..08a2fde40 100644 --- a/R/whatWQPsites.R +++ b/R/whatWQPsites.R @@ -36,14 +36,14 @@ #' @examplesIf is_dataRetrieval_user() #' \donttest{ #' -#' site1 <- whatWQPsites(siteid = "USGS-01594440") +#' #site1 <- whatWQPsites(siteid = "USGS-01594440") #' -#' type <- "Stream" -#' sites <- whatWQPsites( -#' countycode = "US:55:025", -#' characteristicName = "Phosphorus", -#' siteType = type -#' ) +#' #type <- "Stream" +#' #sites <- whatWQPsites( +#' # countycode = "US:55:025", +#' # characteristicName = "Phosphorus", +#' # siteType = type +#' #) #' } whatWQPsites <- function(..., legacy = TRUE, convertType = TRUE) { values <- readWQPdots(..., legacy = legacy) @@ -118,36 +118,36 @@ whatWQPsites <- function(..., legacy = TRUE, convertType = TRUE) { #' @examplesIf is_dataRetrieval_user() #' \donttest{ #' # Summary of a single site for the last 5 years: -#' site_5 <- readWQPsummary( -#' siteid = "USGS-07144100", -#' summaryYears = 5 -#' ) +#' #site_5 <- readWQPsummary( +#' # siteid = "USGS-07144100", +#' # summaryYears = 5 +#'# ) #' #' # Summary of a single site for the full period of record: -#' site_all <- readWQPsummary( -#' siteid = "USGS-07144100", -#' summaryYears = "all" -#' ) +#' #site_all <- readWQPsummary( +#' # siteid = "USGS-07144100", +#' # summaryYears = "all" +#' # ) #' #' # Summary of the data available from streams in a single county: -#' dane_county_data <- readWQPsummary( -#' countycode = "US:55:025", -#' summaryYears = 5, -#' siteType = "Stream" -#' ) +#' # dane_county_data <- readWQPsummary( +#' # countycode = "US:55:025", +#' # summaryYears = 5, +#' # siteType = "Stream" +#' # ) #' #' # Summary of the data all available from lakes in a single county: -#' lake_sites <- readWQPsummary( -#' siteType = "Lake, Reservoir, Impoundment", -#' countycode = "US:55:025" -#' ) +#' # lake_sites <- readWQPsummary( +#' # siteType = "Lake, Reservoir, Impoundment", +#' # countycode = "US:55:025" +#' # ) #' #' # Summary of the data available for the last 5 years in New Jersey: -#' state1 <- readWQPsummary( -#' statecode = "NJ", -#' summaryYears = 5, -#' siteType = "Stream" -#' ) +#' #state1 <- readWQPsummary( +#' # statecode = "NJ", +#' # summaryYears = 5, +#' # siteType = "Stream" +#' # ) #' } readWQPsummary <- function(...) { wqp_message() diff --git a/_pkgdown.yml b/_pkgdown.yml index ed2f068e0..f16382908 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -58,12 +58,8 @@ navbar: href: articles/wqp_large_pull_script.html - text: Large Request Pipeline Approach href: articles/wqp_large_pull_targets.html - - text: Stat Service - href: articles/statsServiceMap.html - text: NLDI Interface href: articles/nldi.html - - text: Moving Averages - href: articles/movingAverages.html - text: How to Contribute href: articles/Contributing.html right: diff --git a/environment.yml b/environment.yml new file mode 100644 index 000000000..2244b414b --- /dev/null +++ b/environment.yml @@ -0,0 +1,36 @@ +name: dataretrieval +channels: + - conda-forge +dependencies: + - _libgcc_mutex=0.1=conda_forge + - _openmp_mutex=4.5=2_gnu + - bzip2=1.0.8=hda65f42_8 + - ca-certificates=2025.8.3=hbd8a1cb_0 + - ld_impl_linux-64=2.44=h1423503_1 + - libexpat=2.7.1=hecca717_0 + - libffi=3.4.6=h2dba641_1 + - libgcc=15.1.0=h767d61c_5 + - libgcc-ng=15.1.0=h69a702a_5 + - libgomp=15.1.0=h767d61c_5 + - liblzma=5.8.1=hb9d3cd8_2 + - liblzma-devel=5.8.1=hb9d3cd8_2 + - libnsl=2.0.1=hb9d3cd8_1 + - libsqlite=3.50.4=h0c1763c_0 + - libuuid=2.41.1=he9a06e4_0 + - libxcrypt=4.4.36=hd590300_1 + - libzlib=1.3.1=hb9d3cd8_2 + - ncurses=6.5=h2d0b736_3 + - openssl=3.5.3=h26f9b46_0 + - pip=25.2=pyh8b19718_0 + - python=3.11.8=hab00c5b_0_cpython + - readline=8.2=h8c095d6_2 + - matplotlib + - setuptools=80.9.0=pyhff2d567_0 + - tk=8.6.13=noxft_hd72426e_102 + - tzdata=2025b=h78e105d_0 + - wheel=0.45.1=pyhd8ed1ab_1 + - xz=5.8.1=hbcc6ac9_2 + - xz-gpl-tools=5.8.1=hbcc6ac9_2 + - xz-tools=5.8.1=hb9d3cd8_2 + - dataretrieval +prefix: /home/user/miniforge3/envs/dataretrieval diff --git a/man/readNWISstat.Rd b/man/readNWISstat.Rd index e2d9907cf..ab394f0a0 100644 --- a/man/readNWISstat.Rd +++ b/man/readNWISstat.Rd @@ -62,28 +62,28 @@ Retrieves site statistics from the USGS Statistics Web Service beta. \examples{ \dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} \donttest{ -x1 <- readNWISstat( - siteNumbers = c("02319394"), - parameterCd = c("00060"), - statReportType = "annual" -) +# x1 <- readNWISstat( +# siteNumbers = c("02319394"), +# parameterCd = c("00060"), +# statReportType = "annual" +# ) # all the annual mean discharge data for two sites -x2 <- readNWISstat( - siteNumbers = c("02319394", "02171500"), - parameterCd = c("00010", "00060"), - statReportType = "annual" -) +#x2 <- readNWISstat( +# siteNumbers = c("02319394", "02171500"), +# parameterCd = c("00010", "00060"), +# statReportType = "annual" +# ) # Request p25, p75, and mean values for temperature and discharge for the 2000s # Note that p25 and p75 were not available for temperature, and return NAs -x <- readNWISstat( - siteNumbers = c("02171500"), - parameterCd = c("00010", "00060"), - statReportType = "daily", - statType = c("mean", "median"), - startDate = "2000", endDate = "2010" -) +#x <- readNWISstat( +# siteNumbers = c("02171500"), +# parameterCd = c("00010", "00060"), +# statReportType = "daily", +# statType = c("mean", "median"), +# startDate = "2000", endDate = "2010" +# ) } \dontshow{\}) # examplesIf} } diff --git a/man/readNWISuv.Rd b/man/readNWISuv.Rd index f2bf779c7..2878063f3 100644 --- a/man/readNWISuv.Rd +++ b/man/readNWISuv.Rd @@ -69,25 +69,10 @@ startDate <- "2014-10-10" endDate <- "2014-10-10" \donttest{ -rawData <- readNWISuv(site_id, parameterCd, startDate, endDate) +#rawData <- readNWISuv(site_id, parameterCd, startDate, endDate) -rawData_today <- readNWISuv(site_id, parameterCd, Sys.Date(), Sys.Date()) +#rawData_today <- readNWISuv(site_id, parameterCd, Sys.Date(), Sys.Date()) -timeZoneChange <- readNWISuv( - c("04024430", "04024000"), parameterCd, - "2013-11-03", "2013-11-03" -) - -centralTime <- readNWISuv(site_id, parameterCd, - "2014-10-10T12:00", "2014-10-10T23:59", - tz = "America/Chicago" -) - -# Adding 'Z' to the time indicates to the web service to call the data with UTC time: -GMTdata <- readNWISuv( - site_id, parameterCd, - "2014-10-10T00:00Z", "2014-10-10T23:59Z" -) } \dontshow{\}) # examplesIf} } diff --git a/man/readWQPdata.Rd b/man/readWQPdata.Rd index 68680d59c..a2a915b44 100644 --- a/man/readWQPdata.Rd +++ b/man/readWQPdata.Rd @@ -105,47 +105,47 @@ Sampling Activity \tab ActivityWQX3 \tab /wqx3/Activity/search \cr \donttest{ # Legacy: -nameToUse <- "pH" -pHData <- readWQPdata(siteid = "USGS-04024315", - characteristicName = nameToUse) -ncol(pHData) -attr(pHData, "siteInfo") -attr(pHData, "queryTime") -attr(pHData, "url") +#nameToUse <- "pH" +#pHData <- readWQPdata(siteid = "USGS-04024315", +# characteristicName = nameToUse) +#ncol(pHData) +#attr(pHData, "siteInfo") +#attr(pHData, "queryTime") +#attr(pHData, "url") # WQX3: -pHData_wqx3 <- readWQPdata(siteid = "USGS-04024315", - characteristicName = nameToUse, - service = "ResultWQX3", - dataProfile = "basicPhysChem") -attr(pHData_wqx3, "url") +#pHData_wqx3 <- readWQPdata(siteid = "USGS-04024315", +# characteristicName = nameToUse, +# service = "ResultWQX3", +# dataProfile = "basicPhysChem") +# attr(pHData_wqx3, "url") # More examples: # querying by county -DeWitt <- readWQPdata( - statecode = "Illinois", - countycode = "DeWitt", - characteristicName = "Nitrogen" -) +#DeWitt <- readWQPdata( +# statecode = "Illinois", +# countycode = "DeWitt", +# characteristicName = "Nitrogen" +# ) -attr(DeWitt, "url") +#attr(DeWitt, "url") -DeWitt_wqx3 <- readWQPdata( - statecode = "Illinois", - countycode = "DeWitt", - characteristicName = "Nitrogen", - service = "ResultWQX3", - dataProfile = "basicPhysChem", - ignore_attributes = TRUE) +#DeWitt_wqx3 <- readWQPdata( +# statecode = "Illinois", +# countycode = "DeWitt", +# characteristicName = "Nitrogen", +# service = "ResultWQX3", +# dataProfile = "basicPhysChem", +# ignore_attributes = TRUE) -attr(DeWitt_wqx3, "url") +#attr(DeWitt_wqx3, "url") # Data profile: "Sampling Activity" -activity <- readWQPdata( - siteid = "USGS-04024315", - service = "Activity" -) -attr(activity, "url") +#activity <- readWQPdata( +# siteid = "USGS-04024315", +# service = "Activity" +#) +#attr(activity, "url") # activity_wqx3 <- readWQPdata( # siteid = "USGS-04024315", @@ -153,14 +153,14 @@ attr(activity, "url") # ) # attr(activity_wqx3, "url") -Dane_activity <- readWQPdata( - statecode = "Wisconsin", - countycode = "Dane", - startDateLo = "2023-01-01", - startDateHi = "2023-12-31", - service = "Activity" -) -attr(Dane_activity, "url") +#Dane_activity <- readWQPdata( +# statecode = "Wisconsin", +# countycode = "Dane", +# startDateLo = "2023-01-01", +# startDateHi = "2023-12-31", +# service = "Activity" +# ) +#attr(Dane_activity, "url") # Dane_activity_wqx3 <- readWQPdata( # statecode = "Wisconsin", @@ -176,47 +176,47 @@ attr(Dane_activity, "url") # Data profiles: "Organization Data" -org_data <- readWQPdata( - statecode = "WI", - countycode = "Dane", - service = "Organization" -) +#org_data <- readWQPdata( +# statecode = "WI", +# countycode = "Dane", +# service = "Organization" +# ) # Data profiles: "Project Data" -project_data <- readWQPdata( - statecode = "WI", - countycode = "Dane", - service = "Project" -) +#project_data <- readWQPdata( +# statecode = "WI", +# countycode = "Dane", +# service = "Project" +# ) # Data profiles: "Project Monitoring Location Weighting Data" -proj_mlwd <- readWQPdata( - statecode = "WI", - countycode = "Dane", - service = "ProjectMonitoringLocationWeighting" -) +#proj_mlwd <- readWQPdata( +# statecode = "WI", +# countycode = "Dane", +# service = "ProjectMonitoringLocationWeighting" +# ) # Data profiles: "Sample Results (physical/chemical metadata)" -samp_data <- readWQPdata( - siteid = "USGS-04024315", - dataProfile = "resultPhysChem", - service = "Result" -) +# samp_data <- readWQPdata( +# siteid = "USGS-04024315", +# dataProfile = "resultPhysChem", +# service = "Result" +# ) # Data profiles: "Sample Results (biological metadata)" -samp_bio <- readWQPdata( - siteid = "USGS-04024315", - dataProfile = "biological", - service = "Result" -) +#samp_bio <- readWQPdata( +# siteid = "USGS-04024315", +# dataProfile = "biological", +# service = "Result" +# ) # Data profiles: "Sample Results (narrow)" -samp_narrow <- readWQPdata( - siteid = "USGS-04024315", - service = "Result", - dataProfile = "narrowResult" -) +# samp_narrow <- readWQPdata( +# siteid = "USGS-04024315", +# service = "Result", +# dataProfile = "narrowResult" +# ) # samp_narrow_wqx3 <- readWQPdata( # siteid = "USGS-04024315", @@ -226,38 +226,38 @@ samp_narrow <- readWQPdata( # Data profiles: "Sampling Activity" -samp_activity <- readWQPdata( - siteid = "USGS-04024315", - dataProfile = "activityAll", - service = "Activity" -) +#samp_activity <- readWQPdata( +# siteid = "USGS-04024315", +# dataProfile = "activityAll", +# service = "Activity" +# ) # Data profile: "Sampling Activity Metrics" -act_metrics <- readWQPdata( - statecode = "WI", - countycode = "Dane", - service = "ActivityMetric" -) +# act_metrics <- readWQPdata( +# statecode = "WI", +# countycode = "Dane", +# service = "ActivityMetric" +# ) # Data profile: "Result Detection Quantitation Limit Data" -dl_data <- readWQPdata( - siteid = "USGS-04024315", - service = "ResultDetectionQuantitationLimit" -) +# dl_data <- readWQPdata( +# siteid = "USGS-04024315", +# service = "ResultDetectionQuantitationLimit" +# ) # other options: -Phosphorus <- readWQPdata( - statecode = "WI", countycode = "Dane", - characteristicName = "Phosphorus", - startDateLo = "2023-01-01", - ignore_attributes = TRUE, - convertType = FALSE -) +# Phosphorus <- readWQPdata( +# statecode = "WI", countycode = "Dane", +# characteristicName = "Phosphorus", +# startDateLo = "2023-01-01", +# ignore_attributes = TRUE, +# convertType = FALSE +# ) -rawPHsites_legacy <- readWQPdata(siteid = c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), - characteristicName = "pH", - service = "Result", - dataProfile = "narrowResult" ) +#rawPHsites_legacy <- readWQPdata(siteid = c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), +# characteristicName = "pH", +# service = "Result", +# dataProfile = "narrowResult" ) # rawPHsites <- readWQPdata(siteid = c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), # characteristicName = "pH", diff --git a/man/readWQPqw.Rd b/man/readWQPqw.Rd index 5049d688e..e0fbd54d4 100644 --- a/man/readWQPqw.Rd +++ b/man/readWQPqw.Rd @@ -77,28 +77,28 @@ site name, such as 'USGS-01234567'. \examples{ \dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} \donttest{ -rawPcode <- readWQPqw("USGS-01594440", "01075", "", "") +#rawPcode <- readWQPqw("USGS-01594440", "01075", "", "") -attr(rawPcode, "siteInfo") -attr(rawPcode, "queryTime") -attr(rawPcode, "url") +#attr(rawPcode, "siteInfo") +#attr(rawPcode, "queryTime") +#attr(rawPcode, "url") -rawCharacteristicName <- readWQPqw("WIDNR_WQX-10032762", "Specific conductance", "", "") -pHsites_legacy <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), - "pH", "", "") -ncol(pHsites_legacy) -attr(pHsites_legacy, "url") +#rawCharacteristicName <- readWQPqw("WIDNR_WQX-10032762", "Specific conductance", "", "") +#pHsites_legacy <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), +# "pH", "", "") +#ncol(pHsites_legacy) +#attr(pHsites_legacy, "url") # pHsites_modern <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), # "pH", "", "", legacy = FALSE) # ncol(pHsites_modern) # attr(pHsites_modern, "url") -nwisEx <- readWQPqw("USGS-04024000", c("34247", "30234", "32104", "34220"), "", "2022-12-20") +# nwisEx <- readWQPqw("USGS-04024000", c("34247", "30234", "32104", "34220"), "", "2022-12-20") -DO <- readWQPqw(siteNumbers = "USGS-05288705", - parameterCd = "00300", - convertType = FALSE) +# DO <- readWQPqw(siteNumbers = "USGS-05288705", +# parameterCd = "00300", +# convertType = FALSE) } \dontshow{\}) # examplesIf} } diff --git a/man/readWQPsummary.Rd b/man/readWQPsummary.Rd index 9dfd922d0..a939331ee 100644 --- a/man/readWQPsummary.Rd +++ b/man/readWQPsummary.Rd @@ -36,36 +36,36 @@ available data at the WQP sites, and some metadata on the sites themselves. \dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} \donttest{ # Summary of a single site for the last 5 years: -site_5 <- readWQPsummary( - siteid = "USGS-07144100", - summaryYears = 5 -) +#site_5 <- readWQPsummary( +# siteid = "USGS-07144100", +# summaryYears = 5 +# ) # Summary of a single site for the full period of record: -site_all <- readWQPsummary( - siteid = "USGS-07144100", - summaryYears = "all" -) +#site_all <- readWQPsummary( +# siteid = "USGS-07144100", +# summaryYears = "all" +# ) # Summary of the data available from streams in a single county: -dane_county_data <- readWQPsummary( - countycode = "US:55:025", - summaryYears = 5, - siteType = "Stream" -) +# dane_county_data <- readWQPsummary( +# countycode = "US:55:025", +# summaryYears = 5, +# siteType = "Stream" +# ) # Summary of the data all available from lakes in a single county: -lake_sites <- readWQPsummary( - siteType = "Lake, Reservoir, Impoundment", - countycode = "US:55:025" -) +# lake_sites <- readWQPsummary( +# siteType = "Lake, Reservoir, Impoundment", +# countycode = "US:55:025" +# ) # Summary of the data available for the last 5 years in New Jersey: -state1 <- readWQPsummary( - statecode = "NJ", - summaryYears = 5, - siteType = "Stream" -) +#state1 <- readWQPsummary( +# statecode = "NJ", +# summaryYears = 5, +# siteType = "Stream" +# ) } \dontshow{\}) # examplesIf} } diff --git a/man/read_waterdata_combined_meta.Rd b/man/read_waterdata_combined_meta.Rd index f5f2e4de1..5ce5b3193 100644 --- a/man/read_waterdata_combined_meta.Rd +++ b/man/read_waterdata_combined_meta.Rd @@ -91,7 +91,7 @@ Multiple statistic_ids can be requested as a character vector.} \item{data_type}{The computational period type of data collected at the monitoring location.} -\item{computation_identifier}{Indicates whether the data from this time series represent a specific statistical computation. +\item{computation_identifier}{Indicates the computation performed to calculate this time series. Values of "Instantaneous" reflect point measurements. Multiple computation_identifiers can be requested as a character vector.} \item{computation_period_identifier}{Multiple computation_period_identifiers can be requested as a character vector.} @@ -108,11 +108,11 @@ for timely best science and to assist with daily operations which need real-time information. Non-primary time series data are only retained by this system for 120 days.} -\item{web_description}{A description of what this time series represents, as used by WDFN and other USGS data dissemination products.} +\item{web_description}{An optional description of the time series. WDFN and other USGS data dissemination products use this field, in combination with sublocation_identifier, to distinguish the differences between multiple time series for the same parameter code, statistic code, and monitoring location.} \item{parent_time_series_id}{The unique identifier representing the parent or "upchain" time series that a daily values time series is generated from. Daily values time series have one and only one parent time series.} -\item{begin}{The datetime of the earliest observation in the time series. Together with \code{end}, this field represents the period of record of a time series. Note that some time series may have large gaps in their collection record. +\item{begin}{The datetime of the earliest observation in the time series. Together with \code{end_utc}, this field represents the period of record of a time series. Note that some time series may have large gaps in their collection record. You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). Examples: \itemize{ @@ -122,11 +122,11 @@ Examples: \item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours } -Only features that have a \code{begin} that intersects the value of datetime are selected. +Only features that have a \code{begin_utc} that intersects the value of datetime are selected. See also Details below for more information.} -\item{end}{The datetime of the most recent observation in the time series. Data returned by this endpoint updates at most once per day, and potentially less frequently than that, and as such there may be more recent observations within a time series than the time series \code{end} value reflects. Together with \code{begin}, this field represents the period of record of a time series. It is additionally used to determine whether a time series is "active". +\item{end}{The datetime of the most recent observation in the time series. Data returned by this endpoint updates at most once per day, and potentially less frequently than that, and as such there may be more recent observations within a time series than the time series \code{end_utc} value reflects. Together with \code{begin_utc}, this field represents the period of record of a time series. It is additionally used to determine whether a time series is "active". You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). Examples: \itemize{ @@ -136,7 +136,7 @@ Examples: \item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours } -Only features that have a \code{end} that intersects the value of datetime are selected. +Only features that have a \code{end_utc} that intersects the value of datetime are selected. See also Details below for more information.} diff --git a/man/read_waterdata_field_measurements.Rd b/man/read_waterdata_field_measurements.Rd index 508d2c9cd..8242d19e6 100644 --- a/man/read_waterdata_field_measurements.Rd +++ b/man/read_waterdata_field_measurements.Rd @@ -41,7 +41,7 @@ Multiple parameter_codes can be requested as a character vector.} \item{properties}{A vector of requested columns to be returned from the query. Available options are: -geometry, field_measurement_id, field_visit_id, parameter_code, monitoring_location_id, observing_procedure_code, observing_procedure, value, unit_of_measure, time, qualifier, vertical_datum, approval_status, measuring_agency, last_modified, control_condition, measurement_rated. +geometry, field_measurement_id, field_measurements_series_id, field_visit_id, parameter_code, monitoring_location_id, observing_procedure_code, observing_procedure, value, unit_of_measure, time, qualifier, vertical_datum, approval_status, measuring_agency, last_modified, control_condition, measurement_rated. The default (\code{NA}) will return all columns of the data.} \item{field_visit_id}{A universally unique identifier (UUID) for the field visit. Multiple measurements may be made during a single field visit.} @@ -74,9 +74,13 @@ See also Details below for more information.} \item{measuring_agency}{The agency performing the measurement.} -\item{control_condition}{What and where the control of flow is for the gage pool.} +\item{control_condition}{The state of the control feature at the time of observation. -\item{measurement_rated}{Rated measurement based on the hydrologic/hydraulic conditions in which the measurement was made +What and where the control of flow is for the gage pool.} + +\item{measurement_rated}{A qualitative estimate of the quality of a measurement. + +Rated measurement based on the hydrologic/hydraulic conditions in which the measurement was made (excellent (2 percent), good (5 percent), fair (8 percent), or poor (more than 8 percent). percent)} \item{skipGeometry}{This option can be used to skip response geometries for diff --git a/man/read_waterdata_field_meta.Rd b/man/read_waterdata_field_meta.Rd index 56b9af00b..83d6bc752 100644 --- a/man/read_waterdata_field_meta.Rd +++ b/man/read_waterdata_field_meta.Rd @@ -36,7 +36,7 @@ Multiple parameter_names can be requested as a character vector.} Multiple parameter_descriptions can be requested as a character vector.} -\item{begin}{The datetime of the earliest observation in the time series. Together with \code{end}, this field represents the period of record of a time series. Note that some time series may have large gaps in their collection record. +\item{begin}{The datetime of the earliest observation in the time series. Together with \code{end_utc}, this field represents the period of record of a time series. Note that some time series may have large gaps in their collection record. You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). Examples: \itemize{ @@ -46,11 +46,11 @@ Examples: \item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours } -Only features that have a \code{begin} that intersects the value of datetime are selected. +Only features that have a \code{begin_utc} that intersects the value of datetime are selected. See also Details below for more information.} -\item{end}{The datetime of the most recent observation in the time series. Data returned by this endpoint updates at most once per day, and potentially less frequently than that, and as such there may be more recent observations within a time series than the time series \code{end} value reflects. Together with \code{begin}, this field represents the period of record of a time series. It is additionally used to determine whether a time series is "active". +\item{end}{The datetime of the most recent observation in the time series. Data returned by this endpoint updates at most once per day, and potentially less frequently than that, and as such there may be more recent observations within a time series than the time series \code{end_utc} value reflects. Together with \code{begin_utc}, this field represents the period of record of a time series. It is additionally used to determine whether a time series is "active". You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). Examples: \itemize{ @@ -60,7 +60,7 @@ Examples: \item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours } -Only features that have a \code{end} that intersects the value of datetime are selected. +Only features that have a \code{end_utc} that intersects the value of datetime are selected. See also Details below for more information.} diff --git a/man/read_waterdata_monitoring_location.Rd b/man/read_waterdata_monitoring_location.Rd index b8e87b7d0..178cad7a9 100644 --- a/man/read_waterdata_monitoring_location.Rd +++ b/man/read_waterdata_monitoring_location.Rd @@ -52,7 +52,7 @@ read_waterdata_monitoring_location( ) } \arguments{ -\item{monitoring_location_id}{A unique identifier representing a single monitoring location. This corresponds to the \code{id} field in the \code{monitoring-locations} endpoint. Monitoring location IDs are created by combining the agency code of the agency responsible for the monitoring location (e.g. USGS) with the ID number of the monitoring location (e.g. 02238500), separated by a hyphen (e.g. USGS-02238500). +\item{monitoring_location_id}{A unique identifier representing a single monitoring location. This corresponds to the \code{monitoring_location_id} field in other endpoints. Monitoring location IDs are created by combining the agency code of the agency responsible for the monitoring location (e.g. USGS) with the ID number of the monitoring location (e.g. 02238500), separated by a hyphen (e.g. USGS-02238500). Multiple monitoring_location_ids can be requested as a character vector.} diff --git a/man/read_waterdata_ts_meta.Rd b/man/read_waterdata_ts_meta.Rd index 181b237f0..7a878d240 100644 --- a/man/read_waterdata_ts_meta.Rd +++ b/man/read_waterdata_ts_meta.Rd @@ -68,7 +68,7 @@ Only features that have a \code{last_modified} that intersects the value of date See also Details below for more information.} -\item{begin_utc}{The datetime of the earliest observation in the time series. Together with \code{end}, this field represents the period of record of a time series. Note that some time series may have large gaps in their collection record. +\item{begin_utc}{The datetime of the earliest observation in the time series. Together with \code{end_utc}, this field represents the period of record of a time series. Note that some time series may have large gaps in their collection record. You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). Examples: \itemize{ @@ -78,12 +78,12 @@ Examples: \item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours } -Only features that have a \code{begin} that intersects the value of datetime are selected. +Only features that have a \code{begin_utc} that intersects the value of datetime are selected. #' See also Details below for more information.} -\item{end_utc}{The datetime of the most recent observation in the time series. Data returned by this endpoint updates at most once per day, and potentially less frequently than that, and as such there may be more recent observations within a time series than the time series \code{end} value reflects. Together with \code{begin}, this field represents the period of record of a time series. It is additionally used to determine whether a time series is "active". +\item{end_utc}{The datetime of the most recent observation in the time series. Data returned by this endpoint updates at most once per day, and potentially less frequently than that, and as such there may be more recent observations within a time series than the time series \code{end_utc} value reflects. Together with \code{begin_utc}, this field represents the period of record of a time series. It is additionally used to determine whether a time series is "active". You can query this field using date-times or intervals, adhering to RFC 3339, or using ISO 8601 duration objects. Intervals may be bounded or half-bounded (double-dots at start or end). Examples: \itemize{ @@ -93,7 +93,7 @@ Examples: \item Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours } -Only features that have a \code{end} that intersects the value of datetime are selected. +Only features that have a \code{end_utc} that intersects the value of datetime are selected. See also Details below for more information.} @@ -106,7 +106,7 @@ See also Details below for more information.} \item{computation_period_identifier}{Indicates the period of data used for any statistical computations. Multiple computation_period_identifiers can be requested as a character vector.} -\item{computation_identifier}{Indicates whether the data from this time series represent a specific statistical computation. +\item{computation_identifier}{Indicates the computation performed to calculate this time series. Values of "Instantaneous" reflect point measurements. Multiple computation_identifiers can be requested as a character vector.} \item{thresholds}{Thresholds represent known numeric limits for a time series, for example the historic maximum value for a parameter or a level below which a sensor is non-operative. These thresholds are sometimes used to automatically determine if an observation is erroneous due to sensor error, and therefore shouldn't be included in the time series.} @@ -123,9 +123,9 @@ this system for 120 days.} \item{parent_time_series_id}{The unique identifier representing the parent or "upchain" time series that a daily values time series is generated from. Daily values time series have one and only one parent time series.} -\item{time_series_id}{A unique identifier representing a single time series. This corresponds to the \code{id} field in the \code{time-series-metadata} endpoint.} +\item{time_series_id}{A unique identifier representing a single time series. This corresponds to the "time_series_id" field in other endpoints.} -\item{web_description}{A description of what this time series represents, as used by WDFN and other USGS data dissemination products.} +\item{web_description}{An optional description of the time series. WDFN and other USGS data dissemination products use this field, in combination with sublocation_identifier, to distinguish the differences between multiple time series for the same parameter code, statistic code, and monitoring location.} \item{skipGeometry}{This option can be used to skip response geometries for each feature. The returning object will be a data frame with no spatial diff --git a/man/whatWQPdata.Rd b/man/whatWQPdata.Rd index 8b02c97fb..b16183d06 100644 --- a/man/whatWQPdata.Rd +++ b/man/whatWQPdata.Rd @@ -46,20 +46,20 @@ kind of data discovery see \code{readWQPsummary}. \examples{ \dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} \donttest{ -site1 <- whatWQPdata(siteid = "USGS-01594440") +#site1 <- whatWQPdata(siteid = "USGS-01594440") -type <- "Stream" -sites <- whatWQPdata(countycode = "US:55:025", siteType = type) +#type <- "Stream" +#sites <- whatWQPdata(countycode = "US:55:025", siteType = type) -lakeSites <- whatWQPdata(siteType = "Lake, Reservoir, Impoundment", - countycode = "US:55:025") -lakeSites_chars <- whatWQPdata( - siteType = "Lake, Reservoir, Impoundment", - countycode = "US:55:025", convertType = FALSE) +#lakeSites <- whatWQPdata(siteType = "Lake, Reservoir, Impoundment", +# countycode = "US:55:025") +#lakeSites_chars <- whatWQPdata( +# siteType = "Lake, Reservoir, Impoundment", +# countycode = "US:55:025", convertType = FALSE) -bbox <- c(-86.9736, 34.4883, -86.6135, 34.6562) -what_bb <- whatWQPdata(bBox = bbox) +#bbox <- c(-86.9736, 34.4883, -86.6135, 34.6562) +#what_bb <- whatWQPdata(bBox = bbox) } \dontshow{\}) # examplesIf} } diff --git a/man/wqpSpecials.Rd b/man/wqpSpecials.Rd index 233435505..a0d0fd848 100644 --- a/man/wqpSpecials.Rd +++ b/man/wqpSpecials.Rd @@ -51,34 +51,34 @@ not return information on what data was collected at the site. \examples{ \donttest{ -site1 <- whatWQPsamples(siteid = "USGS-01594440") +#site1 <- whatWQPsamples(siteid = "USGS-01594440") -type <- "Stream" +#type <- "Stream" -sites <- whatWQPsamples(countycode = "US:55:025", siteType = type) +#sites <- whatWQPsamples(countycode = "US:55:025", siteType = type) -lakeSites_samples <- whatWQPsamples(siteType = "Lake, Reservoir, Impoundment", - countycode = "US:55:025") +#lakeSites_samples <- whatWQPsamples(siteType = "Lake, Reservoir, Impoundment", +# countycode = "US:55:025") } \donttest{ -type <- "Stream" +#type <- "Stream" -sites <- whatWQPmetrics(countycode = "US:55:025", siteType = type) -lakeSites_metrics <- whatWQPmetrics(siteType = "Lake, Reservoir, Impoundment", - countycode = "US:55:025") +#sites <- whatWQPmetrics(countycode = "US:55:025", siteType = type) +#lakeSites_metrics <- whatWQPmetrics(siteType = "Lake, Reservoir, Impoundment", +# countycode = "US:55:025") } \dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} \donttest{ -site1 <- whatWQPsites(siteid = "USGS-01594440") +#site1 <- whatWQPsites(siteid = "USGS-01594440") -type <- "Stream" -sites <- whatWQPsites( - countycode = "US:55:025", - characteristicName = "Phosphorus", - siteType = type -) +#type <- "Stream" +#sites <- whatWQPsites( +# countycode = "US:55:025", +# characteristicName = "Phosphorus", +# siteType = type +#) } \dontshow{\}) # examplesIf} } diff --git a/man/wqp_check_status.Rd b/man/wqp_check_status.Rd index cccd26900..492bc80a1 100644 --- a/man/wqp_check_status.Rd +++ b/man/wqp_check_status.Rd @@ -23,12 +23,12 @@ function will be attached as an attribute to the data. \examples{ \dontshow{if (is_dataRetrieval_user()) withAutoprint(\{ # examplesIf} \donttest{ -rawPcode <- readWQPqw("USGS-01594440", "01075", - ignore_attributes = TRUE, legacy = FALSE) -headerInfo <- attr(rawPcode, "headerInfo") -wqp_request_id <- headerInfo$`wqp-request-id` -count_info <- wqp_check_status(wqp_request_id) -count_info[["dataProviders"]] +#rawPcode <- readWQPqw("USGS-01594440", "01075", +# ignore_attributes = TRUE, legacy = FALSE) +# headerInfo <- attr(rawPcode, "headerInfo") +#wqp_request_id <- headerInfo$`wqp-request-id` +#count_info <- wqp_check_status(wqp_request_id) +#count_info[["dataProviders"]] } \dontshow{\}) # examplesIf} } diff --git a/tutorials/quick_intro_deck.qmd b/tutorials/quick_intro_deck.qmd index 7046eef8a..125507745 100644 --- a/tutorials/quick_intro_deck.qmd +++ b/tutorials/quick_intro_deck.qmd @@ -15,44 +15,64 @@ title-slide-attributes: data-background-size: 15% data-background-position: 2% 2% editor: source +engine: knitr editor_options: chunk_output_type: console execute: echo: true warning: false message: false +params: + run_python: true --- ```{r} #| echo: false #| include: false -# library(dataRetrieval) +#| # library(dataRetrieval) library(ggplot2) library(dplyr) +library(reticulate) +py_require("dataretrieval") +py_require("panda") +py_require("matplotlib") + options(dplyr.summarise.inform = FALSE) -dt_me <- function(x, - page_length = 8, - paging = TRUE, - font = "0.7em", - escape = TRUE){ - DT::datatable(x, - rownames = FALSE, - options = list(pageLength = page_length, - info = FALSE, - searching = FALSE, - paging = paging, - lengthChange = FALSE, - initComplete = htmlwidgets::JS( - "function(settings, json) {", - paste0("$(this.api().table().container()).css({'font-size': '", - font, "'});"), - "}")), escape = escape) +evaluate_python <- params$run_python + +dt_me <- function( + x, + page_length = 8, + paging = TRUE, + font = "0.7em", + escape = TRUE +) { + DT::datatable( + x, + rownames = FALSE, + options = list( + pageLength = page_length, + info = FALSE, + searching = FALSE, + paging = paging, + lengthChange = FALSE, + initComplete = htmlwidgets::JS( + "function(settings, json) {", + paste0( + "$(this.api().table().container()).css({'font-size': '", + font, + "'});" + ), + "}" + ) + ), + escape = escape + ) } theme_set(theme_grey(base_size = 24)) -update_geom_defaults("point", list(size = 3)) - +update_geom_defaults("point", list(size = 3)) ``` @@ -111,11 +131,14 @@ In this ~45 minute introduction, the goal is: `dataRetrieval` is available on the Comprehensive R Archive Network (CRAN) repository. To install `dataRetrieval` on your computer, open RStudio and run this line of code in the Console: +::: {.panel-tabset} + +### R + ```{r} #| echo: true #| eval: false install.packages("dataRetrieval") - ``` Then each time you open R, you'll need to load the library: @@ -125,6 +148,24 @@ Then each time you open R, you'll need to load the library: library(dataRetrieval) ``` +### Python + +```{bash} +#| echo: true +#| eval: false +pip install dataretrieval + +``` + +Then each time you open Python, you'll need to load the library: + +```{python} +#| eval: !expr evaluate_python +from dataretrieval import waterdata +``` + +::: + ::: footer ::: @@ -152,14 +193,29 @@ library(dataRetrieval) ## Documentation within R: function help pages {.smaller} +::: {.panel-tabset} + +### R + Within R, you can call help files for any `dataRetrieval` function: ```{r} #| echo: true #| eval: false -?readWQPdata +?read_waterdata_daily ``` +### Python + +Within Python, you can call help for any `dataRetrieval` function: + +```{python} +#| eval: !expr evaluate_python +help(waterdata.get_daily) +``` + +::: + :::: {.columns} ::: {.column width="50%"} @@ -177,20 +233,36 @@ Scroll down to the "Examples" to see how each function can be run. Examples +::: {.panel-tabset} + +### R + ```{r} #| eval: false -# Legacy: -nameToUse <- "pH" -pHData <- readWQPdata(siteid = "USGS-04024315", - characteristicName = nameToUse) -ncol(pHData) -attr(pHData, "siteInfo") -attr(pHData, "queryTime") -attr(pHData, "url") +site <- "USGS-02238500" +dv_data_sf <- read_waterdata_daily( + monitoring_location_id = site, + parameter_code = "00060", + time = c("2021-01-01", "2022-01-01") +) +``` + +### Python + +```{python} +#| eval: false +df, md = waterdata.get_daily( + + monitoring_location_id="USGS-02238500", + parameter_code="00060", + time="2021-01-01T00:00:00Z/2022-01-01T00:00:00Z", +) ``` ::: +::: + :::: ::: footer @@ -370,9 +442,13 @@ We're going walk through 3 retrievals: ::: -## Workflow 1: Daily data for known site +## Workflow 1: Daily data for known site {.smaller} + +Let's pull daily mean discharge data for site "USGS-0940550", getting all the data from October 10, 2025 onward. -Let's pull daily mean discharge data for site "USGS-0940550", getting all the data from October 10, 2024 onward. +::: {.panel-tabset} + +### R ```{r} #| message: true @@ -380,15 +456,41 @@ library(dataRetrieval) site <- "USGS-09405500" pcode <- "00060" # Discharge stat_cd <- "00003" # Mean -range <- c("2024-10-01", NA) +range <- c("2025-10-01", NA) + +df <- read_waterdata_daily( + monitoring_location_id = site, + parameter_code = pcode, + statistic_id = stat_cd, + time = range +) -df <- read_waterdata_daily(monitoring_location_id = site, - parameter_code = pcode, - statistic_id = stat_cd, - time = range) +nrow(df) +``` + +### Python + +```{python} +#| eval: !expr evaluate_python +from dataretrieval import waterdata + +site = "USGS-09405500" +pcode = "00060" # Discharge +stat_cd = "00003" # Mean +df, md = waterdata.get_daily( + monitoring_location_id=site, + parameter_code=pcode, + statistic_id=stat_cd, + time="2025-10-01/..", +) + +df.shape[0] ``` + +::: + ::: footer ::: @@ -399,12 +501,11 @@ In RStudio, click on the data frame in the upper right Environment tab to open a ```{r} #| echo: false - -dt_me(df |> - sf::st_drop_geometry(), - page_length = 3) - - +dt_me( + df |> + sf::st_drop_geometry(), + page_length = 3 +) ``` ::: footer @@ -413,6 +514,10 @@ dt_me(df |> ## Workflow 1: Plot Daily Data +::: {.panel-tabset} + +### R + Let's use `ggplot2` to visualize the data. ```{r} @@ -421,12 +526,27 @@ Let's use `ggplot2` to visualize the data. library(ggplot2) ggplot(data = df) + - geom_point(aes(x = time, - y = value, - color = approval_status)) + geom_point(aes(x = time, y = value, color = approval_status)) +``` + +### Python +Let's use `matplotlib` to visualize the data. + +```{python} +#| echo: true +#| output-location: column +import matplotlib.pyplot as plt +import pandas as pd + +df["approval_status"] = pd.Categorical(df["approval_status"]).codes + +plt.scatter(x=df.time, y=df.value, c=df.approval_status) ``` + +::: + ## Water Data API Notes: Argument input Use your "tab" key! @@ -444,9 +564,10 @@ Use your "tab" key! ```{r} #| eval: false #| echo: true -discharge <- read_waterdata_daily(parameter_code = "00060", - statistic_id = "00003") - +discharge <- read_waterdata_daily( + parameter_code = "00060", + statistic_id = "00003" +) ``` ::: {.fragment} @@ -492,9 +613,11 @@ Here are a bunch of valid inputs: time = "2025-01-01" time = as.Date("2025-01-01") time = "2025-01-01T23:20:50Z" -time = as.POSIXct("2025-01-01T23:20:50Z", - format = "%Y-%m-%dT%H:%M:%S", - tz = "UTC") +time = as.POSIXct( + "2025-01-01T23:20:50Z", + format = "%Y-%m-%dT%H:%M:%S", + tz = "UTC" +) # Ask for specific range time = c("2024-01-01", "2025-01-01") # or Dates or POSIXs # Asking beginning of record to specific end: @@ -517,22 +640,48 @@ Use your "tab" key! ![](images/autocomplete_samples.png) -## Workflow 2: Discrete data for known site +## Workflow 2: Discrete data for known site {.smaller} Let's get orthophosphate ("00660") data from the Shenandoah River at Front Royal, VA ("USGS-01631000"). +::: {.panel-tabset} + +### R + ```{r} #| message: true site <- "USGS-01631000" pcode <- "00660" -qw_data <- read_waterdata_samples(monitoringLocationIdentifier = site, - usgsPCode = pcode, - dataType = "results", - dataProfile = "basicphyschem") +qw_data <- read_waterdata_samples( + monitoringLocationIdentifier = site, + usgsPCode = pcode, + dataType = "results", + dataProfile = "basicphyschem" +) ncol(qw_data) ``` +R generates a few POSIXct columns to combine date, time, timezone information. + +### Python +```{python} +#| eval: !expr evaluate_python +site = "USGS-01631000" +pcode = "00660" + +qw_data, md_qw = waterdata.get_samples( + monitoringLocationIdentifier = site, + usgsPCode = pcode, + service = "results", + profile = "basicphyschem", +) + +qw_data.shape[1] +``` + +::: + That's a LOT of columns returned. We won't look at them here, but you can use `View` in RStudio to explore on your own. ::: footer @@ -549,21 +698,31 @@ That's a LOT of columns returned. We won't look at them here, but you can use `V ```{r} #| echo: false - -df <- tibble(dataType = c("results", "locations", "activities", "projects", "organizations"), - Description = c("Results data and metadata for measures and observations matching your query", - "Find monitoring locations that have data matching your query", - "Information about the monitoring activities conducted that produced data", - "Information on the projects that have results matching your data query", - "Information about the organizations that have provided data that matches your query"), - dataProfile = c('fullphyschem
basicphyschem
fullbio
basicbio
narrow
resultdetectionquantitationlimit
labsampleprep
count', - 'site
count', - 'sampact
actmetric
actgroup
ncount', - 'project
projectmonitoringlocationweight', - 'organization
count')) +df <- tibble( + dataType = c( + "results", + "locations", + "activities", + "projects", + "organizations" + ), + Description = c( + "Results data and metadata for measures and observations matching your query", + "Find monitoring locations that have data matching your query", + "Information about the monitoring activities conducted that produced data", + "Information on the projects that have results matching your data query", + "Information about the organizations that have provided data that matches your query" + ), + dataProfile = c( + 'fullphyschem
basicphyschem
fullbio
basicbio
narrow
resultdetectionquantitationlimit
labsampleprep
count', + 'site
count', + 'sampact
actmetric
actgroup
ncount', + 'project
projectmonitoringlocationweight', + 'organization
count' + ) +) dt_me(df, escape = FALSE, paging = FALSE) - ``` ::: footer @@ -577,12 +736,16 @@ dt_me(df, escape = FALSE, paging = FALSE) * We'll look at Suisun Bay a Van Sickle Island NR Pittsburg CA ("USGS-11455508"), with parameter code "99133" which is Nitrate plus Nitrite. -## Workflow 3: Continuous data for known site +## Workflow 3: Continuous data for known site {.smaller} :::: {.columns} ::: {.column width="65%"} +::: {.panel-tabset} + +### R + ```{r} #| results: markup site_id <- "USGS-11455508" @@ -590,14 +753,35 @@ p_code_rt <- "99133" start_date <- "2024-01-01" end_date <- "2024-06-01" -continuous_data <- read_waterdata_continuous(monitoring_location_id = site_id, - parameter_code = p_code_rt, - time = c(start_date, end_date)) +continuous_data <- read_waterdata_continuous( + monitoring_location_id = site_id, + parameter_code = p_code_rt, + time = c(start_date, end_date) +) +nrow(continuous_data) +``` + +### Python + +```{python} +#| eval: !expr evaluate_python +site_id = "USGS-11455508" +p_code_rt = "99133" +date_range = "2024-01-01/2024-06-01" + +continuous_data, md_cont = waterdata.get_continuous( + monitoring_location_id = site_id, + parameter_code = p_code_rt, + time = date_range +) +continuous_data.shape[0] ``` ::: +::: + ::: {.column width="35%"} ``` @@ -626,8 +810,7 @@ https://api.waterdata.usgs.gov/ogcapi/v0/collections/continuous/items?f=json&lan ```{r} #| output-location: column ggplot(data = continuous_data) + - geom_point(aes(x = time, - y = value)) + geom_point(aes(x = time, y = value)) ``` @@ -647,18 +830,19 @@ The next slides will demo how to use those. ## Data Discovery: Time Series {.smaller} ```{r} -ts_available <- read_waterdata_combined_meta(monitoring_location_id = "USGS-04183500") +ts_available <- read_waterdata_combined_meta( + monitoring_location_id = "USGS-04183500" +) ``` ```{r} #| echo: false - -dt_me(ts_available |> - sf::st_drop_geometry() |> - select(data_type, - parameter_name, - parameter_code, statistic_id, begin, end), page_length = 6) - +dt_me( + ts_available |> + sf::st_drop_geometry() |> + select(data_type, parameter_name, parameter_code, statistic_id, begin, end), + page_length = 6 +) ``` ::: footer @@ -668,19 +852,24 @@ dt_me(ts_available |> ## Data Discovery: Discrete {.smaller} ```{r} -discrete_available <- summarize_waterdata_samples(monitoringLocationIdentifier = "USGS-04183500") - +discrete_available <- summarize_waterdata_samples( + monitoringLocationIdentifier = "USGS-04183500" +) ``` ```{r} #| echo: false - -dt_me(discrete_available |> - select(characteristicUserSupplied, - resultCount, activityCount, - firstActivity, mostRecentActivity), - page_length = 6) - +dt_me( + discrete_available |> + select( + characteristicUserSupplied, + resultCount, + activityCount, + firstActivity, + mostRecentActivity + ), + page_length = 6 +) ``` ::: footer @@ -692,8 +881,10 @@ dt_me(discrete_available |> * characteristicUserSupplied can be an input to `read_waterdata_sample` ```{r} -discrete1 <- read_waterdata_samples(characteristicUserSupplied = "Phosphorus as phosphorus, water, unfiltered", - monitoringLocationIdentifier = "USGS-04183500") +discrete1 <- read_waterdata_samples( + characteristicUserSupplied = "Phosphorus as phosphorus, water, unfiltered", + monitoringLocationIdentifier = "USGS-04183500" +) nrow(discrete1) ``` diff --git a/vignettes/movingAverages.Rmd b/vignettes/movingAverages.Rmd deleted file mode 100644 index 96b024b4e..000000000 --- a/vignettes/movingAverages.Rmd +++ /dev/null @@ -1,278 +0,0 @@ ---- -title: "Calculating Moving Averages and Historical Flow Quantiles" -author: "Laura DeCicco" -date: "2016-10-25" -output: - rmarkdown::html_vignette: - toc: true - fig_caption: yes - fig_height: 7 - fig_width: 7 -vignette: > - %\VignetteIndexEntry{Calculating Moving Averages and Historical Flow Quantiles} - \usepackage[utf8]{inputenc} - %\VignetteEngine{knitr::rmarkdown} -editor_options: - chunk_output_type: console ---- - -**WARNING** - -This post is very old! A better way to do all these plots and calculations can be found here: - -**WARNING** - -This post will show simple way to calculate moving averages, calculate historical-flow quantiles, and plot that information. The goal is to reproduce the graph at this link: -[PA Graph](http://pa.water.usgs.gov/drought/indicators/sw/images/f30_01538000.html). The motivation for this post was inspired by a USGS colleague that that is considering creating these type of plots in R. We thought this plot provided an especially fun challenge - maybe you will, too! - -First we get the data using the [dataRetrieval](https://CRAN.R-project.org/package=dataRetrieval) package. The siteNumber and parameterCd could be adjusted for other sites or measured parameters. In this example, we are getting discharge (parameter code 00060) at a site in PA. - -It may be important to note that this script is a bit lazy in handling leap days. - -## Get data using dataRetrieval - -```{r message=FALSE} -library(dataRetrieval) - -# Retrieve daily Q -siteNumber <- c("01538000") -parameterCd <- "00060" # Discharge -dailyQ <- readNWISdv(siteNumber, parameterCd) -dailyQ <- renameNWISColumns(dailyQ) -stationInfo <- readNWISsite(siteNumber) -nrow(dailyQ) -``` - -## Calculate moving average - -Next, we calculate a 30-day moving average on all of the flow data: - -```{r message=FALSE} -library(dplyr) -library(zoo) - -# Check for missing days, if so, add NA rows: -if (as.numeric(diff(range(dailyQ$Date))) != (nrow(dailyQ) + 1)) { - fullDates <- seq( - from = min(dailyQ$Date), - to = max(dailyQ$Date), by = "1 day" - ) - fullDates <- data.frame( - Date = fullDates, - agency_cd = unique(dailyQ$agency_cd), - site_no = unique(dailyQ$site_no) - ) - dailyQ <- fullDates %>% - left_join(dailyQ, - by = c("Date", "agency_cd", "site_no") - ) %>% - arrange(Date) -} - -dailyQ <- dailyQ %>% - mutate( - rollMean = rollmean(Flow, 30, fill = NA, align = "center"), - day.of.year = as.numeric(strftime(Date, - format = "%j" - )) - ) -``` - -## Calculate historical percentiles - -We can use the `quantile` function to calculate historical percentile flows. Then use the `loess` function for smoothing. The argument `smooth.span` defines how much smoothing should be applied. To get a smooth transistion at the start of the graph, we can add include an earlier year which is not plotted at the end. - -```{r message=FALSE} -summaryQ <- dailyQ %>% - group_by(day.of.year) %>% - summarize( - p75 = quantile(rollMean, probs = .75, na.rm = TRUE), - p25 = quantile(rollMean, probs = .25, na.rm = TRUE), - p10 = quantile(rollMean, probs = 0.1, na.rm = TRUE), - p05 = quantile(rollMean, probs = 0.05, na.rm = TRUE), - p00 = quantile(rollMean, probs = 0, na.rm = TRUE) - ) - -current.year <- as.numeric(strftime(Sys.Date(), format = "%Y")) - -summary.0 <- summaryQ %>% - mutate( - Date = as.Date(day.of.year - 1, - origin = paste0(current.year - 2, "-01-01") - ), - day.of.year = day.of.year - 365 - ) -summary.1 <- summaryQ %>% - mutate(Date = as.Date(day.of.year - 1, - origin = paste0(current.year - 1, "-01-01") - )) -summary.2 <- summaryQ %>% - mutate( - Date = as.Date(day.of.year - 1, - origin = paste0(current.year, "-01-01") - ), - day.of.year = day.of.year + 365 - ) - -summaryQ <- bind_rows(summary.0, summary.1, summary.2) - - -smooth.span <- 0.3 - -summaryQ$sm.75 <- predict(loess(p75 ~ day.of.year, data = summaryQ, span = smooth.span)) -summaryQ$sm.25 <- predict(loess(p25 ~ day.of.year, data = summaryQ, span = smooth.span)) -summaryQ$sm.10 <- predict(loess(p10 ~ day.of.year, data = summaryQ, span = smooth.span)) -summaryQ$sm.05 <- predict(loess(p05 ~ day.of.year, data = summaryQ, span = smooth.span)) -summaryQ$sm.00 <- predict(loess(p00 ~ day.of.year, data = summaryQ, span = smooth.span)) - -latest.years <- dailyQ %>% - filter(Date >= as.Date(paste0(current.year - 1, "-01-01"))) %>% - mutate(day.of.year = seq_len(nrow(.))) - -# Let's just take the middle chunk: -summaryQ <- summaryQ %>% - filter(day.of.year %in% 1:365) - -summaryQ <- summaryQ %>% - bind_rows( - summaryQ, - summaryQ - ) %>% - mutate(day.of.year = seq_len(nrow(.)) - 365) -``` - -## Plot using base R - -Many of the graphical requirements defined by the USGS are difficult to achieve in `ggplot2`. Base R plotting can be used to obtain these types of graphs: - -```{r fig.cap="Simple 30-day moving average daily flow plot using base R"} - -title.text <- paste0( - stationInfo$station_nm, "\n", - "Provisional Data - Subject to change\n", - "Record Start = ", min(dailyQ$Date), - " Number of years = ", - as.integer(as.numeric(difftime( - time1 = max(dailyQ$Date), - time2 = min(dailyQ$Date), - units = "weeks" - )) / 52.25), - "\nDate of plot = ", Sys.Date(), - " Drainage Area = ", stationInfo$drain_area_va, "mi^2" -) - -mid.month.days <- c(15, 45, 74, 105, 135, 166, 196, 227, 258, 288, 319, 349) -month.letters <- c("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D") -start.month.days <- c(1, 32, 61, 92, 121, 152, 182, 214, 245, 274, 305, 335) -label.text <- c("Normal", "Drought Watch", "Drought Warning", "Drought Emergency") - -plot(latest.years$day.of.year, latest.years$rollMean, - ylim = c(1, 1000), xlim = c(1, 733), - log = "y", axes = FALSE, type = "n", xaxs = "i", yaxs = "i", - ylab = "30-day moving ave", - xlab = "" -) -title(title.text, cex.main = 0.75) -polygon(c(summaryQ$day.of.year, rev(summaryQ$day.of.year)), - c(summaryQ$sm.75, rev(summaryQ$sm.25)), - col = "darkgreen", border = FALSE -) -polygon(c(summaryQ$day.of.year, rev(summaryQ$day.of.year)), - c(summaryQ$sm.25, rev(summaryQ$sm.10)), - col = "yellow", border = FALSE -) -polygon(c(summaryQ$day.of.year, rev(summaryQ$day.of.year)), - c(summaryQ$sm.10, rev(summaryQ$sm.05)), - col = "orange", border = FALSE -) -polygon(c(summaryQ$day.of.year, rev(summaryQ$day.of.year)), - c(summaryQ$sm.05, rev(summaryQ$sm.00)), - col = "red", border = FALSE -) -lines(latest.years$day.of.year, latest.years$rollMean, - lwd = 2, col = "black" -) -abline(v = 366) -axis(2, las = 1, at = c(1, 100, 1000), tck = -0.02) -axis(2, at = c(seq(1, 90, by = 10)), labels = NA, tck = -0.01) -axis(2, at = c(seq(100, 1000, by = 100)), labels = NA, tck = -0.01) -axis(1, - at = c(mid.month.days, 365 + mid.month.days), - labels = rep(month.letters, 2), - tick = FALSE, line = -0.5, cex.axis = 0.75 -) -axis(1, - at = c(start.month.days, 365 + start.month.days), - labels = NA, tck = -0.02 -) -axis(1, - at = c(182, 547), labels = c(current.year - 1, current.year), - line = .5, tick = FALSE -) -legend("bottom", label.text, - horiz = TRUE, - fill = c("darkgreen", "yellow", "orange", "red"), - inset = c(0, 0), xpd = TRUE, bty = "n", cex = 0.75 -) -box() -``` - - -## Plot using ggplot2 - -Finally, we can also try to create the graph using the `ggplot2` package. The following script shows a simple way to re-create the graph in `ggplot2` with no effort on imitating desired style: - - -```{r fig.cap="Simple 30-day moving average daily flow plot using ggplot2", alt.text = "30-day moving average daily flow plot, no effort on style", message=FALSE, warning=FALSE, fig.height=5} -library(ggplot2) - -simple.plot <- ggplot(data = summaryQ, aes(x = day.of.year)) + - geom_ribbon(aes(ymin = sm.25, ymax = sm.75, fill = "Normal")) + - geom_ribbon(aes(ymin = sm.10, ymax = sm.25, fill = "Drought Watch")) + - geom_ribbon(aes(ymin = sm.05, ymax = sm.10, fill = "Drought Warning")) + - geom_ribbon(aes(ymin = sm.00, ymax = sm.05, fill = "Drought Emergency")) + - scale_y_log10(limits = c(1, 1000)) + - geom_line(data = latest.years, aes(x = day.of.year, y = rollMean, color = "30-Day Mean"), size = 2) + - geom_vline(xintercept = 365) - -simple.plot -``` - -Next, we can play with various options to do a better job to imitate the style: - -```{r fig.cap="Detailed 30-day moving average daily flow plot", alt.text = "30-day moving average daily flow plot", message=FALSE, warning=FALSE} - -styled.plot <- simple.plot + - scale_x_continuous( - breaks = c(mid.month.days, 365 + mid.month.days), - labels = rep(month.letters, 2), - expand = c(0, 0), - limits = c(0, 730) - ) + - annotation_logticks(sides = "l") + - expand_limits(x = 0) + - annotate( - geom = "text", - x = c(182, 547), - y = 1, - label = c(current.year - 1, current.year), size = 4 - ) + - theme_bw() + - theme( - axis.ticks.x = element_blank(), - panel.grid.major = element_blank(), - panel.grid.minor = element_blank() - ) + - labs(title = title.text, - y = "30-day moving ave", x = "" - ) + - scale_fill_manual( - name = "", breaks = label.text, - values = c("red", "orange", "yellow", "darkgreen") - ) + - scale_color_manual(name = "", values = "black") + - theme(legend.position = "bottom") - -styled.plot -``` - diff --git a/vignettes/statsServiceMap.Rmd b/vignettes/statsServiceMap.Rmd deleted file mode 100644 index 08b218bb6..000000000 --- a/vignettes/statsServiceMap.Rmd +++ /dev/null @@ -1,197 +0,0 @@ ---- -title: "Using the dataRetrieval Stats Service" -author: "David Watkins" -date: "2016-10-05" -output: - rmarkdown::html_vignette: - toc: true - fig_caption: yes - fig_height: 7 - fig_width: 7 -vignette: > - %\VignetteIndexEntry{Using the dataRetrieval Stats Service} - \usepackage[utf8]{inputenc} - %\VignetteEngine{knitr::rmarkdown} ---- - -# Introduction - -This script utilizes the new `dataRetrieval` package access to the [USGS Statistics Web Service](https://waterservices.usgs.gov/docs/statistics/). We will be pulling daily mean data using the daily value service in `readNWISdata`, and using the stats service data to put it in the context of the site's history. Here we are retrieving data for July 12th in the Upper Midwest, where a major storm system had recently passed through. You can modify this script to look at other areas and dates simply by modifying the `states` and `storm.date` objects. - -To run this code, we recommend having either `dataRetreival` version 2.5.13 (currently the latest release on CRAN) or version 2.6.1 (currently the latest Github release). - -# Get the data - -There are two separate `dataRetrieval` calls here — one to retrieve the daily discharge data, and one to retrieve the historical discharge statistics. Both calls are inside loops to split them into smaller pieces, to accomodate web service restrictions. The daily values service allows only single states as a filter, so we loop over the list of states. The stats service does not allow requests of more than ten sites, so the loop iterates by groups of ten site codes. Retrieving the data can take a few tens of seconds. Once we have both the daily value and statistics data, the two data frames are joined by site number via [dplyr's](https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html) `left_join` function. We use a [pipe](https://cran.r-project.org/web/packages/magrittr/vignettes/magrittr.html) to send the output of the join to `na.omit()` function. Then we add a column to the final data frame to hold the color value for each station. - -```{r getData, warning=FALSE, message=FALSE} -# example stats service map, comparing real-time current discharge to history for each site -# reusable for other state(s) -# David Watkins June 2016 - - -library(maps) -library(dplyr) -library(lubridate) -library(dataRetrieval) - -# pick state(s) and date -states <- c("WI", "MN", "ND", "SD", "IA") -storm.date <- "2016-07-12" - -# download each state individually -for (st in states) { - stDV <- renameNWISColumns(readNWISdata( - service = "dv", - parameterCd = "00060", - stateCd = st, - startDate = storm.date, - endDate = storm.date - )) - if (st != states[1]) { - storm.data <- full_join(storm.data, stDV) - sites <- full_join(sites, attr(stDV, "siteInfo")) - } else { - storm.data <- stDV - sites <- attr(stDV, "siteInfo") - } -} - -# retrieve stats data, dealing with 10 site limit to stat service requests -reqBks <- seq(1, nrow(sites), by = 10) -statData <- data.frame() -for (i in reqBks) { - getSites <- sites$site_no[i:(i + 9)] - currentSites <- readNWISstat( - siteNumbers = getSites, - parameterCd = "00060", - statReportType = "daily", - statType = c("p10", "p25", "p50", "p75", "p90", "mean") - ) - statData <- rbind(statData, currentSites) -} - -statData.storm <- statData[statData$month_nu == month(storm.date) & - statData$day_nu == day(storm.date), ] - -finalJoin <- left_join(storm.data, statData.storm) -finalJoin <- left_join(finalJoin, sites) - -finalJoin[, grep("_va", names(finalJoin))] <- sapply( - finalJoin[ - , - grep("_va", names(finalJoin)) - ], - function(x) as.numeric(x) -) - -# remove sites without current data -finalJoin <- finalJoin[!is.na(finalJoin$Flow), ] - - -# classify current discharge values -finalJoin$class <- NA - -finalJoin$class[finalJoin$Flow > finalJoin$p75_va] <- "navy" -finalJoin$class[finalJoin$Flow < finalJoin$p25_va] <- "red" - -finalJoin$class[finalJoin$Flow > finalJoin$p25_va & - finalJoin$Flow <= finalJoin$p50_va] <- "green" -finalJoin$class[finalJoin$Flow > finalJoin$p50_va & - finalJoin$Flow <= finalJoin$p75_va] <- "blue" - -finalJoin$class[is.na(finalJoin$class) & - finalJoin$Flow > finalJoin$p50_va] <- "cyan" -finalJoin$class[is.na(finalJoin$class) & - finalJoin$Flow < finalJoin$p50_va] <- "yellow" - -# take a look at the columns that we will plot later: -head(finalJoin[, c("dec_lon_va", "dec_lat_va", "class")]) -``` - -# Make the static plot - -The base map consists of two plots. The first makes the county lines with a gray background, and the second overlays the heavier state lines. After that we add the points for each stream gage, colored by the column we added to `finalJoin`. In the finishing details, `grconvertXY` is a handy function that converts your inputs from a normalized (0-1) coordinate system to the actual map coordinates, which allows the legend and scale to stay in the same relative location on different maps. - -```{r plot, fig.cap="Map discharge percentiles"} -# convert states from postal codes to full names -states <- stateCdLookup(states, outputType = "fullName") -par(pty = "s") -map("county", regions = states, fill = TRUE, col = "gray87", lwd = 0.5) -map("state", regions = states, fill = FALSE, lwd = 2, add = TRUE) -points(finalJoin$dec_lon_va, - finalJoin$dec_lat_va, - col = finalJoin$class, pch = 19 -) -title(paste("Daily discharge value percentile rank\n", storm.date), line = 1) -par(mar = c(5.1, 4.1, 4.1, 6), xpd = TRUE) - -legend.colors <- c( - "cyan", "yellow", - "red", - "green", "blue", - "navy" -) -legend.names <- c( - "Q > P50*", "Q < P50*", - "Q < P25", - "P25 < Q < P50", "P50 < Q < P75", - "Q > P75" -) - -legend("bottomleft", - inset = c(0.01, .01), - legend = legend.names, - pch = 19, cex = 0.75, pt.cex = 1.2, - col = legend.colors, - ncol = 2 -) -map.scale( - ratio = FALSE, cex = 0.75, - grconvertX(.07, "npc"), - grconvertY(.2, "npc") -) -text("*Other percentiles not available for these sites", - cex = 0.75, - x = grconvertX(0.2, "npc"), - y = grconvertY(-0.08, "npc") -) -``` - -# Make an interactive plot - -Static maps are great for papers and presentations. When possible, interactive maps allow the reader more flexibility to examine the data. The R leaflet package makes it easy to create useful interactive maps. - -```{r leaflet, fig.height=5} -library(leaflet) - -finalJoin$popup <- with(finalJoin, paste( - "", station_nm, - "
", - "Measured Flow:", Flow, - "ft3/s
", - "25% historical:", p25_va, - "ft3/s
", - "50% historical:", p50_va, - "ft3/s
", - "75% historical:", p75_va, - "ft3/s" -)) - -leafMapStat <- leaflet(data = finalJoin) %>% - addProviderTiles("CartoDB.Positron") %>% - addCircleMarkers(~dec_lon_va, ~dec_lat_va, - color = ~class, radius = 3, stroke = FALSE, - fillOpacity = 0.8, opacity = 0.8, - popup = ~popup - ) - -leafMapStat <- addLegend(leafMapStat, - position = "bottomleft", - colors = legend.colors, - labels = legend.names, - opacity = 0.8 -) - -leafMapStat -```