knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(kableExtra)
Install deqalcrit from github by running this code:
devtools::install_github('TravisPritchardODEQ/deqalcrit')
Only Oregon DEQ users with properly setup access to use the AWQMSdata backage will be able to use all features. Other users will be able to use the Al_crit_calculator(), Al_default_DOC(), and Al_default_criteria() functions, as those do not need access to AWQMS.
| Function | Purpose | |--------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------| | al_anc_query(al_df) | Queries AWQMS to get ancillary data needed to calculate Al criteria. | | al_combine_ancillary(al_df, ancillary_df) | Combines Al data and output from al_get_ancillary in preparation to calculate criteria. | | al_crit_calculator(df, ph_col = "pH", hardness_col = "Hardness", DOC_col = "DOC", lat_col = "Lat_DD", long_col = "Long_DD", verbose = FALSE) | Calculates aluminum criteria based on EPA's 2018 national recommended freshwater aquatic life criteria for aluminum. | | al_default_DOC(lat, long) | Looks up default DOC values used in calculating Al criteria. | | al_default_criteria(lat, long, type) | Looks up default acute or chronic Al criteria values. |
This section illustrates a sample workflow for calculating aluminum criteria.
First, lets load some needed packages:
library(deqalcrit) library(AWQMSdata)
Next, get some Al data out of AWQMS. In this example, we are going to use data from the Surface Water Ambient Monitoring program at station 10917-ORDEQ, which is on the Pudding River. We will use the AWQMSdata package to query Oregon's AWQMS database from the backend. To install and setup this package, see https://github.com/TravisPritchardODEQ/AWQMSdata
al_data_AWQMS <- AWQMSdata::AWQMS_Data(char = "Aluminum", media = 'Water', project = 'Surface Water Ambient Monitoring', station = '10917-ORDEQ')
This dataframe is very wide, so for illustration purposes, let's get rid of some columns we do not need. Columns that need to be present for the calculator to work are:
MLocID,
Lat_DD,
Long_DD,
SampleStartDate,
SampleStartTime,
SampleMedia
SampleSubmedia
If these columns don't exist, the ancillary data joins won't work.
al_data <- al_data_AWQMS %>% dplyr::select(MLocID, AU_ID, Lat_DD, Long_DD, SampleStartDate, SampleStartTime, SampleMedia, SampleSubmedia, Char_Name, Char_Name, Sample_Fraction, Result_Numeric,Result_Operator, Result_Unit )
That gets us:
kbl(al_data) %>% kable_paper() %>% scroll_box(width = "700px", height = "500px")
Next, we need to get all the ancillary data. The al_get_ancillary() function will query AWQMS and fetch all ancillary data needed to determine the criteria. It is a wrapper around the AWQMS_Data() function that queries the ancillary parameters from monitoring locations in the aluminum dataset. The date range for the query is the min/max date of the entire dataset. This supplies much more data than needed, however, it was the easiest to implement and the code will discard unneeded data later.
ancillary_data<- deqalcrit::al_anc_query(al_data)
The parameters that are queried are:
cat(paste('-', al_ancillary_params), sep = '\n')
Now, we have to run some calculations on these values to get the final DOC, pH, and Hardness values. And then join them to the Aluminum dataset. al_combine_ancillary() will perform the calculations identified in the implementation document and then perform the join. The calculations are a bit complex, but here is what is going on:
al_data_joined <- deqalcrit::al_combine_ancillary(al_df = al_data, ancillary_df = ancillary_data)
That gets us:
kbl(al_data_joined) %>% kable_paper() %>% scroll_box(width = "700px", height = "500px")
At this point, calculating the criteria is as easy as:
al_criteria <- deqalcrit::al_crit_calculator(al_data_joined)
kbl(al_criteria) %>% kable_paper() %>% scroll_box(width = "700px", height = "500px")
If the aluminum result is missing a value for DOC, pH, or hardness; it will lookup the default criteria values using the lat/long and querying the GIS web service at https://arcgis.deq.state.or.us/arcgis/rest/services/WQ/OR_Ecoregions_Aluminum/MapServer
And if we wanted the extra information provided in EPA's criteria calculation:
al_criteria_extra <- deqalcrit::al_crit_calculator(al_data_joined, verbose = TRUE)
kbl(al_criteria_extra) %>% kable_paper() %>% scroll_box(width = "700px", height = "500px")
These functions use DEQ's map services to lookup default DOC and criteria values. These functions send lat/long information to the map server and returns default values based on geographic location.
deqalcrit::al_default_DOC(45.23366, -122.7502) deqalcrit::al_default_criteria(45.23366, -122.7502, type = "Chronic") deqalcrit::al_default_criteria(45.23366, -122.7502, type = "Acute") deqalcrit::al_default_criteria(45.23366, -122.7502, type = "Ecoregion")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.