DOI-USGS / dataRetrieval

This R package is designed to obtain USGS or EPA water quality sample data, streamflow data, and metadata directly from web services.
https://doi-usgs.github.io/dataRetrieval/
Other
259 stars 84 forks source link

Downloading multiple datasets within one parameter #598

Closed TomUniBonn closed 2 years ago

TomUniBonn commented 2 years ago

When downloading a parameter (in this case water temperature: "00010") only one of the available datasets within the parameter is retrievable via readNWISdv, even if there are are multiple. Since there aren't multiple parameter codes, how do you access different datasets within your set parameter?

The code:

startDate<-"1950-01-01"
endDate<-"2022-01-01"
siteid<-"09180500"
Upstream<-readNWISdv(siteid,Parameter,startDate,endDate)%>%renameNWISColumns()
head(Upstream)

The table then only contains the dataset which is starting in 2006 instead of the additional instantaneous water temperature dataset measured from 1949 onwards at this staion.

Session info:

Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] moments_0.14         zoo_1.8-9            patchwork_1.1.1     
 [4] lubridate_1.8.0      forcats_0.5.1        stringr_1.4.0       
 [7] dplyr_1.0.7          purrr_0.3.4          readr_2.0.2         
[10] tidyr_1.1.4          tibble_3.1.5         ggplot2_3.3.5       
[13] tidyverse_1.3.1      dataRetrieval_2.7.10

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7       cellranger_1.1.0 pillar_1.6.4     compiler_4.1.1  
 [5] dbplyr_2.1.1     tools_4.1.1      lattice_0.20-44  jsonlite_1.7.2  
 [9] lifecycle_1.0.1  gtable_0.3.0     pkgconfig_2.0.3  rlang_0.4.11    
[13] reprex_2.0.1     cli_3.0.1        rstudioapi_0.13  DBI_1.1.1       
[17] haven_2.4.3      withr_2.4.2      httr_1.4.2       xml2_1.3.2      
[21] fs_1.5.0         generics_0.1.0   vctrs_0.3.8      hms_1.1.1       
[25] grid_4.1.1       tidyselect_1.1.1 glue_1.4.2       R6_2.5.1        
[29] fansi_0.5.0      readxl_1.3.1     tzdb_0.1.2       modelr_0.1.8    
[33] magrittr_2.0.1   scales_1.1.1     backports_1.2.1  ellipsis_0.3.2  
[37] rvest_1.0.2      assertthat_0.2.1 colorspace_2.0-2 utf8_1.2.2      
[41] stringi_1.7.5    munsell_0.5.0    broom_0.7.9      crayon_1.4.1

Thanks in advance.

ldecicco-USGS commented 2 years ago

If you try the whatNWISdata function, you can get an idea of where the data is:

library(dataRetrieval)
startDate<-"1950-01-01"
endDate<-"2022-01-01"
siteid<-"09180500"
available <- whatNWISdata(siteNumber = siteid, parameterCd = "00010")

Looking at that "available" data frame: image

You can see there is data available in the "dv", "uv", and "qw" services. Each of those are different, so you would need to do 3 separate calls:

uv <- readNWISuv(siteid, "00010")
dv <- readNWISdv(siteid, "00010")
qw <- readNWISqw(siteid, "00010")

(qw == discrete measurements, dv is daily - by default a daily mean, uv = "unit values" which is typically sensor data)

How you decide to merge those sets together, will depend on what you are doing.

The function readNWISqw will give you a warning that the services are going to be retired. Usually I would switching to the readWQPqw function. In this case, I'm not seeing the temperature results on the Water Quality Portal for this site. I'm not sure why that is, but I can ask around.