Skip to content

Commit 7a6d75e

Browse files
author
reedmaxwell
authored
Update Waterfall_4panel_Plot.R
1 parent ae7a7f0 commit 7a6d75e

File tree

1 file changed

+164
-164
lines changed

1 file changed

+164
-164
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,167 @@
1-
### Waterfall and ET Hillslope plots
2-
### LEC, RMM 25-May-18, (edited 7-Sep-18)
3-
4-
##This script loads in EcoSLIM output and makes Figures 4 and 5 from Maxwell et al Ecohydrology 2018
5-
6-
library("MASS")
1+
### Waterfall and ET Hillslope plots
2+
### LEC, RMM 25-May-18, (edited 7-Sep-18)
3+
4+
##This script loads in EcoSLIM output and makes Figures 4 and 5 from Maxwell et al Ecohydrology 2018
5+
6+
library("MASS")
77
library(fields)
88
rm(list=ls())
9-
10-
## you may need to edit the working directory
11-
setwd('~/EcoSLIM/Examples/Hillslope_Simulations/paper_cases/R_scripts')
9+
10+
## you may need to edit the working directory uncomment and adjust as needed
11+
##setwd('~/EcoSLIM/Examples/Hillslope_Simulations/paper_cases/R_scripts')
1212
source("./slicedens.R")
13-
14-
months=c("OCT","NOV","DEC","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP")
15-
16-
## make waterfall four panel (Fig 4)
17-
fout = 'Figure4_waterfall_4-panel.pdf'
18-
pdf(file=fout,width=9, height=9)
19-
20-
par(mfrow=c(2,2))
21-
22-
#Read EcoSlim output files and put in independent matrices for plotting
23-
## load trees with ER forcing
24-
fin='./ER_hillslope_trees/SLIM_hillslope_ER_trees_exited_particles.bin'
25-
length=file.info(fin)$size/8
26-
ncol=8
27-
print(length)/ncol
28-
to.read = file(fin,'rb')
29-
part=matrix(0, nrow=(length/ncol), ncol=ncol)
30-
for(i in 1:(length/ncol)){
31-
part[i,]= readBin(to.read, double(), endian='little', size=8,n=ncol)
32-
}
33-
close(to.read)
34-
colnames(part)=c("Time", "x", "y", "z", "Ptime", "Mass", "Comp", "ExitStatus")
35-
npart=nrow(part)
36-
37-
#3D Histograms of particle ages
38-
out = which( (part[,8] == 1) & (part[,1]>=(19*8760)))
39-
et = which((part[,8] == 2) & (part[,1]>=(19*8760)))
40-
den3d_out_er_trees <- kde2d( (part[out,5])/24/365,part[out,1]/24/365, n = 50)
41-
42-
den3d_et_er_trees_time <- kde2d( (part[et,5])/24/365,part[et,1]/24/365, n = 50)
43-
den3d_et_er_trees_space <- kde2d( (part[et,5])/24/365,part[et,2], n = 100)
44-
45-
#Outflow
46-
x=part[out,5]/24/365
47-
y=part[out,1]/24/365
48-
z <- y
49-
trans=0.7
50-
fcol <- rbind(c(0,.1,.5,trans), c(.3,.8,.8,trans), c(1,1,0, trans))
51-
fcol=fcol[3:1,]
52-
lcol <- rbind(c(0,.3,.3,.8), c(.1,.1,.2,.7), c(0,0,1,.65))
53-
54-
55-
slicedens(x,y,z,fcol=fcol, bcol='white', lcol=lcol,gboost=.9, yinc=1, slices=12, xlab="Outflow Residence Time [YR] ",ylab="",main="A) ER Trees Outflow",yaxlab=months)
56-
57-
#ET
58-
x=part[et,5]/24/365
59-
y=part[et,1]/24/365
60-
z <- y
61-
62-
slicedens(x,y,z,fcol=fcol, bcol='white', lcol=lcol,gboost=.90, yinc=7, slices=12, xlab="ET Residence Time [YR]",ylab="", main="B) ER Trees ET",yaxlab=months)
63-
64-
65-
## load shrubs with LW forcing
66-
fin='../LW_hillslope_shrub/SLIM_hillslope_LW_shrub_exited_particles.bin'
67-
length=file.info(fin)$size/8
68-
ncol=8
69-
print(length)/ncol
70-
to.read = file(fin,'rb')
71-
part=matrix(0, nrow=(length/ncol), ncol=ncol)
72-
for(i in 1:(length/ncol)){
73-
part[i,]= readBin(to.read, double(), endian='little', size=8,n=ncol)
74-
}
75-
close(to.read)
76-
colnames(part)=c("Time", "x", "y", "z", "Ptime", "Mass", "Comp", "ExitStatus")
77-
npart=nrow(part)
78-
79-
#3D Histograms of particle ages
80-
out = which( (part[,8] == 1) & (part[,1]>=(19*8760)))
81-
et = which((part[,8] == 2) & (part[,1]>=(19*8760)))
82-
den3d_out_lw_shrubs <- kde2d( (part[out,5])/24/365,part[out,1]/24/365, n = 50)
83-
den3d_et_lw_shrubs_time <- kde2d( (part[et,5])/24/365,part[et,1]/24/365, n = 50)
84-
den3d_et_lw_shrubs_space <- kde2d( (part[et,5])/24/365,part[et,2], n = 100)
85-
86-
87-
## load trees with LW forcing
88-
fin='../LW_hillslope_trees/SLIM_hillslope_LW_trees_exited_particles.bin'
89-
length=file.info(fin)$size/8
90-
ncol=8
91-
print(length)/ncol
92-
to.read = file(fin,'rb')
93-
part=matrix(0, nrow=(length/ncol), ncol=ncol)
94-
for(i in 1:(length/ncol)){
95-
part[i,]= readBin(to.read, double(), endian='little', size=8,n=ncol)
96-
}
97-
close(to.read)
98-
colnames(part)=c("Time", "x", "y", "z", "Ptime", "Mass", "Comp", "ExitStatus")
99-
npart=nrow(part)
100-
101-
#3D Histograms of particle ages
102-
out = which( (part[,8] == 1) & (part[,1]>=(19*8760)))
103-
et = which((part[,8] == 2) & (part[,1]>=(19*8760)))
104-
den3d_out_lw_trees <- kde2d( (part[out,5])/24/365,part[out,1]/24/365, n = 50)
105-
den3d_et_lw_trees_time <- kde2d( (part[et,5])/24/365,part[et,1]/24/365, n = 50)
106-
den3d_et_lw_trees_space <- kde2d( (part[et,5])/24/365,part[et,2], n = 100)
107-
108-
#Outflow
109-
x=part[out,5]/24/365
110-
y=part[out,1]/24/365
111-
z <- y
112-
trans=0.7
113-
fcol <- rbind(c(0,.1,.5,trans), c(.3,.8,.8,trans), c(1,1,0, trans))
114-
fcol=fcol[3:1,]
115-
lcol <- rbind(c(0,.3,.3,.8), c(.1,.1,.2,.7), c(0,0,1,.65))
116-
117-
118-
slicedens(x,y,z,fcol=fcol, bcol='white', lcol=lcol,gboost=.9, yinc=1, slices=12, xlab="Outflow Residence Time [YR]",main="C) LW Trees Outflow",ylab="",yaxlab=months)
119-
120-
#ET
121-
x=part[et,5]/24/365
122-
y=part[et,1]/24/365
123-
z <- y
124-
125-
slicedens(x,y,z,fcol=fcol, bcol='white', lcol=lcol,gboost=.90, yinc=7, slices=12, xlab="ET Residence Time [YR]",main="D) LW Trees ET",ylab="",yaxlab=months)
126-
127-
dev.off()
128-
129-
## load shrubs with ER forcing
130-
fin='./ER_hillslope_shrub/SLIM_hillslope_ER_shrub_exited_particles.bin'
131-
length=file.info(fin)$size/8
132-
ncol=8
133-
print(length)/ncol
134-
to.read = file(fin,'rb')
135-
part=matrix(0, nrow=(length/ncol), ncol=ncol)
136-
for(i in 1:(length/ncol)){
137-
part[i,]= readBin(to.read, double(), endian='little', size=8,n=ncol)
138-
}
139-
close(to.read)
140-
colnames(part)=c("Time", "x", "y", "z", "Ptime", "Mass", "Comp", "ExitStatus")
141-
npart=nrow(part)
142-
143-
#3D Histograms of particle ages
144-
out = which( (part[,8] == 1) & (part[,1]>=(19*8760)))
145-
et = which((part[,8] == 2) & (part[,1]>=(19*8760)))
146-
den3d_out_er_shrubs <- kde2d( (part[out,5])/24/365,part[out,1]/24/365, n = 50)
147-
den3d_et_er_shrubs_time <- kde2d( (part[et,5])/24/365,part[et,1]/24/365, n = 50)
148-
den3d_et_er_shrubs_space <- kde2d( (part[et,5])/24/365,part[et,2], n = 100)
149-
150-
## make ET distribution four panel (Fig 5)
151-
fout = 'Figure5_ET_hillsllope_4-panel.pdf'
152-
pdf(file=fout)
153-
154-
par(mfrow=c(2,2))
155-
156-
image(den3d_et_er_shrubs_space,xlab = "ET residence time [yr]", ylab = "X Location Hillslope [m]",col = heat.colors(9),zlim=c(0.0001,0.05),xlim=c(0,10),breaks=c(0.000001,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05),main="A) ER Shrubs")
157-
158-
image(den3d_et_er_trees_space,xlab = "ET residence time [yr]", ylab = "X Location Hillslope [m]",col = heat.colors(9),zlim=c(0.0001,0.05),xlim=c(0,10),breaks=c(0.000001,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05),main="B) ER Trees")
159-
160-
image(den3d_et_lw_shrubs_space,xlab = "ET residence time [yr]", ylab = "X Location Hillslope [m]",col = heat.colors(9),zlim=c(0.0001,0.05),xlim=c(0,10),breaks=c(0.000001,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05),main="C) LW Shrubs")
161-
162-
image(den3d_et_lw_trees_space,xlab = "ET residence time [yr]", ylab = "X Location Hillslope [m]",col = heat.colors(9),zlim=c(0.0001,0.05),xlim=c(0,10),breaks=c(0.000001,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05),main="D) LW Trees")
163-
164-
image.plot(den3d_et_lw_trees_space, zlim=c(0.0001,0.05), cex=0.7,col=(heat.colors(9)), legend.only=T, legend.width=0.5, legend.shrink=0.5, legend.args=list(text=' Density [-]',cex=0.85,side=3,line=0.1), smallplot=c(.65,.68, .55,.75))
165-
dev.off()
166-
167-
13+
14+
months=c("OCT","NOV","DEC","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP")
15+
16+
## make waterfall four panel (Fig 4)
17+
fout = 'Figure4_waterfall_4-panel.pdf'
18+
pdf(file=fout,width=9, height=9)
19+
20+
par(mfrow=c(2,2))
21+
22+
#Read EcoSlim output files and put in independent matrices for plotting
23+
## load trees with ER forcing
24+
fin='./ER_hillslope_trees/SLIM_hillslope_ER_trees_exited_particles.bin'
25+
length=file.info(fin)$size/8
26+
ncol=8
27+
print(length)/ncol
28+
to.read = file(fin,'rb')
29+
part=matrix(0, nrow=(length/ncol), ncol=ncol)
30+
for(i in 1:(length/ncol)){
31+
part[i,]= readBin(to.read, double(), endian='little', size=8,n=ncol)
32+
}
33+
close(to.read)
34+
colnames(part)=c("Time", "x", "y", "z", "Ptime", "Mass", "Comp", "ExitStatus")
35+
npart=nrow(part)
36+
37+
#3D Histograms of particle ages
38+
out = which( (part[,8] == 1) & (part[,1]>=(19*8760)))
39+
et = which((part[,8] == 2) & (part[,1]>=(19*8760)))
40+
den3d_out_er_trees <- kde2d( (part[out,5])/24/365,part[out,1]/24/365, n = 50)
41+
42+
den3d_et_er_trees_time <- kde2d( (part[et,5])/24/365,part[et,1]/24/365, n = 50)
43+
den3d_et_er_trees_space <- kde2d( (part[et,5])/24/365,part[et,2], n = 100)
44+
45+
#Outflow
46+
x=part[out,5]/24/365
47+
y=part[out,1]/24/365
48+
z <- y
49+
trans=0.7
50+
fcol <- rbind(c(0,.1,.5,trans), c(.3,.8,.8,trans), c(1,1,0, trans))
51+
fcol=fcol[3:1,]
52+
lcol <- rbind(c(0,.3,.3,.8), c(.1,.1,.2,.7), c(0,0,1,.65))
53+
54+
55+
slicedens(x,y,z,fcol=fcol, bcol='white', lcol=lcol,gboost=.9, yinc=1, slices=12, xlab="Outflow Residence Time [YR] ",ylab="",main="A) ER Trees Outflow",yaxlab=months)
56+
57+
#ET
58+
x=part[et,5]/24/365
59+
y=part[et,1]/24/365
60+
z <- y
61+
62+
slicedens(x,y,z,fcol=fcol, bcol='white', lcol=lcol,gboost=.90, yinc=7, slices=12, xlab="ET Residence Time [YR]",ylab="", main="B) ER Trees ET",yaxlab=months)
63+
64+
65+
## load shrubs with LW forcing
66+
fin='../LW_hillslope_shrub/SLIM_hillslope_LW_shrub_exited_particles.bin'
67+
length=file.info(fin)$size/8
68+
ncol=8
69+
print(length)/ncol
70+
to.read = file(fin,'rb')
71+
part=matrix(0, nrow=(length/ncol), ncol=ncol)
72+
for(i in 1:(length/ncol)){
73+
part[i,]= readBin(to.read, double(), endian='little', size=8,n=ncol)
74+
}
75+
close(to.read)
76+
colnames(part)=c("Time", "x", "y", "z", "Ptime", "Mass", "Comp", "ExitStatus")
77+
npart=nrow(part)
78+
79+
#3D Histograms of particle ages
80+
out = which( (part[,8] == 1) & (part[,1]>=(19*8760)))
81+
et = which((part[,8] == 2) & (part[,1]>=(19*8760)))
82+
den3d_out_lw_shrubs <- kde2d( (part[out,5])/24/365,part[out,1]/24/365, n = 50)
83+
den3d_et_lw_shrubs_time <- kde2d( (part[et,5])/24/365,part[et,1]/24/365, n = 50)
84+
den3d_et_lw_shrubs_space <- kde2d( (part[et,5])/24/365,part[et,2], n = 100)
85+
86+
87+
## load trees with LW forcing
88+
fin='../LW_hillslope_trees/SLIM_hillslope_LW_trees_exited_particles.bin'
89+
length=file.info(fin)$size/8
90+
ncol=8
91+
print(length)/ncol
92+
to.read = file(fin,'rb')
93+
part=matrix(0, nrow=(length/ncol), ncol=ncol)
94+
for(i in 1:(length/ncol)){
95+
part[i,]= readBin(to.read, double(), endian='little', size=8,n=ncol)
96+
}
97+
close(to.read)
98+
colnames(part)=c("Time", "x", "y", "z", "Ptime", "Mass", "Comp", "ExitStatus")
99+
npart=nrow(part)
100+
101+
#3D Histograms of particle ages
102+
out = which( (part[,8] == 1) & (part[,1]>=(19*8760)))
103+
et = which((part[,8] == 2) & (part[,1]>=(19*8760)))
104+
den3d_out_lw_trees <- kde2d( (part[out,5])/24/365,part[out,1]/24/365, n = 50)
105+
den3d_et_lw_trees_time <- kde2d( (part[et,5])/24/365,part[et,1]/24/365, n = 50)
106+
den3d_et_lw_trees_space <- kde2d( (part[et,5])/24/365,part[et,2], n = 100)
107+
108+
#Outflow
109+
x=part[out,5]/24/365
110+
y=part[out,1]/24/365
111+
z <- y
112+
trans=0.7
113+
fcol <- rbind(c(0,.1,.5,trans), c(.3,.8,.8,trans), c(1,1,0, trans))
114+
fcol=fcol[3:1,]
115+
lcol <- rbind(c(0,.3,.3,.8), c(.1,.1,.2,.7), c(0,0,1,.65))
116+
117+
118+
slicedens(x,y,z,fcol=fcol, bcol='white', lcol=lcol,gboost=.9, yinc=1, slices=12, xlab="Outflow Residence Time [YR]",main="C) LW Trees Outflow",ylab="",yaxlab=months)
119+
120+
#ET
121+
x=part[et,5]/24/365
122+
y=part[et,1]/24/365
123+
z <- y
124+
125+
slicedens(x,y,z,fcol=fcol, bcol='white', lcol=lcol,gboost=.90, yinc=7, slices=12, xlab="ET Residence Time [YR]",main="D) LW Trees ET",ylab="",yaxlab=months)
126+
127+
dev.off()
128+
129+
## load shrubs with ER forcing
130+
fin='./ER_hillslope_shrub/SLIM_hillslope_ER_shrub_exited_particles.bin'
131+
length=file.info(fin)$size/8
132+
ncol=8
133+
print(length)/ncol
134+
to.read = file(fin,'rb')
135+
part=matrix(0, nrow=(length/ncol), ncol=ncol)
136+
for(i in 1:(length/ncol)){
137+
part[i,]= readBin(to.read, double(), endian='little', size=8,n=ncol)
138+
}
139+
close(to.read)
140+
colnames(part)=c("Time", "x", "y", "z", "Ptime", "Mass", "Comp", "ExitStatus")
141+
npart=nrow(part)
142+
143+
#3D Histograms of particle ages
144+
out = which( (part[,8] == 1) & (part[,1]>=(19*8760)))
145+
et = which((part[,8] == 2) & (part[,1]>=(19*8760)))
146+
den3d_out_er_shrubs <- kde2d( (part[out,5])/24/365,part[out,1]/24/365, n = 50)
147+
den3d_et_er_shrubs_time <- kde2d( (part[et,5])/24/365,part[et,1]/24/365, n = 50)
148+
den3d_et_er_shrubs_space <- kde2d( (part[et,5])/24/365,part[et,2], n = 100)
149+
150+
## make ET distribution four panel (Fig 5)
151+
fout = 'Figure5_ET_hillsllope_4-panel.pdf'
152+
pdf(file=fout)
153+
154+
par(mfrow=c(2,2))
155+
156+
image(den3d_et_er_shrubs_space,xlab = "ET residence time [yr]", ylab = "X Location Hillslope [m]",col = heat.colors(9),zlim=c(0.0001,0.05),xlim=c(0,10),breaks=c(0.000001,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05),main="A) ER Shrubs")
157+
158+
image(den3d_et_er_trees_space,xlab = "ET residence time [yr]", ylab = "X Location Hillslope [m]",col = heat.colors(9),zlim=c(0.0001,0.05),xlim=c(0,10),breaks=c(0.000001,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05),main="B) ER Trees")
159+
160+
image(den3d_et_lw_shrubs_space,xlab = "ET residence time [yr]", ylab = "X Location Hillslope [m]",col = heat.colors(9),zlim=c(0.0001,0.05),xlim=c(0,10),breaks=c(0.000001,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05),main="C) LW Shrubs")
161+
162+
image(den3d_et_lw_trees_space,xlab = "ET residence time [yr]", ylab = "X Location Hillslope [m]",col = heat.colors(9),zlim=c(0.0001,0.05),xlim=c(0,10),breaks=c(0.000001,0.000005,0.00001,0.00005,0.0001,0.0005,0.001,0.005,0.01,0.05),main="D) LW Trees")
163+
164+
image.plot(den3d_et_lw_trees_space, zlim=c(0.0001,0.05), cex=0.7,col=(heat.colors(9)), legend.only=T, legend.width=0.5, legend.shrink=0.5, legend.args=list(text=' Density [-]',cex=0.85,side=3,line=0.1), smallplot=c(.65,.68, .55,.75))
165+
dev.off()
166+
167+

0 commit comments

Comments
 (0)