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
256 stars 85 forks source link

readNWISdata with peak service #619

Closed ldecicco-USGS closed 1 year ago

ldecicco-USGS commented 2 years ago

I would expect this to work:

peaks <- readNWISdata(stateCd="PA", service="peak")

But, you need this instead:

peaks <- readNWISdata(stateCd="PA", service="peak",
                      list_of_search_criteria="state_cd")

We should check state, county, and HUC queries and make sure the peak requests act similar to the other services.

ldecicco-USGS commented 2 years ago
url <- "https://nwis.waterdata.usgs.gov/nwis/peak?state_cd=pa&group_key=county_cd&sitefile_output_format=html_table&column_name=agency_cd&column_name=site_no&column_name=station_nm&set_logscale_y=1&format=rdb&date_format=YYYY-MM-DD&rdb_compression=value&hn2_compression=file&list_of_search_criteria=state_cd"

x <- importRDB1(url)
ldecicco-USGS commented 2 years ago

Generally, the readNWISdata function requires the user to be pretty savvy with understanding how to call their data. However, when we can make their lives a little easier we try.

The question here is for the peak service: https://nwis.waterdata.usgs.gov/nwis/peak

So, right now, for the user to get peak data for a single state, they need to do this:

x2 <- readNWISdata(state_cd = "PA",
                   list_of_search_criteria="state_cd", 
                   service = "peak")

If you don't add that list_of_search_criteria="state_cd",, you get the whole country.

What we could do is add another check here. Somewhere in readNWISdots we could add:

    if (service == "peak" & "state_cd" %in% names(values)){
       values["list_of_search_criteria"] <- "state_cd"
    }

Then we'd want to add an example to the readNWISdata helpfile that looks like this:

pa_peaks <- readNWISdata(state_cd = "PA",
                   service = "peak")

We should then also add that as a test in the testthat folder.

So, things to do: