Revision 4101796f
Added by Rick Reeves over 13 years ago
- ID 4101796f494583beaccd181018b78e103754ca60
terrain/rscripts/CreateImageDiffPlotsOverlayNewPlots.R | ||
---|---|---|
11 | 11 |
# 1) Comma Separated Value (CSV) table containing randomly-sampled elevation value pairs, |
12 | 12 |
# extracted from ASTER/CGIAR mosaic and CDEM images, created by the R script: makeImagePairTable.r |
13 | 13 |
# Note: At present, be sure that this file has been sorted by column 1 (ColumnID) in Excel |
14 |
# before using in this program. |
|
14 |
# before using in this program. |
|
15 |
# NOTE: This filename is set in the body of the script. |
|
15 | 16 |
# |
16 | 17 |
# 2) sampling factor: integer (range=1 to number of recors in input table. Determines |
17 | 18 |
# the size of randomly-selected sampe of total table record 'triplets' (north, border, |
... | ... | |
19 | 20 |
# sampling factor = 1 : plot every table record |
20 | 21 |
# 10 : plot a random sample containing 1/10th of records |
21 | 22 |
# 100 : plot random sample containing 1/100th of records. |
22 |
# |
|
23 |
# 3) JpgPlotFileFlag: Set to TRUE to have *individual* plots written to JPG files. |
|
24 |
# |
|
23 | 25 |
# To run: |
24 | 26 |
# |
25 | 27 |
# 1) place this file and the input file "tableForMark4000_5_8_SortColID.csv" in folder |
... | ... | |
32 | 34 |
# Author: Rick Reeves, NCEAS |
33 | 35 |
# May 14, 2011 |
34 | 36 |
# May 17, 2011: This version generates 'delta scatterplots' specified by Mark and Jim. |
37 |
# May 18, 2011: If JpgPlotFlag set, write individual plot files to JPG files. |
|
35 | 38 |
############################################################################################## |
36 |
CreateImageDiffPlots <- function(plotSampFact = 1) |
|
39 |
CreateImageDiffPlots <- function(plotSampFact = 1,JpgPlotFileFlag = TRUE)
|
|
37 | 40 |
{ |
38 |
# Check plotSampleFact range |
|
41 |
|
|
42 |
# Check plotSampleFact range |
|
39 | 43 |
|
40 | 44 |
if (plotSampFact < 1) |
41 | 45 |
plotSampFact = 1 |
42 | 46 |
|
43 |
# if (plotSampFact > ) |
|
44 |
# plotSampFact = 100 |
|
45 |
|
|
46 | 47 |
# Read input table that was sorted OFFLINE in Excel on the first column (ColumnID) |
47 | 48 |
|
48 |
pointTable <-read.csv("pixelPairs36000_5_8EvenSortCol1.csv")
|
|
49 |
pointTable <-read.csv("pixelPairs36000_5_8_TS.csv")
|
|
49 | 50 |
# Table created by randomly sampling from two superimposed |
50 | 51 |
# image: |
51 | 52 |
# 1) DOM mosaic image comprised of ASTER and SRTM components. |
... | ... | |
136 | 137 |
|
137 | 138 |
# We need to tailor the plot 'triplet' X and Y axes to the dynamic ranges of all three data sets. |
138 | 139 |
|
139 |
|
|
140 |
|
|
141 | 140 |
# Create values for the three 'delta across pixel boundaries' plots: |
142 | 141 |
# 1) Y-Axis: columnIDs |
143 | 142 |
# 2) Y-Axis: CDEM elevations |
... | ... | |
151 | 150 |
normDeltaBoundaryBorder <- (deltaBoundaryBorder / borderRowTbl$cdemNorth * 100) |
152 | 151 |
normDeltaBoundarySRTM <- (deltaBoundarySRTM / southRowTbl$cdemNorth * 100) |
153 | 152 |
|
154 |
par(mfrow=c(1,3)) # Create a three column multi-plot
|
|
153 |
par(mfrow=c(3,1)) # Create a set of three column multi-plots
|
|
155 | 154 |
|
156 | 155 |
commonXAxis <- c(0,max(pointTable$ColumnID)) |
157 | 156 |
commonYAxis <- range(c(deltaBoundarySRTM,deltaBoundaryBorder,deltaBoundaryASTER),na.rm=TRUE) |
158 |
|
|
157 |
|
|
159 | 158 |
xAxisLbl <- sprintf("M/SD: ASTER: %.2f / %.2f",mean(deltaBoundaryASTER,na.rm=TRUE),sd(deltaBoundaryASTER,na.rm=TRUE)) |
160 | 159 |
plot(northRowTbl$ColumnID,deltaBoundaryASTER,xlim=commonXAxis, ylim=commonYAxis,main="Row Boundary Delta: ASTER",xlab=xAxisLbl,col="red",pch=plotCh1) |
161 |
|
|
162 | 160 |
xAxisLbl <- sprintf("M/SD: BORDER: %.2f / %.2f",mean(deltaBoundaryBorder,na.rm=TRUE),sd(deltaBoundaryBorder,na.rm=TRUE)) |
163 | 161 |
plot(northRowTbl$ColumnID,deltaBoundaryBorder,xlim=commonXAxis, ylim=commonYAxis,main="Row Boundary Delta: Border",sub="E-W Col",xlab=xAxisLbl,col="darkgreen",pch=plotCh2) |
164 |
|
|
165 | 162 |
xAxisLbl <- sprintf("M/SD: SRTM: %.2f / %.2f",mean(deltaBoundarySRTM,na.rm=TRUE),sd(deltaBoundarySRTM,na.rm=TRUE)) |
166 |
plot(northRowTbl$ColumnID,deltaBoundarySRTM,main="Row Boundary Delta: SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
|
167 |
|
|
163 |
plot(northRowTbl$ColumnID,deltaBoundarySRTM,main="Boundary Delta: SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
|
168 | 164 |
message("ColumnID-X-Axis is done") |
169 | 165 |
browser() |
170 | 166 |
#dev.new() |
171 |
|
|
172 |
par(mfrow=c(1,3)) # Create a three column multi-plot pointTable$diffNorthMosaicCDEM/pointTable$elevNorth * 100)) |
|
167 |
# par(mfrow=c(3,1)) # Create a three column multi-plot pointTable$diffNorthMosaicCDEM/pointTable$elevNorth * 100)) |
|
173 | 168 |
|
174 | 169 |
commonXAxis <- c(0,max(pointTable$cdemNorth)) |
175 | 170 |
commonYAxis <- range(c(deltaBoundarySRTM,deltaBoundaryBorder,deltaBoundaryASTER),na.rm=TRUE) |
176 | 171 |
|
177 | 172 |
xAxisLbl <- sprintf("M/SD: ASTER: %.2f / %.2f",mean(deltaBoundaryASTER,na.rm=TRUE),sd(deltaBoundaryASTER,na.rm=TRUE)) |
178 | 173 |
plot(northRowTbl$cdemNorth,deltaBoundaryASTER,xlim=commonXAxis, ylim=commonYAxis,main="Boundary Delta (CDEM Elev): ASTER",xlab=xAxisLbl,col="red",pch=plotCh1) |
179 |
|
|
180 | 174 |
xAxisLbl <- sprintf("M/SD: BORDER: %.2f / %.2f",mean(deltaBoundaryBorder,na.rm=TRUE),sd(deltaBoundaryBorder,na.rm=TRUE)) |
181 | 175 |
plot(northRowTbl$cdemNorth,deltaBoundaryBorder,xlim=commonXAxis, ylim=commonYAxis,main="Boundary Delta (CDEM Elev): Border",sub="vs Elev",xlab=xAxisLbl,col="darkgreen",pch=plotCh2) |
182 |
|
|
183 | 176 |
xAxisLbl <- sprintf("M/SD: SRTM: %.2f / %.2f",mean(deltaBoundarySRTM,na.rm=TRUE),sd(deltaBoundarySRTM,na.rm=TRUE)) |
184 | 177 |
plot(northRowTbl$cdemNorth,deltaBoundarySRTM,main="Boundary Delta (CDEM Elev): SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
185 | 178 |
message("ColumnID-CDEM Elevation done") |
186 | 179 |
browser() |
187 | 180 |
commonXAxis <- c(0,max(pointTable$cdemNorth)) |
188 | 181 |
commonYAxis <- range(c(normDeltaBoundarySRTM,normDeltaBoundaryBorder,normDeltaBoundaryASTER),na.rm=TRUE) |
189 |
|
|
190 | 182 |
xAxisLbl <- sprintf("M/SD: ASTER: %.2f / %.2f",mean(normDeltaBoundaryASTER,na.rm=TRUE),sd(normDeltaBoundaryASTER,na.rm=TRUE)) |
191 | 183 |
plot(northRowTbl$cdemNorth,normDeltaBoundaryASTER,xlim=commonXAxis, ylim=commonYAxis,main="Norm Bdry Delta (CDEM Elev): ASTER",xlab=xAxisLbl,col="red",pch=plotCh1) |
192 |
|
|
193 | 184 |
xAxisLbl <- sprintf("M/SD: BORDER: %.2f / %.2f",mean(normDeltaBoundaryBorder,na.rm=TRUE),sd(normDeltaBoundaryBorder,na.rm=TRUE)) |
194 | 185 |
plot(northRowTbl$cdemNorth,normDeltaBoundaryBorder,xlim=commonXAxis, ylim=commonYAxis,main="Norm Bdry Delta (CDEM Elev): Border",sub="vs Elev",xlab=xAxisLbl,col="darkgreen",pch=plotCh2) |
195 |
|
|
196 | 186 |
xAxisLbl <- sprintf("M/SD: SRTM: %.2f / %.2f",mean(normDeltaBoundarySRTM,na.rm=TRUE),sd(normDeltaBoundarySRTM,na.rm=TRUE)) |
197 | 187 |
plot(northRowTbl$cdemNorth,normDeltaBoundarySRTM,main="Norm Bdry Delta (CDEM Elev): SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
198 | 188 |
message("NORMALIZED ColumnID-CDEM Elevation done") |
... | ... | |
202 | 192 |
|
203 | 193 |
xAxisLbl <- sprintf("M/SD: ASTER: %.2f / %.2f",mean(normDeltaBoundaryASTER,na.rm=TRUE),sd(normDeltaBoundaryASTER,na.rm=TRUE)) |
204 | 194 |
plot(northRowTbl$ColumnID,normDeltaBoundaryASTER,xlim=commonXAxis, ylim=commonYAxis,main="Norm Bdry Delta: ASTER",xlab=xAxisLbl,col="red",pch=plotCh1) |
205 |
|
|
206 | 195 |
xAxisLbl <- sprintf("M/SD: BORDER: %.2f / %.2f",mean(normDeltaBoundaryBorder,na.rm=TRUE),sd(normDeltaBoundaryBorder,na.rm=TRUE)) |
207 | 196 |
plot(northRowTbl$ColumnID,normDeltaBoundaryBorder,xlim=commonXAxis, ylim=commonYAxis,main="Norm Bdry Delta: Border",sub="E-W Col",xlab=xAxisLbl,col="darkgreen",pch=plotCh2) |
208 |
|
|
209 | 197 |
xAxisLbl <- sprintf("M/SD: SRTM: %.2f / %.2f",mean(normDeltaBoundarySRTM,na.rm=TRUE),sd(normDeltaBoundarySRTM,na.rm=TRUE)) |
210 | 198 |
plot(northRowTbl$ColumnID,normDeltaBoundarySRTM,main="Norm Bdry Delta: SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
211 |
|
|
212 | 199 |
message("NORMALIZED ColumnID-X-Axis is done...") |
200 |
|
|
201 |
# if 'plot flag' is set, send the plots to a JPG file. |
|
202 |
|
|
203 |
if (JpgPlotFileFlag) |
|
204 |
{ |
|
205 |
message("creating JPG plot files...") |
|
206 |
browser() |
|
207 |
jpeg(file="RowBoundaryDeltaColIDXAxisASTER.jpg") |
|
208 |
xAxisLbl <- sprintf("M/SD: ASTER: %.2f / %.2f",mean(deltaBoundaryASTER,na.rm=TRUE),sd(deltaBoundaryASTER,na.rm=TRUE)) |
|
209 |
plot(northRowTbl$ColumnID,deltaBoundaryASTER,xlim=commonXAxis, ylim=commonYAxis,main="Row Boundary Delta: ASTER",xlab=xAxisLbl,col="red",pch=plotCh1) |
|
210 |
dev.off() |
|
211 |
jpeg(file="RowBoundaryDeltaColIDXAxisBORDER.jpg") |
|
212 |
xAxisLbl <- sprintf("M/SD: BORDER: %.2f / %.2f",mean(deltaBoundaryBorder,na.rm=TRUE),sd(deltaBoundaryBorder,na.rm=TRUE)) |
|
213 |
plot(northRowTbl$ColumnID,deltaBoundaryBorder,xlim=commonXAxis, ylim=commonYAxis,main="Row Boundary Delta: Border",sub="E-W Col",xlab=xAxisLbl,col="darkgreen",pch=plotCh2) |
|
214 |
dev.off() |
|
215 |
jpeg(file="RowBoundaryDeltaColIDXAxisSRTM.jpg") |
|
216 |
xAxisLbl <- sprintf("M/SD: SRTM: %.2f / %.2f",mean(deltaBoundarySRTM,na.rm=TRUE),sd(deltaBoundarySRTM,na.rm=TRUE)) |
|
217 |
plot(northRowTbl$ColumnID,deltaBoundarySRTM,main="Row Boundary Delta: SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
|
218 |
message("ColumnID-X-Axis plots are done") |
|
219 |
#dev.new() |
|
220 |
commonXAxis <- c(0,max(pointTable$cdemNorth)) |
|
221 |
commonYAxis <- range(c(deltaBoundarySRTM,deltaBoundaryBorder,deltaBoundaryASTER),na.rm=TRUE) |
|
222 |
jpeg(file="RowBoundaryDeltaCDEMElevXAxisASTER.jpg") |
|
223 |
xAxisLbl <- sprintf("M/SD: ASTER: %.2f / %.2f",mean(deltaBoundaryASTER,na.rm=TRUE),sd(deltaBoundaryASTER,na.rm=TRUE)) |
|
224 |
plot(northRowTbl$cdemNorth,deltaBoundaryASTER,xlim=commonXAxis, ylim=commonYAxis,main="Boundary Delta (CDEM Elev): ASTER",xlab=xAxisLbl,col="red",pch=plotCh1) |
|
225 |
dev.off() |
|
226 |
jpeg(file="RowBoundaryDeltaCDEMElevXAxisBORDER.jpg") |
|
227 |
xAxisLbl <- sprintf("M/SD: BORDER: %.2f / %.2f",mean(deltaBoundaryBorder,na.rm=TRUE),sd(deltaBoundaryBorder,na.rm=TRUE)) |
|
228 |
plot(northRowTbl$cdemNorth,deltaBoundaryBorder,xlim=commonXAxis, ylim=commonYAxis,main="Boundary Delta (CDEM Elev): Border",sub="vs Elev",xlab=xAxisLbl,col="darkgreen",pch=plotCh2) |
|
229 |
dev.off() |
|
230 |
jpeg(file="RowBoundaryDeltaCDEMElevXAxisCDEM.jpg") |
|
231 |
xAxisLbl <- sprintf("M/SD: SRTM: %.2f / %.2f",mean(deltaBoundarySRTM,na.rm=TRUE),sd(deltaBoundarySRTM,na.rm=TRUE)) |
|
232 |
plot(northRowTbl$cdemNorth,deltaBoundarySRTM,main="Boundary Delta (CDEM Elev): SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
|
233 |
dev.off() |
|
234 |
message("ColumnID-CDEM Elevation Plots are done") |
|
235 |
#browser() |
|
236 |
commonXAxis <- c(0,max(pointTable$cdemNorth)) |
|
237 |
commonYAxis <- range(c(normDeltaBoundarySRTM,normDeltaBoundaryBorder,normDeltaBoundaryASTER),na.rm=TRUE) |
|
238 |
jpeg(file="NormRowBoundaryDeltaColIDXAxisASTER.jpg") |
|
239 |
xAxisLbl <- sprintf("M/SD: ASTER: %.2f / %.2f",mean(normDeltaBoundaryASTER,na.rm=TRUE),sd(normDeltaBoundaryASTER,na.rm=TRUE)) |
|
240 |
plot(northRowTbl$cdemNorth,normDeltaBoundaryASTER,xlim=commonXAxis, ylim=commonYAxis,main="Norm Bdry Delta (CDEM Elev): ASTER",xlab=xAxisLbl,col="red",pch=plotCh1) |
|
241 |
dev.off() |
|
242 |
jpeg(file="NormRowBoundaryDeltaColIDXAxisBORDER.jpg") |
|
243 |
xAxisLbl <- sprintf("M/SD: BORDER: %.2f / %.2f",mean(normDeltaBoundaryBorder,na.rm=TRUE),sd(normDeltaBoundaryBorder,na.rm=TRUE)) |
|
244 |
plot(northRowTbl$cdemNorth,normDeltaBoundaryBorder,xlim=commonXAxis, ylim=commonYAxis,main="Norm Bdry Delta (CDEM Elev): Border",sub="vs Elev",xlab=xAxisLbl,col="darkgreen",pch=plotCh2) |
|
245 |
dev.off() |
|
246 |
jpeg(file="NormRowBoundaryDeltaColIDXAxisSRTM.jpg") |
|
247 |
xAxisLbl <- sprintf("M/SD: SRTM: %.2f / %.2f",mean(normDeltaBoundarySRTM,na.rm=TRUE),sd(normDeltaBoundarySRTM,na.rm=TRUE)) |
|
248 |
plot(northRowTbl$cdemNorth,normDeltaBoundarySRTM,main="Norm Bdry Delta (CDEM Elev): SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
|
249 |
dev.off() |
|
250 |
message("NORMALIZED ColumnID-CDEM Elevation Plots are done") |
|
251 |
browser() |
|
252 |
commonXAxis <- c(0,max(pointTable$ColumnID)) |
|
253 |
commonYAxis <- range(c(normDeltaBoundarySRTM,normDeltaBoundaryBorder,normDeltaBoundaryASTER),na.rm=TRUE) |
|
254 |
jpeg(file="NormRowBoundaryDeltaCDEMElevXAxisASTER.jpg") |
|
255 |
xAxisLbl <- sprintf("M/SD: ASTER: %.2f / %.2f",mean(normDeltaBoundaryASTER,na.rm=TRUE),sd(normDeltaBoundaryASTER,na.rm=TRUE)) |
|
256 |
plot(northRowTbl$ColumnID,normDeltaBoundaryASTER,xlim=commonXAxis, ylim=commonYAxis,main="Norm Bdry Delta: ASTER",xlab=xAxisLbl,col="red",pch=plotCh1) |
|
257 |
dev.off() |
|
258 |
jpeg(file="NormRowBoundaryDeltaCDEMElevXAxisBORDER.jpg") |
|
259 |
xAxisLbl <- sprintf("M/SD: BORDER: %.2f / %.2f",mean(normDeltaBoundaryBorder,na.rm=TRUE),sd(normDeltaBoundaryBorder,na.rm=TRUE)) |
|
260 |
plot(northRowTbl$ColumnID,normDeltaBoundaryBorder,xlim=commonXAxis, ylim=commonYAxis,main="Norm Bdry Delta: Border",sub="E-W Col",xlab=xAxisLbl,col="darkgreen",pch=plotCh2) |
|
261 |
dev.off() |
|
262 |
jpeg(file="NormRowBoundaryDeltaCDEMElevXAxisSRTM.jpg") |
|
263 |
xAxisLbl <- sprintf("M/SD: SRTM: %.2f / %.2f",mean(normDeltaBoundarySRTM,na.rm=TRUE),sd(normDeltaBoundarySRTM,na.rm=TRUE)) |
|
264 |
plot(northRowTbl$ColumnID,normDeltaBoundarySRTM,main="Norm Bdry Delta: SRTM",xlim=commonXAxis, ylim=commonYAxis,xlab=xAxisLbl,col="blue",pch=plotCh3) |
|
265 |
dev.off() |
|
266 |
message("NORMALIZED ColumnID-X-Axis Plot files have been created..") |
|
267 |
} |
|
213 | 268 |
message("...All plots created - hit key to delete them...") |
214 | 269 |
browser() |
215 | 270 |
graphics.off() |
Also available in: Unified diff
Added option: write individual plots (not trplets - yet) to separate JPG files. New command line argument: JpgPlotFileFlag