knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(kableExtra)
Install odeqALcrit from github by running this code:
devtools::install_github('TravisPritchardODEQ/odeqIRtools')
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.
This section illustrates a sample workflow for calculating aluminum criteria.
First, lets load some needed packages:
library(odeqALcrit) 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
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 it was the easiest to implement and we'll discard the unneeded data later.
ancillary_data<- odeqALcrit::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 <- odeqALcrit::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 <- odeqALcrit::AL_crit_calculator(al_data_joined)
kbl(al_criteria) %>% kable_paper() %>% scroll_box(width = "700px", height = "500px")
And if we wanted the extra information provided in EPA's criteria calculation:
al_criteria_extra <- odeqALcrit::AL_crit_calculator(al_data_joined, verbose = TRUE)
kbl(al_criteria_extra) %>% kable_paper() %>% scroll_box(width = "700px", height = "500px")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.