-
Notifications
You must be signed in to change notification settings - Fork 36
/
BasinStatsPlots.m
1555 lines (1387 loc) · 48.2 KB
/
BasinStatsPlots.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 BasinStatsPlots(basin_table,plots,varargin)
%
% Usage:
% BasinStatsPlots(basin_table,plots);
% BasinStatsPlots(basin_table,plots,'name',value,...);
%
% Description:
% Function to take the complied outputs from 'ProcessRiverBasins' and 'SubDivideBigBasins' and produce various plots
% of aggregated basin values.
%
% Required inputs:
% basin_table - Table output from 'CompileBasinStats'
% plots - Type of plot you want to produce, valid inputs are:
% 'grd_ksn' - plot of mean basin gradient vs mean basin channel steepness (e.g. see Forte et al, 2016, Earth and Planetary
% Science Letters for discussion of use of these plots)
% 'grd_rlf' - similar to 'grd_ksn' but uses local relief instead of ksn, requires that relief was calculated when running
% ProcessRiverBasins. Assumes relief radius is 2500 (can set alternative radii with 'rlf_radius' optional parameter)
% 'rlf_ksn' - plot of mean basin relief vs mean basin channel steepness
% 'compare_filtered' - plot comparing mean values vs filtered mean values if you ran 'CompileBasinStats' and filtered by a category
% 'category_mean_hist' - if you calculated 'means_by_category' when running 'CompileBasinStats', you can plot distributions of the
% means by category as histograms using this option. Requires an input to 'cat_mean1'
% 'category_mean_compare' -if you calculated 'means_by_category' for more than one value (e.g. both gradient and ksn), you can compare
% the mean values by category using this plot. Requires inputs to both 'cat_mean1' (value that will be plotted on x axis)
% and 'cat_mean2' (value that will be plotted on y axis)
% 'stacked_hypsometry' - plot hypsometries for the basins
% 'compare_mean_and_dist' - plots a histogram of values within a selected basin or across all basins for a statistic of interest to
% compare to the mean value, accepts an input for 'statistic_of_interest' and 'basin_num'.
% 'scatterplot_matrix' - matrix of scatterplots and histograms, designed to be sort of similar to 'lattice' plots in R. Providing a table
% for which you calculated filtered means and leaving 'use_filtered' set to false may produce a large matrix
% 'xy' - generic plot, requires entries to optional 'xval' and 'yval' inputs
%
%%%%%%%%%%%%%%%%%%
% Optional Inputs:
%
%%% General Parameters
% uncertianty ['se'] - uncertainty to value use for plots, valid options are 'se' (standard error), 'std' (standard deviation), or 'none'.
% Providing 'none' indicates you do not want to plot errorbars. Behavior of this option will depend on how you ran ProcessRiverBasins,
% e.g. if you only calculated standard deviations when running ProcessRiverBasins but supply 'se' here, the code will ignore your choice
% and use the standard deviation values.
% use_filtered [false] - logical flag to use filtered values for 'grd_ksn', 'grd_rlf', 'rlf_ksn', or 'scatterplot_matrix'. Will only work if
% you calculated filtered values when running 'CompileBasinStats'.
% color_by [] - value to color points by, valid for 'grd_ksn','grd_rlf','rlf_ksn', and 'xy', either the name of a column in the provided table
% or a m x 1 array of numeric values the same length as the provided table
% cmap [] - colormap to use if an entry is provided to 'color_by', can be the name of a standard colormap or a nx3 array of rgb values
% to use as a colormap.
% define_region [] - set of coordinates to define a rectangular region to draw data from, expects a four element matrix (row or column) that define
% the minimum x, maximum x, minimum y, and maximum y coordinate to include OR define as true to bring up a plot of all basin centers
% for you to select a region by drawing a rectangle. Works with all plots.
% rlf_radius [2500] - radius of relief used when plotting relief related values
% save_figure [false] - logical flag to save pdfs of all figures produced
%
%%% xy plot
% xval [] - value to plot on x axis for plot type 'xy' provided as name of column as it appears in the provided table or a a m x 1 array of numeric
% values the same length as the provided table
% yval [] - value to plot on y axis for plot type 'xy' provided as name of column as it appears in the provided table or a a m x 1 array of numeric
% values the same length as the provided table
%
%%% compare_mean_and_dist plot
% statistic_of_interest ['ksn'] - statistic of interest for plotting histogram to compare with mean value. Valid inputs are 'ksn', 'gradient',
% 'elevation', 'relief' (if you provide relief, the code will look for relief calculated at the radius specified with the optional 'rlf_radius' parameter),
% or the name of an additional grid provided to 'ProcessRiverBasins', e.g. if you provided a precipitation grid and provided the name 'precip'
% and a column named 'mean_precip' exists in the table, then 'precip' would be a valid input to this parameter.
% basin_num [] - number of basin (as it appears in the ID column of the table) to use for 'compare_mean_and_dist', if empty, 'compare_mean_and_dist'
% will use all basins.
%
%%% category_mean_hist OR category_mean_compare
% cat_mean1 [] - category to use for plotting, see 'category_mean_hist' or 'category_mean_compare', valid inputs are 'ksn', 'rlf', 'gradient', or
% the name of an additional grid provided to ProcessRiverMeans.
% cat_mean2 [] - category to use for plotting, 'category_mean_compare' , valid inputs are 'ksn', 'rlf', 'gradient', or the name of an additional grid
% provided to ProcessRiverMeans.
%
%%% Fit Gradient-Ksn Relationship
% fit_grd_ksn [false] - logical flag to initiate fitting of gradient - ksn relationship. Setting this flag to true only produces a result if the
% plot type is set to 'grd_ksn'. The relationship is a fit using a power law relationship between erosion rate and channel steepness and erosion
% rate and mean hillslope gradient. See Forte et al, 2016, Earth and Planetary Science Letters for further discussion. The fit optimizes
% values of hillslope diffusivity (D), fluvial erodibility (K), and threshold gradient (Sc). The best fit values for these will be printed
% to the console.
% start_diffusivity [0.01] - starting value for optimization of hillslope diffusivity parameter.
% start_erodibility [1e-7] - starting value for optimization of fluvial erodibility parameter.
% start_threshold_gradient [0.8] - starting value for optimzation of threshold hillslope gradient parameter.
% n_val [2] - n value on slope parameter, this is not a free parameter in the fit.
%
%%% Fit Relief-Ksn Relationship
% fit_rlf_ksn [false] - logical flag to initiate simple linear fit of relief-ksn relationship (expectation is a linear relationship). Setting this
% flag to true only produces a result if the plot type is set to 'rlf_ksn'.
%
%%% Fit Filtered Data
% fit_filtered [false] - logical flat to initiate a simple linear fit to filtered data. Setting this to true only produces a result if plot type
% is set to 'compare_filtered'.
%
%%%%%%%%%%%%%%%%%%
% Examples:
%
% % Plot of mean basin gradient vs 2500 m^2 relief using default relief radius
% BasinStatsPlots(T,'grd_rlf');
%
% % Plot of mean basin gradient vs mean basin channel steepness colored by mean elevation
% BasinStatsPlots(T,'grd_ksn','color_by','mean_el');
%
% % Plot of mean basin gradient vs mean basin channel steepenss colored by mode geology, where colormap has been scaled to provide unique colors for units
% cmap=colorcube(numel(unique(T.mode_geology)));
% BasinStatsPlots(T,'grd_ksn','color_by','mode_geology','cmap',cmap);
%
% % Plot of mean basin channel steepenss vs basin drainage area
% BasinStatsPlots(T,'xy','xval','drainage_area','yval','mean_ksn');
%
% % Histograms of mean 2500 m^2 relief by individual categories (e.g. geology)
% BasinStatsPlots(T,'category_mean_hist','cat_mean1','rlf');
%
% % Plots of mean basin gradient vs mean basin channel steepness within individual categories
% BasinStatsPlots(T,'category_mean_compare','cat_mean1','ksn','cat_mean2','gradient');
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function Written by Adam M. Forte - Updated : 06/18/18 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parse Inputs
p = inputParser;
p.FunctionName = 'BasinStatsPlots';
addRequired(p,'basin_table',@(x) isa(x,'table'));
addRequired(p,'plots',@(x) ischar(validatestring(x,{'grd_ksn','grd_rlf','rlf_ksn',...
'compare_filtered','category_mean_hist','category_mean_compare','xy','stacked_hypsometry',...
'compare_mean_and_dist','scatterplot_matrix'})));
addParameter(p,'uncertainty','se',@(x) ischar(validatestring(x,{'se','std','none'})));
addParameter(p,'use_filtered',false,@(x) islogical(x) && isscalar(x));
addParameter(p,'color_by',[],@(x) ischar(x) || isnumeric(x) & size(x,2)==1 || isempty(x));
addParameter(p,'cmap',[],@(x) ischar(x) || isnumeric(x) & size(x,2)==3);
addParameter(p,'xval',[],@(x) ischar(x) || isnumeric(x) & size(x,2)==1);
addParameter(p,'yval',[],@(x) ischar(x) || isnumeric(x) & size(x,2)==1);
addParameter(p,'define_region',[],@(x) isnumeric(x) & numel(x)==4 || islogical(x));
addParameter(p,'statistic_of_interest','ksn',@(x) ischar(x));
addParameter(p,'basin_num',[],@(x) isnumeric(x) && isscalar(x));
addParameter(p,'rlf_radius',2500,@(x) isnumeric(x) && isscalar(x));
addParameter(p,'cat_mean1',[],@(x) ischar(x));
addParameter(p,'cat_mean2',[],@(x) ischar(x));
addParameter(p,'fit_grd_ksn',false,@(x) isscalar(x) && islogical(x));
addParameter(p,'start_diffusivity',0.01,@(x) isscalar(x) && isnumeric(x));
addParameter(p,'start_erodibility',1e-7,@(x) isscalar(x) && isnumeric(x));
addParameter(p,'start_threshold_gradient',0.8,@(x) isscalar(x) && isnumeric(x));
addParameter(p,'n_val',2,@(x) isscalar(x) && isnumeric(x));
addParameter(p,'fit_rlf_ksn',false,@(x) isscalar(x) && islogical(x));
addParameter(p,'fit_filtered',false,@(x) isscalar(x) && islogical(x));
addParameter(p,'save_figure',false,@(x) isscalar(x) && islogical(x));
addParameter(p,'out_dir',[],@(x) isdir(x));
parse(p,basin_table,plots,varargin{:});
T=p.Results.basin_table;
plts=p.Results.plots;
uncertainty=p.Results.uncertainty;
use_filtered=p.Results.use_filtered;
color_by=p.Results.color_by;
cmap=p.Results.cmap;
xval=p.Results.xval;
yval=p.Results.yval;
regionOI=p.Results.define_region;
basin_num=p.Results.basin_num;
stOI=p.Results.statistic_of_interest;
rr=p.Results.rlf_radius;
cm1=p.Results.cat_mean1;
cm2=p.Results.cat_mean2;
fit_grd_ksn=p.Results.fit_grd_ksn;
fit_rlf_ksn=p.Results.fit_rlf_ksn;
fit_filtered=p.Results.fit_filtered;
D_in=p.Results.start_diffusivity;
K_in=p.Results.start_erodibility;
s_in=p.Results.start_threshold_gradient;
n_val=p.Results.n_val;
save_figure=p.Results.save_figure;
out_dir=p.Results.out_dir;
if isempty(out_dir)
out_dir=pwd;
end
if isempty(cmap);
cmap=parula(50);
end
% Deal with variable inputs
if ~isempty(color_by) & isnumeric(color_by)
cval=color_by;
color_by='color_by';
T.color_by=cval;
end
if ~isempty(xval) & isnumeric(xval);
xv=xval;
xval='xval';
T.xval=xv;
end
if ~isempty(yval) & isnumeric(yval);
yv=yval;
yval='yval';
T.yval=yv;
end
% Deal with region if specified
if ~isempty(regionOI) && ~islogical(regionOI)
rIDX=T.center_x>=regionOI(1) & T.center_x<=regionOI(2) & T.center_y>=regionOI(3) & T.center_y<=regionOI(4);
T=T(rIDX,:);
if isempty(T)
if isdeployed
errordlg('Provided region has eliminated all entries from the table, check that the coordinates are correct')
end
error('Provided region has eliminated all entries from the table, check that the coordinates are correct');
end
elseif ~isempty(regionOI) && islogical(regionOI) && regionOI
f1=figure(1);
clf
hold on
scatter(T.center_x,T.center_y,20,'k','filled');
title('Draw a rectangle around the data you would like to select');
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
rgn=getrect;
close(f1);
regionOI=zeros(4,1);
regionOI(1)=rgn(1);
regionOI(2)=rgn(1)+rgn(3);
regionOI(3)=rgn(2);
regionOI(4)=rgn(2)+rgn(4);
rIDX=T.center_x>=regionOI(1) & T.center_x<=regionOI(2) & T.center_y>=regionOI(3) & T.center_y<=regionOI(4);
T=T(rIDX,:);
end
% Generate Plots
switch plts
case 'grd_ksn'
if use_filtered
g=T.mean_gradient_f;
k=T.mean_ksn_f;
else
g=T.mean_gradient;
k=T.mean_ksn;
end
if use_filtered
if ismember('std_ksn_f',T.Properties.VariableNames) & strcmp(uncertainty,'std')
sk=T.std_ksn_f;
sg=T.std_gradient_f;
elseif ismember('se_ksn_f',T.Properties.VariableNames) & strcmp(uncertainty,'se')
sk=T.se_ksn_f;
sg=T.se_gradient_f;
elseif ismember('std_ksn_f',T.Properties.VariableNames) & ~ismember('se_ksn_f',T.Properties.VariableNames)
sk=T.std_ksn_f;
sg=T.std_gradient_f;
elseif ismember('se_ksn_f',T.Properties.VariableNames) & ~ismember('std_ksn_f',T.Properties.VariableNames)
sk=T.se_ksn_f;
sg=T.se_gradient_f;
end
else
if ismember('std_ksn',T.Properties.VariableNames) & strcmp(uncertainty,'std')
sk=T.std_ksn;
sg=T.std_gradient;
elseif ismember('se_ksn',T.Properties.VariableNames) & strcmp(uncertainty,'se')
sk=T.se_ksn;
sg=T.se_gradient;
elseif ismember('std_ksn',T.Properties.VariableNames) & ~ismember('se_ksn',T.Properties.VariableNames)
sk=T.std_ksn;
sg=T.std_gradient;
elseif ismember('se_ksn',T.Properties.VariableNames) & ~ismember('std_ksn',T.Properties.VariableNames)
sk=T.se_ksn;
sg=T.se_gradient;
end
end
if fit_grd_ksn
[pf]=KGF(k,g,D_in,K_in,s_in,n_val);
[mg,mk,er,l]=KGG(pf.D,pf.K,pf.Sc,pf.n,k);
end
f=figure(1);
clf
set(f,'Units','normalized','Position',[0.05 0.1 0.5 0.5],'renderer','painters');
hold on
if ~strcmp(uncertainty,'none')
errorbar(k,g,sg,sg,sk,sk,'.k','CapSize',0);
end
if ~isempty(color_by) & isnumeric(T.(color_by));
colormap(cmap);
scatter(k,g,30,T.(color_by),'filled');
cb=colorbar;
% Remove any underscores
color_by_label=strrep(color_by,'_',' ');
ylabel(cb,color_by_label);
elseif ~isempty(color_by) & isa(T.(color_by),'cell');
colormap(cmap);
scatter(k,g,30,categorical(T.(color_by)),'filled');
cb=colorbar('Ticks',[1:numel(unique(T.(color_by)))],'YTickLabel',unique(T.(color_by)));
% Remove any underscores
color_by_label=strrep(color_by,'_',' ');
ylabel(cb,color_by_label);
else
scatter(k,g,30,'k','filled');
end
if fit_grd_ksn
p1=plot(mk,mg,'-r','LineWidth',2);
disp(['Fluvial Erodibility (K) = ' num2str(pf.K)]);
disp(['Diffusivity (D) = ' num2str(pf.D)]);
disp(['Threshold Gradient (Sc) = ' num2str(pf.Sc)]);
leg_text=['Fluvial Erodibility (K) = ' num2str(pf.K) newline 'Diffusivity (D) = ' num2str(pf.D) newline 'Threshold Gradient (Sc) = ' num2str(pf.Sc)];
legend(p1,leg_text,'location','best');
end
xlabel('Mean Basin k_{sn}');
ylabel('Mean Basin Gradient');
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
case 'grd_rlf'
% Validate Relief Entry
if use_filtered
m_rlfN=['mean_rlf' num2str(rr) '_f'];
se_rlfN=['se_rlf' num2str(rr) '_f'];
std_rlfN=['std_rlf' num2str(rr) '_f'];
if ismember(m_rlfN,T.Properties.VariableNames)
r=T.(m_rlfN);
else
if isdeployed
errordlg('Relief radius is not recognized, confirm that you calculated local relief at this radius when running "ProcessRiverBasins"')
end
error('Relief radius is not recognized, confirm that you calculated local relief at this radius when running "ProcessRiverBasins"')
end
g=T.mean_gradient_f;
else
m_rlfN=['mean_rlf' num2str(rr)];
se_rlfN=['se_rlf' num2str(rr)];
std_rlfN=['std_rlf' num2str(rr)];
if ismember(m_rlfN,T.Properties.VariableNames)
r=T.(m_rlfN);
else
if isdeployed
errordlg('Relief radius is not recognized, confirm that you calculated local relief at this radius when running "ProcessRiverBasins"')
end
error('Relief radius is not recognized, confirm that you calculated local relief at this radius when running "ProcessRiverBasins"')
end
g=T.mean_gradient;
end
if use_filtered
if ismember('std_gradient_f',T.Properties.VariableNames) & strcmp(uncertainty,'std')
sr=T.(std_rlfN);
sg=T.std_gradient_f;
elseif ismember('se_gradient_f',T.Properties.VariableNames) & strcmp(uncertainty,'se')
sr=T.(se_rlfN);
sg=T.se_gradient_f;
elseif ismember('std_gradient_f',T.Properties.VariableNames) & ~ismember('se_gradient_f',T.Properties.VariableNames)
sr=T.(std_rlfN);
sg=T.std_gradient_f;
elseif ismember('se_gradient_f',T.Properties.VariableNames) & ~ismember('std_gradient_f',T.Properties.VariableNames)
sr=T.(se_rlfN);
sg=T.se_gradient_f;
end
else
if ismember('std_gradient',T.Properties.VariableNames) & strcmp(uncertainty,'std')
sr=T.(std_rlfN);
sg=T.std_gradient;
elseif ismember('se_gradient',T.Properties.VariableNames) & strcmp(uncertainty,'se')
sr=T.(se_rlfN);
sg=T.se_gradient;
elseif ismember('std_gradient',T.Properties.VariableNames) & ~ismember('se_gradient',T.Properties.VariableNames)
sr=T.(std_rlfN);
sg=T.std_gradient;
elseif ismember('se_gradient',T.Properties.VariableNames) & ~ismember('std_gradient',T.Properties.VariableNames)
sr=T.(se_rlfN);
sg=T.se_gradient;
end
end
f=figure(1);
set(f,'Units','normalized','Position',[0.05 0.1 0.5 0.5],'renderer','painters');
clf
hold on
if ~strcmp(uncertainty,'none')
errorbar(r,g,sg,sg,sr,sr,'.k','CapSize',0);
end
if ~isempty(color_by) & isnumeric(T.(color_by));
colormap(cmap);
scatter(r,g,30,T.(color_by),'filled');
cb=colorbar;
% Remove any underscores
color_by_label=strrep(color_by,'_',' ');
ylabel(cb,color_by_label);
elseif ~isempty(color_by) & isa(T.(color_by),'cell');
colormap(cmap);
scatter(r,g,30,categorical(T.(color_by)),'filled');
cb=colorbar('Ticks',[1:numel(unique(T.(color_by)))],'YTickLabel',unique(T.(color_by)));
% Remove any underscores
color_by_label=strrep(color_by,'_',' ');
ylabel(cb,color_by_label);
else
scatter(r,g,30,'k','filled');
end
xlabel(['Mean Basin ' num2str(rr) ' m^2 Relief']);
ylabel('Mean Basin Gradient');
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
case 'rlf_ksn'
% Validate Relief Entry
if use_filtered
m_rlfN=['mean_rlf' num2str(rr) '_f'];
se_rlfN=['se_rlf' num2str(rr) '_f'];
std_rlfN=['std_rlf' num2str(rr) '_f'];
if ismember(m_rlfN,T.Properties.VariableNames)
r=T.(m_rlfN);
else
if isdeployed
errordlg('Relief radius is not recognized, confirm that you calculated local relief at this radius when running "ProcessRiverBasins"')
end
error('Relief radius is not recognized, confirm that you calculated local relief at this radius when running "ProcessRiverBasins"')
end
k=T.mean_ksn_f;
else
m_rlfN=['mean_rlf' num2str(rr)];
se_rlfN=['se_rlf' num2str(rr)];
std_rlfN=['std_rlf' num2str(rr)];
if ismember(m_rlfN,T.Properties.VariableNames)
r=T.(m_rlfN);
else
if isdeployed
errordlg('Relief radius is not recognized, confirm that you calculated local relief at this radius when running "ProcessRiverBasins"')
end
error('Relief radius is not recognized, confirm that you calculated local relief at this radius when running "ProcessRiverBasins"')
end
k=T.mean_ksn;
end
if use_filtered
if ismember('std_ksn_f',T.Properties.VariableNames) & strcmp(uncertainty,'std')
sk=T.std_ksn_f;
sr=T.(std_rlfN);
elseif ismember('se_ksn_f',T.Properties.VariableNames) & strcmp(uncertainty,'se')
sk=T.se_ksn_f;
sr=T.(se_rlfN);
elseif ismember('std_ksn_f',T.Properties.VariableNames) & ~ismember('se_ksn_f',T.Properties.VariableNames)
sk=T.std_ksn_f;
sr=T.(std_rlfN);
elseif ismember('se_ksn_f',T.Properties.VariableNames) & ~ismember('std_ksn_f',T.Properties.VariableNames)
sk=T.se_ksn_f;
sr=T.(se_rlfN);
end
else
if ismember('std_ksn',T.Properties.VariableNames) & strcmp(uncertainty,'std')
sk=T.std_ksn;
sr=T.(std_rlfN);
elseif ismember('se_ksn',T.Properties.VariableNames) & strcmp(uncertainty,'se')
sk=T.se_ksn;
sr=T.(se_rlfN);
elseif ismember('std_ksn',T.Properties.VariableNames) & ~ismember('se_ksn',T.Properties.VariableNames)
sk=T.std_ksn;
sr=T.(std_rlfN);
elseif ismember('se_ksn',T.Properties.VariableNames) & ~ismember('std_ksn',T.Properties.VariableNames)
sk=T.se_ksn;
sr=T.(se_rlfN);
end
end
if fit_rlf_ksn
ft=fittype('a*x');
[fobj,gof]=fit(k,r,ft,'StartPoint',k\r);
krs=coeffvalues(fobj);
krs_unc=confint(fobj);
end
f=figure(1);
set(f,'Units','normalized','Position',[0.05 0.1 0.5 0.5],'renderer','painters');
clf
hold on
if ~strcmp(uncertainty,'none')
errorbar(k,r,sr,sr,sk,sk,'.k','CapSize',0);
end
if ~isempty(color_by) & isnumeric(T.(color_by));
colormap(cmap);
scatter(k,r,30,T.(color_by),'filled');
cb=colorbar;
% Remove any underscores
color_by_label=strrep(color_by,'_',' ');
ylabel(cb,color_by_label);
elseif ~isempty(color_by) & isa(T.(color_by),'cell');
colormap(cmap);
scatter(k,r,30,categorical(T.(color_by)),'filled');
cb=colorbar('Ticks',[1:numel(unique(T.(color_by)))],'YTickLabel',unique(T.(color_by)));
% Remove any underscores
color_by_label=strrep(color_by,'_',' ');
ylabel(cb,color_by_label);
else
scatter(k,r,30,'k','filled');
end
if fit_rlf_ksn
ksn_vec=linspace(0,max(k)+50,100);
rlf_vec=krs*ksn_vec;
rlf_vec_pos=(krs_unc(2))*ksn_vec;
rlf_vec_neg=(krs_unc(1))*ksn_vec;
p1=plot(ksn_vec,rlf_vec,'-r','LineWidth',2);
plot(ksn_vec,rlf_vec_pos,'--r');
plot(ksn_vec,rlf_vec_neg,'--r');
disp(['Relationship slope = ' num2str(krs)]);
disp(['Uncertainty on slope = ' num2str(krs_unc(1)) ' : ' num2str(krs_unc(2))]);
disp(['r-square = ' num2str(gof.rsquare)]);
leg_text=['Relationship slope = ' num2str(krs) newline 'Uncertainty on slope = ' num2str(krs_unc(1)) ' : ' num2str(krs_unc(2)) newline 'r-square = ' num2str(gof.rsquare)];
legend(p1,leg_text,'location','best');
end
ylabel(['Mean Basin ' num2str(rr) ' m^2 Relief']);
xlabel('Mean Basin k_{sn}');
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
case 'stacked_hypsometry'
hypsCell=T.hypsometry;
HI=T.hyp_integral;
numHyps=numel(hypsCell);
normEl=zeros(100,numHyps);
normF=zeros(100,numHyps);
El=normEl;
F=normF;
for ii=1:numHyps
normEl(:,ii)=(hypsCell{ii}(:,2)-min(hypsCell{ii}(:,2)))/(max(hypsCell{ii}(:,2))-min(hypsCell{ii}(:,2)));
normF(:,ii)=(hypsCell{ii}(:,1))/100;
El(:,ii)=hypsCell{ii}(:,2);
F(:,ii)=hypsCell{ii}(:,1);
end
histIm=zeros(100,100);
jj=100:-1:1;
for ii=1:100
[N,~]=histcounts(normF(ii,:),linspace(0,1,101));
histIm(jj(ii),:)=log10(N);
end
if ~isempty(color_by) & isnumeric(T.(color_by));
col_val=T.(color_by);
f(1)=figure(1);
set(f(1),'Units','normalized','Position',[0.05 0.5 0.4 0.4],'renderer','painters');
clf
hold on
colormap(cmap);
cm=colormap;
num_col=size(cm,1);
[cix,ed]=discretize(col_val,num_col);
for ii=1:num_col
idx=cix==ii;
plot(normF(:,idx),normEl(:,idx),'Color',cm(ii,:));
end
caxis([min(ed) max(ed)]);
cb=colorbar;
% Remove any underscores
color_by_label=strrep(color_by,'_',' ');
ylabel(cb,color_by_label);
axis equal
xlabel('Normalized Area');
ylabel('Normalized Elevation');
xlim([0 1]);
ylim([0 1]);
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
else
f(1)=figure(1);
set(f(1),'Units','normalized','Position',[0.05 0.5 0.4 0.4],'renderer','painters');
clf
hold on
plot(normF,normEl,'-k');
axis equal
xlabel('Normalized Area');
ylabel('Normalized Elevation');
xlim([0 1]);
ylim([0 1]);
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
end
if ~isempty(color_by) & isnumeric(T.(color_by));
col_val=T.(color_by);
f(2)=figure(2);
set(f(2),'Units','normalized','Position',[0.05 0.05 0.4 0.4],'renderer','painters');
clf
hold on
colormap(cmap);
cm=colormap;
num_col=size(cm,1);
[cix,ed]=discretize(col_val,num_col);
for ii=1:num_col
idx=cix==ii;
plot(F(:,idx),El(:,idx),'Color',cm(ii,:));
end
caxis([min(ed) max(ed)]);
cb=colorbar;
% Remove any underscores
color_by_label=strrep(color_by,'_',' ');
ylabel(cb,color_by_label);
axis square
xlabel('Percentage Area');
ylabel('Elevation');
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
else
f(2)=figure(2);
set(f(2),'Units','normalized','Position',[0.05 0.05 0.4 0.4],'renderer','painters');
clf
hold on
plot(F,El,'-k');
axis square
xlabel('Percentage Area');
ylabel('Elevation');
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
end
num_bins=20;
[hix,hed]=discretize(HI,linspace(0,1,num_bins+1));
f(3)=figure(3);
set(f(3),'Units','normalized','Position',[0.5 0.5 0.4 0.4],'renderer','painters');
clf
for ii=1:num_bins
sbplt(ii)=subplot(4,5,ii);
hold on
idx=hix==ii;
perc(ii,1)=round((nnz(idx)/numel(idx))*100,1);
nF=normF(:,idx);
nE=normEl(:,idx);
mF{ii,1}=mean(nF,2);
mE{ii,1}=mean(nE,2);
plot(nF,nE,'LineWidth',0.5,'Color',[0.4 0.4 0.4]);
plot(mF{ii,1},mE{ii,1},'-r','LineWidth',2);
if ii<=num_bins/2
text(0.75,0.9,[num2str(perc(ii,1)) '%']);
else
text(0.1,0.1,[num2str(perc(ii,1)) '%']);
end
axis equal
title(['HI ' num2str(hed(ii)) ' to ' num2str(hed(ii+1))])
xlabel('Normalized Area');
ylabel('Normalized Elevation');
xlim([0 1]);
ylim([0 1]);
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(sbplt(ii));
end
hold off
end
f(4)=figure(4);
set(f(4),'Units','normalized','Position',[0.5 0.05 0.4 0.4]);
clf
X=linspace(0,1,100);
Y=linspace(0,1,100);
hold on
colormap(jet);
imagesc(X,Y,histIm);
axis equal
xlabel('Normalized Area');
ylabel('Normalized Elevation');
xlim([0 1]);
ylim([0 1]);
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
f(5)=figure(5);
set(f(5),'Units','normalized','Position',[0.25 0.25 0.4 0.4],'renderer','painters');
clf
hold on
colormap(jet);
idx=perc>0;
pf=perc(idx);
jc=jet(100);
for ii=1:num_bins
ix=round((perc(ii,1)/max(pf))*100);
if ix==0
cl=[1 1 1];
else
cl=jc(ix,:);
end
plot(mF{ii,1},mE{ii,1},'Color',cl,'LineWidth',2);
end
caxis([min(pf) max(pf)]);
cb=colorbar;
ylabel(cb,'Percentage of Basins')
axis equal
xlabel('Normalized Area');
ylabel('Normalized Elevation');
xlim([0 1]);
ylim([0 1]);
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
case 'scatterplot_matrix'
% Find values with means
if use_filtered
VN=T.Properties.VariableNames;
ix=regexp(VN,regexptranslate('wildcard','mean_*_f'));
ix=cellfun(@any,ix);
VNoi=VN(ix);
else
VN=T.Properties.VariableNames;
ix=regexp(VN,regexptranslate('wildcard','mean_*'));
ix=cellfun(@any,ix);
VNoi=VN(ix);
end
% Add azimuth if it was calculated
aix=regexp(VN,regexptranslate('wildcard','dist_along*'));
aix=cellfun(@any,aix);
if ~isempty(aix);
VNoi=horzcat(VNoi,VN(aix));
end
num_sc=numel(VNoi);
f=figure(1);
set(f,'Units','normalized','Position',[0.05 0.5 0.9 0.9],'renderer','painters');
clf
pos=1;
for ii=1:num_sc
yval=T.(VNoi{ii});
yname=VNoi{ii};
yname=strrep(yname,'_',' ');
for jj=1:num_sc
subplot(num_sc,num_sc,pos)
hold on
if ii==jj
histogram(yval,25,'FaceColor','k');
if jj==num_sc & ii==num_sc
xlabel(yname);
end
axis square
else
xval=T.(VNoi{jj});
xname=VNoi{jj};
xname=strrep(xname,'_',' ');
scatter(xval,yval,5,'k','filled');
warning off
f=fit(xval,yval,'poly2');
warning on
xx=linspace(min(xval),max(xval),50);
yy=f(xx);
plot(xx,yy,'-r');
if ii==num_sc
xlabel(xname);
end
if jj==1
ylabel(yname);
end
axis square
end
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
pos=pos+1;
end
end
case 'compare_filtered'
VN=T.Properties.VariableNames;
ix=regexp(VN,regexptranslate('wildcard','mean_*_f'));
ix=cellfun(@any,ix);
VNoi=VN(ix);
if isempty(VNoi)
if isdeployed
errordlg('No filtered values were found in provided table')
end
error('No filtered values were found in provided table');
end
if fit_filtered
ft=fittype('a*x');
end
num_filt=numel(VNoi);
for ii=1:num_filt
fN=VNoi{ii};
N=strrep(fN,'_f','');
% Parse value
if strcmp(N,'mean_ksn')
t='Mean Channel Steepness';
elseif strcmp(N,'mean_gradient');
t='Mean Gradient';
elseif regexp(N,regexptranslate('wildcard','mean_rlf*'));
t=['Mean ' strrep(N,'mean_rlf','') ' m^2 Relief'];
else
t=['Mean ' strrep(N,'mean_','')];
end
max_val=max([max(T.(fN)) max(T.(N))]);
max_vec=[0 max_val];
slp=round(T.(N)./T.(fN),1);
idx1=slp==1;
idx2=slp<1;
idx3=slp>1;
if fit_filtered
idx=isnan(T.(fN)) | isnan(T.(N));
x=double(T.(fN)(~idx));
y=double(T.(N)(~idx));
[fobj,gof]=fit(x,y,ft,'StartPoint',x\y);
cf=coeffvalues(fobj);
cf_unc=confint(fobj);
end
f(ii)=figure(ii);
set(gcf,'Units','normalized','Position',[0.05 0.1 0.5 0.5],'renderer','painters');
clf
hold on
plot(max_vec,max_vec,'-k');
sp(1)=scatter(T.(fN)(idx1),T.(N)(idx1),30,'k','filled');
sp(2)=scatter(T.(fN)(idx2),T.(N)(idx2),30,'r','filled');
sp(3)=scatter(T.(fN)(idx3),T.(N)(idx3),30,'b','filled');
if fit_filtered
fvec=linspace(0,max(T.(fN)),100);
vec=cf*fvec;
vec_pos=(cf_unc(2))*fvec;
vec_neg=(cf_unc(1))*fvec;
pl=plot(fvec,vec,'-g','LineWidth',2);
plot(fvec,vec_pos,'--g');
plot(fvec,vec_neg,'--g');
disp(['Fits on ' t ':']);
disp([' Relationship slope = ' num2str(cf)]);
disp([' Uncertainty on slope = ' num2str(cf_unc(1)) ' : ' num2str(cf_unc(2))]);
disp([' r-square = ' num2str(gof.rsquare)]);
leg_text={'Filtered = Unfiltered','Filtered > Unfiltered','Filtered < Unfiltered',['Best Fit:' newline ' Relationship slope = ' num2str(cf) newline ' Uncertainty on slope = ' num2str(cf_unc(1)) ' : ' num2str(cf_unc(2)) newline ' r-square = ' num2str(gof.rsquare)]};
legend([sp pl],leg_text,'location','northwest')
else
legend(sp,{'Filtered = Unfiltered','Filtered > Unfiltered','Filtered < Unfiltered'},'location','northwest')
end
xlabel('Filtered Means');
ylabel('Unfiltered Means');
title(t);
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
end
case 'category_mean_hist'
if isempty(cm1)
if isdeployed
errordlg('For plot option "category_mean_hist" you must provide an input for "cat_mean1"')
end
error('For plot option "category_mean_hist" you must provide an input for "cat_mean1"')
elseif strcmp(cm1,'ksn')
VN=T.Properties.VariableNames;
ix=regexp(VN,regexptranslate('wildcard','mksn*'));
ix=cellfun(@any,ix);
VNoi=VN(ix);
Cat_Names=cellfun(@(x) strrep(x,'mksn_',''),VNoi,'UniformOutput',false);
Main_Title='Mean k_{sn} within ';
elseif strcmp(cm1,'gradient')
VN=T.Properties.VariableNames;
ix=regexp(VN,regexptranslate('wildcard','mgrad*'));
ix=cellfun(@any,ix);
VNoi=VN(ix);
Cat_Names=cellfun(@(x) strrep(x,'mgrad_',''),VNoi,'UniformOutput',false);
Main_Title='Mean gradient within ';
elseif strcmp(cm1,'rlf')
VN=T.Properties.VariableNames;
srch_strng=['mr' num2str(rr) '*'];
ix=regexp(VN,regexptranslate('wildcard',srch_strng));
ix=cellfun(@any,ix);
VNoi=VN(ix);
if isempty(VNoi)
if isdeployed
errordlg('Entry for "cat_mean1" is not recognized, check that relief radius correct')
end
error('Entry for "cat_mean1" is not recognized, check that relief radius correct');
end
srch_strng=['mr' num2str(rr) '_'];
Cat_Names=cellfun(@(x) strrep(x,srch_strng,''),VNoi,'UniformOutput',false);
Main_Title=['Mean ' num2str(rr) '_Relief within '];
else
VN=T.Properties.VariableNames;
srch_strng=['m' cm1 '*'];
ix=regexp(VN,regexptranslate('wildcard',srch_strng));
ix=cellfun(@any,ix);
VNoi=VN(ix);
if isempty(VNoi)
if isdeployed
errordlg('Entry for "cat_mean1" is not recognized')
end
error('Entry for "cat_mean1" is not recognized');
end
srch_strng=['m' cm1 '_'];
Cat_Names=cellfun(@(x) strrep(x,srch_strng,''),VNoi,'UniformOutput',false);
Main_Title=['Mean ' cm1 ' within '];
end
for ii=1:numel(VNoi)
vals=T.(VNoi{ii});
vals(isnan(vals))=[];
if ~isempty(vals)
val_list{ii,1}=vals;
end
end
val_list=vertcat(val_list{:});
[~,edges]=discretize(val_list,100);
for ii=1:numel(VNoi)
vals=T.(VNoi{ii});
vals(isnan(vals))=[];
if ~isempty(vals)
f(ii)=figure(ii);
set(gcf,'Units','normalized','Position',[0.05 0.1 0.5 0.5],'renderer','painters');
clf
hold on
histogram(vals,edges);
title([Main_Title Cat_Names{ii}]);
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
end
end
case 'category_mean_compare'
if isempty(cm1)
if isdeployed
errordlg('For plot option "category_mean_compare" you must provide an input for "cat_mean1"')
end
error('For plot option "category_mean_compare" you must provide an input for "cat_mean1"')
elseif strcmp(cm1,'ksn')
VN=T.Properties.VariableNames;
ix=regexp(VN,regexptranslate('wildcard','mksn*'));
ix=cellfun(@any,ix);
VNoi1=VN(ix);
Cat_Names=cellfun(@(x) strrep(x,'mksn_',''),VNoi1,'UniformOutput',false);