forked from amforte/Topographic-Analysis-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeCombinedSwath.m
460 lines (371 loc) · 14.1 KB
/
MakeCombinedSwath.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
function [SW,SwathMat,xypoints,outData]=MakeCombinedSwath(DEM,points,width,sample,smooth,data_type,data,data_width)
% Function requires TopoToolbox to run
%
% Required Inputs:
% DEM - DEM Grid Object with which to make topo swath
% points - n x 2 matrix containing x,y points for swath, minimum are two points (start and end points).
% First row contains starting point and proceeds down rows, additional points besides a start and end are
% treated as bends in the swath. Coordinates for points must be in the same coordinate system as DEM and must
% lie within the DEM (cannot be coordinates on the very edge of the DEM)
% width - width of swath in map units
% sample - resampling distance along swath in map units, provide DEM.cellsize for no resampling, where DEM is the name of the
% DEM GRIDobj.
% smooth - smoothing distance, width of filter in map units over which to smooth values, provie 0 if no smoothing is desired
% data_type - the type of additional data you are providing to plot along with the swath, supported inputs are:
% 'points3' - generic point dataset, expects a n x 3 matrix with values of x, y, and z
% 'points4' - generic point dataset, expects a n x 4 matrix with values of x, y, z, and extra value. Dots will be sclaed by this extra value
% 'eqs' - earthquakes, expects a n x 4 matrix with x, y, depth, and magnitude. Points will be scaled by magnitude and colored by distance from swath line
% 'ksn_chandata' - will plot swath through ksn values, expects a chandata file from Profiler
% 'ksn_TT' - will plot swath through ksn values, expects output from KSN_TT function
% 'chi_TT' - will plot swath through chi values, expects output of TopoToolbox chiplot function
% data_width - width in map units of swath through provided data. Values greater than data_width/2 from the center line of the toposwath will be removed
%
% Outputs:
% SW - TopoToolbox Swath object, contains various information as a structure. Can plot path and box of swath with plot(SW) and
% plot version of swath profile with plotdz(SW);
% SwathMat - n x 4 matrix containing distance along the swath, min elevation, mean elevation, max elevation
% xypoints - n x 2 matrix containing x,y points of each swath sample point, along swath center line
% outData - data for plotting the swath through the provided data, form of output depends on data_type:
% 'points3' - distances, elev, distance from base line, x coordinate, y coordinate, transformed x coordinate, transformed y coordinate
% 'points4' - distances, elev, value, distance from base line, x coordinate, y coordinate, transformed x coordinate, transformed y coordinate
% 'eqs' - distances, depth, magnitude, distance from base line, x coordinate, y coordinate, transformed x coordinate, transformed y coordinate
% 'ksn_chandata' - distances, elev, ksn, distance from base line, x coordinate, y coordinate, transformed x coordinate, transformed y coordinate
% 'ksn_TT' - distances, ksn, distance from base line, x coordinate, y coordinate, transformed x coordinate, transformed y coordinate
% 'chi_TT' - distances, chi, distance from base line, x coordinate, y coordinate, transformed x coordinate, transformed y coordinate
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function Written by Adam M. Forte - Last Revised Fall 2015 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Produce topo swath and associated datasets
[SW,SwathMat,xypoints,bends]=MakeTopoSwath(DEM,points,width,sample,smooth,'false');
sw_y=xypoints(:,2);
sw_x=xypoints(:,1);
[nsw_x,nsw_y]=ReFrameRot(SW,sw_x,sw_y);
swdist=SwathMat(:,1);
min_elevs=SwathMat(:,2);
mean_elevs=SwathMat(:,3);
max_elevs=SwathMat(:,4);
% Perform different procedures depending on the type of data provided
switch data_type
case 'points3'
x_coord=data(:,1);
y_coord=data(:,2);
z=data(:,3);
% Transform data
[n_x,n_y]=ReFrameRot(SW,x_coord,y_coord);
% Find distances along swath profile of each point
num_points=numel(x_coord);
point_distances=zeros(num_points,1);
DistFromBaseLine=zeros(num_points,1);
for ii=1:num_points
xoi=n_x(ii);
distances=nsw_x-xoi;
[~,I]=min(abs(distances));
point_distances(ii)=swdist(I);
baseLine=nsw_y(I);
DistFromBaseLine(ii)=abs(baseLine-n_y(ii));
end
outData=[point_distances z DistFromBaseLine x_coord y_coord n_x n_y];
% Filter out any data points outside of provided width
idx=DistFromBaseLine<=(data_width/2);
outData=outData(idx,:);
% Plot Swath
f1=figure(1);
clf
set(f1,'Units','inches','Position',[1.0 1.5 16 4],'renderer','painters','PaperSize',[16 4],'PaperOrientation','portrait','PaperPositionMode','auto');
hold on
plot(swdist,min_elevs,'-b');
plot(swdist,max_elevs,'-b');
plot(swdist,mean_elevs,'-k');
for jj=1:numel(bends)
vline(bends(jj),'k','bend');
end
scatter(outData(:,1),outData(:,2),20,'k','filled');
xlabel('Distance along swath (m)');
ylabel('Elevation (m)');
xlim([0 max(swdist)]);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'points4'
x_coord=data(:,1);
y_coord=data(:,2);
z=data(:,3);
scale=data(:,4);
% Transform data
[n_x,n_y]=ReFrameRot(SW,x_coord,y_coord);
% Find distances along swath profile of each point
num_points=numel(x_coord);
point_distances=zeros(num_points,1);
DistFromBaseLine=zeros(num_points,1);
for ii=1:num_points
xoi=n_x(ii);
distances=nsw_x-xoi;
[~,I]=min(abs(distances));
point_distances(ii)=swdist(I);
baseLine=nsw_y(I);
DistFromBaseLine(ii)=abs(baseLine-n_y(ii));
end
outData=[point_distances z scale DistFromBaseLine x_coord y_coord n_x n_y];
% Filter out any data points outside of provided width
idx=DistFromBaseLine<=(data_width/2);
outData=outData(idx,:);
% Plot Swath
f1=figure(1);
clf
set(f1,'Units','inches','Position',[1.0 1.5 16 4],'renderer','painters','PaperSize',[16 4],'PaperOrientation','portrait','PaperPositionMode','auto');
hold on
plot(swdist,min_elevs,'-b');
plot(swdist,max_elevs,'-b');
plot(swdist,mean_elevs,'-k');
for jj=1:numel(bends)
vline(bends(jj),'k','bend');
end
scatter(outData(:,1),outData(:,2),outData(:,3),'k','filled');
xlabel('Distance along swath (m)');
ylabel('Elevation (m)');
xlim([0 max(swdist)]);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'eqs'
x_coord=data(:,1);
y_coord=data(:,2);
depth=data(:,3);
magnitude=data(:,4);
% Transform data
[n_x,n_y]=ReFrameRot(SW,x_coord,y_coord);
% Find distances along swath profile of each point
num_points=numel(x_coord);
point_distances=zeros(num_points,1);
DistFromBaseLine=zeros(num_points,1);
for ii=1:num_points
xoi=n_x(ii);
distances=nsw_x-xoi;
[~,I]=min(abs(distances));
point_distances(ii)=swdist(I);
baseLine=nsw_y(I);
DistFromBaseLine(ii)=abs(baseLine-n_y(ii));
end
outData=[point_distances depth magnitude DistFromBaseLine x_coord y_coord n_x n_y];
% Filter out any data points outside of provided width
idx=DistFromBaseLine<=(data_width/2);
outData=outData(idx,:);
% Plot Swath
f1=figure(1);
clf
set(f1,'Units','inches','Position',[1.0 1.5 16 6],'renderer','painters','PaperSize',[16 6],'PaperOrientation','portrait','PaperPositionMode','auto');
hold on
plot(swdist,min_elevs,'-b');
plot(swdist,max_elevs,'-b');
plot(swdist,mean_elevs,'-k');
for jj=1:numel(bends)
vline(bends(jj),'k','bend');
end
scatter(outData(:,1),outData(:,2),outData(:,3),outData(:,4),'filled');
xlabel('Distance along swath (m)');
ylabel('Elevation (m)');
xlim([0 max(swdist)]);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'ksn_chandata'
x_coord=data(:,9);
y_coord=data(:,10);
ksn=data(:,8);
elev=data(:,4);
% Transform data
[n_x,n_y]=ReFrameRot(SW,x_coord,y_coord);
% Find distances along swath profile of each point
num_points=numel(x_coord);
point_distances=zeros(num_points,1);
DistFromBaseLine=zeros(num_points,1);
for ii=1:num_points
xoi=n_x(ii);
distances=nsw_x-xoi;
[~,I]=min(abs(distances));
point_distances(ii)=swdist(I);
baseLine=nsw_y(I);
DistFromBaseLine(ii)=abs(baseLine-n_y(ii));
end
outData=[point_distances elev ksn DistFromBaseLine x_coord y_coord n_x n_y];
% Filter out any data points outside of provided width
idx=DistFromBaseLine<=(data_width/2);
outData=outData(idx,:);
% Plot Swath
f1=figure(1);
clf
set(f1,'Units','inches','Position',[1.0 1.5 16 8],'renderer','painters','PaperSize',[16 8],'PaperOrientation','portrait','PaperPositionMode','auto');
subplot(2,1,1);
hold on
plot(swdist,min_elevs,'-b');
plot(swdist,max_elevs,'-b');
plot(swdist,mean_elevs,'-k');
for jj=1:numel(bends)
vline(bends(jj),'k','bend');
end
xlabel('Distance along swath (m)');
ylabel('Elevation (m)');
xlim([0 max(swdist)]);
hold off
subplot(2,1,2);
hold on
scatter(outData(:,1),outData(:,3),20,'k','filled');
xlabel('Distance along swath (m)');
ylabel('KSN');
xlim([0 max(swdist)]);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'ksn_TT'
% Find number of segments in provided KSN map structure
numSegs=numel(data);
% Loop through stream segments to extract x,y,ksn
streamData=zeros(numSegs,3);
for kk=1:numSegs
xx=mean(data(kk,1).X);
yy=mean(data(kk,1).Y);
ksn=mean(data(kk,1).ksn);
streamData(kk,:)=[xx yy ksn];
end
x_coord=streamData(:,1);
y_coord=streamData(:,2);
ksn=streamData(:,3);
% Transform data
[n_x,n_y]=ReFrameRot(SW,x_coord,y_coord);
% Find distances along swath profile of each point
num_points=numel(x_coord);
point_distances=zeros(num_points,1);
DistFromBaseLine=zeros(num_points,1);
for ii=1:num_points
xoi=n_x(ii);
distances=nsw_x-xoi;
[~,I]=min(abs(distances));
point_distances(ii)=swdist(I);
baseLine=nsw_y(I);
DistFromBaseLine(ii)=abs(baseLine-n_y(ii));
end
outData=[point_distances ksn DistFromBaseLine x_coord y_coord n_x n_y];
% Filter out any data points outside of provided width
idx=DistFromBaseLine<=(data_width/2);
outData=outData(idx,:);
% Plot Swath
f1=figure(1);
clf
set(f1,'Units','inches','Position',[1.0 1.5 16 8],'renderer','painters','PaperSize',[16 8],'PaperOrientation','portrait','PaperPositionMode','auto');
subplot(2,1,1);
hold on
plot(swdist,min_elevs,'-b');
plot(swdist,max_elevs,'-b');
plot(swdist,mean_elevs,'-k');
for jj=1:numel(bends)
vline(bends(jj),'k','bend');
end
xlabel('Distance along swath (m)');
ylabel('Elevation (m)');
xlim([0 max(swdist)]);
hold off
subplot(2,1,2);
hold on
scatter(outData(:,1),outData(:,2),20,'k','filled');
xlabel('Distance along swath (m)');
ylabel('KSN');
xlim([0 max(swdist)]);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'chi_TT'
% Extract values of interest
x_coord=data.x;
y_coord=data.y;
chi=data.chi;
% Transform data
[n_x,n_y]=ReFrameRot(SW,x_coord,y_coord);
% Find distances along swath profile of each point
num_points=numel(x_coord);
point_distances=zeros(num_points,1);
DistFromBaseLine=zeros(num_points,1);
for ii=1:num_points
xoi=n_x(ii);
distances=nsw_x-xoi;
[~,I]=min(abs(distances));
point_distances(ii)=swdist(I);
baseLine=nsw_y(I);
DistFromBaseLine(ii)=abs(baseLine-n_y(ii));
end
outData=[point_distances chi DistFromBaseLine x_coord y_coord n_x n_y];
% Filter out any data points outside of provided width
idx=DistFromBaseLine<=(data_width/2);
outData=outData(idx,:);
% Plot Swath
f1=figure(1);
clf
set(f1,'Units','inches','Position',[1.0 1.5 16 8],'renderer','painters','PaperSize',[16 8],'PaperOrientation','portrait','PaperPositionMode','auto');
subplot(2,1,1);
hold on
plot(swdist,min_elevs,'-b');
plot(swdist,max_elevs,'-b');
plot(swdist,mean_elevs,'-k');
for jj=1:numel(bends)
vline(bends(jj),'k','bend');
end
xlabel('Distance along swath (m)');
ylabel('Elevation (m)');
xlim([0 max(swdist)]);
hold off
subplot(2,1,2);
hold on
scatter(outData(:,1),outData(:,2),20,'k','filled');
xlabel('Distance along swath (m)');
ylabel('Chi');
xlim([0 max(swdist)]);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 'points3_err'
x_coord=data(:,1);
y_coord=data(:,2);
z=data(:,3);
err=data(:,4);
% Transform data
[n_x,n_y]=ReFrameRot(SW,x_coord,y_coord);
% Find distances along swath profile of each point
num_points=numel(x_coord);
point_distances=zeros(num_points,1);
DistFromBaseLine=zeros(num_points,1);
for ii=1:num_points
xoi=n_x(ii);
distances=nsw_x-xoi;
[~,I]=min(abs(distances));
point_distances(ii)=swdist(I);
baseLine=nsw_y(I);
DistFromBaseLine(ii)=abs(baseLine-n_y(ii));
end
outData=[point_distances z err DistFromBaseLine x_coord y_coord n_x n_y];
% Filter out any data points outside of provided width
idx=DistFromBaseLine<=(data_width/2);
outData=outData(idx,:);
% Plot Swath
f1=figure(1);
clf
set(f1,'Units','inches','Position',[1.0 5.5 16 4],'renderer','painters','PaperSize',[16 4],'PaperOrientation','portrait','PaperPositionMode','auto');
hold on
plot(swdist,min_elevs,'-b');
plot(swdist,max_elevs,'-b');
plot(swdist,mean_elevs,'-k');
for jj=1:numel(bends)
vline(bends(jj),'k','bend');
end
xlabel('Distance along swath (m)');
ylabel('Elevation (m)');
xlim([0 max(swdist)]);
hold off
% Plot Swath
f2=figure(2);
clf
set(f2,'Units','inches','Position',[1.0 1.5 16 4],'renderer','painters','PaperSize',[16 4],'PaperOrientation','portrait','PaperPositionMode','auto');
hold on
errbar(outData(:,1),outData(:,2),outData(:,3),'-r')
scatter(outData(:,1),outData(:,2),20,'k','filled');
xlabel('Distance along swath (m)');
ylabel('Elevation (m)');
xlim([0 max(swdist)]);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
% Function End
end