Skip to content

Instantly share code, notes, and snippets.

View TonyLadson's full-sized avatar

Tony Ladson TonyLadson

View GitHub Profile
# Geometric Distribution of 1% floods
# probability of 4 or fewer safe years
pgeom(4, 0.01)
# [1] 0.04900995
# probability of exactly 4 safe years and then a flood in the 5th
dgeom(4, 0.01)
#[1] 0.00960596
Hydro <- function(tt, t.peak = 1, Qmin = 1, Qmax = 10, beta = 5) {
Qmin + (Qmax - Qmin)*( (tt/t.peak) * (exp(1 - tt/t.peak)))^beta
}
tt.seq <- seq(0,4,0.01)
op <- par(oma = c(1, 2, 0, 0))
library(ggplot)
library(grid)
library(devtools)
library(dplyr)
library(lubridate)
source_gist('cc60bbb3cbadf0e72619') # ggplot theme
# Data is stored in a data frame with the date, flow and quality code
# You'll need to provide your own data for this to work.
@TonyLadson
TonyLadson / FlikePlot.R
Last active July 31, 2018 06:17
Take results from Flike and produce a nice looking frequency plot (see https://tonyladson.wordpress.com/2015/10/20/better-frequency-plots-from-web-based-flike/)
##########################################################
#
# Plotting Flike Output
# see https://tonyladson.wordpress.com/2015/10/20/better-frequency-plots-from-web-based-flike/
#
############################################################
library(stringr)
require(ggplot2)
require(zoo)
require(dplyr)
# MakeNames_Hydstra
# Hydstra files have names spread across 4 rows. This gist, turns the data into a single string
MakeNames_Hydstra <- function(Hydstra.csv){
@TonyLadson
TonyLadson / FDC.R
Created November 16, 2015 00:55
Plot a flow duration curve
FDC <- function(Q, xnormal=TRUE, xlab='%time flow equalled or exceeded',
ylab='flow',Qreturn=FALSE, plotFlow=FALSE, add=FALSE, alpha=0.5, ...) {
# Q - flow data (vector of flow values)
# xnormal - logical value to determine if the percentiles should be plotted in a normal (probit) scale
# Qreturn - logical value indicating if quantiles should be returned
# plotFlow - logical value indicating if a time series of flow should be overplotted on flow duration curve
# add - should fdc be added to an existing plot?
# alpha - transparency value for overplotting of flow time series
library(repmis)
library(dplyr)
library(ggplot2)
library(grid)
library(scales)
# download sample files from dropbox
wq <- repmis::source_data('https://dl.dropboxusercontent.com/u/10963448/wq.csv')
flow <- repmis::source_data('https://dl.dropboxusercontent.com/u/10963448/flow.csv')
# Confidence intervals for the mean for non-normal data
# See https://tonyladson.wordpress.com/2016/01/11/plotting-water-quality-samples-on-a-hydrograph/
# Modified Cox function for calculating confidence intervals for the mean
# Based on Olsson, 2005
# http://www.amstat.org/publications/jse/v13n1/olsson.html
# x is a set of log-normal data
# See https://tonyladson.wordpress.com/2016/02/08/envelop-curve-for-record-australian-rainfall/
# remove(list = objects())
library(XML)
library(dplyr)
library(MASS)
library(xtable)
library(quantreg)
library(dplyr)
library(lubridate)
library(stringr)
library(readr)
library(ggplot2)
library(devtools)
library(splines)