-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKwireplot.R
130 lines (117 loc) · 3.31 KB
/
Kwireplot.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
################################
## Wireplot for Q, K, and tau
################################
library(tidyverse)
library(ggplot2)
library(lattice)
library(latticeExtra)
library(RColorBrewer)
## Plot setup
# clrs <- colorRampPalette(brewer.pal(9, "YlOrRd"))
# trellis.par.set("axis.line", list(col = NA, lty = 1, lwd = 1))
# theme.novpadding <- list(
# layout.heights = list(top.padding = 0, bottom.padding = 0),
# layout.widths = list(left.padding = 0, right.padding = 0, zlab.axis.padding = 2)
# )
#
# ## Minimum threshold of what is considered a flood
# Qmin <- 40000
# ## Half saturation constant
# a <- 3000
# ## Rate that K returns to pre-disturbance level
# g <- 0.1
#
# ## Maximum flood size to run model to
# Qmax = 100000
#
# ## Timesteps to run model out to - days
# t = 55
#
#
#
# dfK <- data.frame(Q = seq(0, Qmax, by = 200))
# for(i in 1:length(dfK$Q)){
# if (dfK$Q[i] < Qmin) {
# dfK$Q[i] <- 0
# } else {
# dfK$Q[i] <- (dfK$Q[i] - Qmin)/(a + dfK$Q[i]- Qmin)
# }}
#
# KQT <- data.frame(Q = numeric(((Qmax/200) + 1) * (t + 1)))
# ## Filling in Q
# KQT$Q <- rep(seq(0, Qmax, by =200), each = t + 1)
#
# for(i in 1:length(KQT$Q)){
# if (KQT$Q[i] < Qmin) {
# KQT$Qf[i] <- 0
# } else {
# KQT$Qf[i] <- (KQT$Q[i] - Qmin)/(a + KQT$Q[i]- Qmin)
# }}
#
#
# for (i in 1:length(KQT$Q)){
# # Calculate K arrying capacity immediately following the disturbance
# KQT$K0[i] <- 10000 + ((40000-10000)*KQT$Qf[i])
# }
#
# KQT$t <- rep(seq(0, t), (Qmax/200) + 1)
#
# for (i in 1:length(KQT$Q)){
# KQT$K[i] <- 10000 + (KQT$K0[i] - 10000) * exp(-g * KQT$t[i])}
#
#
#
# z_at <- c(10000 , 20000 , 30000, 40000)
# z_labs <- c("1e+4", "2e+4", "3e+4", "4e+4")
#
# wireframe(K ~ t + Q, data = KQT, # distance =c(2, 5, 8)
# aspect = c(1, .4),
# drape = TRUE,
# shade = F,
# colorkey = FALSE,
# col = alpha('#ffeda0', 0.08),
# scales = list(arrows = FALSE, col = 'black', z = list(at = z_at, lab = z_labs), distance = 1.5),
# screen = list(z = -40, x = -70),
# #panel.3d.wireframe = panel.3d.contour, # can't use because Rtools is deprecated
# #par.settings = theme.novpadding,
# col.regions = clrs(1000),
# main = 'Baetis spp. K')
#
#
#
#
# axis = list(side=2, at=c(0, 1e+4, 1.5e+4, 2e+4, 2.5e+4, 3e+4, 3.5e+4))
#
## Minimum threshold of what is considered a flood
Qmin <- 0.25
## Half saturation constant
a <- 0.01
## Rate that K returns to pre-disturbance level
g <- 0.1
## Maximum flood size to run model to
Qmax = 2
## Timesteps to run model out to - days
t = 55
dfK <- data.frame(Q = seq(0, Qmax, by = 0.002))
for(i in 1:length(dfK$Q)){
if (dfK$Q[i] < Qmin) {
dfK$Q[i] <- 0
} else {
dfK$Q[i] <- (dfK$Q[i] - Qmin)/(a + dfK$Q[i]- Qmin)
}}
KQT <- data.frame(Q = numeric(((Qmax/0.002) + 1) * (t + 1)))
## Filling in Q
KQT$Q <- rep(seq(0, Qmax, by =0.002), each = t + 1)
for(i in 1:length(KQT$Q)){
if (KQT$Q[i] < Qmin) {
KQT$Qf[i] <- 0
} else {
KQT$Qf[i] <- (KQT$Q[i] - Qmin)/(a + KQT$Q[i]- Qmin)
}}
for (i in 1:length(KQT$Q)){
# Calculate K arrying capacity immediately following the disturbance
KQT$K0[i] <- 10000 + ((40000-10000)*KQT$Qf[i])
}
KQT$t <- rep(seq(0, t), (Qmax/0.002) + 1)
for (i in 1:length(KQT$Q)){
KQT$K[i] <- 10000 + (KQT$K0[i] - 10000) * exp(-g * KQT$t[i])}