Skip to content

Instantly share code, notes, and snippets.

View TonyLadson's full-sized avatar

Tony Ladson TonyLadson

View GitHub Profile
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
@TonyLadson
TonyLadson / Get_tidy_preburst_losses.R
Created March 29, 2020 21:51
Function to get pre-burst and loss information from the data hub. See https://tonyladson.wordpress.com/2020/03/23/tidy-pre-burst-data/
Get_tidy_prebust_losses <- function(lat, lon){
require(RCurl)
require(stringr)
require(tidyverse)
require(glue)
# Functions_____________________________________________________________________________
# Function to get the text file from the data hub for a latitude and longitude
@TonyLadson
TonyLadson / Get_losses.R
Last active March 29, 2020 21:40
Function to return initial and continuing loss from the data hub for a given latitude and longitude
# # Exampe usage
# lat = -33.87
# lon = 151.206
#
# Get_losses(lat = lat, lon = lon)
# $ILs
# [1] 28
#
# $CL
# [1] 1.6
@TonyLadson
TonyLadson / Get_tidy_preburst.R
Last active March 24, 2020 01:00
Function to get preburst data from the data hub and convert it into a tidy format. See https://tonyladson.wordpress.com/2020/03/23/tidy-pre-burst-data/
Get_tidy_prebust <- function(lat, lon){
require(RCurl)
require(stringr)
require(tidyverse)
require(glue)
# Functions_____________________________________________________________________________
# Function to get the text file from the data hub for a latitude and longitude
@TonyLadson
TonyLadson / Get_preburst.R
Last active March 20, 2020 04:51
Function to scrape the data hub and return information on pre-burst rainfall, see https://tonyladson.wordpress.com/2020/03/16/scraping-the-data-hub/
# lat and lon must be latitude and longitude of some point on Australia, latitude must be negative
Get_preburst <- function(percentile = c(50, 10, 25, 75, 90), type = c("depth", "ratio"), lat, lon){
require(tidyverse)
require(stringr)
require(glue)
require(RCurl)
# Check inputs--------------------
@TonyLadson
TonyLadson / WP_treemap.R
Last active September 3, 2019 22:39
Making a treemap for hydrological purposes. See the blog https://tonyladson.wordpress.com/2019/09/02/using-a-treemap-to-show-gauged-areas/
library(treemap)
library(tidyverse)
wp <- tribble(~catchment, ~sub_catchment, ~area,
'Bunyip', 'Gauged', 697,
'Bunyip', 'Ungauged', 479,
'Lang Lang', 'Gauged', 272,
'Lang Lang', 'Ungauged', 151,
# Burst initial loss = storm initial loss - preburst rainfall
# Storm initial loss ------------------------------------------------------
# emprical distribution of initial loss
# From ARR Table Table 5.3.13
# http://book.arr.org.au.s3-website-ap-southeast-2.amazonaws.com
# Data from the ARR data hub for Toomuc Creek
pre_burst <- tribble(~perc, ~depth, ~ ratio,
10,0,0,
25,0,0,
50,1.5, 0.029,
75,13.3, 0.256,
90,38.4, 0.739)
@TonyLadson
TonyLadson / Loss_pdf.R
Last active August 1, 2019 22:29
Calculating an empirical probability density plot for Initial and Continuing Loss. See https://tonyladson.wordpress.com/2019/07/30/the-distribution-of-losses-ii/
library(tidyverse)
library(pracma)
library(here)
loss_std <- structure(list(Percentile = c(100, 90, 80, 70, 60, 50, 40, 30,
20, 10, 0), IL = c(0.14, 0.39, 0.53, 0.68, 0.85, 1, 1.2, 1.4,
1.71, 2.26, 3.19), CL = c(0.15, 0.35, 0.48, 0.61, 0.79, 1, 1.24,
1.5, 1.88, 2.48, 3.85), prob = c(0, 0.1, 0.2, 0.3, 0.4, 0.5,
0.6, 0.7, 0.8, 0.9, 1)), class = c("tbl_df", "tbl", "data.frame"
@TonyLadson
TonyLadson / Loss.R
Last active August 1, 2019 22:30
Distribution of Initial and continuing losses. Gist to support a blog https://tonyladson.wordpress.com/2019/07/23/the-distribution-of-losses/
# Generating initial loss values from the standardised initial losses from ARR
# Book 5
# Chapter 3.6.1
# Table 5.3.13
# The original source of this is Nathan et al. (2003)
# Nathan, R.J., Weinmann, P.E. and Hill, P.I. (2003), Use of a Monte-Carlo Simulation to
# estimate the Expected Probability of large to extreme floods, Proceedings of the 28th
# International Hydrology and Water Resources Symposium, pp: 1105-1112, 10-14 November,
# Wollongong.