-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFig1.R
222 lines (155 loc) · 7.23 KB
/
Fig1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
## ---------------------------------------------------------------------------
##
## Script name: Code to replicate analyses in Falster et al (2024) HESS
##
## Purpose of script: Re-create Figure 1 - observed Murray-Darling Basin precipitation anomalies
##
## Script author: Georgina Falster
##
## Date create/updated: 2024-02-19
##
## Email: georgina.falster@anu.edu.au (institutional) / georgina.falster@gmail.com (permanent)
##
## Citation: https://doi.org/10.5194/egusphere-2023-1398
## ----------------------------------------------------------------------------
##
## Please cite the paper if using or re-purposing this code.
##
## ----------------------------------------------------------------------------
# =============================================================================
# Notes for running this script
# =============================================================================
# This script requires the following inputs:
# 1. annual-total timeseries of observed area-mean Murray-Darling Basin rainfall
# Please edit all filepaths as necessary to where you have these data stored
# =============================================================================
# set display options
# =============================================================================
options(scipen = 10, digits = 4)
# =============================================================================
# load packages
# =============================================================================
library(magrittr)
library(tidyverse)
library(viridis)
# =============================================================================
# read in Murray-Darling Basin area-mean precipitation (from AGCD)
# =============================================================================
# I had to do this in two parts - there may now be a continuous version of AWAP
awap <- read.csv("data/AGCDv1_annual_precip_MDB_1900-2020.csv") %>%
rename(prec = precip) %>%
mutate(year = as.numeric(substr(date, 1, 4))) %>%
select(-date) %>%
filter(year < 2020)
awap1 <- read.csv("data/AGCDv1_annual_precip_MDB_2020-2022.csv") %>%
rename(prec = precip) %>%
mutate(year = as.numeric(substr(date, 1, 4))) %>%
select(-date)
awap <- rbind(awap, awap1)
rm(awap1)
# ---------------------
# anomalies relative to the entire period
# ---------------------
prec.mean <- mean(awap$prec)
awap$prec.anom <- awap$prec-prec.mean
rm(prec.mean)
# =============================================================================
# identify 2S2E droughts
# =============================================================================
awap$drought.2S2E <- NA
rowcount <- 1
while(rowcount <= nrow(awap)) {
# end test
if(rowcount == 123) {
if(awap$drought.2S2E[rowcount-1] == "yes" & awap$prec.anom[rowcount] < 0) {
awap$drought.2S2E[rowcount] <- "yes"
} else {
awap$drought.2S2E[rowcount] <- "no"
}
rowcount = rowcount+1
}
# another end test
if(awap$prec.anom[rowcount] < 0 & awap$prec.anom[rowcount +1] < 0 & rowcount == 122) {
awap$drought.2S2E[rowcount] <- "yes"
awap$drought.2S2E[rowcount+1] <- "yes"
rowcount <- rowcount+1
}
# check for first drought.2S2E year
if(rowcount < nrow(awap)) {
if(awap$prec.anom[rowcount] < 0 & awap$prec.anom[rowcount +1] < 0) {
awap$drought.2S2E[rowcount] <- "yes"
# ok we've started a 2S2E drought: let's see when it finishes
done <- "no"
k <- 1
while(done == "no") {
if(awap$prec.anom[rowcount+k] > 0 & awap$prec.anom[rowcount+1+k] > 0) {
awap$drought.2S2E[rowcount+k] <- "no"
awap$drought.2S2E[rowcount+1+k] <- "no"
done <- "yes"
} else {
awap$drought.2S2E[rowcount+k] <- "yes"
k = k+1
}
if(rowcount+1+k > 123) {
awap$drought.2S2E[rowcount+k] <- "yes"
done <- "yes"
}
}
} else {
awap$drought.2S2E[rowcount] <- "no"
k = 1
}
# so we've identified a drought.2S2E (or found that this isn't the start of one). Let's update the counter and go again
rowcount <- rowcount+k
rm(k)
}
}
# =============================================================================
# Historical droughts (from Helman 2009)
# =============================================================================
# Available from https://silo.tips/download/droughts-in-the-murray-darling-basin-since-european-settlement
# Note: these are multi-year droughts only (from Table 1), with Millennium Drought adjusted to recent 'accepted' values
# only including droughts referred to in the text (Falster et al. 2024 HESS)
hist.droughts <- data.frame(name = c("Federation", "WWII","Millennium", "Tinderbox"),
start = c(1895, 1935, 1997, 2017),
end = c(1903, 1945,2009, 2019))
hist.droughts$middle <- rowMeans(select(hist.droughts, -name))
# adjust Federation Drought so it shows up
hist.droughts$middle[which(hist.droughts$name == "Federation")] <- 1901.5
# =============================================================================
# Plot the results
# =============================================================================
# -------------------------------------------------------------
# some preparations
# -------------------------------------------------------------
awap <- mutate(awap, col_tag = ifelse(prec.anom < 0, "neg", "pos"))
col_vals <- c("neg" = "#8C510A", "pos" = "#01665E")
# -------------------------------------------------------------
# the plot
# -------------------------------------------------------------
prec_plot <- ggplot(data = awap) +
# add windows showing historical droughts
# added 1 so it goes to the end of the year
geom_rect(data = hist.droughts, aes(xmin = start, xmax = end+1, ymin = 0, ymax = Inf), alpha = 0.4, fill = "darkorange3") +
# and the drought names
geom_text(data = hist.droughts, aes(x = middle, y = 185, label = name), angle = 90, hjust = 0, size = 6,
colour = "darkorange4", fontface = "bold") +
# the precip timeseries
geom_col(aes(x = year, y = prec.anom, fill = col_tag), position = position_nudge(x = 0.5)) +
# colours scaling
scale_fill_manual(values = col_vals) +
# show 2S2E droughts s windows on the bottom
geom_rect(data = filter(awap, drought.2S2E == "yes"), aes(xmin = year, xmax = year+1, ymin = -Inf, ymax = 0), alpha = 0.4, fill = "grey") +
# sort out x axis
scale_x_continuous(breaks = seq(1900, 2022, 10)) +
scale_y_continuous(limits = c(-250, 350), breaks = seq(-250, 300, 50)) +
coord_cartesian(xlim = c(1900, 2022), expand = FALSE) +
# labels etc
labs(x = "Year (CE)", y = "Annual precipitation anomaly (mm)\nover the Murray-Darling Basin") +
guides(fill = "none") +
# and finally themes
theme_bw() +
theme(axis.text.y = element_text(size = 10),
axis.text.x = element_text(size = 12),
axis.title = element_text(size = 12),
)