Skip to content

Instantly share code, notes, and snippets.

Avatar

Tony Ladson TonyLadson

View GitHub Profile
View gist:286077221cc07022a77aa74d0a6c211c
library(tidyverse)
library(deming)
# Functions ---------------------------------------------------------------
# given a point (x1, y1) and a line defined by a slope m and intercept c1
# function to return the point x on the line where a line drawn perpendicular to x1, y1
# will intercept the line
View Flood_sampling_distribution.R
library(tidyverse)
#pbinom(q, size, prob, lower.tail = TRUE, log.p = FALSE)
# Probability of 1, 1% flood in 100 years
dbinom(1, size = 100, prob = 0.01, log = FALSE)
choose(100,1) *0.01^1*0.99^99
View Issues_column_graph.R
library(tidyverse)
issues <- tribble(~issue, ~pc,
'Inflows', 6,
'Demand changes', 6,
'System operation', 18,
'Equity of water sharing arrangements', 10,
'State entitlements and policies', 10,
'Environmental water', 11,
'Reliability of different licences', 4,
'Miscellaneous', 4,
View ARF_poly_interp.R
# Smooth interpolation between long and short duration ARFs using a cubic.
library(tidyverse)
library(pracma)
devtools::source_url("https://gist.githubusercontent.com/TonyLadson/fc870cf7ebfe39ea3d1a812bcc53c8fb/raw/d8112631a92a32be749cabe334a22931c035711e/ARF2019.R?raw=TRUE")
View ARF_map.R
library(tidyverse)
xdf <- tribble(~area_min, ~area_max, ~dur_min, ~dur_max, ~type,
10, 1000, 0, 12, 'short',
10, 30000, 24, 168, 'long',
10, 30000, 12, 24, 'interpolation',
0, 1, 0, 168, 'ARF = 1',
1, 10, 0, 12, 'Interp3',
1, 10, 12, 24, 'Interp2',
1, 10, 24, 168, 'Interp1')
@TonyLadson
TonyLadson / ARF_interp.R
Created May 12, 2020
Code to reproduce the figures in the blog: ARR2019 – Areal Reduction Factors: interpolating between short and long duration ARFs
View ARF_interp.R
# Load the functions we need
devtools::source_url("https://gist.githubusercontent.com/TonyLadson/fc870cf7ebfe39ea3d1a812bcc53c8fb/raw/d8112631a92a32be749cabe334a22931c035711e/ARF2019.R?raw=TRUE")
#source(file.path('ARR2019_ARF', "ARF_2019.R"))
#source(file.path('ARR2019_ARF', "ARF_tests.R")) # Check that we pass tests
# Functions and constants ------------------------------------------------------
View ARF_sd.R
library(tidyverse)
library(optimx)
devtools::source_url("https://gist.githubusercontent.com/TonyLadson/fc870cf7ebfe39ea3d1a812bcc53c8fb/raw/d8112631a92a32be749cabe334a22931c035711e/ARF2019.R?raw=TRUE")
#source(file.path('ARR2019_ARF', "ARF_2019.R"))
#source(file.path('ARR2019_ARF', "ARF_tests.R")) # Check that we pass tests
View ARF_edge_cases.R
library(tidyverse)
devtools::source_url("https://gist.githubusercontent.com/TonyLadson/fc870cf7ebfe39ea3d1a812bcc53c8fb/raw/d8112631a92a32be749cabe334a22931c035711e/ARF2019.R?raw=TRUE")
#source(file.path('ARR2019_ARF', "ARF_2019.R"))
#source(file.path('ARR2019_ARF', "ARF_tests.R"))
# Functions and data ------------------------------------------------------
@TonyLadson
TonyLadson / ARF2019.R
Created Apr 13, 2020
Function to calculate The Australian Rainfall and Runoff 2019 Areal Reduction Factors see https://tonyladson.wordpress.com/2020/04/05/arr2019-areal-reduction-factors/
View ARF2019.R
library(stringr)
library(testthat)
region_names <-
c("East Coast North", "Semi-arid Inland QLD", "Tasmania", "SW WA",
"Central NSW", "SE Coast", "Southern Semi-arid", "Southern Temperate",
"Northern Coastal", "Inland Arid")
params <-
structure(list(`East Coast North` = c(0.327, 0.241, 0.448, 0.36, 0.00096, 0.48, -0.21, 0.012, -0.0013),
@TonyLadson
TonyLadson / 2020-03-29_sane-legend.R
Created Apr 11, 2020 — forked from jennybc/2020-03-29_sane-legend.R
Make the legend order = data order, with forcats::fct_reorder2()
View 2020-03-29_sane-legend.R
library(tidyverse)
library(patchwork)
dat_wide <- tibble(
x = 1:3,
top = c(4.5, 4, 5.5),
middle = c(4, 4.75, 5),
bottom = c(3.5, 3.75, 4.5)
)