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
########################################################################################### | |
# | |
# Fitting non-linear models in R | |
# See tonyladson | |
# | |
# 5 June 2016 | |
############################################################################################### | |
# | |
# Example data come from Figure 5 from Ian Cordery's thesis | |
# Also Figure 3 from Cordery, 1970 |
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
# | |
# API - Antecedent Precipitation Index | |
# | |
# | |
# | |
library(stringr) | |
library(readr) | |
library(dplyr) | |
library(lubridate) |
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
library(RCurl) | |
library(jsonlite) | |
library(stringr) | |
library(dplyr) | |
library(ggplot2) | |
rffe.data <- postForm("http://rffe.arr.org.au/", | |
catchment_name = "test1", |
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
library(stringr) | |
library(readr) | |
library(dplyr) | |
library(lubridate) | |
library(ggplot2) | |
library(scales) | |
library(treemap) | |
#__________________________________________________________________________________________ |
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
# Function to calculate 100% saturated dissolved oxygen in mg/L as a function of temperature in degrees Celcius | |
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 |
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
# format_out either 'deg' - decimal degrees, or 'dms' - deg:min:sec | |
UTM2deg <- function(easting, northing, zone, format_out = c('deg', 'dms')){ | |
format_out <- match.arg(format_out) | |
# Helper function to convert from decimal dms to dd:mm:ss | |
Deg2dms <- function(x){ | |
dd <- trunc(x) | |
mm <- trunc(60*(x - dd)) |
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
# x is a dataframe | |
Fix_names <- function(x){ | |
my.names <- make.names(names(x)) | |
my.names <- str_to_lower(my.names) | |
# change multiple consecutive dots to one dot, delete leading and trailing dots | |
my.names <- str_replace_all(my.names, c("[.]+" = "\\.", "[.]$" = "", "^[.]" = "")) | |
names(x) <- my.names | |
x |
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
# Function to calculate 100% saturated dissolved oxygen in water in mg/L as a function of temperature in degrees Celcius | |
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 |
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
# Figure 1 | |
# DO - date of sample | |
WQ %>% | |
ggplot(aes(x = date, y = do.mg.l)) + geom_point() + | |
labs(y = 'DO (mg/L)', x = 'Date') + | |
theme_grey(base_size = 16) | |
# Figure 2 | |
# DO - temperature |
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
# Convert from 'HH:MM:SS' to fractions of a day | |
# This also works with HH.HHHH | |
# and is vectorised | |
Time_convert <- function(x){ | |
f <- function(x,y){ | |
as.numeric(x)/60 + as.numeric(y) | |
} | |
split_time <- str_split(x, ':') |