Last active
August 22, 2016 06:57
-
-
Save TonyLadson/708368bdb411f04a8af7bea1b4b04bdd to your computer and use it in GitHub Desktop.
Function to plot DO as a function of temperature and overlay contours of percentage saturation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my_df - data frame with DO and temperature data | |
# DO - (quoted) name of column of DO values (mg/L) e.g. 'DO' | |
# temp - (quoted) name of column of temperature values (degrees Celcius) e.g. 'temp' | |
# outputs a graph | |
CheckPlot_DO <- function(my_df, DO_col, temp_col) { | |
DO <- my_df[[DO_col]] | |
temp <- my_df[[temp_col]] | |
Calc_DOsat100 = function(temp){ | |
# temp = temperature in degrees C | |
# relationship between temperature and dissolved oxygen as defined by the APHA | |
# American Public Health Association (1992) | |
# Standard methods for the examination of water and wastewater. 18th ed. Washington DC. | |
# Required constants | |
C1 = 139.34411 | |
C2 = 1.575701e+5 | |
C3 = 6.642308e+7 | |
C4 = 1.243800e+10 | |
C5 = 8.621949e+11 | |
Ta =temp + 273.15 | |
exp(-C1 + C2/Ta - C3/(Ta^2) + C4/(Ta^3) - C5/(Ta^4)) | |
} | |
temp_seq <- seq(min(temp, na.rm = TRUE), max(temp, na.rm = TRUE), length.out = 101) | |
DO_100 <- Calc_DOsat100(temp_seq) | |
plot(temp, DO, xlab = 'Temperature', ylab = 'DO') | |
lines(temp_seq, DO_100, col = 'blue', lty = 2, lwd = 2) | |
lines(temp_seq, 2*DO_100, col = 'blue', lty = 2, lwd = 2) | |
lines(temp_seq, 3*DO_100, col = 'blue', lty = 2, lwd = 2) | |
text(x = max(temp_seq), y = DO_100[length(temp_seq)], '100%', col = 'blue', pos = 3) | |
text(x = max(temp_seq), y = 2*DO_100[length(temp_seq)], '200%', col = 'blue', pos = 3) | |
text(x = max(temp_seq), y = 3*DO_100[length(temp_seq)], '300%', col = 'blue', pos = 3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment