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
260 stars 84 forks source link

readNWISdv only returns mean statistic #666

Closed marcus-aguilar closed 1 year ago

marcus-aguilar commented 1 year ago

The following code should return the min and max discharge at USGS 0205000, but returns an empty data frame. The code works when statCD = "00003" which indicates that mean is available and works at other gage sites (e.g. "02310308"). I've tried on different R builds, but have not had any success. Thanks!

data1<-readNWISdv("02055000", "00065", "2016-01-01", "2016-02-29",c("00001","00002"))

ldecicco-USGS commented 1 year ago

Unfortunately, the only stats available from the web services for that site are discharge daily mean ("00003"). dataRetrieval doesn't calculate those stats on the fly, it pulls it from the web services that pre-calculate these stats.

You can see what is available like this:

all_available_data <- whatNWISdata(siteNumber = "02055000")

If we look at this result, we'll see that there's actually only "uv" is available for gage height:

all_available_data <- all_available_data[!is.na(all_available_data$parm_cd), ]

gage_height <- all_available_data[all_available_data$parm_cd == "00065", ]
gage_height$data_type_cd
[1] "uv"

To get that data, you can use the readNWISuv function:

gage <- readNWISuv("02055000", "00065") 

You could use that "uv" data to calculate min/maxs for the day.

On the other hand, you could use the discharge data ("00060") to get daily means (statCd = "00003"). But, if you are after the min/max of the day, that won't help you:

all_available_data[all_available_data$parm_cd == "00060",
                   c("data_type_cd", "stat_cd")]
   data_type_cd stat_cd
2            dv   00003
10           qw    <NA>
91           uv    <NA>

Let me know if any of that wasn't clear!