Project

General

Profile

Download (6.77 KB) Statistics
| Branch: | Revision:
1 48392b95 Jim Regetz
# R code to plot latitudinal profiles of mean slope, along with both
2
# RMSE and correlation coefficients comparing fused layers with both the
3
# raw ASTER and with the Canada DEM
4
#
5
# Jim Regetz
6
# NCEAS
7
# Created on 08-Jun-2011
8
9
library(raster)
10
11
datadir <- "/home/regetz/media/temp/terrain/slope"
12
13
# load slope rasters
14
s.aster <- raster(file.path(datadir, "aster_300straddle_s.tif"))
15
s.srtm <- raster(file.path(datadir, "srtm_150below_s.tif"))
16
s.uncor <- raster(file.path(datadir, "fused_300straddle_s.tif"))
17
s.eramp <- raster(file.path(datadir, "fused_300straddle_rampexp_s.tif"))
18
s.bg <- raster(file.path(datadir, "fused_300straddle_blendgau_s.tif"))
19
s.can <- raster(file.path(datadir, "cdem_300straddle_s.tif"))
20
21
# extract raster latitudes for later
22
lats300 <- yFromRow(s.aster, 1:nrow(s.aster))
23
lats150 <- yFromRow(s.srtm, 1:nrow(s.srtm))
24
25
# initialize output pdf device driver
26
pdf("slope-assessment.pdf", height=8, width=11.5)
27
28
29
#
30
# plot latitudinal profiles of mean slope
31
#
32
33
par(mfrow=c(2,2), omi=c(1,1,1,1))
34
ylim <- c(1, 6)
35
36
plot(lats300, rowMeans(as.matrix(s.uncor), na.rm=TRUE), type="l",
37
    xlab="Latitude", ylab="Mean slope", ylim=ylim)
38
text(min(lats300), max(ylim)-0.5, pos=4, font=3, labels="uncorrected")
39
abline(v=60, col="red", lty=2)
40
mtext(expression(paste("Latitudinal profiles of mean slope (",
41
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
42
43
plot(lats300, rowMeans(as.matrix(s.can), na.rm=TRUE), type="l",
44
    xlab="Latitude", ylab="Mean slope", ylim=ylim)
45
text(min(lats300), max(ylim)-0.5, pos=4, font=3, labels="Canada DEM")
46
abline(v=60, col="red", lty=2)
47
48
plot(lats300, rowMeans(as.matrix(s.eramp), na.rm=TRUE), type="l",
49
    xlab="Latitude", ylab="Mean slope", ylim=ylim)
50
text(min(lats300), max(ylim)-0.5, pos=4, font=3, labels="exponential ramp")
51
abline(v=60, col="red", lty=2)
52
53
plot(lats300, rowMeans(as.matrix(s.bg), na.rm=TRUE), type="l",
54
    xlab="Latitude", ylab="Mean slope", ylim=ylim)
55
text(min(lats300), max(ylim)-0.5, pos=4, font=3, labels="gaussian blend")
56
abline(v=60, col="red", lty=2)
57
58
59
#
60
# plot latitudinal profiles of RMSE
61
#
62
63
# simple helper function to calculate row-wise RMSEs
64 b02e39a0 Jim Regetz
rmse <- function(r1, r2, na.rm=TRUE, use) {
65
    diffs <- abs(as.matrix(r1) - as.matrix(r2))
66
    if (!missing(use)) diffs[!use] <- NA
67
    sqrt(rowMeans(diffs^2, na.rm=na.rm))
68 48392b95 Jim Regetz
}
69
70
par(mfrow=c(2,3), omi=c(1,1,1,1))
71
72
# ...with respect to ASTER
73
plot(lats300, rmse(s.uncor, s.aster), type="l", xlab="Latitude",
74
    ylab="RMSE", ylim=c(0, 5))
75
lines(lats150, rmse(crop(s.uncor, extent(s.srtm)), s.srtm), col="blue")
76
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
77
    lty=c(1, 1), bty="n")
78
text(min(lats300), 4.5, pos=4, font=3, labels="uncorrected")
79
abline(v=60, col="red", lty=2)
80
mtext(expression(paste(
81
    "Slope discrepancies with respect to separate ASTER/SRTM components (",
82
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
83
84
plot(lats300, rmse(s.eramp, s.aster), type="l", xlab="Latitude",
85
    ylab="RMSE", ylim=c(0, 5))
86
lines(lats150, rmse(crop(s.eramp, extent(s.srtm)), s.srtm), col="blue")
87
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
88
    lty=c(1, 1), bty="n")
89
text(min(lats300), 4.5, pos=4, font=3, labels="exponential ramp")
90
abline(v=60, col="red", lty=2)
91
92
plot(lats300, rmse(s.bg, s.aster), type="l", xlab="Latitude",
93
    ylab="RMSE", ylim=c(0, 5))
94
lines(lats150, rmse(crop(s.bg, extent(s.srtm)), s.srtm), col="blue")
95
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
96
    lty=c(1, 1), bty="n")
97
text(min(lats300), 4.5, pos=4, font=3, labels="gaussian blend")
98
abline(v=60, col="red", lty=2)
99
100
# ...with respect to CDEM
101
plot(lats300, rmse(s.uncor, s.can), type="l", xlab="Latitude",
102
    ylab="RMSE", ylim=c(0, 5))
103
text(min(lats300), 4.5, pos=4, font=3, labels="uncorrected")
104
abline(v=60, col="red", lty=2)
105
mtext(expression(paste(
106
    "Slope discrepancies with respect to Canada DEM (",
107
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
108
109
plot(lats300, rmse(s.eramp, s.can), type="l", xlab="Latitude",
110
    ylab="RMSE", ylim=c(0, 5))
111
text(min(lats300), 4.5, pos=4, font=3, labels="exponential ramp")
112
abline(v=60, col="red", lty=2)
113
114
plot(lats300, rmse(s.bg, s.can), type="l", xlab="Latitude",
115
    ylab="RMSE", ylim=c(0, 5))
116
text(min(lats300), 4.5, pos=4, font=3, labels="gaussian blend")
117
abline(v=60, col="red", lty=2)
118
119
120
#
121
# plot latitudinal profiles of correlation coefficients
122
#
123
124
# simple helper function to calculate row-wise correlation coefficients
125
corByLat <- function(r1, r2, rows) {
126
    if (missing(rows)) {
127
        rows <- 1:nrow(r1)
128
    }
129
    m1 <- as.matrix(r1)
130
    m2 <- as.matrix(r2)
131
    sapply(rows, function(row) cor(m1[row,], m2[row,],
132
        use="pairwise.complete.obs"))
133
}
134
135
par(mfrow=c(2,3), omi=c(1,1,1,1))
136
137
ylim <- c(0.65, 1)
138
139
# ...with respect to ASTER
140
plot(lats300, corByLat(s.uncor, s.aster), type="l", xlab="Latitude",
141
    ylab="Correlation", ylim=ylim)
142
lines(lats150, corByLat(crop(s.uncor, extent(s.srtm)), s.srtm), col="blue")
143
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
144
    lty=c(1, 1), bty="n")
145
text(min(lats300), min(ylim), pos=4, font=3, labels="uncorrected")
146
abline(v=60, col="red", lty=2)
147
mtext(expression(paste(
148
    "Slope correlations with respect to separate ASTER/SRTM components (",
149
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
150
151
plot(lats300, corByLat(s.eramp, s.aster), type="l", xlab="Latitude",
152
    ylab="Correlation", ylim=ylim)
153
lines(lats150, corByLat(crop(s.eramp, extent(s.srtm)), s.srtm), col="blue")
154
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
155
    lty=c(1, 1), bty="n")
156
text(min(lats300), min(ylim), pos=4, font=3, labels="exponential ramp")
157
abline(v=60, col="red", lty=2)
158
159
plot(lats300, corByLat(s.bg, s.aster), type="l", xlab="Latitude",
160
    ylab="Correlation", ylim=ylim)
161
lines(lats150, corByLat(crop(s.bg, extent(s.srtm)), s.srtm), col="blue")
162
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
163
    lty=c(1, 1), bty="n")
164
text(min(lats300), min(ylim), pos=4, font=3, labels="gaussian blend")
165
abline(v=60, col="red", lty=2)
166
167
# ...with respect to CDEM
168
plot(lats300, corByLat(s.uncor, s.can), type="l", xlab="Latitude",
169
    ylab="Correlation", ylim=ylim)
170
text(min(lats300), min(ylim), pos=4, font=3, labels="uncorrected")
171
abline(v=60, col="red", lty=2)
172
mtext(expression(paste(
173
    "Slope correlations with respect to Canada DEM (",
174
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
175
176
plot(lats300, corByLat(s.eramp, s.can), type="l", xlab="Latitude",
177
    ylab="Correlation", ylim=ylim)
178
text(min(lats300), min(ylim), pos=4, font=3, labels="exponential ramp")
179
abline(v=60, col="red", lty=2)
180
181
plot(lats300, corByLat(s.bg, s.can), type="l", xlab="Latitude",
182
    ylab="Correlation", ylim=ylim)
183
text(min(lats300), min(ylim), pos=4, font=3, labels="gaussian blend")
184
abline(v=60, col="red", lty=2)
185
186
# close pdf device driver
187
dev.off()