forked from amforte/Topographic-Analysis-Kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotChi.m
116 lines (102 loc) · 3.34 KB
/
PlotChi.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
function PlotChi(DEM,S,chi,chi_type,varargin)
%
% Usage:
% PlotChi(DEM,S,chi,'chimap');
% PlotChi(DEM,S,chi,'chigrid');
% PlotChi(DEM,S,chi,'chimap','name',value,...);
%
% Description:
% Function to plot a map of normalized channel steepness on a hillshade colored
% by elevation.
%
% Required Inputs:
% DEM - Digital Elevation as a GRIDobj used to produce the provided chi data
% S - STREAMobj used when producing chi values
% chi - chi data either as an ascii file or a GRIDobj (e.g. as output from KsnChiBatch)
% chi_type - value indicating if the provided chi data is a 'chimap' (along streams only) or
% a continuous grid 'chigrid'
%
% Optional Inputs:
% chi_lim [] - 1 x n vector setting the min and max for the color scaling for chi. If left blank
% will default to 0 and the maximum in the dataset
%
% Examples:
% PlotChi(DEM,S,chimap,'chimap'); % Plot chi from an output chimap (as a GRIDobj)
% PlotChi(DEM,S,'Topo_chigrid.txt','chigrid','chi_lim',[0 10]);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function Written by Adam M. Forte - Updated : 09/30/19 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parse Inputs
p = inputParser;
p.FunctionName = 'PlotChi';
addRequired(p,'DEM',@(x) isa(x,'GRIDobj'));
addRequired(p,'S',@(x) isa(x,'STREAMobj'));
addRequired(p,'chi',@(x) isa(x,'GRIDobj') || regexp(x,regexptranslate('wildcard','*.txt')));
addRequired(p,'chi_type',@(x) ischar(validatestring(x,{'chimap','chigrid'})));
addParameter(p,'chi_lim',[],@(x) isnumeric(x) && numel(x)==2);
addParameter(p,'override_resample',false,@(x) isscalar(x) && islogical(x)); % Hidden option for GUIs
parse(p,DEM,S,chi,chi_type,varargin{:});
DEM=p.Results.DEM;
S=p.Results.S;
chi=p.Results.chi;
chi_type=p.Results.chi_type;
chi_lim=p.Results.chi_lim;
os=p.Results.override_resample;
if ischar(chi) & logical(regexp(chi,regexptranslate('wildcard','*.txt')))
chi=GRIDobj(chi);
if ~validatealignment(DEM,chi) && ~os
chi=resample(chi,DEM);
elseif ~validatealignment(DEM,chi) && os
chi.refmat=DEM.refmat;
chi.georef=DEM.georef;
end
elseif isa(chi,'GRIDobj');
if ~validatealignment(DEM,chi)
chi=resample(chi,DEM);
end
else
if isdeployed
errordlg('Input to "chi" not recognized as a valid ascii or a GRIDobj')
end
error('Input to "chi" not recognized as a valid ascii or a GRIDobj');
end
switch chi_type
case 'chigrid'
f1=figure(1);
set(f1,'Units','normalized','Position',[0.05 0.1 0.8 0.8],'renderer','painters');
hold on
if isempty(chi_lim)
imageschs(DEM,chi,'colormap','jet');
else
imageschs(DEM,chi,'colormap','jet','caxis',chi_lim);
end
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
case 'chimap'
nal=getnal(S,chi);
f1=figure(1);
set(f1,'Visible','off');
[RGB]=imageschs(DEM,DEM,'colormap','gray');
[~,R]=GRIDobj2im(DEM);
imshow(flipud(RGB),R);
axis xy
hold on
colormap(jet);
plotc(S,nal);
if isempty(chi_lim)
caxis([0 max(nal)]);
else
caxis([min(chi_lim) max(chi_lim)])
end
c1=colorbar;
ylabel(c1,'\chi');
if ~verLessThan('matlab','9.5')
disableDefaultInteractivity(gca);
end
hold off
set(f1,'Visible','on','Units','normalized','Position',[0.05 0.1 0.8 0.8],'renderer','painters');
end
end