Skip to contents

Publicly available hydrological and meteorological data from USGS can be discovered and accessed from the National Water Infrastructure Service (NWIS). The NWIS can be accessed using USGS’s R package, dataRetrieval. hymetDP offers users convenient dataRetrieval wrapper functions to simplify the integration of USGS data with published, hymetDP-formatted data packages.

Create a hymetDP dataset from USGS data

Discover USGS sites

To select specific sites using create_USGS_hymet(), you will need to know the site’s USGS Site ID (.

Use dataRetrieval::whatNWISsites() to discover USGS sites by State or area.

We can get a table of all USGS stream sites that measure discharge:

sites <- dataRetrieval::whatNWISsites(stateCd="PR", siteType="ST", parameterCd="00060")
head(sites)
#>   agency_cd  site_no                         station_nm site_tp_cd dec_lat_va
#> 1      USGS 50146200           RIO GRANDE NR RINCON, PR         ST   18.36634
#> 2      USGS 50146400          RIO INGENIO NR AGUADA, PR         ST   18.37856
#> 3      USGS 50146600          RIO CULEBRA NR AGUADA, PR         ST   18.37189
#> 4      USGS 50130320       QUEBRADA MAMEY AT JOYUDA, PR         ST   18.12885
#> 5      USGS 50146100 RIO GRANDE DE ANASCO NR ANASCO, PR         ST   18.27273
#> 6      USGS 50149100       RIO CULEBRINAS NR AGUADA, PR         ST   18.39884
#>   dec_long_va colocated           queryTime
#> 1   -67.23185     FALSE 2022-06-28 14:27:58
#> 2   -67.20907     FALSE 2022-06-28 14:27:58
#> 3   -67.19268     FALSE 2022-06-28 14:27:58
#> 4   -67.16879     FALSE 2022-06-28 14:27:58
#> 5   -67.16157     FALSE 2022-06-28 14:27:58
#> 6   -67.16074     FALSE 2022-06-28 14:27:58

See USGS Site Web Service for a complete list of argument options for dataRetrieval::whatNWISsites()

Select USGS parameters

Inspect the supported_USGS_params to see which USGS parameters are currently supported for conversion to hymetDP.

View(supported_USGS_params)

Create the hymetDP-formatted dataset from USGS data

Specify USGS sites, parameter codes, and start and end dates as arguments to create_USGS_hymet() to compile and format data for the given parameters at the location and the time period.

site <- c("06879650", "50065500")
param <- c("00060")
start <- c("2021-01-01T12:30:00Z")
end <- c("2021-01-08T12:30:00Z")

usgs_hymet <- hymetDP::create_USGS_hymet(site, param, start, end)
#> Downloading data from USGS site 06879650, parameter 00060
#> Downloading data from USGS site 50065500, parameter 00060
#> Generating hymetDP tables...

str(usgs_hymet)
#> List of 7
#>  $ Sources             :'data.frame':    2 obs. of  12 variables:
#>   ..$ SourceCode       : chr [1:2] "1" "2"
#>   ..$ Organization     : chr [1:2] "USGS" "USGS"
#>   ..$ SourceDescription: chr [1:2] "Data pulled from USGS National Water Infrastructure Service (NWIS) using the dataRetrieval R package" "Data pulled from USGS National Water Infrastructure Service (NWIS) using the dataRetrieval R package"
#>   ..$ SourceLink       : chr [1:2] "https://waterdata.usgs.gov/monitoring-location/06879650/#parameterCode=00060" "https://waterdata.usgs.gov/monitoring-location/50065500/#parameterCode=00060"
#>   ..$ ContactName      : chr [1:2] "Unknown" "Unknown"
#>   ..$ Phone            : chr [1:2] "Unknown" "Unknown"
#>   ..$ Email            : chr [1:2] "Unknown" "Unknown"
#>   ..$ Address          : chr [1:2] "Unknown" "Unknown"
#>   ..$ City             : chr [1:2] "Unknown" "Unknown"
#>   ..$ State            : chr [1:2] "Kansas" "Puerto Rico"
#>   ..$ ZipCode          : chr [1:2] "Unknown" "Unknown"
#>   ..$ Citation         : chr [1:2] "U.S. Geological Survey, 2001, National Water Information System data available on the World Wide Web (Water Dat"| __truncated__ "U.S. Geological Survey, 2001, National Water Information System data available on the World Wide Web (Water Dat"| __truncated__
#>  $ Methods             :'data.frame':    2 obs. of  3 variables:
#>   ..$ MethodCode       : chr [1:2] "1" "2"
#>   ..$ MethodDescription: chr [1:2] "Data pulled from USGS National Water Infrastructure Service (NWIS) using the dataRetrieval R package" "Data pulled from USGS National Water Infrastructure Service (NWIS) using the dataRetrieval R package"
#>   ..$ MethodLink       : chr [1:2] NA NA
#>  $ Variables           :'data.frame':    1 obs. of  11 variables:
#>   ..$ VariableCode     : chr "00060"
#>   ..$ VariableName     : chr "Streamflow"
#>   ..$ VariableUnitsName: chr "cubic feet per second"
#>   ..$ SampleMedium     : chr "Surface water"
#>   ..$ ValueType        : chr "Derived Value"
#>   ..$ IsRegular        : logi TRUE
#>   ..$ TimeSupport      : num 15
#>   ..$ TimeUnitsName    : chr "minute"
#>   ..$ DataType         : chr "Continuous"
#>   ..$ GeneralCategory  : chr "Hydrology"
#>   ..$ NoDataValue      : num -9999
#>  $ Sites               :'data.frame':    2 obs. of  15 variables:
#>   ..$ SiteCode              : chr [1:2] "06879650" "50065500"
#>   ..$ SiteName              : chr [1:2] "KINGS C NR MANHATTAN, KS" "RIO MAMEYES NR SABANA, PR"
#>   ..$ Latitude              : num [1:2] 39.1 18.3
#>   ..$ Longitude             : num [1:2] -96.6 -65.8
#>   ..$ LatLongDatumSRSName   : chr [1:2] "NAD83" "NAD27"
#>   ..$ Elevation_m           : num [1:2] NA NA
#>   ..$ VerticalDatum         : chr [1:2] "Unknown" "Unknown"
#>   ..$ LocalX                : num [1:2] NA NA
#>   ..$ LocalY                : num [1:2] NA NA
#>   ..$ LocalProjectionSRSName: chr [1:2] "Unknown" "Unknown"
#>   ..$ PosAccuracy_m         : num [1:2] NA NA
#>   ..$ State                 : chr [1:2] "Kansas" "Puerto Rico"
#>   ..$ County                : chr [1:2] "Riley County" "Rio Grande Municipio"
#>   ..$ Comments              : chr [1:2] NA NA
#>   ..$ SiteType              : chr [1:2] "Stream" "Stream"
#>  $ QualityControlLevels:'data.frame':    1 obs. of  3 variables:
#>   ..$ QualityControlLevelCode: chr "A"
#>   ..$ Definition             : chr "Approved for publication -- Processing and review completed."
#>   ..$ Explanation            : chr "Water-Level Approval-Status Codes"
#>  $ DataValues          :'data.frame':    1344 obs. of  15 variables:
#>   ..$ ValueID                : chr [1:1344] "1" "2" "3" "4" ...
#>   ..$ DataValue              : num [1:1344] 0 0 0 0 0 0 0 0 0 0 ...
#>   ..$ ValueAccuracy          : num [1:1344] NA NA NA NA NA NA NA NA NA NA ...
#>   ..$ LocalDateTime          : chr [1:1344] "2021-01-01 07:30:00" "2021-01-01 07:45:00" "2021-01-01 08:00:00" "2021-01-01 08:15:00" ...
#>   ..$ UTCOffset              : num [1:1344] -6 -6 -6 -6 -6 -6 -6 -6 -6 -6 ...
#>   ..$ DateTimeUTC            : chr [1:1344] "2021-01-01 13:30:00" "2021-01-01 13:45:00" "2021-01-01 14:00:00" "2021-01-01 14:15:00" ...
#>   ..$ SiteCode               : chr [1:1344] "06879650" "06879650" "06879650" "06879650" ...
#>   ..$ VariableCode           : chr [1:1344] "00060" "00060" "00060" "00060" ...
#>   ..$ OffsetValue            : num [1:1344] NA NA NA NA NA NA NA NA NA NA ...
#>   ..$ OffsetTypeCode         : chr [1:1344] NA NA NA NA ...
#>   ..$ CensorCode             : chr [1:1344] "unk" "unk" "unk" "unk" ...
#>   ..$ QualifierCode          : chr [1:1344] NA NA NA NA ...
#>   ..$ MethodCode             : chr [1:1344] "1" "1" "1" "1" ...
#>   ..$ SourceCode             : chr [1:1344] "1" "1" "1" "1" ...
#>   ..$ QualityControlLevelCode: chr [1:1344] "A" "A" "A" "A" ...
#>  $ SeriesCatalog       :'data.frame':    2 obs. of  24 variables:
#>   ..$ SeriesID               : num [1:2] 1 2
#>   ..$ SiteCode               : chr [1:2] "06879650" "50065500"
#>   ..$ SiteName               : chr [1:2] "KINGS C NR MANHATTAN, KS" "RIO MAMEYES NR SABANA, PR"
#>   ..$ VariableCode           : chr [1:2] "00060" "00060"
#>   ..$ VariableName           : chr [1:2] "Streamflow" "Streamflow"
#>   ..$ VariableUnitsName      : chr [1:2] "cubic feet per second" "cubic feet per second"
#>   ..$ SampleMedium           : chr [1:2] "Surface water" "Surface water"
#>   ..$ ValueType              : chr [1:2] "Derived Value" "Derived Value"
#>   ..$ TimeSupport            : num [1:2] 15 15
#>   ..$ TimeUnitsName          : chr [1:2] "minute" "minute"
#>   ..$ DataType               : chr [1:2] "Continuous" "Continuous"
#>   ..$ GeneralCategory        : chr [1:2] "Hydrology" "Hydrology"
#>   ..$ MethodCode             : chr [1:2] "1" "2"
#>   ..$ MethodDescription      : chr [1:2] "Data pulled from USGS National Water Infrastructure Service (NWIS) using the dataRetrieval R package" "Data pulled from USGS National Water Infrastructure Service (NWIS) using the dataRetrieval R package"
#>   ..$ SourceCode             : chr [1:2] "1" "2"
#>   ..$ Organization           : chr [1:2] "USGS" "USGS"
#>   ..$ SourceDescription      : chr [1:2] "Data pulled from USGS National Water Infrastructure Service (NWIS) using the dataRetrieval R package" "Data pulled from USGS National Water Infrastructure Service (NWIS) using the dataRetrieval R package"
#>   ..$ Citation               : chr [1:2] "U.S. Geological Survey, 2001, National Water Information System data available on the World Wide Web (Water Dat"| __truncated__ "U.S. Geological Survey, 2001, National Water Information System data available on the World Wide Web (Water Dat"| __truncated__
#>   ..$ QualityControlLevelCode: chr [1:2] "A" "A"
#>   ..$ BeginDateTime          : chr [1:2] "2021-01-01 07:30:00" "2021-01-01 06:30:00"
#>   ..$ EndDateTime            : chr [1:2] "2021-01-08 07:30:00" "2021-01-08 06:30:00"
#>   ..$ BeginDateTimeUTC       : chr [1:2] "2021-01-01 13:30:00" "2021-01-01 12:30:00"
#>   ..$ EndDateTimeUTC         : chr [1:2] "2021-01-08 13:30:00" "2021-01-08 12:30:00"
#>   ..$ ValueCount             : num [1:2] 673 671

Write hymetDP tables to file

path = tempdir()

hymetDP::write_tables(
  path = path,
  DataValues = usgs_hymet$DataValues,
  Variables = usgs_hymet$Variables,
  Methods = usgs_hymet$Methods,
  Sources = usgs_hymet$Sources,
  Sites = usgs_hymet$Sites,
  QualityControlLevels = usgs_hymet$QualityControlLevels,
  SeriesCatalog = usgs_hymet$SeriesCatalog)
#> Writing tables to file:
#>   DataValues
#>   Variables
#>   Methods
#>   Sources
#>   Sites
#>   QualityControlLevels
#>   SeriesCatalog

Create EML

Create Ecological Metadata Language (EML) metadata for the derived dataset.

# Coming soon!