Skip to content

Instantly share code, notes, and snippets.

View TonyLadson's full-sized avatar

Tony Ladson TonyLadson

View GitHub Profile
@TonyLadson
TonyLadson / OneHundredYearPoisson.R
Last active November 15, 2015 21:58
Examples: Poission distribution as applied to the 100-year flood. https://tonyladson.wordpress.com/2015/06/29/100-year-flood-poisson-distribution/
dpois(0,1) # prob of zero 100-year floods in 100 years
dpois(0,1) # prob of zero 100-year floods in 100 years
[1] 0.3678794
dpois(1,1) # prob of one 100-year floods in 100 years
[1] 0.3678794
dpois(2,1) # prob of two 100-year floods in 100 years
[1] 0.1839397
# simulation
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){
# 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)
# This script takes the standard download of annual max, min, mean data from
# http://data.water.vic.gov.au/monitoring.htm
# Plots a bar plot with ggplot
library(stringr)
library(dplyr)
library(lubridate)
library(ggplot2)
library(devtools)
library(scales)
# Usage
#
# source_gist('https://gist.github.com/TonyLadson/280fd3ae3e730b3bb370')
# DeltaTable_Kite(g = 0.1, aep = 0.02)
# [1] 2.3425
DeltaTable_Kite <- function(g, aep){
# g = skew
# aep = annual exceedance probability
@TonyLadson
TonyLadson / Routing.R
Last active March 10, 2016 22:55
Runoff Routing based on Mein, R. G., E. M. Laurenson and T. A. McMahon (1974) see https://tonyladson.wordpress.com/2016/03/10/routing-in-rorb/
# Routing
# Based on discussion in
# Mein, R. G., E. M. Laurenson and T. A. McMahon (1974).
# "Simple nonlinear model for flood estimation." Journal of the Hydraulics Division, American Society of Civil Engineers 100(HY11): 1507-1518.
# Time stepping solution - ideas from Section 23.2, p490 of
# Jones, O., Maillardet, R. and Robinson, A. (2014) Introduction to scientific programming and simulation using R.
# CRC Press
BwTheme = theme_bw() +
theme(
panel.background = element_rect(fill="gray98"),
axis.title.x = element_text(colour="grey20", size=20, margin=margin(20,0,0,0)),
axis.text.x = element_text(colour="grey20",size=14),
axis.title.y = element_text(colour="grey20",size=20, margin = margin(0,20,0,0)),
axis.text.y = element_text(colour="grey20",size=14),
legend.title = element_text(colour="grey20",size=12),
plot.margin = unit(c(0.5, 0.5, 1, 0.5), "cm")) # top, right, bottom, left
@TonyLadson
TonyLadson / FindGEVparameters.R
Created April 11, 2016 12:05
Find the GEV parameters used to generate design rainfalls
#
# Interpolating design rainfall intensities
#
library(dplyr)
library(stringr)
library(optimx)
# Assemble data
@TonyLadson
TonyLadson / Routing_DE.R
Last active April 11, 2016 12:07
Solving the routing equation using a differential equation solver. See https://tonyladson.wordpress.com/2016/03/15/routing-in-rorb-ii/
library(deSolve)
# dQ/dt = (I - Q)/(kmQ^(m-1))
# Specify the inflow hydrograph, using a function as discussed at
# https://tonyladson.wordpress.com/2015/07/21/hydrograph-as-a-function/
my.Qmin <- 0
my.Qmax <- 1
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')