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

Cannot retreive gage height data from Attoyac at Chireno (#08038000) #612

Closed albrechtcf closed 2 years ago

albrechtcf commented 2 years ago

I am unable to retrieve gage height values from gage #08038000. The code that I'm using successfully retrieves data from nearby gages, such as Angelina at Alto (gage #08036500). Code below shows two uses of readNWISdata(), where the first ("ang.alt<-...) functions normally and the second ("att.chi<-...) does not.

library(data.table)
library(dataRetrieval)

call.begin <- as.Date("2012-10-01") ; call.end <- as.Date("2022-03-10")

ang.alt <- as.data.table(  
  readNWISdata( 
    siteNumber="08036500", 
    service = "dv",
    asDateTime = TRUE, 
    convertType = TRUE, 
    startDate = call.begin,
    endDate = call.end,
    tz = "America/Chicago", 
    parameterCd = c("00065")  )) 

att.chi<- as.data.table(  
  readNWISdata( 
    siteNumber="08038000", 
    service = "dv",
    asDateTime = TRUE, 
    convertType = TRUE, 
    startDate = call.begin,
    endDate = call.end,
    tz = "America/Chicago", 
    parameterCd = c("00065")  ))

The first code block ("ang.alt<-..." ) functions as expected.

> ang.alt
      agency_cd  site_no            dateTime X_00065_00003 X_00065_00003_cd           tz_cd
   1:      USGS 08036500 2012-09-30 19:00:00         15.41                A America/Chicago
   2:      USGS 08036500 2012-10-01 19:00:00         14.71                A America/Chicago
   3:      USGS 08036500 2012-10-02 19:00:00         15.33                A America/Chicago
   4:      USGS 08036500 2012-10-03 19:00:00         16.10                A America/Chicago
   5:      USGS 08036500 2012-10-04 19:00:00         16.64                A America/Chicago
  ---                                                                                      
3432:      USGS 08036500 2022-03-05 18:00:00         14.89                P America/Chicago
3433:      USGS 08036500 2022-03-06 18:00:00         14.58                P America/Chicago
3434:      USGS 08036500 2022-03-07 18:00:00         14.37                P America/Chicago
3435:      USGS 08036500 2022-03-08 18:00:00         14.54                P America/Chicago
3436:      USGS 08036500 2022-03-09 18:00:00         14.57                P America/Chicago

The second ("att.chi<-..."), when run, generates a 4-column data table with no rows.

> att.chi
Empty data.table (0 rows and 4 cols): agency_cd,site_no,dateTime,tz_cd

Can you help me figure out why I'm unable to retrieve gage height from gage #08038000?

ldecicco-USGS commented 2 years ago

The first think I would check is:

y <- whatNWISdata(siteNumber="08038000")

If I look at that table, I see gage height is only available in the data_type_cd = "uv", which means you can get gage height like this:

att.chi <- dataRetrieval::readNWISdata( 
  siteNumber="08038000", 
  service = "uv", #This is the different line!
  asDateTime = TRUE, 
  convertType = TRUE, 
  startDate = call.begin,
  endDate = call.end,
  tz = "America/Chicago", 
  parameterCd = c("00065")  )

However...now you have "unit" data instead of daily data. You can also look at that "y" data frame above and see there's daily discharge data for that site (pcode 00060). If using discharge is an option, than that's one solution. The other would be to group the unit data by day, and take the mean yourself...it should be pretty reasonable to do with the data.table package you are using.

albrechtcf commented 2 years ago

Thank you!