Project

General

Profile

« Previous | Next » 

Revision 48392b95

Added by Jim Regetz over 13 years ago

  • ID 48392b959bd2a90dff6425cbecb9b6015f0bf98a

separated out code to profile slope near 60N boundary

View differences:

terrain/dem/dem-fusion.txt
214 214
plot(crop(rampexp, window), main="north exponential ramp (hillshade)")
215 215
plot(crop(blendgau, window), main="south gaussian blend (hillshade)")
216 216
dev.off()
217

  
218

  
219
#=======================================================================
220
# R -- assess boundary artifacts with respect to slope
221
#=======================================================================
222

  
223
s.aster <- raster("aster_300straddle_s.tif")
224
s.srtm <- raster("srtm_150below_s.tif")
225
s.uncor <- raster("fused_300straddle_s.tif")
226
s.eramp <- raster("fused_300straddle_rampexp_s.tif")
227
s.bg <- raster("fused_300straddle_blendgau_s.tif")
228
s.can <- raster("cdem_300straddle_s.tif")
229

  
230

  
231
rmse <- function(r1, r2) {
232
    sqrt(rowMeans(as.matrix((r1 - r2)^2), na.rm=TRUE))
233
}
234

  
235
pdf("slope-rmse.pdf", height=8, width=11.5)
236
par(mfrow=c(2,3), omi=c(1,1,1,1))
237
lats300 <- yFromRow(s.aster, 1:nrow(s.aster))
238
lats150 <- yFromRow(s.srtm, 1:nrow(s.srtm))
239
# Latitudinal RMSE profiles with respect to ASTER
240
plot(lats300, rmse(s.uncor, s.aster), type="l", xlab="Latitude",
241
    ylab="RMSE", ylim=c(0, 5))
242
lines(lats150, rmse(crop(s.uncor, extent(s.srtm)), s.srtm), col="blue")
243
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
244
    lty=c(1, 1), bty="n")
245
text(min(lats300), 4.5, pos=4, font=3, labels="uncorrected")
246
abline(v=60, col="red", lty=2)
247
mtext("Slope discrepancies with respect to separate ASTER/SRTM components",
248
    adj=0, line=2, font=2)
249
plot(lats300, rmse(s.eramp, s.aster), type="l", xlab="Latitude",
250
    ylab="RMSE", ylim=c(0, 5))
251
lines(lats150, rmse(crop(s.eramp, extent(s.srtm)), s.srtm), col="blue")
252
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
253
    lty=c(1, 1), bty="n")
254
text(min(lats300), 4.5, pos=4, font=3, labels="exponential ramp")
255
abline(v=60, col="red", lty=2)
256
plot(lats300, rmse(s.bg, s.aster), type="l", xlab="Latitude",
257
    ylab="RMSE", ylim=c(0, 5))
258
lines(lats150, rmse(crop(s.bg, extent(s.srtm)), s.srtm), col="blue")
259
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
260
    lty=c(1, 1), bty="n")
261
text(min(lats300), 4.5, pos=4, font=3, labels="gaussian blend")
262
abline(v=60, col="red", lty=2)
263

  
264
# Latitudinal RMSE profiles with respect to CDEM
265
plot(lats300, rmse(s.uncor, s.can), type="l", xlab="Latitude",
266
    ylab="RMSE", ylim=c(0, 5))
267
text(min(lats300), 4.5, pos=4, font=3, labels="uncorrected")
268
abline(v=60, col="red", lty=2)
269
mtext("Slope discrepancies with respect to Canada DEM",
270
    adj=0, line=2, font=2)
271
plot(lats300, rmse(s.eramp, s.can), type="l", xlab="Latitude",
272
    ylab="RMSE", ylim=c(0, 5))
273
text(min(lats300), 4.5, pos=4, font=3, labels="exponential ramp")
274
abline(v=60, col="red", lty=2)
275
plot(lats300, rmse(s.bg, s.can), type="l", xlab="Latitude",
276
    ylab="RMSE", ylim=c(0, 5))
277
text(min(lats300), 4.5, pos=4, font=3, labels="gaussian blend")
278
abline(v=60, col="red", lty=2)
279
dev.off()
280

  
281

  
282
####
283
corByLat <- function(r1, r2, rows) {
284
    if (missing(rows)) {
285
        rows <- 1:nrow(r1)
286
    }
287
    m1 <- as.matrix(r1)
288
    m2 <- as.matrix(r2)
289
    sapply(rows, function(row) cor(m1[row,], m2[row,],
290
        use="pairwise.complete.obs"))
291
}
292

  
293
pdf("slope-corr.pdf", height=8, width=11.5)
294
par(mfrow=c(2,3), omi=c(1,1,1,1))
295
lats300 <- yFromRow(s.aster, 1:nrow(s.aster))
296
lats150 <- yFromRow(s.srtm, 1:nrow(s.srtm))
297
ylim <- c(0.65, 1)
298
# Latitudinal RMSE profiles with respect to ASTER
299
plot(lats300, corByLat(s.uncor, s.aster), type="l", xlab="Latitude",
300
    ylab="Correlation", ylim=ylim)
301
lines(lats150, corByLat(crop(s.uncor, extent(s.srtm)), s.srtm), col="blue")
302
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
303
    lty=c(1, 1), bty="n")
304
text(min(lats300), min(ylim), pos=4, font=3, labels="uncorrected")
305
abline(v=60, col="red", lty=2)
306
mtext("Slope correlations with separate ASTER/SRTM components",
307
    adj=0, line=2, font=2)
308
plot(lats300, corByLat(s.eramp, s.aster), type="l", xlab="Latitude",
309
    ylab="Correlation", ylim=ylim)
310
lines(lats150, corByLat(crop(s.eramp, extent(s.srtm)), s.srtm), col="blue")
311
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
312
    lty=c(1, 1), bty="n")
313
text(min(lats300), min(ylim), pos=4, font=3, labels="exponential ramp")
314
abline(v=60, col="red", lty=2)
315
plot(lats300, corByLat(s.bg, s.aster), type="l", xlab="Latitude",
316
    ylab="Correlation", ylim=ylim)
317
lines(lats150, corByLat(crop(s.bg, extent(s.srtm)), s.srtm), col="blue")
318
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
319
    lty=c(1, 1), bty="n")
320
text(min(lats300), min(ylim), pos=4, font=3, labels="gaussian blend")
321
abline(v=60, col="red", lty=2)
322

  
323
# Latitudinal correlation profiles with respect to CDEM
324
plot(lats300, corByLat(s.uncor, s.can), type="l", xlab="Latitude",
325
    ylab="Correlation", ylim=ylim)
326
text(min(lats300), min(ylim), pos=4, font=3, labels="uncorrected")
327
abline(v=60, col="red", lty=2)
328
mtext("Slope correlations with Canada DEM",
329
    adj=0, line=2, font=2)
330
plot(lats300, corByLat(s.eramp, s.can), type="l", xlab="Latitude",
331
    ylab="Correlation", ylim=ylim)
332
text(min(lats300), min(ylim), pos=4, font=3, labels="exponential ramp")
333
abline(v=60, col="red", lty=2)
334
plot(lats300, corByLat(s.bg, s.can), type="l", xlab="Latitude",
335
    ylab="Correlation", ylim=ylim)
336
text(min(lats300), min(ylim), pos=4, font=3, labels="gaussian blend")
337
abline(v=60, col="red", lty=2)
338
dev.off()
339

  
terrain/slope/slope-assessment.R
1
# 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
rmse <- function(r1, r2, na.rm=TRUE) {
65
    sqrt(rowMeans(as.matrix((r1 - r2)^2), na.rm=na.rm))
66
}
67

  
68
par(mfrow=c(2,3), omi=c(1,1,1,1))
69

  
70
# ...with respect to ASTER
71
plot(lats300, rmse(s.uncor, s.aster), type="l", xlab="Latitude",
72
    ylab="RMSE", ylim=c(0, 5))
73
lines(lats150, rmse(crop(s.uncor, extent(s.srtm)), s.srtm), col="blue")
74
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
75
    lty=c(1, 1), bty="n")
76
text(min(lats300), 4.5, pos=4, font=3, labels="uncorrected")
77
abline(v=60, col="red", lty=2)
78
mtext(expression(paste(
79
    "Slope discrepancies with respect to separate ASTER/SRTM components (",
80
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
81

  
82
plot(lats300, rmse(s.eramp, s.aster), type="l", xlab="Latitude",
83
    ylab="RMSE", ylim=c(0, 5))
84
lines(lats150, rmse(crop(s.eramp, extent(s.srtm)), s.srtm), col="blue")
85
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
86
    lty=c(1, 1), bty="n")
87
text(min(lats300), 4.5, pos=4, font=3, labels="exponential ramp")
88
abline(v=60, col="red", lty=2)
89

  
90
plot(lats300, rmse(s.bg, s.aster), type="l", xlab="Latitude",
91
    ylab="RMSE", ylim=c(0, 5))
92
lines(lats150, rmse(crop(s.bg, extent(s.srtm)), s.srtm), col="blue")
93
legend("topright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
94
    lty=c(1, 1), bty="n")
95
text(min(lats300), 4.5, pos=4, font=3, labels="gaussian blend")
96
abline(v=60, col="red", lty=2)
97

  
98
# ...with respect to CDEM
99
plot(lats300, rmse(s.uncor, s.can), type="l", xlab="Latitude",
100
    ylab="RMSE", ylim=c(0, 5))
101
text(min(lats300), 4.5, pos=4, font=3, labels="uncorrected")
102
abline(v=60, col="red", lty=2)
103
mtext(expression(paste(
104
    "Slope discrepancies with respect to Canada DEM (",
105
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
106

  
107
plot(lats300, rmse(s.eramp, s.can), type="l", xlab="Latitude",
108
    ylab="RMSE", ylim=c(0, 5))
109
text(min(lats300), 4.5, pos=4, font=3, labels="exponential ramp")
110
abline(v=60, col="red", lty=2)
111

  
112
plot(lats300, rmse(s.bg, s.can), type="l", xlab="Latitude",
113
    ylab="RMSE", ylim=c(0, 5))
114
text(min(lats300), 4.5, pos=4, font=3, labels="gaussian blend")
115
abline(v=60, col="red", lty=2)
116

  
117

  
118
#
119
# plot latitudinal profiles of correlation coefficients
120
#
121

  
122
# simple helper function to calculate row-wise correlation coefficients
123
corByLat <- function(r1, r2, rows) {
124
    if (missing(rows)) {
125
        rows <- 1:nrow(r1)
126
    }
127
    m1 <- as.matrix(r1)
128
    m2 <- as.matrix(r2)
129
    sapply(rows, function(row) cor(m1[row,], m2[row,],
130
        use="pairwise.complete.obs"))
131
}
132

  
133
par(mfrow=c(2,3), omi=c(1,1,1,1))
134

  
135
ylim <- c(0.65, 1)
136

  
137
# ...with respect to ASTER
138
plot(lats300, corByLat(s.uncor, s.aster), type="l", xlab="Latitude",
139
    ylab="Correlation", ylim=ylim)
140
lines(lats150, corByLat(crop(s.uncor, extent(s.srtm)), s.srtm), col="blue")
141
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
142
    lty=c(1, 1), bty="n")
143
text(min(lats300), min(ylim), pos=4, font=3, labels="uncorrected")
144
abline(v=60, col="red", lty=2)
145
mtext(expression(paste(
146
    "Slope correlations with respect to separate ASTER/SRTM components (",
147
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
148

  
149
plot(lats300, corByLat(s.eramp, s.aster), type="l", xlab="Latitude",
150
    ylab="Correlation", ylim=ylim)
151
lines(lats150, corByLat(crop(s.eramp, extent(s.srtm)), s.srtm), col="blue")
152
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
153
    lty=c(1, 1), bty="n")
154
text(min(lats300), min(ylim), pos=4, font=3, labels="exponential ramp")
155
abline(v=60, col="red", lty=2)
156

  
157
plot(lats300, corByLat(s.bg, s.aster), type="l", xlab="Latitude",
158
    ylab="Correlation", ylim=ylim)
159
lines(lats150, corByLat(crop(s.bg, extent(s.srtm)), s.srtm), col="blue")
160
legend("bottomright", legend=c("ASTER", "SRTM"), col=c("black", "blue"),
161
    lty=c(1, 1), bty="n")
162
text(min(lats300), min(ylim), pos=4, font=3, labels="gaussian blend")
163
abline(v=60, col="red", lty=2)
164

  
165
# ...with respect to CDEM
166
plot(lats300, corByLat(s.uncor, s.can), type="l", xlab="Latitude",
167
    ylab="Correlation", ylim=ylim)
168
text(min(lats300), min(ylim), pos=4, font=3, labels="uncorrected")
169
abline(v=60, col="red", lty=2)
170
mtext(expression(paste(
171
    "Slope correlations with respect to Canada DEM (",
172
    136*degree, "W to ", 96*degree, "W)")), adj=0, line=2, font=2)
173

  
174
plot(lats300, corByLat(s.eramp, s.can), type="l", xlab="Latitude",
175
    ylab="Correlation", ylim=ylim)
176
text(min(lats300), min(ylim), pos=4, font=3, labels="exponential ramp")
177
abline(v=60, col="red", lty=2)
178

  
179
plot(lats300, corByLat(s.bg, s.can), type="l", xlab="Latitude",
180
    ylab="Correlation", ylim=ylim)
181
text(min(lats300), min(ylim), pos=4, font=3, labels="gaussian blend")
182
abline(v=60, col="red", lty=2)
183

  
184
# close pdf device driver
185
dev.off()

Also available in: Unified diff