Project

General

Profile

Download (14.3 KB) Statistics
| Branch: | Revision:
1
% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-
2
%
3
% Using Gregor Gorjanc's bash script:
4
%   sweave -old=<pdfviewer> <filename.Rnw>
5
%
6
% Using my simple bash script wrapper:
7
%   sweave_jr <basename>
8
%
9
% Using the lower level commands, in two steps: 
10
%   R CMD Sweave <filename.Rnw>
11
%   pdflatex <filename.tex>
12
%
13
% To extract R code from within R:
14
%   Stangle("<filename.Rnw>", annotate=FALSE)
15
\documentclass[8pt]{article}
16
\usepackage[final]{pdfpages}
17
\usepackage{fancyhdr}
18
\usepackage[font=normalsize,singlelinecheck=false]{subfig}
19

    
20

    
21
\title{SRTM/ASTER boundary analysis}
22
\author{Jim Regetz}
23
\date{Last update: 23 Jun 2011}
24

    
25
%\SweaveOpts{echo=true}
26
\usepackage[utf8]{inputenc}
27
\usepackage{a4wide}
28
\usepackage{verbatim}
29
\usepackage{listings}
30
\usepackage[colorlinks=true,urlcolor=red]{hyperref}
31
\usepackage{color}
32

    
33
%\topmargin 70pt
34

    
35
\pagestyle{fancy}
36
\rfoot{}
37
\cfoot{\Large\thepage}
38
\renewcommand {\headrulewidth}{0pt}
39
\renewcommand {\footrulewidth}{0pt}
40

    
41
% set some listings options
42
\lstset{
43
  basicstyle=\small\ttfamily,
44
  stringstyle=\ttfamily,
45
  commentstyle=\itshape\ttfamily,
46
  showstringspaces=false,
47
}
48

    
49
\begin{document}
50

    
51
% define custom colors for R input and output
52
\definecolor{dkblue}{rgb}{0,0,0.7}
53
\definecolor{dkgray}{gray}{0.25}
54

    
55
% define simple macro for marking up inline R code
56
\def\rfunc#1{\textcolor{dkblue}{\texttt{#1}}}
57
\def\robj#1{\textcolor{black}{\texttt{#1}}}
58

    
59
% nicer settings from Ross Ihaka
60
\DefineVerbatimEnvironment{Sinput}{Verbatim} %  {xleftmargin=2em,formatcom=\color{dkblue},fontsize=\footnotesize}
61
  {xleftmargin=2em,formatcom=\color{dkblue}}
62
\DefineVerbatimEnvironment{Soutput}{Verbatim}
63
%  {xleftmargin=2em,formatcom=\color{dkgray},fontsize=\footnotesize}
64
  {xleftmargin=2em,formatcom=\color{dkgray}}
65
\DefineVerbatimEnvironment{Scode}{Verbatim}{xleftmargin=2em}
66
\fvset{listparameters={\setlength{\topsep}{0pt}}}
67
\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}}
68

    
69
% set some specific R options that affect the output format
70
<<echo=FALSE,print=FALSE>>=
71
options(width=80)
72
options(continue=" ")
73
@
74

    
75
\paragraph{Region of analysis} For testing purposes, I used a narrow
76
band along the 60N boundary in Canada (Figure \ref{focal-area}). The
77
latitudinal extent of this band is 59.875N - 60.125N (i.e., 300 3"
78
pixels straddling 60N), and the longitudinal extent is 136W to 96W
79
(i.e., 48000 pixels wide).
80

    
81
\begin{figure}[htp]
82
  \caption{Focal area}
83
  \centering
84
<<echo=FALSE,results=hide,fig=TRUE,height=5,width=7>>=
85
  par(omi=c(0,0,0,0))
86
  library(raster)
87
  library(maps)
88
  demdir <- "/home/regetz/media/temp/terrain/dem/"
89
  dem <- raster(file.path(demdir, "fused_300straddle.tif"))
90
  map("world", xlim=c(-140,-70), ylim=c(40, 70), fill=TRUE, col="grey",
91
      mar=c(4,0,0,0))
92
  grid(col="darkgray")
93
  axis(1)
94
  axis(2)
95
  box()
96
  plot(extent(dem), col="red", add=TRUE)
97
  arrows(-110, 57, -113, 59.7, col="red", length=0.1)
98
  text(-110, 57, labels="focal region", col="red", font=3, pos=1)
99
@
100
  \label{focal-area}
101
\end{figure}
102

    
103
\paragraph{Fusion approaches} This document includes latitudinal
104
characterizations of terrain values based on three different variants of
105
a fused ASTER/SRTM DEM. I also explored (and briefly describe below) two
106
additional approaches to fusing the layers, but do not include further
107
assessment of these here.
108

    
109
\subparagraph{Simple fusion} Naive concatentation of SRTM below 60N with
110
ASTER above 60N, without applying any modifications to deal with
111
boundary artifacts (Figure \ref{blend-simple}).
112

    
113
\subparagraph{Multiresolution spline} Application of Burt \& Adelson's
114
(1983) method for blending overlapping images using multiresolution
115
splines, as implmented in the \emph{enblend} software package. Data prep
116
and post-processing were handled in R (see Listing \ref{code-enblend}).
117
As presented here, the ASTER and SRTM inputs were prepared such that the
118
overlap zone is 75 latitudinal rows (6.75km) (Figure
119
\ref{blend-multires}).
120

    
121
\subparagraph{Gaussian weighted average} Blend of the two layers using
122
weighted averaging such that the relative contribution of the SRTM
123
elevation is zero at 60N, and increases according to a Gaussian function
124
of distance moving south away from 60N. As presented here, this function
125
was parameterized such that the ASTER and SRTM are equally weighted at a
126
distance of $\sim$2.4km (26 cells) from the boundary, and the influence of
127
ASTER is negligible by $\sim$5km from the boundary (Figure
128
\ref{blend-gaussian}).
129

    
130
\subparagraph{Others not shown} Fused with exponential ramp north of
131
60N. The first step is to take the pixel-wise difference between ASTER
132
and SRTM in the row immediately below 60N (i.e., the northmost extent of
133
SRTM). An exponentially declining fraction of this difference is then
134
then added back into the ASTER values north of 60N. This does a fine job
135
of eliminating the artificial shelf and thus the appearance of a seam
136
right along the 60N boundary, but it does not address the abrupt
137
transition in texture (i.e., the sudden appearance of high frequency
138
variability moving north across the boundary). Additionally, it
139
introduces vertical ``ridges'' running north from the boundary. These
140
arise because the calculated ramps are independent from one longitudinal
141
``column'' to the next, and thus any changes in the boundary difference
142
from one pixel to the next lead to adjacent ramps with different
143
inclines.
144

    
145
I also tried a simple LOESS predictive model. This involved first
146
calculating the difference between ASTER and SRTM everywhere south of
147
60N, and then fitting a LOESS line to these differences using the actual
148
ASTER elevation as a predictor. I then used the fitted model to predict
149
the ASTER-SRTM difference for ASTER cells north of 60N, and add a
150
declining fraction (based on a Gaussian curve) of this difference to the
151
ASTER values north of 60N. Conceptually, this amounts to applying an
152
ASTER-predicted correction to the ASTER elevation values, where the
153
correction term declines to zero according with increasing distance
154
north of the bonudary. However, this method alone didn't yield
155
particularly promising results in removing the 60N seam itself,
156
presumably because adding a predicted correction at the boundary does
157
not close the SRTM-ASTER gap nearly as efficiently as do corrections
158
that are based on the actual elevation values. I therefore haven't
159
pursued this any further, although it (or something like it) may prove
160
useful in combination with one of the other methods.
161

    
162
\begin{figure}
163
  \caption{SRTM/ASTER blend configurations}
164
  \centering
165
  \subfloat[Simple fusion]{
166
    \label{blend-simple}
167
<<echo=FALSE,results=hide,fig=TRUE, height=3, width=6>>=
168
  par(omi=c(0,0,0,0), mar=c(4,4,0,2)+0.1)
169
  plot(0, xlim=c(-150, 150), ylim=c(0, 1), type="n", xaxt="n", yaxt="n",
170
      bty="n", xlab="Latitude", ylab=NA)
171
  rect(0, 0, 150, 0.75, col="red", density=5, angle=45)
172
  rect(-150, 0, 0, 0.75, col="blue", density=5, angle=135)
173
#  axis(1, at=seq(-120, 120, by=60), labels=seq(59.9, 60.1, by=0.05))
174
  axis(1, at=seq(-150, 150, by=75), labels=c(59.875, NA, 60, NA, 60.125))
175
  text(-150, 0.9, labels="SRTM", pos=4, col="blue")
176
  text(150, 0.9, labels="ASTER", pos=2, col="red")
177
@
178
  }\\
179
  \subfloat[Multiresolution spline]{
180
    \label{blend-multires}
181
<<echo=FALSE,results=hide,fig=TRUE, height=3, width=6>>=
182
  par(omi=c(0,0,0,0), mar=c(4,4,0,2)+0.1)
183
  plot(0, xlim=c(-150, 150), ylim=c(0, 1), type="n", xaxt="n", yaxt="n",
184
      bty="n", xlab="Latitude", ylab=NA)
185
  rect(-75, 0, 0, 0.75, col="lightgray")
186
  rect(-75, 0, 150, 0.75, col="red", density=5, angle=45)
187
  rect(-150, 0, 0, 0.75, col="blue", density=5, angle=135)
188
  #axis(1, at=seq(-150, 150, by=60), labels=seq(59.875, 60.125, by=0.05))
189
  #axis(1, at=0, labels=60, col="red", cex=0.85)
190
  #axis(1, at=seq(-120, 120, by=60), labels=seq(59.9, 60.1, by=0.05))
191
  axis(1, at=seq(-150, 150, by=75), labels=c(59.875, NA, 60, NA, 60.125))
192
  text(-150, 0.9, labels="SRTM", pos=4, col="blue")
193
  text(-37.5, 0.8, labels="overlap", pos=3, font=3)
194
  text(150, 0.9, labels="ASTER", pos=2, col="red")
195
@
196
  }\\
197
  \subfloat[Gaussian weighted average]{
198
    \label{blend-gaussian}
199
<<echo=FALSE,results=hide,fig=TRUE, height=3, width=6>>=
200
  par(omi=c(0,0,0,0), mar=c(4,4,1,2)+0.1)
201
  curve(exp(-0.001*x^2), from=-150, to=0, xlim=c(-150, 150), col="red",
202
      xaxt="n", bty="n", xlab="Latitude", ylab="Weighting")
203
  curve(1+0*x, from=0, to=150, add=TRUE, col="red")
204
  curve(1-exp(-0.001*x^2), from=-150, to=0, add=TRUE, col="blue")
205
  #axis(1, at=seq(-150, 150, by=60), labels=seq(59.875, 60.125, by=0.05))
206
  #axis(1, at=0, labels=60, col="red", cex=0.85)
207
  #axis(1, at=seq(-120, 120, by=60), labels=seq(59.9, 60.1, by=0.05))
208
  axis(1, at=seq(-150, 150, by=75), labels=c(59.875, NA, 60, NA, 60.125))
209
  text(-100, 0.6, labels="gaussian\nblend")
210
  text(-140, 0.9, labels="SRTM", col="blue", pos=4)
211
  text(-140, 0.1, labels="ASTER", col="red", pos=4)
212
@
213
  }
214
\end{figure}
215

    
216
\newpage
217

    
218
%\includepdfset{pagecommand=\thispagestyle{fancy}}
219
%\setkeys{Gin}{width=1.8\linewidth}
220
%\captionsetup[table]{position=top}
221

    
222

    
223
\paragraph{Latitudinal terrain profiles (means)}
224

    
225
\subparagraph{Elevation} As indicated in Figure \ref{mean-elevation},
226
the mean SRTM elevation is uniformly higher than the mean ASTER
227
elevation at all latitudes in the area of overlap, by $\sim$11 meters.
228
However, the shape of the profile itself is nearly identical between the
229
two. As point of reference, the Canada DEM shares a similarly shaped
230
profile, but with elevation values intermediate to the ASTER and SRTM.
231

    
232
Not surprisingly, simple fusion produces an artificial cliff in the mean
233
elevation profile. This artifact is completely removed by both the
234
multiresolution spline and gaussian weighted average methods. The
235
transition is, at least to the eye, slightly smoother in the former
236
case, although ultimately this would depend on the chosen zone of
237
overlap and on the exact parameterization of the weighting function.
238

    
239

    
240
\subparagraph{Slope} As indicated in Figure \ref{mean-slope},
241
the mean ASTER slope is uniformly steeper than the mean SRTM
242
elevation at all latitudes in the area of overlap, by nearly 1 degree.
243
However, the shape of the profile itself is nearly identical between the
244
two. Although this may partly reflect inherent SRTM vs ASTER
245
differences, my guess is that CGIAR postprocessing of the particular
246
SRTM product we're using has removed some of the high frequency
247
``noise'' that remains in ASTER.
248

    
249
Note that the he Canada DEM tends to be flatter than both ASTER and
250
SRTM (presumably because it is at least partially derived from
251
contour-based data (\textbf{check!})). Moreover, this figure makes it
252
clear that the Canada DEM has some major artifacts at regular intervals.
253
The spike especially at 60N (which coincides with provincial boundaries
254
across the entirety of western Canada) means we probably need to scuttle
255
our plans to use this DEM as a reference dataset for boundary analysis.
256

    
257
The simple fused layer exhibits a dramatic spike in slope at the
258
immediate 60N boundary, undoubtedly associated with the artificial
259
elevation cliff. This artifact is eliminated by both the multiresolution
260
spline and gaussian weighting. However, former exhibits a sudden step
261
change in slope in the SRTM-ASTER overlap region, whereas the transition
262
is smoothed out in the latter. This likely reflects the fact that the
263
multiresolution spline effectively uses a very narrow transition zone
264
for stitching together high frequency components of the input images,
265
and I surmise these are precisely the features responsible for the shift
266
in mean slope. 
267

    
268
\subparagraph{Aspect} As indicated in Figure \ref{mean-aspect},
269
the mean aspect of ASTER and SRTM are quite similar across all latitudes
270
in the area of overlap. However, the shape of the
271
profile itself is nearly identical between the
272
two. Although this may partly reflect inherent SRTM vs ASTER
273
differences, my guess is that CGIAR postprocessing of the particular
274
SRTM product we're using has removed some of the high frequency
275
``noise'' that remains in ASTER.
276

    
277
%TODO: recalc aspect using circular mean?
278
%TODO: run flow for enblend output? or just leave what we have, and
279
%discuss that? be sure to mention that we're doing flow for a smaller
280
%longitudinal range
281

    
282
%
283
% Latitudinal terrain profiles (means)
284
%
285
\begin{figure}[t!]
286
  \centering
287
  \caption{Latitudinal terrain profiles}
288
  \subfloat[Mean elevation (m)]{
289
    \includegraphics[page=1, trim=1in 1in 1in 1in, width=\linewidth]{../dem/elevation-assessment.pdf}
290
    \label{mean-elevation}
291
  }\\
292
  \newpage
293
  \subfloat[Mean slope (degrees)]{
294
    \includegraphics[page=1, trim=1in 1in 1in 1in, width=\linewidth]{../slope/slope-assessment.pdf}
295
    \label{mean-slope}
296
  }
297
\end{figure}
298
\begin{figure}[h!]
299
  \ContinuedFloat
300
  \centering
301
  \captionsetup{position=top}
302
  \subfloat[Aspect (direction, 0=East)]{
303
    \includegraphics[page=1, trim=1in 1in 1in 1in, width=\linewidth]{../aspect/aspect-assessment.pdf}
304
    \label{mean-aspect}
305
  }\\
306
  \subfloat[Flow (D8 direction, 0=East)]{
307
    \includegraphics[page=1, trim=1in 1in 1in 1in, width=\linewidth]{../flow/flowdir-assessment.pdf}
308
    \label{mean-flow}
309
  }
310
\end{figure}
311

    
312
\paragraph{Summary of findings}
313
\begin{itemize}
314
 \item CDEM itself has problems
315
  \begin{itemize}
316
   \item 60N coincides with provincial boundaries; there are clear 60N
317
     artifacts in this layer!
318
   \item other evident tiling artifacts too
319
  \end{itemize}
320
 \item Big SRTM vs ASTER differences:
321
  \begin{itemize}
322
   \item ASTER is generally lower elevation
323
   \item ASTER has more high-frequency variability ("texture"), which
324
     affects slope/aspect?
325
  \end{itemize}
326
 \item Exponential ramping
327
  \begin{itemize}
328
   \item fixes seam itself
329
   \item leaves dramatic transition in SRTM/ASTER textural differences
330
   \item introduces ridging
331
  \end{itemize}
332
 \item Blending
333
  \begin{itemize}
334
   \item fixes seam itself
335
   \item smooths transition in textural differences
336
  \end{itemize}
337
 \item Other comments
338
  \begin{itemize}
339
   \item Routing is a big ball of wax
340
  \end{itemize}
341
\end{itemize}
342

    
343
\paragraph{To do (possibly)}
344
\begin{itemize}
345
 \item add constant offset to ASTER? or maybe an offset that is a
346
 function of elevation? (revisit LOESS fit)
347
 \item smooth ASTER?
348
\end{itemize}
349

    
350
%TODO: include and discuss the RMSE/correlation plots
351

    
352
%\includepdf[landscape=true,pages=-]{../dem/elevation-assessment.pdf}
353
%\includepdf[landscape=true,pages=-]{../slope/slope-assessment.pdf}
354
%\includepdf[landscape=true,pages=-]{../aspect/aspect-assessment.pdf}
355
%\includepdf[landscape=true,pages=-]{../flow/flowdir-assessment.pdf}
356

    
357
\newpage
358

    
359
\appendix
360

    
361
\lstinputlisting[language=R, caption={R wrapper code for multiresolution
362
    spline}, label=code-enblend]{../dem/enblend.R}
363

    
364
\end{document}
365

    
    (1-1/1)