-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCross-fan profiles.R
213 lines (191 loc) · 7.04 KB
/
Cross-fan profiles.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
# Script to plot cross-fan profiles at 0.25, 0.5, 1 and 1.5 m downfan
# Compares aggrading and degrading conditions
# Anya Leenman
# 8 July 2021
#---------------------------------------
# Housekeeping
rm(list = ls())
drive <- "E"
run <- 5
repe <- 1
radii <- c(0.25, 0.5, 1, 1.5) # radii at which to extract profile
library(raster)
library(dplyr)
library(lubridate)
setwd(paste0(drive, "://Experiments/Processing/Run", run, "/Run", run, "_rep", repe,
"/_1min_intervals"))
DEM_list <- list.files("./summary_data/DEM_7mm_smoothed", pattern = ".tif")
t_list <- lapply(DEM_list, FUN = substring, 1, 4)
t_df <- data.frame(tvec = as.numeric(unlist(t_list))) %>%
mutate(t_h = ifelse((tvec %% 100) == 0, tvec / 100, floor (tvec / 100))) %>% # get hour
mutate(t_m = ifelse((tvec %% 100) == 0, 0, tvec - t_h * 100)) %>% # get minute
mutate(time = paste(t_h, t_m, sep = ":")) %>% # concatenate to hh:mm format
mutate(time = hm(time)) %>% # convert to time format using lubridate
mutate(t_sec = period_to_seconds(time)) %>% # Convert to number of seconds since start
mutate(t_min = t_sec / 60) %>% # time in minutes
mutate(t_hr = t_min / 60) %>% # time in hours
dplyr::select(-time, -t_h, -t_m) # remove unnecessary columns
#filter(complete.cases(.)) %>% # get rid of rows with NA.
# divide into high-low feed cycles (coded so that high feed is START):
if(run <= 7){
t_df <- mutate(t_df, cycle = ceiling((t_min - 715) / 10)) %>% # assign cycle
mutate(time_in_cycle = t_min - 705 - 10 * cycle) # assign minute in cycle
} else if(run == 8){
t_df <- mutate(t_df, cycle = ceiling((t_min - 710) / 20)) %>% # assign cycle
mutate(time_in_cycle = t_min - 690 - 20 * cycle) # assign minute in cycle
} else if(run == 9) {
t_df <- mutate(t_df, cycle = ceiling((t_min - 700) / 40)) %>% # assign cycle
mutate(time_in_cycle = t_min - 660 - 40 * cycle) # assign minute in cycle
}
# get cycle length
cycle_len = max(unique(t_df$time_in_cycle))
# list of timesteps at end of low-feed (degraded state) or high-feed (aggraded state)
deg_steps <- #timesteps at end of low-feed, when fan degraded
filter(t_df, time_in_cycle == cycle_len)
agg_steps <- # timesteps at end of high-feed, when fan aggraded.
filter(t_df, time_in_cycle == cycle_len/2)
# filter to every 80 minutes (data too close in time otherwise)
if(run <= 7){
deg_steps <-
filter(deg_steps, cycle %% 8 == 0) # get every 8th cycle
agg_steps <-
filter(agg_steps, cycle %% 8 == 0) # get every 8th cycle
} else if(run == 8){
deg_steps <-
filter(deg_steps, cycle %% 4 == 0) # get every 4th cycle
agg_steps <-
filter(agg_steps, cycle %% 4 == 0) # get every 4th cycle
} else if(run == 9){
deg_steps <-
filter(deg_steps, cycle %% 2 == 0) # get every 2nd cycle
agg_steps <-
filter(agg_steps, cycle %% 2 == 0) # get every 2nd cycle
}
# set up profile lines along which to extract DEM
prof_list <- list()
for(j in 1:length(radii)){
rad <- radii[j]
x_line <- seq(0, rad, 0.0001)
y_line <- sqrt(rad ^ 2 - x_line ^ 2)
cds <- cbind(x_line, y_line)
l <- spLines(cds)
# lines(l)
l_length <- 1/4 * 2 * pi * rad
# extract pts at 1 centimetre intervals (adjust if needed)
l_pts <- rgeos::gInterpolate(l, d = seq(0, l_length, 0.01), normalized = FALSE)
prof_list[[j]] <- l_pts
# points(prof_list[[j]])
}
# set up blank plots
if(run >=7){
png(
filename = paste0(
drive, ":/Experiments/writing/3_feed_duration/figures/arc-DEM-profiles_run",
run, ".png"),
units = "in",
width = 6,
height = 4,
res = 300,
type = "cairo-png")
} else if(run <7){
png(
filename = paste0(
drive, ":/Experiments/writing/2_floods/Figs/arc-DEM-profiles_run",
run, ".png"),
units = "in",
width = 6,
height = 4,
res = 300,
type = "cairo-png")
}
pars <- c('plt','usr')
par(mfrow = c(2, 4), # 2*4 grid
mai = rep(0.2, 4),
oma = c(2,2.5,0,0))
ylims = c(-0.23, -0.1)
axis_lims = data.frame(x1 = rep(0, 4), # get axis lengths right
x2 = c(0.4, 0.8, 1.6, 2.4),
y1 = rep(ylims[1], 4),
y2 = rep(ylims[2], 4))
# upper row
plot(c(axis_lims$x1[1], axis_lims$x2[1]),
c(axis_lims$y1[1], axis_lims$y2[1]),
type = "n",
xlab = "", ylab = "")
par1 <- c(list(mfg=c(1,1,2,4)), par(pars))
plot(c(axis_lims$x1[2], axis_lims$x2[2]),
c(axis_lims$y1[2], axis_lims$y2[2]),
type = "n",
xlab = "", ylab = "")
par2 <- c(list(mfg=c(1,2,2,4)), par(pars))
plot(c(axis_lims$x1[3], axis_lims$x2[3]),
c(axis_lims$y1[3], axis_lims$y2[3]),
type = "n",
xlab = "", ylab = "")
par3 <- c(list(mfg=c(1,3,2,4)), par(pars))
plot(c(axis_lims$x1[4], axis_lims$x2[4]),
c(axis_lims$y1[4], axis_lims$y2[4]),
type = "n",
xlab = "", ylab = "")
par4 <- c(list(mfg=c(1,4,2,4)), par(pars))
# rep for lower row
plot(c(axis_lims$x1[1], axis_lims$x2[1]),
c(axis_lims$y1[1], axis_lims$y2[1]),
type = "n",
xlab = "", ylab = "")
par5 <- c(list(mfg=c(2,1,2,4)), par(pars))
plot(c(axis_lims$x1[2], axis_lims$x2[2]),
c(axis_lims$y1[2], axis_lims$y2[2]),
type = "n",
xlab = "", ylab = "")
par6 <- c(list(mfg=c(2,2,2,4)), par(pars))
plot(c(axis_lims$x1[3], axis_lims$x2[3]),
c(axis_lims$y1[3], axis_lims$y2[3]),
type = "n",
xlab = "", ylab = "")
par7 <- c(list(mfg=c(2,3,2,4)), par(pars))
plot(c(axis_lims$x1[4], axis_lims$x2[4]),
c(axis_lims$y1[4], axis_lims$y2[4]),
type = "n",
xlab = "", ylab = "")
par8 <- c(list(mfg=c(2,4,2,4)), par(pars))
mtext("Cross-fan distance (m)", side = 1, line = 1, outer = T)
mtext("Elevation (m) relative to top of walls", side = 2, line = 1, outer = T)
par_list <- list(
par1, par2, par3, par4, par5, par6, par7, par8
)
# set up colours for lines
colz <- gray.colors(nrow(deg_steps), start = 0, end = 0.8,
gamma = 2.2, rev = T)
# Extract arc profiles from DEM at specified radii
# first for degraded state (end of low-feed)
# for (i in 50:60){ # debug version
for (i in 1:nrow(deg_steps)){ # real version
t_step <- deg_steps$tvec[i]
print(t_step)
# import chosen DEM
DEM <- raster(paste0("./summary_data/DEM_7mm_smoothed/", t_step, ".tif") )
# extract profiles from DEM
for(k in 1:length(prof_list)){
prof <- extract(DEM, prof_list[[k]])
xcoord <- seq(0, length(prof)/100, 0.01)[1:length(prof)]
par(par_list[[k]])
lines(xcoord, prof, col = colz[i])
}
}
# Extract arc profiles from DEM at specified radii
# Rep for aggraded state
for (i in 1:nrow(agg_steps)){
t_step <- agg_steps$tvec[i]
print(t_step)
# import chosen DEM
DEM <- raster(paste0("./summary_data/DEM_7mm_smoothed/", t_step, ".tif") )
# extract profiles from DEM
for(k in 1:length(prof_list)){
prof <- extract(DEM, prof_list[[k]])
xcoord <- seq(0, length(prof)/100, 0.01)[1:length(prof)]
par(par_list[[k+4]])
lines(xcoord, prof, col = colz[i])
}
}
dev.off()