Project

General

Profile

« Previous | Next » 

Revision 9dcb0aed

Added by Jim Regetz over 13 years ago

  • ID 9dcb0aed23320ab3ae79d18d5a5b4e73864ecdbd

added GRASS terraflow code plus basic R diagnostics for 60N test case

View differences:

terrain/flow/flow-diagnostics.R
1
#
2
# informal concordance analysis of flow accumulation in the 60N boundary
3
# region of Canada
4
#
5
# Jim Regetz
6
# NCEAS
7
# Created on 17-Jun-2011
8

  
9
# data directory (local to xander)
10
datadir <- "~/media/temp/dem/new/flow"
11

  
12
# load flow direction rasters produced by terraflow (mfd)
13
# Canadian DEM
14
fl.can <- raster(file.path(datadir, "flowdir_small.tif"))
15
# uncorrected fused srtm/aster
16
fl.uncor <- raster(file.path(datadir, "flowdir_smc.tif"))
17
# gaussian blended srtm/aster
18
fl.bg <- raster(file.path(datadir, "flowdir_smbg.tif"))
19

  
20
# plot cross-latitude profile of mean direction
21
lats <- yFromRow(fl.uncor, 1:nrow(fl.uncor))
22
plot(lats, rowMeans(as.matrix(fl.uncor), na.rm=TRUE), type="l", lwd=2)
23
lines(lats, rowMeans(as.matrix(fl.bg), na.rm=TRUE), col="red")
24
lines(lats, rowMeans(as.matrix(fl.can), na.rm=TRUE), col="blue")
25
plot(lats, rowMeans(as.matrix(fl.bg==fl.can), na.rm=TRUE), col="red")
26

  
27

  
terrain/flow/grass-terraflow.sh
1
# GRASS commands -- testing some stuff for flow direction
2
#
3
# Jim Regetz
4
# NCEAS
5
# Created 15-Jun-2011
6

  
7
export DEMDIR=~/media/temp/dem/new/flow
8
export OUTDIR=~/media/temp/dem/new/flow
9

  
10
#
11
# Canada 60N test area (small)
12
#
13

  
14
# adjust region to get the resolution exactly right
15
g.region nsres=0:00:03 ewres=0:00:03
16

  
17
# load sample data for testing flow stuff
18
r.in.gdal input=$DEMDIR/fused_small.tif output=fused_small
19
r.in.gdal input=$DEMDIR/fused_small_blendgau.tif output=fused_small_blendgau
20
r.in.gdal input=$DEMDIR/cdem_small.tif output=cdem_small
21

  
22
# oops -- global 3" is too big for terraflow?
23
# let's restrict it to the specific test swatch extent for now...
24
g.region n=60.125 s=59.875 w=-135 e=-134
25

  
26
# do flow -- took ~5 sec on xander (14-Jun-2011)
27
r.terraflow.short elevation=fused_small filled=filled_small \
28
  direction=direction_small swatershed=swatershed_small \
29
  accumulation=accumulation_small tci=tci_small
30
r.terraflow.short elevation=fused_small_blendgau filled=filled_smbg \
31
  direction=direction_smbg swatershed=swatershed_smbg \
32
  accumulation=accumulation_smbg tci=tci_smbg
33
r.terraflow.short elevation=cdem_small filled=filled_smc \
34
  direction=direction_smc swatershed=swatershed_smc \
35
  accumulation=accumulation_smc tci=tci_smc
36

  
37
# now with SFD (D8) algorithm
38
r.terraflow.short -s elevation=fused_small_blendgau filled=filled_smbg_sfd \
39
  direction=direction_smbg_sfd swatershed=swatershed_smbg_sfd \
40
  accumulation=accumulation_smbg_sfd tci=tci_smbg_sfd
41
r.terraflow.short -s elevation=cdem_small filled=filled_smc_sfd \
42
  direction=direction_smc_sfd swatershed=swatershed_smc_sfd \
43
  accumulation=accumulation_smc_sfd tci=tci_smc_sfd
44

  
45
# export flow dir rasters as tif
46
r.out.gdal input=direction_small output=$OUTDIR/flowdir_small.tif
47
r.out.gdal input=direction_smbg output=$OUTDIR/flowdir_smbg.tif
48
r.out.gdal input=direction_smbg_sfd output=$OUTDIR/flowdir_smbg_sfd.tif
49
r.out.gdal input=direction_smc output=$OUTDIR/flowdir_smc.tif
50

  
51
# for fun, map arrows by recoding SFD directions as AGNPS
52
# first recode flowdirs to use AGNPS directional coding
53
r.recode input=direction_smbg_sfd output=agnps_smbg << EOF
54
1:1:3:3
55
2:2:4:4
56
4:4:5:5
57
8:8:6:6
58
16:16:7:7
59
32:32:8:8
60
64:64:1:1
61
128:128:2:2
62
EOF
63
# now make a hillshade map
64
r.shaded.relief map=fused_small_blendgau shadedmap=fused_small_bg_hs \
65
  units=meters
66
d.mon start=x0
67
#g.region n=60:03:00N s=59:59:00N w=134:40:00W e=134:35:00W
68
g.region n=60:05:00N s=59:55:00N w=134:40:00W e=134:30:00W
69
d.erase
70
d.rast fused_small_bg_hs
71
d.rast.arrow map=agnps_smbg type=agnps grid_color=none
72
# add ~5km gridlines, including 60N
73
d.grid -b size=00:02:30 origin=0,60 color=red
74
# write out to png
75
d.out.png output=$OUTDIR/flowarrows_blended_sm.png
76
g.region rast=fused_small_blendgau
77

  
78
# now with canada dem
79
r.recode input=direction_smc_sfd output=agnps_smc << EOF
80
1:1:3:3
81
2:2:4:4
82
4:4:5:5
83
8:8:6:6
84
16:16:7:7
85
32:32:8:8
86
64:64:1:1
87
128:128:2:2
88
EOF
89
r.shaded.relief map=cdem_small shadedmap=cdem_small_hs units=meters
90
d.mon start=x1
91
g.region n=60:05:00N s=59:55:00N w=134:40:00W e=134:30:00W
92
d.erase
93
d.rast cdem_small_hs
94
d.rast.arrow map=agnps_smc type=agnps grid_color=none
95
g.region rast=fused_small_blendgau

Also available in: Unified diff