-
Notifications
You must be signed in to change notification settings - Fork 10
/
AcrossDivide.m
1606 lines (1411 loc) · 59.4 KB
/
AcrossDivide.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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [head_vals]=AcrossDivide(DEM,FD,DS_OUT,varargin)
% Function is designed to evaluate across divide differences in various proposed metrics for drainage divide stability. Allows for several different
% strategies for defining a divide of interest and then evaluates across divide differences in four metrics: (1) mean upstream elevation,
% (2) mean upstream gradient, (3) mean upstream local relief, and (4) chi. Seleting a divide of interest depends on the definition of the drainage basins that define this
% divide, see details of the 'outlet_method' parameter for more discussion. Produces a plot of across divide values and a table of values. Title of subplots will also specify
% which direction the divide is predicted to move based on that metric.
%
% If you use the result of this code in a publication, please cite Forte, A.M. & Whipple, K.X., 2018, Criteria and Tools for Determining
% Drainage Divide Stability, Earth and Planetary Science Letters, v.493, p.102-112, DOI:10.1016/j.epsl.2018.04.026
%
% Required Inputs:
% DEM - GRIDobj of the digital elevation model of your area loaded into the workspace
% FD - FLOWobj of the flow direction of your area loaded into the workspace
% DS_OUT - output structure from the 'DivideStability' function
% Optional Inputs:
% outlet_method ['auto_outlets'] - switch to specify how drainage basin outlets are selected, this will control how divides are defined, see descriptions below:
% 'auto_outlets' - default method. Defines different drainage basins on the basis of stream outlets. This will work well on smaller areas, but for larger
% DEMs, this may produce extremely large basins and thus may not provide fine enough detail for selecting portions of a drainage divide.
% 'streamorder' - defines drainage basins based on outlets but also junctions of streams above a provided minimum stream order (default is 3, modify with
% 'minimum_order' parameter).
% 'pick_new_outlets' - will open a gui interface to pick the outlets of drainage basins that define the divide of interest. To speed plotting, the original stream
% network is downsampled based on stream order, the default is to only plot and snap selected pour points to third order or greater drainages. The minimum stream
% order used for this downsampling can be modified with the optional 'minimum_order' parameter. This downsampling does not effect the channel heads as the location of
% these is still computed from the original full stream newtork provided to the code
% 'picked_outlets' - short circuits the gui selection of drainage basins that happens with other 'outlet-method' options and allows the user to provide a list of pour points
% that define the drainage basins which share the divide of interest. This option requires that the user also supply an input for the optional 'river_mouths' option. This
% input can either be (1) a mx3 array with columns x, y, and pairs of numbers defining particular divides of (2) the path to a valid shapefile. Coordinates for either should be the same
% as the projection used in the DEM file. If a shapefile, the file must be a point file and must only have one value column. For either type of input, the third columns of numbers
% groups basins into being on the same side of a divide, e.g. all the provided pour points with a 1 in the third column are all on one side of a divide of interest, all the pour
% points with a 2 in the third column are on the opposite of the divide. Can provide any number of divide pairs, but must always define both sides of a divide so the maximum value
% in this third column must be even, e.g. pour points with numbers 1,2,3,4,5,6,7,8 would define 4 divide pairs 1-2, 3-4, 5-6, 7-8.
% divide_buffer ['moderate'] - switch to control distance between channel heads within selected basins that are considered to define the divide, options are
% 'conservative', 'moderate', and 'lax' with increasing acceptable distance
% wl_method ['std_dev'] - switch to determine restrictiveness of criteria for defining whether a divide is stable, 'std_dev' uses the standard deviation to determine if the means of
% a give metric overlap, alternatively 'std_err' uses the standard error, 'bootstrap' uses the 95% confidence interval from a normal bootstrap statistic, and 'ttest' uses a
% paired t-test to assess whether the means overlap.
% minimum_order [3] - minimum stream order for either defining which confluences should be used to define drainage basins ('outlet_method','streamorder') or how much to downsample the
% stream network for plotting purposes ('outlet_method','pick_new_outlets').
% river_mouths - mx3 array with columns x,y, and a series of even and odd numbers (e.g., 1,2,3,4) indicating which side of the divide that particular pour point is on. Required input for
% 'outlet_method','picked_outlets'. When picking outlets to define multiple segments of a divide, stay consistent so that odd and even numbers are always on the same side of the divide,
% this is necessary to ensure that the function 'AlongDividePlot' works properly.
% save_shape_files [false] - flag to output a shapefile of the drainage basins used to define the divide and the values at selected channel heads(true) or to not save them (false - default)
% out_file_name ['basinsDivide'] - name for shapefiles and plots if optional save functions are used, DO NOT include a file extension in this name.
% save_plot [false] - save the divide stability plot, if true will use the name provided for 'drainage_basin_name'.
% save_heads [false] - save the channel head values as a mat file, will use the name provided for 'drainage_basin_name' as a prefix.
% extract_profiles [false] - option to extract and save out channel profiles for channels downstream of channel heads used to define the divide,
% output is necessary as an input for 'DivideProfiles' function.
% plot_style [histograms] - method of displaying divide output metrics, either 'points' or 'histograms'
% chi_ref_area [1] - reference area used for calculating chi profiles if 'extract_profiles' is true.
% theta_ref [0.5] - reference concavity used for calculating chi profiles if 'extract_profiles' is true.
% display_map [true] - display map of selected channel heads (optional argument only recognized if 'outlet_method' is 'picked_outlets' to supress display of map figure)
% Outputs:
% head_vals - mx8 array with columns x and y coordinates of relevant channel heads, mean upstream elevation, mean upstream gradient, mean upstream relief, and chi at these channel heads
% and a divide identifying number (e.g. 1, 2, 3, 4,...) to indicate which channel heads are grouped together on one or the other side of a divide an individual channel ID number
%
% Examples:
% [channel_head_values]=AcrossDivide(DEM,FD,DivStabil_OUT);
% [channel_head_values]=AcrossDivide(DEM,FD,DivStabil_OUT,'outlet_method','streamorder','minimum_order',4);
% [channel_head_values]=AcrossDivide(DEM,FD,DivStabil_OUT,'outlet_method','picked_outlets','river_mouths',array_of_river_mouths);
% [channel_head_values]=AcrossDivide(DEM,FD,DivStabil_OUT,'outlet_method','picked_outlets','river_mouths','name_of_shape_file'); % DO NOT APPEND THE .shp TO THE NAME OF THE FILE
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function Written by Adam M. Forte - Last Revised Spring 2018 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
p=inputParser;
p.FunctionName = 'AcrossDivide';
addRequired(p,'DEM',@(x) isa(x,'GRIDobj'));
addRequired(p,'FD',@(x) isa(x,'FLOWobj'));
addRequired(p,'DS_OUT',@(x) isa(x,'struct'));
addParamValue(p,'outlet_method','auto_outlets',@(x) ischar(validatestring(x,{'auto_outlets','picked_outlets','streamorder','pick_new_outlets'})));
addParamValue(p,'river_mouths',[],@(x) (isnumeric(x) && size(x,2)==3) | ischar(x));
addParamValue(p,'minimum_order',3,@(x) isscalar(x) && isnumeric(x));
addParamValue(p,'divide_buffer','moderate',@(x) ischar(validatestring(x,{'conservative','moderate','lax'})));
addParamValue(p,'wl_method','std_dev',@(x) ischar(validatestring(x,{'std_dev','std_err','bootstrap','ttest'})));
addParamValue(p,'save_shape_files',false,@(x) islogical(x));
addParamValue(p,'out_file_name','basinsDivide',@(x) ischar(x));
addParamValue(p,'plot_style','histograms',@(x) ischar(validatestring(x,{'points','histograms'})));
addParamValue(p,'save_plot',false,@(x) islogical(x));
addParamValue(p,'display_map',true,@(x) islogical(x));
addParamValue(p,'save_heads',false,@(x) islogical(x));
addParamValue(p,'extract_profiles',false,@(x) islogical(x));
addParamValue(p,'chi_ref_area',1,@(x) isscalar(x) && isnumeric(x));
addParamValue(p,'theta_ref',0.5,@(x) isscalar(x) && isnumeric(x));
parse(p,DEM,FD,DS_OUT,varargin{:});
DEM=p.Results.DEM;
FD=p.Results.FD;
DS_OUT=p.Results.DS_OUT;
outlet_method=p.Results.outlet_method;
rm=p.Results.river_mouths;
mo=p.Results.minimum_order;
dbd=p.Results.divide_buffer;
wl_method=p.Results.wl_method;
sv_db=p.Results.save_shape_files;
db_nm=p.Results.out_file_name;
plot_style=p.Results.plot_style;
save_plot=p.Results.save_plot;
dm=p.Results.display_map;
sv_hv=p.Results.save_heads;
ep=p.Results.extract_profiles;
a0=p.Results.chi_ref_area;
mn=p.Results.theta_ref;
% Perform some checks on the river mouths input (if valid)
if strcmp(outlet_method,'picked_outlets') & isempty(rm)
error('Please provide a m x 3 array of river mouths or the valid path to a shapefile');
elseif strcmp(outlet_method,'picked_outlets') & ischar(rm)
disp('Reading shapefile')
try
rm_name=[rm '.shp'];
rm_shp=shaperead(rm_name);
fn=fieldnames(rm_shp);
rm=horzcat([rm_shp.X]',[rm_shp.Y]',[rm_shp.(fn{4})]');
catch
error('Error reading shapefile, make sure the name provided did NOT include .shp, the shapefile is a point file with a single value column, and you have a license for the Mapping Toolbox');
end
end
% Load in necessary results from DivideStability function
S=DS_OUT.Stream;
ra=DS_OUT.Ref_Area;
chXY=DS_OUT.chXY; chX=chXY(:,1); chY=chXY(:,2);
chIX=DS_OUT.chIX;
E=DS_OUT.E;
R=DS_OUT.R;
G=DS_OUT.G;
C=DS_OUT.C;
% Switch between different methods
switch outlet_method
%%%%%%%%%%%%%%%%%%
case 'auto_outlets'
disp('Finding Ridgelines...')
[RL,DB]=FindRidgeLines(FD,S,'auto_outlets');
disp('Completed')
ch_db=DB.Z(chIX);
f1=figure(1);
clf
set(f1,'Units','normalized','Position',[0.1 0.1 0.75 0.75]);
hold on
imageschs(DEM,RL);
hold off
mg=msgbox('Zoom or pan to area of interest and then press enter');
uiwait(mg);
pause()
hold on
plot(S,'-w');
scatter(chX,chY,5,'w','filled');
hold off
str='Click within drainage basins defining one side of the divide of interest, presss "Enter/Return", click within drainage basins on other side of the divide and then press "Enter/Return" again.';
mg=msgbox(str);
uiwait(mg);
% Select and paint channel heads on one side of divide
[x1,y1]=ginput;
ix1=coord2ind(DEM,x1,y1);
db1=DB.Z(ix1);
chIDX1=ismember(ch_db,db1);
chIX1=chIX(chIDX1);
chXY1=chXY(chIDX1,:); chX1=chXY1(:,1); chY1=chXY1(:,2);
aE1=E(chIDX1); aG1=G(chIDX1); aR1=R(chIDX1); aC1=C(chIDX1);
hold on
scatter(chX1,chY1,20,'y','filled');
hold off
% Select and paint channel heads on the other side of the divide
[x2,y2]=ginput;
ix2=coord2ind(DEM,x2,y2);
db2=DB.Z(ix2);
chIDX2=ismember(ch_db,db2);
chIX2=chIX(chIDX2);
chXY2=chXY(chIDX2,:); chX2=chXY2(:,1); chY2=chXY2(:,2);
aE2=E(chIDX2); aG2=G(chIDX2); aR2=R(chIDX2); aC2=C(chIDX2);
hold on
scatter(chX2,chY2,20,'g','filled');
hold off
%%%%%%%%%%%%%%%%%%%
case 'streamorder'
disp('Finding Ridgelines...')
[RL,DB]=FindRidgeLines(FD,S,'streamorder','minimum_order',mo);
disp('Completed')
ch_db=DB.Z(chIX);
f1=figure(1);
clf
set(f1,'Units','normalized','Position',[0.1 0.1 0.75 0.75]);
hold on
imageschs(DEM,RL);
hold off
mg=msgbox('Zoom or pan to area of interest and then press enter');
uiwait(mg);
pause()
hold on
plot(S,'-w');
scatter(chX,chY,5,'w','filled');
hold off
str='Click within drainage basins defining one side of the divide of interest, presss "Enter/Return", click within drainage basins on other side of the divide and then press "Enter/Return" again.';
mg=msgbox(str);
uiwait(mg);
% Select and paint channel heads on one side of divide
[x1,y1]=ginput;
ix1=coord2ind(DEM,x1,y1);
db1=DB.Z(ix1);
chIDX1=ismember(ch_db,db1);
chIX1=chIX(chIDX1);
chXY1=chXY(chIDX1,:); chX1=chXY1(:,1); chY1=chXY1(:,2);
aE1=E(chIDX1); aG1=G(chIDX1); aR1=R(chIDX1); aC1=C(chIDX1);
hold on
scatter(chX1,chY1,20,'y','filled');
hold off
% Select and paint channel heads on the other side of the divide
[x2,y2]=ginput;
ix2=coord2ind(DEM,x2,y2);
db2=DB.Z(ix2);
chIDX2=ismember(ch_db,db2);
chIX2=chIX(chIDX2);
chXY2=chXY(chIDX2,:); chX2=chXY2(:,1); chY2=chXY2(:,2);
aE2=E(chIDX2); aG2=G(chIDX2); aR2=R(chIDX2); aC2=C(chIDX2);
hold on
scatter(chX2,chY2,20,'g','filled');
hold off
%%%%%%%%%%%%%%%%%%%%%%
case 'pick_new_outlets'
f1=figure(1);
clf
set(f1,'Units','normalized','Position',[0.1 0.1 0.75 0.75]);
hold on
imageschs(DEM,DEM);
hold off
mg=msgbox('Zoom or pan to area of interest and then press enter');
uiwait(mg);
pause()
hold on
crit=['>=' num2str(mo)];
Sd=modify(S,'streamorder',crit);
plot(Sd,'-w');
hold off
mg=msgbox('Select outlets of basins that define the drainage divide of interest');
uiwait(mg);
[xb,yb]=ginput;
[xb,yb]=snap2stream(Sd,xb,yb);
rm=[xb yb];
disp('Finding Ridgelines...')
[RL,DB]=FindRidgeLines(FD,S,'outlets','river_mouths',rm);
% DB=GridExpand(DB,DEM,nan);
disp('Completed')
f1=figure(1);
clf
set(f1,'Units','normalized','Position',[0.1 0.1 0.75 0.75]);
hold on
imageschs(DEM,RL);
hold off
ch_db=DB.Z(chIX);
mg=msgbox('Zoom or pan to area of interest and then press enter');
uiwait(mg);
pause()
hold on
plot(S,'-w');
scatter(chX,chY,5,'w','filled');
hold off
str='Click within drainage basins defining one side of the divide of interest, presss "Enter/Return", click within drainage basins on other side of the divide and then press "Enter/Return" again.';
mg=msgbox(str);
uiwait(mg);
% Select and paint channel heads on one side of divide
[x1,y1]=ginput;
ix1=coord2ind(DEM,x1,y1);
db1=DB.Z(ix1);
chIDX1=ismember(ch_db,db1);
chIX1=chIX(chIDX1);
chXY1=chXY(chIDX1,:); chX1=chXY1(:,1); chY1=chXY1(:,2);
aE1=E(chIDX1); aG1=G(chIDX1); aR1=R(chIDX1); aC1=C(chIDX1);
hold on
scatter(chX1,chY1,20,'y','filled');
hold off
% Select and paint channel heads on the other side of the divide
[x2,y2]=ginput;
ix2=coord2ind(DEM,x2,y2);
db2=DB.Z(ix2);
chIDX2=ismember(ch_db,db2);
chIX2=chIX(chIDX2);
chXY2=chXY(chIDX2,:); chX2=chXY2(:,1); chY2=chXY2(:,2);
aE2=E(chIDX2); aG2=G(chIDX2); aR2=R(chIDX2); aC2=C(chIDX2);
hold on
scatter(chX2,chY2,20,'g','filled');
hold off
%%%%%%%%%%%%%%%%%%%%%
case 'picked_outlets'
disp('Snapping picked outlets to streams...')
max_rm=max(rm(:,3));
if rem(max_rm,2)~=0
error('Must be numbers defining either side of the divide, so maximum ID number should be even')
end
[rmx,rmy]=snap2stream(S,rm(:,1),rm(:,2));
num_divides=max_rm/2;
odds=[1:2:(num_divides*2)-1];
evens=[2:2:(num_divides*2)];
% Generate empty cells for outputs
chX1=cell(num_divides,1); chY1=cell(num_divides,1);
aE1=cell(num_divides,1); aG1=cell(num_divides,1); aR1=cell(num_divides,1); aC1=cell(num_divides,1);
chX2=cell(num_divides,1); chY2=cell(num_divides,1);
aE2=cell(num_divides,1); aG2=cell(num_divides,1); aR2=cell(num_divides,1); aC2=cell(num_divides,1);
S1=cell(num_divides,1); S2=cell(num_divides,1);
for ii=1:num_divides
idx1=rm(:,3)==odds(ii);
idx2=rm(:,3)==evens(ii);
rm1=[rmx(idx1) rmy(idx1)];
rm2=[rmx(idx2) rmy(idx2)];
disp(['Remaking streams for divide ' num2str(ii)])
rm1ix=coord2ind(DEM,rm1(:,1),rm1(:,2));
S1{ii}=STREAMobj(FD,'unit','mapunits','minarea',ra,'outlets',rm1ix);
rm2ix=coord2ind(DEM,rm2(:,1),rm2(:,2));
S2{ii}=STREAMobj(FD,'unit','mapunits','minarea',ra,'outlets',rm2ix);
disp(['Finding channelheads for divide ' num2str(ii)])
chIX1=streampoi(S1{ii},'channelheads','ix');
chIDX1=ismember(chIX,chIX1);
chXY1=chXY(chIDX1,:); chX1{ii}=chXY1(:,1); chY1{ii}=chXY1(:,2);
aE1{ii}=E(chIDX1); aG1{ii}=G(chIDX1); aR1{ii}=R(chIDX1); aC1{ii}=C(chIDX1);
chIX2=streampoi(S2{ii},'channelheads','ix');
chIDX2=ismember(chIX,chIX2);
chXY2=chXY(chIDX2,:); chX2{ii}=chXY2(:,1); chY2{ii}=chXY2(:,2);
aE2{ii}=E(chIDX2); aG2{ii}=G(chIDX2); aR2{ii}=R(chIDX2); aC2{ii}=C(chIDX2);
end
% warning('picked outlets method is currently unfinished')
end
% Switch for post processing between picked outlets and everything else
if strcmp(outlet_method,'picked_outlets')
for jj=1:num_divides
% Determine Channel Heads of Interest
num1=numel(chX1{jj});
num2=numel(chX2{jj});
switch dbd
case 'conservative'
cut_dist=2.0*sqrt(ra);
case 'moderate'
cut_dist=2.5*sqrt(ra);
case 'lax'
cut_dist=3.0*sqrt(ra);
end
chix1=zeros(num1,1);
for ii=1:num1
chXoi=chX1{jj}(ii);
chYoi=chY1{jj}(ii);
d=EucDist(chXoi,chYoi,chX2{jj},chY2{jj});
ix=d<cut_dist;
if isempty(nonzeros(ix))
chix1(ii)=0;
else
chix1(ii)=1;
end
end
chix2=zeros(num2,1);
for ii=1:num2
chXoi=chX2{jj}(ii);
chYoi=chY2{jj}(ii);
d=EucDist(chXoi,chYoi,chX1{jj},chY1{jj});
ix=d<cut_dist;
if isempty(nonzeros(ix))
chix2(ii)=0;
else
chix2(ii)=1;
end
end
chix1=logical(chix1);
chix2=logical(chix2);
if dm
f1=figure(jj);
clf
set(f1,'Units','normalized','Position',[0.1 0.1 0.75 0.75]);
hold on
imageschs(DEM,DEM,'colormap','gray');
scatter(chX1{jj},chY1{jj},20,'y','filled');
scatter(chX2{jj},chY2{jj},20,'g','filled');
scatter(chX1{jj}(chix1),chY1{jj}(chix1),40,'k','filled','MarkerEdgeColor','y');
scatter(chX2{jj}(chix2),chY2{jj}(chix2),40,'k','filled','MarkerEdgeColor','g');
xlim([min(vertcat(chX1{jj},chX2{jj}))-100 max(vertcat(chX1{jj},chX2{jj}))+100]);
ylim([min(vertcat(chY1{jj},chY2{jj}))-100 max(vertcat(chY1{jj},chY2{jj}))+100]);
hold off
end
if sv_db
disp('Generating drainage basins...')
SO=union(S1{jj},S2{jj},FD);
DB_OUT=drainagebasins(FD,SO);
[db_ms,~,~]=GRIDobj2polygon(DB_OUT,'geometry','Polygon','waitbar',true);
shapewrite(db_ms,[db_nm '_' num2str(jj) '.shp']);
end
[do,p1,p2,Ornt]=DivideOrient(chX1{jj}(chix1),chY1{jj}(chix1),chX2{jj}(chix2),chY2{jj}(chix2));
E1=aE1{jj}(chix1);
G1=aG1{jj}(chix1);
R1=aR1{jj}(chix1);
C1=aC1{jj}(chix1);
E2=aE2{jj}(chix2);
G2=aG2{jj}(chix2);
R2=aR2{jj}(chix2);
C2=aC2{jj}(chix2);
ME1=mean(E1); MG1=mean(G1); MR1=mean(R1); MC1=mean(C1);
ME2=mean(E2); MG2=mean(G2); MR2=mean(R2); MC2=mean(C2);
switch wl_method
case 'std_dev'
stdE1=std(E1); stdG1=std(G1); stdR1=std(R1); stdC1=std(C1);
stdE2=std(E2); stdG2=std(G2); stdR2=std(R2); stdC2=std(C2);
case 'ttest'
stdE1=std(E1); stdG1=std(G1); stdR1=std(R1); stdC1=std(C1);
stdE2=std(E2); stdG2=std(G2); stdR2=std(R2); stdC2=std(C2);
case 'std_err'
stdE1=std(E1)/sqrt(numel(E1)); stdG1=std(G1)/sqrt(numel(G1)); stdR1=std(R1)/sqrt(numel(R1)); stdC1=std(C1)/sqrt(numel(C1));
stdE2=std(E2)/sqrt(numel(E2)); stdG2=std(G2)/sqrt(numel(G2)); stdR2=std(R2)/sqrt(numel(R2)); stdC2=std(C2)/sqrt(numel(C2));
case 'bootstrap'
stdE1=bootCI(E1); stdG1=bootCI(G1); stdR1=bootCI(R1); stdC1=bootCI(C1);
stdE2=bootCI(E2); stdG2=bootCI(G2); stdR2=bootCI(R2); stdC2=bootCI(C2);
end
[WL]=WinnersLosers(E1,E2,G1,G2,R1,R2,C1,C2,wl_method);
[out_str]=OutputParser(WL,Ornt);
dummy1=ones(numel(E1),1);
dummy2=ones(numel(E2),1).*2;
f2=figure(jj+num_divides);
clf
set(f2,'Units','normalized','Position',[0.1 0.1 0.60 0.60],'renderer','painters','PaperPositionMode','auto');
switch plot_style
case 'histograms'
%%% HISTOGRAMS %%%
subplot(2,2,3);
hold on
xr=linspace(min(vertcat(E1,E2)),max(vertcat(E1,E2)),50);
[nE1]=hist(E1,xr); [nE2]=hist(E2,xr);
b1=bar(xr,nE1,'hist');
b2=bar(xr,nE2,'hist');
set(b1,'FaceColor','k');
set(b2,'FaceColor','none','EdgeColor','r');
% d1=max(nE1)+1; d2=max(nE2)+1;
dm1=max(nE1); dm2=max(nE2); am=max([dm1 dm2]);
if ME1>=ME2
d1=am+1;
d2=d1+1;
else
d2=am+1;
d1=d2+1;
end
plot([ME1-stdE1;stdE1+ME1],[d1;d1],'-k','LineWidth',2);
plot([ME2-stdE2;stdE2+ME2],[d2;d2],'-r','LineWidth',2);
h1(1)=scatter(ME1,d1,40,'k','filled');
h1(2)=scatter(ME2,d2,40,'r','filled');
xlabel('Elevation at Reference Area (m)');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','NorthOutside')
set(gca,'YTickLabel',[]);
title(['Elevation: ' out_str{1}])
hold off
subplot(2,2,2);
hold on
xr=linspace(min(vertcat(R1,R2)),max(vertcat(R1,R2)),50);
[nR1]=hist(R1,xr); [nR2]=hist(R2,xr);
b1=bar(xr,nR1,'hist');
b2=bar(xr,nR2,'hist');
set(b1,'FaceColor','k');
set(b2,'FaceColor','none','EdgeColor','r');
% d1=max(nR1)+1; d2=max(nR2)+1;
dm1=max(nR1); dm2=max(nR2); am=max([dm1 dm2]);
if MR1>=MR2
d2=am+1;
d1=d2+1;
else
d1=am+1;
d2=d1+1;
end
plot([MR1-stdR1;stdR1+MR1],[d1;d1],'-k','LineWidth',2);
plot([MR2-stdR2;stdR2+MR2],[d2;d2],'-r','LineWidth',2);
h1(1)=scatter(MR1,d1,40,'k','filled');
h1(2)=scatter(MR2,d2,40,'r','filled');
xlabel('Mean Upstream Relief above Reference Area (m)');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','NorthOutside')
set(gca,'YTickLabel',[]);
title(['Relief: ' out_str{2}])
hold off
subplot(2,2,4);
hold on
xr=linspace(min(vertcat(G1,G2)),max(vertcat(G1,G2)),50);
[nG1]=hist(G1,xr); [nG2]=hist(G2,xr);
b1=bar(xr,nG1,'hist');
b2=bar(xr,nG2,'hist');
set(b1,'FaceColor','k');
set(b2,'FaceColor','none','EdgeColor','r');
% d1=max(nG1)+1; d2=max(nG2)+1;
dm1=max(nG1); dm2=max(nG2); am=max([dm1 dm2]);
if MG1>=MG2
d2=am+1;
d1=d2+1;
else
d1=am+1;
d2=d1+1;
end
plot([MG1-stdG1;stdG1+MG1],[d1;d1],'-k','LineWidth',2);
plot([MG2-stdG2;stdG2+MG2],[d2;d2],'-r','LineWidth',2);
h1(1)=scatter(MG1,d1,40,'k','filled');
h1(2)=scatter(MG2,d2,40,'r','filled');
xlabel('Mean Upstream Gradient above Reference Area');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','NorthOutside')
set(gca,'YTickLabel',[]);
title(['Gradient: ' out_str{3}])
hold off
subplot(2,2,1);
hold on
xr=linspace(min(vertcat(C1,C2)),max(vertcat(C1,C2)),50);
[nC1]=hist(C1,xr); [nC2]=hist(C2,xr);
b1=bar(xr,nC1,'hist');
b2=bar(xr,nC2,'hist');
set(b1,'FaceColor','k');
set(b2,'FaceColor','none','EdgeColor','r');
% d1=max(nC1)+1; d2=max(nC2)+1;
dm1=max(nC1); dm2=max(nC2); am=max([dm1 dm2]);
if MC1>=MC2
d1=am+1;
d2=d1+1;
else
d2=am+1;
d1=d2+1;
end
plot([MC1-stdC1;stdC1+MC1],[d1;d1],'-k','LineWidth',2);
plot([MC2-stdC2;stdC2+MC2],[d2;d2],'-r','LineWidth',2);
h1(1)=scatter(MC1,d1,40,'k','filled');
h1(2)=scatter(MC2,d2,40,'r','filled');
xlabel('Chi at Reference Area');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','NorthOutside')
set(gca,'YTickLabel',[]);
title(['Chi: ' out_str{4}])
hold off
case 'points'
%%% DOTS %%%%
subplot(2,2,3);
hold on
plot([ME1-stdE1;stdE1+ME1],[1;1],'-k','LineWidth',2);
scatter(E1,dummy1,20,'k');
plot([ME2-stdE2;stdE2+ME2],[2;2],'-r','LineWidth',2);
scatter(E2,dummy2,20,'r');
h1(1)=scatter(ME1,1,40,'k','filled');
h1(2)=scatter(ME2,2,40,'r','filled');
xlabel('Mean Upstream Elevation above Reference Area (m)');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','north')
set(gca,'YTickLabel',[]); ylim([0 3]);
title(['Elevation: ' out_str{1}])
hold off
subplot(2,2,2);
hold on
plot([MR1-stdR1;stdR1+MR1],[1;1],'-k','LineWidth',2);
scatter(R1,dummy1,20,'k');
plot([MR2-stdR2;stdR2+MR2],[2;2],'-r','LineWidth',2);
scatter(R2,dummy2,20,'r');
h2(1)=scatter(MR1,1,40,'k','filled');
h2(2)=scatter(MR2,2,40,'r','filled');
xlabel('Mean Upstream Relief above Reference Area (m)');
legend(h2,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','north')
set(gca,'YTickLabel',[]); ylim([0 3]);
title(['Relief: ' out_str{2}])
hold off
subplot(2,2,4);
hold on
plot([MG1-stdG1;stdG1+MG1],[1;1],'-k','LineWidth',2);
scatter(G1,dummy1,20,'k');
plot([MG2-stdG2;stdG2+MG2],[2;2],'-r','LineWidth',2);
scatter(G2,dummy2,20,'r');
h3(1)=scatter(MG1,1,40,'k','filled');
h3(2)=scatter(MG2,2,40,'r','filled');
xlabel('Mean Upstream Gradient above Reference Area');
legend(h3,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','north')
set(gca,'YTickLabel',[]); ylim([0 3]);
title(['Gradient: ' out_str{3}])
hold off
subplot(2,2,1);
hold on
plot([MC1-stdC1;stdC1+MC1],[1;1],'-k','LineWidth',2);
scatter(C1,dummy1,20,'k');
plot([MC2-stdC2;stdC2+MC2],[2;2],'-r','LineWidth',2);
scatter(C2,dummy2,20,'r');
h3(1)=scatter(MC1,1,40,'k','filled');
h3(2)=scatter(MC2,2,40,'r','filled');
xlabel('Chi at Reference Area');
legend(h3,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','north')
set(gca,'YTickLabel',[]); ylim([0 3]);
title(['Chi: ' out_str{4}])
hold off
end
% Package Output
X1=chX1{jj}(chix1); Y1=chY1{jj}(chix1);
X2=chX2{jj}(chix2); Y2=chY2{jj}(chix2);
div1=ones(size(X1)).*odds(jj);
div2=ones(size(X2)).*evens(jj);
val1=[X1 Y1 E1 G1 R1 C1 div1];
val2=[X2 Y2 E2 G2 R2 C2 div2];
head_vals{jj,1}=vertcat(val1,val2);
if save_plot
print(f2,'-depsc',[db_nm '_' num2str(jj) '.eps']);
end
% Loop end
end
head_vals=vertcat(head_vals{:});
else
% Determine Channel Heads of Interest
num1=numel(chX1);
num2=numel(chX2);
switch dbd
case 'conservative'
cut_dist=2.0*sqrt(ra);
case 'moderate'
cut_dist=2.5*sqrt(ra);
case 'lax'
cut_dist=3.0*sqrt(ra);
end
for ii=1:num1
chXoi=chX1(ii);
chYoi=chY1(ii);
d=EucDist(chXoi,chYoi,chX2,chY2);
ix=d<cut_dist;
if isempty(nonzeros(ix))
chix1(ii)=0;
else
chix1(ii)=1;
end
end
for ii=1:num2
chXoi=chX2(ii);
chYoi=chY2(ii);
d=EucDist(chXoi,chYoi,chX1,chY1);
ix=d<cut_dist;
if isempty(nonzeros(ix))
chix2(ii)=0;
else
chix2(ii)=1;
end
end
chix1=logical(chix1);
chix2=logical(chix2);
if strcmp(outlet_method,'picked_outlets')~=1
hold on
scatter(chX1(chix1),chY1(chix1),40,'k','filled','MarkerEdgeColor','y');
scatter(chX2(chix2),chY2(chix2),40,'k','filled','MarkerEdgeColor','g');
hold off
end
if sv_db
disp('Generating drainage basins...')
IXX=GRIDobj(DEM);
IXX.Z(chIX1)=1; IXX.Z(chIX2)=1;
IXX.Z=logical(IXX.Z);
SO=modify(S,'downstreamto',IXX);
DB_OUT=drainagebasins(FD,SO);
[db_ms,~,~]=GRIDobj2polygon(DB_OUT,'geometry','Polygon','waitbar',true);
shapewrite(db_ms,[db_nm '.shp']);
end
[do,p1,p2,Ornt]=DivideOrient(chX1(chix1),chY1(chix1),chX2(chix2),chY2(chix2));
E1=aE1(chix1);
G1=aG1(chix1);
R1=aR1(chix1);
C1=aC1(chix1);
E2=aE2(chix2);
G2=aG2(chix2);
R2=aR2(chix2);
C2=aC2(chix2);
ME1=mean(E1); MG1=mean(G1); MR1=mean(R1); MC1=mean(C1);
ME2=mean(E2); MG2=mean(G2); MR2=mean(R2); MC2=mean(C2);
switch wl_method
case 'std_dev'
stdE1=std(E1); stdG1=std(G1); stdR1=std(R1); stdC1=std(C1);
stdE2=std(E2); stdG2=std(G2); stdR2=std(R2); stdC2=std(C2);
case 'ttest'
stdE1=std(E1); stdG1=std(G1); stdR1=std(R1); stdC1=std(C1);
stdE2=std(E2); stdG2=std(G2); stdR2=std(R2); stdC2=std(C2);
case 'std_err'
stdE1=std(E1)/sqrt(numel(E1)); stdG1=std(G1)/sqrt(numel(G1)); stdR1=std(R1)/sqrt(numel(R1)); stdC1=std(C1)/sqrt(numel(C1));
stdE2=std(E2)/sqrt(numel(E2)); stdG2=std(G2)/sqrt(numel(G2)); stdR2=std(R2)/sqrt(numel(R2)); stdC2=std(C2)/sqrt(numel(C2));
case 'bootstrap'
stdE1=bootCI(E1); stdG1=bootCI(G1); stdR1=bootCI(R1); stdC1=bootCI(C1);
stdE2=bootCI(E2); stdG2=bootCI(G2); stdR2=bootCI(R2); stdC2=bootCI(C2);
end
[WL]=WinnersLosers(E1,E2,G1,G2,R1,R2,C1,C2,wl_method);
[out_str]=OutputParser(WL,Ornt);
dummy1=ones(numel(E1),1);
dummy2=ones(numel(E2),1).*2;
f2=figure(2);
clf
set(f2,'Units','normalized','Position',[0.1 0.1 0.60 0.60],'renderer','painters','PaperPositionMode','auto');
switch plot_style
case 'histograms'
%%% HISTOGRAMS %%%
subplot(2,2,3);
hold on
xr=linspace(min(vertcat(E1,E2)),max(vertcat(E1,E2)),50);
[nE1]=hist(E1,xr); [nE2]=hist(E2,xr);
b1=bar(xr,nE1,'hist');
b2=bar(xr,nE2,'hist');
set(b1,'FaceColor','k');
set(b2,'FaceColor','none','EdgeColor','r');
% d1=max(nE1)+1; d2=max(nE2)+1;
dm1=max(nE1); dm2=max(nE2); am=max([dm1 dm2]);
if ME1>=ME2
d1=am+1;
d2=d1+1;
else
d2=am+1;
d1=d2+1;
end
plot([ME1-stdE1;stdE1+ME1],[d1;d1],'-k','LineWidth',2);
plot([ME2-stdE2;stdE2+ME2],[d2;d2],'-r','LineWidth',2);
h1(1)=scatter(ME1,d1,40,'k','filled');
h1(2)=scatter(ME2,d2,40,'r','filled');
xlabel('Elevation at Reference Area (m)');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','NorthOutside')
set(gca,'YTickLabel',[]);
title(['Elevation: ' out_str{1}])
hold off
subplot(2,2,2);
hold on
xr=linspace(min(vertcat(R1,R2)),max(vertcat(R1,R2)),50);
[nR1]=hist(R1,xr); [nR2]=hist(R2,xr);
b1=bar(xr,nR1,'hist');
b2=bar(xr,nR2,'hist');
set(b1,'FaceColor','k');
set(b2,'FaceColor','none','EdgeColor','r');
% d1=max(nR1)+1; d2=max(nR2)+1;
dm1=max(nR1); dm2=max(nR2); am=max([dm1 dm2]);
if MR1>=MR2
d2=am+1;
d1=d2+1;
else
d1=am+1;
d2=d1+1;
end
plot([MR1-stdR1;stdR1+MR1],[d1;d1],'-k','LineWidth',2);
plot([MR2-stdR2;stdR2+MR2],[d2;d2],'-r','LineWidth',2);
h1(1)=scatter(MR1,d1,40,'k','filled');
h1(2)=scatter(MR2,d2,40,'r','filled');
xlabel('Mean Upstream Relief above Reference Area (m)');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','NorthOutside')
set(gca,'YTickLabel',[]);
title(['Relief: ' out_str{2}])
hold off
subplot(2,2,4);
hold on
xr=linspace(min(vertcat(G1,G2)),max(vertcat(G1,G2)),50);
[nG1]=hist(G1,xr); [nG2]=hist(G2,xr);
b1=bar(xr,nG1,'hist');
b2=bar(xr,nG2,'hist');
set(b1,'FaceColor','k');
set(b2,'FaceColor','none','EdgeColor','r');
% d1=max(nG1)+1; d2=max(nG2)+1;
dm1=max(nG1); dm2=max(nG2); am=max([dm1 dm2]);
if MG1>=MG2
d2=am+1;
d1=d2+1;
else
d1=am+1;
d2=d1+1;
end
plot([MG1-stdG1;stdG1+MG1],[d1;d1],'-k','LineWidth',2);
plot([MG2-stdG2;stdG2+MG2],[d2;d2],'-r','LineWidth',2);
h1(1)=scatter(MG1,d1,40,'k','filled');
h1(2)=scatter(MG2,d2,40,'r','filled');
xlabel('Mean Upstream Gradient above Reference Area');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','NorthOutside')
set(gca,'YTickLabel',[]);
title(['Gradient: ' out_str{3}])
hold off
subplot(2,2,1);
hold on
xr=linspace(min(vertcat(C1,C2)),max(vertcat(C1,C2)),50);
[nC1]=hist(C1,xr); [nC2]=hist(C2,xr);
b1=bar(xr,nC1,'hist');
b2=bar(xr,nC2,'hist');
set(b1,'FaceColor','k');
set(b2,'FaceColor','none','EdgeColor','r');
% d1=max(nC1)+1; d2=max(nC2)+1;
dm1=max(nC1); dm2=max(nC2); am=max([dm1 dm2]);
if MC1>=MC2
d1=am+1;
d2=d1+1;
else
d2=am+1;
d1=d2+1;
end
plot([MC1-stdC1;stdC1+MC1],[d1;d1],'-k','LineWidth',2);
plot([MC2-stdC2;stdC2+MC2],[d2;d2],'-r','LineWidth',2);
h1(1)=scatter(MC1,d1,40,'k','filled');
h1(2)=scatter(MC2,d2,40,'r','filled');
xlabel('Chi at Reference Area');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','NorthOutside')
set(gca,'YTickLabel',[]);
title(['Chi: ' out_str{4}])
hold off
case 'points'
%%% DOTS %%%%
subplot(2,2,3);
hold on
plot([ME1-stdE1;stdE1+ME1],[1;1],'-k','LineWidth',2);
scatter(E1,dummy1,20,'k');
plot([ME2-stdE2;stdE2+ME2],[2;2],'-r','LineWidth',2);
scatter(E2,dummy2,20,'r');
h1(1)=scatter(ME1,1,40,'k','filled');
h1(2)=scatter(ME2,2,40,'r','filled');
xlabel('Mean Upstream Elevation above Reference Area (m)');
legend(h1,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','north')
set(gca,'YTickLabel',[]); ylim([0 3]);
title(['Elevation: ' out_str{1}])
hold off
subplot(2,2,2);
hold on
plot([MR1-stdR1;stdR1+MR1],[1;1],'-k','LineWidth',2);
scatter(R1,dummy1,20,'k');
plot([MR2-stdR2;stdR2+MR2],[2;2],'-r','LineWidth',2);
scatter(R2,dummy2,20,'r');
h2(1)=scatter(MR1,1,40,'k','filled');
h2(2)=scatter(MR2,2,40,'r','filled');
xlabel('Mean Upstream Relief above Reference Area (m)');
legend(h2,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','north')
set(gca,'YTickLabel',[]); ylim([0 3]);
title(['Relief: ' out_str{2}])
hold off
subplot(2,2,4);
hold on
plot([MG1-stdG1;stdG1+MG1],[1;1],'-k','LineWidth',2);
scatter(G1,dummy1,20,'k');
plot([MG2-stdG2;stdG2+MG2],[2;2],'-r','LineWidth',2);
scatter(G2,dummy2,20,'r');
h3(1)=scatter(MG1,1,40,'k','filled');
h3(2)=scatter(MG2,2,40,'r','filled');
xlabel('Mean Upstream Gradient above Reference Area');
legend(h3,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','north')
set(gca,'YTickLabel',[]); ylim([0 3]);
title(['Gradient: ' out_str{3}])
hold off
subplot(2,2,1);
hold on
plot([MC1-stdC1;stdC1+MC1],[1;1],'-k','LineWidth',2);
scatter(C1,dummy1,20,'k');
plot([MC2-stdC2;stdC2+MC2],[2;2],'-r','LineWidth',2);
scatter(C2,dummy2,20,'r');
h3(1)=scatter(MC1,1,40,'k','filled');
h3(2)=scatter(MC2,2,40,'r','filled');
xlabel('Chi at Reference Area');
legend(h3,['Mean of Channels ' p1 ' of Divide'],['Mean of Channels ' p2 ' of Divide'],'location','north')
set(gca,'YTickLabel',[]); ylim([0 3]);
title(['Chi: ' out_str{4}])
hold off
end
% Package Output
X1=chX1(chix1); Y1=chY1(chix1);
X2=chX2(chix2); Y2=chY2(chix2);
div1=ones(size(X1));
div2=ones(size(X2)).*2;
val1=[X1 Y1 E1 G1 R1 C1 div1];
val2=[X2 Y2 E2 G2 R2 C2 div2];
head_vals=vertcat(val1,val2);
if save_plot
print(f2,'-depsc',[db_nm '.eps']);
end
% If Switch End
end
% Add channel ID numbers to channel heads
head_groups=unique(head_vals(:,7));
for ii=1:numel(head_groups)
hgOI=head_groups(ii);
idx=head_vals(:,7)==hgOI;
nl=[1:1:nnz(idx)]';
head_vals(idx,8)=nl;
end
%% Optional Outputs
% Generate shape file of head values
if sv_db
head_valsN=double(head_vals);
X=head_valsN(:,1); Y=head_valsN(:,2); Elev=head_valsN(:,3); Grad=head_valsN(:,4); Rlf=head_valsN(:,5); Chi=head_valsN(:,6); Div=head_valsN(:,7); ChID=head_valsN(:,8);
% Create Geometry column
Geometry=repmat({'Point'},numel(X),1);
T=table(Geometry,X,Y,Elev,Grad,Rlf,Chi,Div,ChID);
MS=table2struct(T);
shapewrite(MS,[db_nm '_head_vals.shp']);
end
% Save out head values in a mat file
if sv_hv
save([db_nm '_head_vals.mat'],'head_vals');
end
% Extract channel profiles
if ep
% Hydrologically condition dem