-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmStat_ConfluencesAnalyzer.m
executable file
·494 lines (394 loc) · 15.1 KB
/
mStat_ConfluencesAnalyzer.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
function varargout = mStat_ConfluencesAnalyzer(varargin)
%-----------------MEANDER STATISTICS TOOLBOX. MStaT------------------------
% MSTAT CONFLUENCE AND DIFLUENCE ANALYZER
%
% This function evaluate the influences of the secondaries channels on
% confluence or bifurcation in the main channel and control in how long
% downstream modify the main channel.
% Collaborations
% Lucas Dominguez. UNL, Argentina
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mStat_ConfluencesAnalyzer_OpeningFcn, ...
'gui_OutputFcn', @mStat_ConfluencesAnalyzer_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before mStat_ConfluencesAnalyzer is made visible.
function mStat_ConfluencesAnalyzer_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% Choose default command line output for mStat_ConfluencesAnalyzer
handles.output = hObject;
set_enable(handles,'init')
set(handles.figure1,'Name',['MStaT: Confluence and Difluence Analyzer '], ...
'DockControls','off')
% Push messages to Log Window:
% ----------------------------
log_text = {...
'';...
['%----------- ' datestr(now) ' ------------%'];...
'LETs START!!!'};
statusLogging(handles.LogWindow, log_text)
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = mStat_ConfluencesAnalyzer_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Toolbar Menu
% --------------------------------------------------------------------
function filefunctions_Callback(hObject, eventdata, handles)
% empty
% --------------------------------------------------------------------
function closefunctions_Callback(hObject, eventdata, handles)
close
% --------------------------------------------------------------------
function newprojects_Callback(hObject, eventdata, handles)
set_enable(handles,'init')
% Push messages to Log Window:
% ----------------------------
log_text = {...
'';...
['%--- ' datestr(now) ' ---%'];...
'NEW PROJECT'};
statusLogging(handles.LogWindow, log_text)
% --------------------------------------------------------------------
function export_Callback(hObject, eventdata, handles)
% empty
% --------------------------------------------------------------------
function matfiles_Callback(hObject, eventdata, handles)
% empty
% --------------------------------------------------------------------
function excelfile_Callback(hObject, eventdata, handles)
% empty
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Initial Panel
%Read data
% --- Executes on button press in mainchannel.
function mainchannel_Callback(hObject, eventdata, handles)
%This function incorporate the main channel data
multisel='off';
persistent lastPath
% If this is the first time running the function this session,
% Initialize lastPath to 0
if isempty(lastPath)
lastPath = 0;
end
[ReadVar]=mStat_ReadInputFiles(multisel,lastPath);
% Use the path to the last selected file
% If 'uigetfile' is called, but no item is selected, 'lastPath' is not overwritten with 0
if ReadVar.Path ~= 0
lastPath = ReadVar.Path;
end
%Create celltable
handles.celltable=cell(1,2);
handles.celltable(1,2)={''};
if ReadVar.File==0
else
% Push messages to Log Window:
% ----------------------------
log_text = {...
'';...
['%--- ' datestr(now) ' ---%'];...
'Main Channel Centerline Loaded:';[cell2mat({ReadVar.File})]};
statusLogging(handles.LogWindow, log_text)
%Convert information
handles.NameMain = {ReadVar.File};
handles.xCoordMain = [];
handles.yCoordMain = [];
handles.xCoordMain(:,1) = ReadVar.xCoord{:,1};
handles.yCoordMain(:,1) = ReadVar.yCoord{:,1};
handles.formatfileread = ReadVar.comp;
guidata(hObject, handles);
%Write File name
handles.celltable(1,1) = {ReadVar.File};
set(handles.inputtable,'Data',handles.celltable)
guidata(hObject,handles)
set_enable(handles,'loadfiles')
set(handles.tributarychannel,'Enable','on');
%Plot
axes(handles.pictureReach)
plot(handles.xCoordMain,handles.yCoordMain,'-k')%Main
hold on
plot(handles.xCoordMain(1,1),handles.yCoordMain(1,1),'ob')
grid on
legend('Main Channel','Initial point','Location','Best')
xlabel('X');ylabel('Y')
axis equal
hold off
end
% --- Executes on button press in tributarychannel.
function tributarychannel_Callback(hObject, eventdata, handles)
%Advantages
msg='Please select all the secondary channels to analyze';
warndlg(msg)
%This function read the tributaries data
multisel='on';
persistent lastPath
% If this is the first time running the function this session,
% Initialize lastPath to 0
if isempty(lastPath)
lastPath = 0;
end
[ReadVar]=mStat_ReadInputFiles(multisel,lastPath);
% Use the path to the last selected file
% If 'uigetfile' is called, but no item is selected, 'lastPath' is not overwritten with 0
if ReadVar.Path ~= 0
lastPath = ReadVar.Path;
end
if isempty(ReadVar.File)
else
if iscell(ReadVar.File)%determinate the number of secondary channels
handles.numfile=size(ReadVar.File,2);
else
handles.numfile=1;
end
for i=1:handles.numfile
if iscell(ReadVar.File)%Multi selection
handles.celltable(i+1,1)={ReadVar.File{i}};
Filename={ReadVar.File{i}};
guidata(hObject,handles)
else %Single selection
handles.celltable(i+1,1)={ReadVar.File};
Filename={ReadVar.File};
guidata(hObject,handles)
end
%Convert information
handles.NameTributary = {ReadVar.File};
handles.xCoordTri=[];
handles.yCoordTri=[];
handles.xCoordTri=ReadVar.xCoord;
handles.yCoordTri=ReadVar.yCoord;
handles.formatfileread=ReadVar.comp;
guidata(hObject, handles);
% Push messages to Log Window:
% ----------------------------
log_text = {...
'';...
['%--- ' datestr(now) ' ---%'];...
'Tributary Channel Centerline Loaded:';[cell2mat(Filename)]};
statusLogging(handles.LogWindow, log_text)
clear Filename
end
%Plot
axes(handles.pictureReach)
plot(handles.xCoordMain,handles.yCoordMain,'-k')%Main
hold on
plot(handles.xCoordMain(1,1),handles.yCoordMain(1,1),'ob')
for i=1:handles.numfile
plot(handles.xCoordTri{i},handles.yCoordTri{i},'-r')%Main
sec = sprintf('Secondary%d',i);
ee=text(handles.xCoordTri{i}(1,1),handles.yCoordTri{i}(1,1),sec);
set(ee,'Clipping','on')
clear sec
end
grid on
legend('Main Channel','Initial point','Secondary Channels','Location','Best')
xlabel('X');ylabel('Y')
axis equal
hold off
guidata(hObject,handles)
%write filename data
set(handles.inputtable, 'Data', cell(handles.numfile+1,2));
if handles.numfile==1
set(handles.inputtable, 'RowName', {'Main Channel','Secondary1'});
elseif handles.numfile==2
set(handles.inputtable, 'RowName', {'Main Channel','Secondary1','Secondary2'});
elseif handles.numfile==3
set(handles.inputtable, 'RowName', {'Main Channel','Secondary1','Secondary2','Secondary3'});
elseif handles.numfile==4
set(handles.inputtable, 'RowName', {'Main Channel','Secondary1','Secondary2','Secondary3','Secondary4'});
elseif handles.numfile==3
set(handles.inputtable, 'RowName', {'Main Channel','Secondary1','Secondary2','Secondary3','Secondary4','Secondary5'});
end
set(handles.inputtable, 'Data', handles.celltable)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Push button Calculate
% --- Executes on button press in calculate.
function calculate_Callback(hObject, eventdata, handles)
% Run the calculate function
hwait = waitbar(0,'Confluence and Difluence Analyzer. Processing...','Name','MStaT ',...
'CreateCancelBtn',...
'setappdata(gcbf,''canceling'',1)');
setappdata(hwait,'canceling',0)
tableData = get(handles.inputtable, 'data');
if size(tableData,1)==1
warndlg('You need incorporate the secondary channels')
else
%Calculate
sel=2;%Toolbox inflection points method by defect
handles.bendSelect=[];
Tools=3;%CDM Confluence and Difluence Module
level=5;%default level
% Read Main
widthMain=str2double(cell2mat(tableData(1,2)));
[Main]=mStat_planar(handles.xCoordMain,handles.yCoordMain,widthMain,sel,...
handles.pictureReach,handles.bendSelect,Tools,level);
waitbar(30/100,hwait);
%Read Tributary data
for i=1:handles.numfile
widthTri{i}=str2double(cell2mat(tableData(1+i,2)));
[Tri{i}]=mStat_planar(handles.xCoordTri{i},handles.yCoordTri{i},widthTri{i},...
sel,handles.pictureReach,handles.bendSelect,Tools,level);
LongTri(i)=Tri{i}.intS(end,1);
waitbar((30+(i*10))/100,hwait);
end
%save data
handles.Main=Main;
handles.Tri=Tri;
guidata(hObject,handles)
if handles.numfile==1 %single file
geovar{1}=Main;
geovar{2}=Tri{1};
else
for t=1:handles.numfile+1
if t==1
geovar{1}=Main;
else
geovar{t}=Tri{t-1};
end
end
end
waitbar(70/100,hwait);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Obtain data to incorporate the
%relation BT/BM
for t=1:handles.numfile
BTdivBM(t)=widthTri{t}./widthMain;
end
%Lambdas relations
for t=1:handles.numfile
lambdaTdivlambdaM(t)=nanmean(Tri{t}.wavelengthOfBends)./nanmean(Main.wavelengthOfBends);
end
%Amplitude relations
for t=1:handles.numfile
AmplitudeTdivAmplitudeM(t)=nanmean(Tri{t}.amplitudeOfBends)./nanmean(Main.amplitudeOfBends);
end
waitbar(75/100,hwait);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Wavelet analyzes
%go to wavelet analyzer
%%Plotting
SIGLVL=0.95;
sel=2;%Toolbox inflection points method by defect
filter=0;
axest=[handles.wavel_axes];
Tools=3;%Confluence and Difluence Analyzer
vars=[];
mStat_plotWavel(geovar{1},sel,SIGLVL,filter,axest,Tools,vars)
waitbar(80/100,hwait);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Determinate the intersection o point close
[Conf]=mStat_ConfluencesInfluences(geovar);
waitbar(90/100,hwait);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%PLOT
axes(handles.pictureReach)
plot(geovar{1}.equallySpacedX,geovar{1}.equallySpacedY,'-k')%Main
hold on
plot(geovar{1}.equallySpacedX(1,1),geovar{1}.equallySpacedY(1,1),'ob')
if handles.numfile>1 %read multy files
for t=1:handles.numfile
plot(geovar{1+t}.equallySpacedX,geovar{1+t}.equallySpacedY,'-r')%secondary coordinate
plot(Conf.XINT{1+t},Conf.YINT{1+t},'or')%Intersection point
%Graph cicle
th = 0:pi/50:2.01*pi;
xunit = Conf.R(t) * cos(th) + Conf.XINT{1+t};
yunit = Conf.R(t) * sin(th) + Conf.XINT{1+t};
plot(xunit, yunit,'-b','Linewidth',2);%circle
end
else%single read file
plot(geovar{2}.equallySpacedX,geovar{2}.equallySpacedY,'-r')%secondary coordinate
plot(Conf.XINT{2},Conf.YINT{2},'or')%Intersection point
%Graph cicle
th = 0:pi/50:2.01*pi;
xunit = Conf.R(1) * cos(th) + Conf.XINT{2};
yunit = Conf.R(1) * sin(th) + Conf.YINT{2};
plot(xunit, yunit,'-b','Linewidth',2);%Circle
end
grid on
legend('Main Channel','Initial point','Secondary Channels','Intersection point',...
'Influences Region','Location','Best')
xlabel('X');ylabel('Y')
axis equal
hold off
%Wavelet analyzes
%go to wavelet analyzer
%%Plotting
SIGLVL=0.95;
sel=2;%Toolbox inflection points method by defect
filter=0;
axest=[handles.wavel_axes];
Tools=3;%Confluence and Difluence Module
vars=Conf;
mStat_plotWavel(geovar{1},sel,SIGLVL,filter,axest,Tools,vars)
end
set_enable(handles,'results')
% Push messages to Log Window:
% ----------------------------
log_text = {...
'';...
['%--- ' datestr(now) ' ---%'];...
'Summary of CBA';...
'Total Length Analyzed [km]:';[cell2mat({(geovar{1}.intS(end,1)+nansum(LongTri))/1000})];...
'B_T/B_M:';[cell2mat({BTdivBM})];...
'\lambda_T/\lambda_M:';[cell2mat({lambdaTdivlambdaM})];...
'\Amp_T/Amp_M:';[cell2mat({AmplitudeTdivAmplitudeM})];...
'R [m]:';[cell2mat({Conf.R})];};
statusLogging(handles.LogWindow, log_text)
%Close waitbar
waitbar(1,hwait)
delete(hwait)
function rm_Callback(hObject, eventdata, handles)
% empty
% --- Executes during object creation, after setting all properties.
function rm_CreateFcn(hObject, eventdata, handles)
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%
%Extra Function
%%%%%%%%%%%%%%%%%%%%%%%%%%
function set_enable(handles,enable_state)
%Set initial an load files
switch enable_state
case 'init'
legend(handles.pictureReach,'hide')
cla(handles.pictureReach)
cla(handles.wavel_axes)
set(handles.calculate,'Enable','off');
set(handles.tributarychannel,'Enable','off');
set(handles.inputtable, 'Data', cell(2,2));
set(handles.export,'Enable','off');
case 'loadfiles'
set(handles.calculate,'Enable','on');
case 'results'
set(handles.export,'Enable','on');
otherwise
end
%%Log Window
% --- Executes on selection change in LogWindow.
function LogWindow_Callback(hObject, eventdata, handles)
% empty
% --- Executes during object creation, after setting all properties.
function LogWindow_CreateFcn(hObject, eventdata, handles)
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end