|
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
|
added GRASS terraflow code plus basic R diagnostics for 60N test case