Attach and Authenticate

First you’ll need to attach your packages.

library(EnviroDataR)
library(DT) # Attaching for tutorial. Not necessary to use envirodata_r.

Next, authenticate your session with EnviroData API.

# username and password hidden for security
username <- XXXXX
password <- YYYYY 

authenticate_envirodata(username, password)

Collect Metadata

EnviroData has a lot of data. It can be intimidating trying to remember essential values when fetching data. For this reason, EnviroData R has a get_metadata() function for retrieving some important metadata that you can use as a reference when conducting your business.

metadata <- get_metadata()
names(metadata)
#> [1] "envirodata_url"              "guideline_list_data"        
#> [3] "discrete_location_list_data" "aquarius_stations_list_data"

As you can see, get_metadata() returns the URL for EnviroData’s API, and three dataframes: guideline details, discrete locations, and Aquarius stations.

Discrete Stations

Orient yourself by looking into into the discrete stations metadata dataframe. For presentation purposes, I’ll display the dataframe using the DT::datatable() function so you can explore the data on your own.

DT::datatable(metadata$discrete_location_list_data, rownames = FALSE, filter="top", 
              options = list(pageLength = 5, scrollX=T))


Next, we can gather some detailed information for a single discrete station using get_wq_locations_details(). An equivalent function also exists for Aquarius stations (get_aquarius_location_details()) that we’ll go over in the next section.

station_of_interest <- '11-03D'
discrete_station_details <- get_wq_locations_details(station_of_interest)

DT::datatable(discrete_station_details, rownames = FALSE, filter="top", options = list(pageLength = 5, scrollX=T))


You can then use base R to get a list of analytes, media types, and guidelines available at the station.

media <- discrete_station_details$MediaType %>% unique()
analytes <- discrete_station_details$Analyte %>% unique()
guidelines <- metadata$guideline_list_data$Guideline %>% unique()

media
#> [1] "Water"
analytes[1:5]
#> [1] "Acidity (as CaCO3)_Concentration (liquid)"                
#> [2] "Alkalinity (PP as CaCO3)_Concentration (liquid)"          
#> [3] "Alkalinity (Total as CaCO3)_Concentration (liquid)"       
#> [4] "Alkalinity, Bicarbonate (as CaCO3)_Concentration (liquid)"
#> [5] "Alkalinity, Carbonate (as CaCO3)_Concentration (liquid)"
guidelines
#>  [1] "BC_WWS_ST"                    "BC_WWS_LT"                   
#>  [3] "JDS_WTF_MAXGRAB"              "SB_ENVBM"                    
#>  [5] "FMMER_MAXMON"                 "FMMER_MAXGRAB"               
#>  [7] "CDWQ_AO"                      "CDWQ_OG"                     
#>  [9] "CDWQ_MAC"                     "BC_AWQG_LTAVE"               
#> [11] "BC_AWQG_STMAX"                "BC_WWQG_LTAVE"               
#> [13] "ED1 Permit Limit average"     "ED1 NMP Level 1"             
#> [15] "WQ8 NMP Level 1"              "WQWTF NMP Level 1"           
#> [17] "ED1 NMP Level 2"              "WQ8 NMP Level 2"             
#> [19] "WQ8 SPO"                      "ED1 SSMP Level 1"            
#> [21] "ED1 SSMP Level 2 "            "ED1 SSMP Level 3"            
#> [23] "WQ8 SSMP Level 3"             "ED1 WMP Level 1"             
#> [25] "ED1 WMP Level 2"              "WQ8 WMP Trigger"             
#> [27] "Antimony Trigger"             "ED1 WMP Level 1  (avg value)"
#> [29] "ED1 WMP Level 2  (avg value)" "CSR_AW"                      
#> [31] "CCME-SOIL"                    "BCWQG_AL"                    
#> [33] "BC_DW_AES"                    "BC_DW_MAC"                   
#> [35] "BC_WWS_NR_LT"                 "BC_WWS_R_LT"                 
#> [37] "FMMER_10PERC_MAXMON"

Finally, we can use get_wq_report_data() function to collect data for the station of interest. We’ll also provide a character vector of guidelines for comparing with the observations.

wq_report_data <- get_wq_report_data(
  start_date = '2012-01-27', end_date = '2016-04-16',
  station = station_of_interest, analytes = analytes, 
  media = media, guidelines = c("BC_WWQG_LTAVE", "BC_AWQG_LTAVE"),
  includeQaQc = FALSE
)

DT::datatable(wq_report_data, rownames = FALSE, filter="top", options = list(pageLength = 5, scrollX=T) )

Aquarius Stations

We can follow a similar workflow for continuous data from Aquarius stations. First look over the Aquarius stations’ metadata.

DT::datatable(metadata$aquarius_stations_list_data, rownames = FALSE, filter="top",
              options = list(pageLength = 5, scrollX=T))


As before, we’ll next look at a specific station more closely using get_aquarius_location_details().

aq_station_of_interest <- 'WQ2'
aq_station_details <- get_aquarius_location_details(aq_station_of_interest)

DT::datatable(aq_station_details, rownames = FALSE, filter="top", options = list(pageLength = 5, scrollX=T))

Finally, we’ll use get_aquarius_report_data() to collect two specific timeseries.

timeseries_of_interest = c(
  "Discharge.Field Visits@WQ2",
  "Water Temp.Daily Water Temperature@WQ2"
)

aq_report_data <- get_aquarius_report_data(
  start_date = "2015-10-24",
  end_date = "2015-11-24",
  timeseries_names = timeseries_of_interest,
  make_nice_names = T
)

DT::datatable(aq_report_data, rownames = FALSE, filter="top", options = list(pageLength = 5, scrollX=T))

Next Steps

There’s a lot more that EnviroData R can do. To get an overview of the available functions, check out the reference page.