-
Notifications
You must be signed in to change notification settings - Fork 6
/
Himalaya_topotools.m
233 lines (207 loc) · 7.33 KB
/
Himalaya_topotools.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
%gdalwarp -tr 30 30 -t_srs epsg:32646 -r bilinear -co COMPRESS=DEFLATE -co ZLEVEL=9 demLat_N28_N34_Lon_E075_E082.dem.nc demLat_N28_N34_Lon_E075_E082.UTM46N.WGS84.tif
addpath(genpath('/home/bodo/topotoolbox'))
rmpath(genpath('/home/bodo/topotoolbox\.git'));
%% Load a DEM
dem_fname="TonsYamuna_SRTM1_30m_UTM46N.tif";
NWHim_dem = GRIDobj(dem_fname);
%imagesc(NWHim_dem)
imageschs(NWHim_dem, NWHim_dem)
NWHim_dem_FIL = fillsinks(NWHim_dem);
NWHim_FD = FLOWobj(NWHim_dem_FIL,'preprocess','carve');
NWHim_FAC = flowacc(NWHim_FD);
figure
imageschs(NWHim_dem, log10(NWHim_FAC))
colorbar
title('Drainage Area (log10)');
dem_resolution = NWHim_dem.refmat(2,1);
% get the DEM resolution, used to convert area threshold to meters squared
area_threshold = 1e6
minApix = area_threshold/(dem_resolution*dem_resolution);
minApix = ceil(minApix); % convert area threshold to meters specified above
NWHim_FAC_w = NWHim_FAC > minApix; % masks flow accum grid (above threshold)
NWHim_rivers_w = NWHim_FAC.*(NWHim_FAC.cellsize.^2) > ...
area_threshold;
NWHim_STR_w = STREAMobj(NWHim_FD, NWHim_FAC_w);
NWHim_rivers_STR = STREAMobj(NWHim_FD, NWHim_rivers_w);
%% extract largest catchment and plot
NWHim_rivers_STR = klargestconncomps(NWHim_rivers_STR, 1);
figure
clf
subplot(2,1,1)
imageschs(NWHim_dem, NWHim_dem, ...
'ticklabels','nice','colorbar',true)
ylabel('UTM-Northing (m)', 'Fontsize', 12);
xlabel('UTM-Easting (m)', 'Fontsize', 12);
hold on
plot(NWHim_rivers_STR, 'k')
title('Tons-Yamuna River')
subplot(2,1,2)
plotdz(NWHim_rivers_STR, NWHim_dem, 'color', 'k', 'linewidth', 0.5)
hold on
plotdz(trunk(NWHim_rivers_STR),NWHim_dem, 'color', 'b', 'linewidth', 3)
%%
[NWHim_dbasins, NWHim_dbasins_outlet] = drainagebasins(NWHim_FD, NWHim_rivers_STR);
%tons_catchment=-964626.971,3476597.7401
[tons_x, tons_y] = snap2stream(NWHim_rivers_STR,-964626.971,3476597.7401)
[tons_dbasins, tons_dbasins_outlet] = ...
drainagebasins(NWHim_FD, tons_x, tons_y);
tons_dbasins.Z = logical(tons_dbasins.Z)
Tons_river_mask = and(NWHim_rivers_w, tons_dbasins);
%mask out Tons basin:
Tons_rivers_STR = STREAMobj(NWHim_FD, Tons_river_mask);
%replot only Tons
figure
clf
subplot(2,1,1)
imageschs(NWHim_dem, NWHim_dem, ...
'ticklabels','nice','colorbar',true)
ylabel('UTM-Northing (m)', 'Fontsize', 12);
xlabel('UTM-Easting (m)', 'Fontsize', 12);
hold on
plot(Tons_rivers_STR, 'k')
title('Tons River')
subplot(2,1,2)
plotdz(Tons_rivers_STR, NWHim_dem, 'color', 'k', 'linewidth', 0.5)
hold on
plotdz(trunk(Tons_rivers_STR),NWHim_dem, 'color', 'b', 'linewidth', 3)
%% calculate slope and area from DEM
% set a minimum gradient (no place in DEM has a slope of 0)
min_str_gradient = 5e-3;
NWHim_mg = imposemin(NWHim_FD, NWHim_dem, min_str_gradient);
NWHim_rivers_slope = gradient(NWHim_rivers_STR,NWHim_mg,'unit','tangent');
NWHim_rivers_area = NWHim_FAC.Z(NWHim_rivers_STR.IXgrid).*...
(NWHim_FAC.cellsize).^2;
NWHim_rivers_slope_5eminus3 = ...
find(NWHim_rivers_slope < 4e-3);
NWHim_rivers_slope(NWHim_rivers_slope_5eminus3) = [];
NWHim_rivers_area(NWHim_rivers_slope_5eminus3) = [];
%use slopearea function
%calculate area-slope relation for entire area (may not be useful)
NWHim_slopearea = ...
slopearea(NWHim_rivers_STR, NWHim_mg,...
NWHim_FAC, ...
'areabinlocs', 'median', ...
'gradaggfun', 'median', ...
'streamgradient', 'robust', ...
'mingradient', 1e-2, ...
'plot', false, ...
'areabins', 50);
%% Figures
figure;
subplot(1,2,1)
loglog(NWHim_rivers_area, NWHim_rivers_slope, ...
'.', 'color', [0.8 0.8 0.8])
xlabel('Drainage Area [m^2]')
ylabel('Slope [m/m]')
grid on
hold on
loglog(NWHim_slopearea.a, ...
NWHim_slopearea.g, ...
'ks', 'markersize' ,5)
aeval = logspace(log10(min(NWHim_slopearea.a)),log10(max(NWHim_slopearea.a)),10);
geval = NWHim_slopearea.ks(1)*aeval.^NWHim_slopearea.theta;
loglog(aeval, geval, 'k-', 'linewidth', 2)
title(['Yons-Tamuna all data, \theta=',num2str(NWHim_slopearea.theta,2),' and ks=',num2str(NWHim_slopearea.ks,3)])
subplot(1,2,2)
loglog(NWHim_rivers_area, ...
NWHim_rivers_slope, '.', ...
'color', [0.8 0.8 0.8])
xlabel('Drainage Area [m^2]')
ylabel('Slope [m/m]')
grid on
hold on
NWHim_slopearea = ...
slopearea(NWHim_rivers_STR, NWHim_mg,...
NWHim_FAC, ...
'areabinlocs', 'median', ...
'gradaggfun', 'median', ...
'streamgradient', 'robust', ...
'hist2', false, ...
'mingradient', 1e-2, ...
'plot', false, ...
'areabins', 50, ...
'theta', 0.45);
loglog(NWHim_slopearea.a, ...
NWHim_slopearea.g, ...
'ks', 'markersize' ,5)
% more flexible fitting of regression
% [beta,R,J,CovB,MSE,ErrorModelInfo] = ...
% nlinfit(NWHim_slopearea.a,NWHim_slopearea.g,@(b,x) ...
% b(1)*x.^b(2),[NWHim_slopearea.ks NWHim_slopearea.theta]);
%
%or use a graphical interface:
%nlintool(NWHim_slopearea.a,NWHim_slopearea.g,@(b,x) b(1)*x.^b(2),[NWHim_slopearea.ks NWHim_slopearea.theta],0.05,...
% 'area','gradient')
aeval = logspace(log10(min(NWHim_slopearea.a)),log10(max(NWHim_slopearea.a)),10);
geval = NWHim_slopearea.ks(1)*aeval.^NWHim_slopearea.theta;
loglog(aeval, geval, 'k-', 'linewidth', 2)
title(['Yons-Tamuna all data, \theta=',num2str(NWHim_slopearea.theta,2),' and ks=',num2str(NWHim_slopearea.ks,3)])
%% Steepness index for Tons River
Tons_rivers_slope = gradient(Tons_rivers_STR,NWHim_mg,'unit','tangent');
Tons_rivers_area = NWHim_FAC.Z(Tons_rivers_STR.IXgrid).*...
(NWHim_FAC.cellsize).^2;
Tons_rivers_slope_5eminus3 = ...
find(Tons_rivers_slope < 4e-3);
Tons_rivers_slope(Tons_rivers_slope_5eminus3) = [];
Tons_rivers_area(Tons_rivers_slope_5eminus3) = [];
%use slopearea function
%calculate area-slope relation for entire area (may not be useful)
Tons_slopearea = ...
slopearea(Tons_rivers_STR, NWHim_mg,...
NWHim_FAC, ...
'areabinlocs', 'median', ...
'gradaggfun', 'median', ...
'streamgradient', 'robust', ...
'mingradient', 1e-2, ...
'plot', false, ...
'areabins', 50);
figure;
loglog(Tons_rivers_area, Tons_rivers_slope, ...
'.', 'color', [0.8 0.8 0.8])
xlabel('Drainage Area [m^2]')
ylabel('Slope [m/m]')
grid on
hold on
loglog(Tons_slopearea.a, ...
Tons_slopearea.g, ...
'ks', 'markersize' ,5)
aeval = logspace(log10(min(Tons_slopearea.a)),log10(max(Tons_slopearea.a)),10);
geval = Tons_slopearea.ks(1)*aeval.^Tons_slopearea.theta;
loglog(aeval, geval, 'k-', 'linewidth', 2)
title(['Tons-Parbati data, \theta=',num2str(Tons_slopearea.theta,2),' and ks=',num2str(Tons_slopearea.ks,3)])
%% Generate a map of steepness indices
NWHim_slopearea = ...
slopearea(NWHim_rivers_STR, NWHim_mg,...
NWHim_FAC, ...
'areabinlocs', 'median', ...
'gradaggfun', 'median', ...
'streamgradient', 'robust', ...
'mingradient', 1e-2, ...
'plot', false, ...
'areabins', 50);
g = gradient(NWHim_rivers_STR, NWHim_dem);
a = getnal(NWHim_rivers_STR, NWHim_FAC)*NWHim_FAC.cellsize^2;
NWHim_ksn = g./(a.^NWHim_slopearea.theta);
NWHim_ksna = aggregate(NWHim_rivers_STR,...
NWHim_ksn,'seglength',1000);
figure
imageschs(NWHim_dem,[],...
'ticklabels','nice', ...
'colormap',[.8 .8 .8],...
'colorbar',false);
hold on
plotc(NWHim_rivers_STR, NWHim_ksna, ...
'linewidth', 2)
caxis([0 300])
h = colorbar;
colormap(jet)
h.Label.String = 'KSn';
box on
axis image
%% Chiplot
c = chiplot(Tons_rivers_STR,NWHim_dem,...
NWHim_FAC,...
'mnplot', false, ...
'fitto', 'ts', ...
'trunkstream', trunk(Tons_rivers_STR), ...
'a0', 1e6);