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
# see https://tonyladson.wordpress.com/2015/02/17/quality-codes-in-hydrologic-data/ | |
library(treemap) | |
library(RColorBrewer) | |
library(ggplot2) | |
library(grid) | |
library(lubridate) | |
# Generate some data |
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
# Usage | |
# LeadingNA(x) | |
# | |
# x is a data frame | |
# Value | |
# A data frame, with two rows, leading NAs and trailing NAs | |
LeadingNA <- function(x){ | |
num.col <- ncol(x) | |
trailing.na <- rep(0, times = num.col) |
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
# Usage | |
# MissingMap(df, date.column, var.column) | |
# df = data.frame that contains a column of dates and column of variables that may have missing values | |
# date.column = quoted name of the column cotaining dates | |
# var.column = quoted name of the column containing the variable | |
# | |
# Produces a tile plot showing here missing values occur in the sequence of dates | |
# https://tonyladson.wordpress.com/2014/12/21/mapping-missing-data/ | |
MissingMap <- function(df, date.column, var.column){ |
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 return delta as used to estimate | |
# confidence intervals for flood frequency analysis | |
# Usage | |
# Delta(g, aep) | |
# | |
# g = skewness | |
# aep = Annual exceedance probability | |
# |
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
########################################################################################################################## | |
# | |
# Delta values | |
# | |
# tony.ladson at gmail.com | |
# 11 March 2015 | |
# | |
# Used to determine confidence intervals for the Log Pearson III distribution | |
# The table of delta values is taken from Table 2.4, Book IV, Section 2 of Australian Rainfall and Runoff third edition. | |
# Confidence interval calculations are based on |
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
isGaugeNum <- function(x) { | |
# returns true if value is missing, or a gauge number i.e. 6 digits followed by a capital letter | |
# otherwise returns false | |
if(!is.character(x)) return(FALSE) | |
if(is.na(x)) return(TRUE) | |
if(str_count(x) != 7) return(FALSE) | |
str_detect(x, "^[0-9]{6}[A-Z]{1}") # 6 digits followed by a capital letter | |
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
isNewSiteNum <- function(x) { | |
# returns true if value is missing, or a site number i.e. 5 capitals follows by 4 digits | |
# otherwise returns false | |
if(is.na(x)) return(TRUE) | |
if(!is.character(x)) return(FALSE) | |
if(str_count(x) != 9) return(FALSE) | |
str_detect(x, "^[A-Z]{5}[:digit:]{4}") # 5 capitals followed by 4 digits |
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
dbinom(0,100,0.01) # zero 1% floods in 100 years | |
dbinom(1,100,0.01) # one 1% floods in 100 years | |
dbinom(2,100,0.01) # two 1% floods in 100 years | |
dbinom(3,100,0.01) # three 1% floods in 100 years | |
dbinom(4,100,0.01) # four 1% floods in 100 years | |
dbinom(5,100,0.01) # five 1% floods in 100 years | |
# at least 1 1% flood in 100 years | |
1 - pbinom(0,100, 0.01) |
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(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. |
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
# 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 |
OlderNewer