1 | %'bed_scan': get the bed shape from laser ipact |
---|
2 | |
---|
3 | %------------------------------------------------------------------------ |
---|
4 | % function GUI_input=bed_scan(Param) |
---|
5 | % |
---|
6 | %------------------------------------------------------------------------ |
---|
7 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
8 | % |
---|
9 | %OUTPUT |
---|
10 | % ParamOut: sets options in the GUI series.fig needed for the function |
---|
11 | % |
---|
12 | %INPUT: |
---|
13 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
14 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
15 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
---|
16 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
---|
17 | % |
---|
18 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
---|
19 | % see the current structure Param) |
---|
20 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
21 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
22 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
23 | % .OutputDirExt: directory extension for data outputs |
---|
24 | % .Action: .ActionName: name of the current activated function |
---|
25 | % .ActionPath: path of the current activated function |
---|
26 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
---|
27 | % .RUN =0 for GUI input, =1 for function activation |
---|
28 | % .RunMode='local','background', 'cluster': type of function use |
---|
29 | % |
---|
30 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
31 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
32 | % .TransformPath: path of the selected transform function |
---|
33 | % .InputFields: sub structure describing the input fields withfields |
---|
34 | % .FieldName: name(s) of the field |
---|
35 | % .VelType: velocity type |
---|
36 | % .FieldName_1: name of the second field in case of two input series |
---|
37 | % .VelType_1: velocity type of the second field in case of two input series |
---|
38 | % .Coord_y: name of y coordinate variable |
---|
39 | % .Coord_x: name of x coordinate variable |
---|
40 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
42 | |
---|
43 | %======================================================================= |
---|
44 | % Copyright 2008-2019, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
45 | % http://www.legi.grenoble-inp.fr |
---|
46 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
47 | % |
---|
48 | % This file is part of the toolbox UVMAT. |
---|
49 | % |
---|
50 | % UVMAT is free software; you can redistribute it and/or modify |
---|
51 | % it under the terms of the GNU General Public License as published |
---|
52 | % by the Free Software Foundation; either version 2 of the license, |
---|
53 | % or (at your option) any later version. |
---|
54 | % |
---|
55 | % UVMAT is distributed in the hope that it will be useful, |
---|
56 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
57 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
58 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
59 | %======================================================================= |
---|
60 | |
---|
61 | function ParamOut=bed_scan (Param) |
---|
62 | |
---|
63 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed |
---|
64 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
---|
65 | ParamOut.NbViewMax=1;% max nbre of input file series (default , no limitation) |
---|
66 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
67 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
68 | ParamOut.NbSlice=1; %nbre of slices ('off' by default) |
---|
69 | ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
70 | ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
71 | ParamOut.FieldTransform = 'off';%can use a transform function |
---|
72 | ParamOut.ProjObject='off';%can use projection object(option 'off'/'on', |
---|
73 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
---|
74 | ParamOut.OutputDirExt='.bed';%set the output dir extension |
---|
75 | ParamOut.OutputFileMode='NbSlice';% ='=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice |
---|
76 | %check the type of the existence and type of the first input file: |
---|
77 | Param.IndexRange.last_i=Param.IndexRange.first_i;%keep only the first index in the series |
---|
78 | if isfield(Param.IndexRange,'first_j') |
---|
79 | Param.IndexRange.last_j=Param.IndexRange.first_j; |
---|
80 | end |
---|
81 | filecell=get_file_series(Param); |
---|
82 | if ~exist(filecell{1,1},'file') |
---|
83 | msgbox_uvmat('WARNING','the first input file does not exist') |
---|
84 | else |
---|
85 | FileInfo=get_file_info(filecell{1,1}); |
---|
86 | FileType=FileInfo.FileType; |
---|
87 | if isempty(find(strcmp(FileType,{'image','multimage','mmreader','video'})));% =1 for images |
---|
88 | msgbox_uvmat('ERROR',['bad input file type for ' mfilename ': an image is needed']) |
---|
89 | end |
---|
90 | end |
---|
91 | return |
---|
92 | end |
---|
93 | |
---|
94 | %%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%% |
---|
95 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
96 | ParamOut=[]; |
---|
97 | RUNHandle=[]; |
---|
98 | WaitbarHandle=[]; |
---|
99 | checkrun=1; |
---|
100 | if ischar(Param)% case of batch: Param is the name of the xml file containing the input parameters |
---|
101 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
102 | checkrun=0; |
---|
103 | else% interactive mode in Matlab |
---|
104 | hseries=findobj(allchild(0),'Tag','series'); |
---|
105 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
106 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
107 | end |
---|
108 | |
---|
109 | %% root input file names and nomenclature type (cell arrays with one element) |
---|
110 | RootPath=Param.InputTable{2,1}; |
---|
111 | % RootFile=Param.InputTable(:,3); |
---|
112 | % SubDir=Param.InputTable(:,2); |
---|
113 | % NomType=Param.InputTable(:,4); |
---|
114 | % FileExt=Param.InputTable(:,5); |
---|
115 | |
---|
116 | %% directory for output files |
---|
117 | DirOut=fullfile(RootPath,[Param.OutputSubDir Param.OutputDirExt]); |
---|
118 | |
---|
119 | %% get the set of input file names (cell array filecell), and file indices |
---|
120 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
121 | % filecell{iview,fileindex}: cell array representing the list of file names |
---|
122 | % iview: line in the table corresponding to a given file series |
---|
123 | % fileindex: file index within the file series, |
---|
124 | % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j |
---|
125 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
126 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
127 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
128 | |
---|
129 | %% frame index for movie or multimage file input |
---|
130 | |
---|
131 | %% calibration data and timing: read the ImaDoc files |
---|
132 | %not relevant for this function |
---|
133 | |
---|
134 | %% check coincidence in time for several input file series |
---|
135 | %not relevant for this function |
---|
136 | |
---|
137 | %% coordinate transform or other user defined transform |
---|
138 | %not relevant for this function |
---|
139 | |
---|
140 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
141 | % EDIT FROM HERE |
---|
142 | |
---|
143 | %% Extension and indexing nomenclature for output file |
---|
144 | |
---|
145 | % name=('EXP18OS_bed_init/im/'); |
---|
146 | % name2=('EXP18OS_end/im/'); |
---|
147 | % path_proj=['/.fsnet/project/coriolis/2018/18ADDUCE/SEDIM_SCANSIDE/']; |
---|
148 | |
---|
149 | %nimages=1800; |
---|
150 | |
---|
151 | %% Load the init bed scan |
---|
152 | |
---|
153 | y=90.05-0.05*i1_series{1}; |
---|
154 | Mfiltre=ones(2,10)/20;%filter matrix for imnages |
---|
155 | tic |
---|
156 | % y=zeros(1,nimages); |
---|
157 | % X_new=zeros(4096,nimages); |
---|
158 | x=1:4096; |
---|
159 | % img=1; |
---|
160 | %filecell{1,img}= list of the images _init |
---|
161 | %filecell{2,img}= list of the images _end |
---|
162 | for img=1:nbfield_i |
---|
163 | img |
---|
164 | image=flipud(imread(filecell{2,img})); |
---|
165 | a=image(700:1900,:); |
---|
166 | % filtering |
---|
167 | a=filter2(Mfiltre,a); |
---|
168 | [imax,iy]=max(a); |
---|
169 | Z=squeeze(iy); |
---|
170 | iy(imax<50)=NaN; |
---|
171 | Z_s(:,img)=smooth(Z,40,'rloess'); |
---|
172 | % y(img)=y0-(0.05.*step); |
---|
173 | % y0=y(img); |
---|
174 | X_new(:,img)=phys_scan(x,y(img)); |
---|
175 | end |
---|
176 | |
---|
177 | toc |
---|
178 | |
---|
179 | nimages2=size(Z_s,2); |
---|
180 | %% |
---|
181 | y_y=1:size(a,1); |
---|
182 | |
---|
183 | % [Xx,Yy]=meshgrid(x,y_y); |
---|
184 | [X,Y]=meshgrid(x,y); |
---|
185 | |
---|
186 | % index=1; |
---|
187 | % [imax,iy]=max(a); |
---|
188 | % |
---|
189 | % Z=squeeze(iy); |
---|
190 | |
---|
191 | %% smooth bed init |
---|
192 | % for i=2:dim(2) |
---|
193 | % if iy(i)<300 |
---|
194 | % imax(i)=imax(i-1); |
---|
195 | % end |
---|
196 | % end |
---|
197 | |
---|
198 | % for i=1:nimages2 |
---|
199 | % Z_s(:,i)=smooth(Z(:,i),50,'rloess'); |
---|
200 | % % Z_s_new(:,i)=phys_scanz(x,Z_s(:,i)',y(i)); |
---|
201 | % |
---|
202 | % end |
---|
203 | |
---|
204 | %% Load the transit bed scan |
---|
205 | for img=1:nbfield_i |
---|
206 | img |
---|
207 | image=flipud(imread(filecell{1,img})); |
---|
208 | b=image(700:1900,:); |
---|
209 | % filtering |
---|
210 | b=filter2(Mfiltre,b); |
---|
211 | [imaxb,iyb]=max(b); |
---|
212 | Zb=squeeze(iyb); |
---|
213 | iyb(imaxb<50)=NaN; |
---|
214 | Z_sb(:,img)=smooth(Zb,20,'rloess'); |
---|
215 | end |
---|
216 | |
---|
217 | |
---|
218 | %% bed change |
---|
219 | dZ=Z_s-Z_sb; |
---|
220 | dZ_new=zeros(4096,nimages2); |
---|
221 | for img=1:nimages2 |
---|
222 | dZ_new(:,img)=phys_scanz(dZ(:,img),y(img)); |
---|
223 | end |
---|
224 | |
---|
225 | |
---|
226 | %% PLOTS |
---|
227 | coord_x=X_new(1,end):0.1:X_new(end,end); |
---|
228 | [Y_m,X_m]=meshgrid(y(1,:),coord_x); |
---|
229 | Y_new=Y'; |
---|
230 | dZ_mesh=griddata(X_new,Y_new,dZ_new,X_m,Y_m); |
---|
231 | |
---|
232 | if checkrun |
---|
233 | figure(1) |
---|
234 | hold on |
---|
235 | plot(x,Z_s+700) |
---|
236 | xlim([0 4096]) |
---|
237 | ylim([0 3000]) |
---|
238 | |
---|
239 | figure(2) |
---|
240 | hold on |
---|
241 | plot(x,Z_sb+700) |
---|
242 | xlim([0 4096]) |
---|
243 | ylim([0 3000]) |
---|
244 | |
---|
245 | figure(3) |
---|
246 | surfc(X_m,Y_m,dZ_mesh) |
---|
247 | shading interp; |
---|
248 | colorbar; |
---|
249 | caxis([0 3]); |
---|
250 | |
---|
251 | figure |
---|
252 | pcolor(X_m,Y_m,dZ_mesh); |
---|
253 | colormap; |
---|
254 | set(gca,'Xdir','reverse'); |
---|
255 | caxis([0 3]); |
---|
256 | shading flat |
---|
257 | hold on |
---|
258 | colorbar |
---|
259 | title('Dz') |
---|
260 | end |
---|
261 | |
---|
262 | save(fullfile(DirOut,'18OS_f.mat'),'dZ','dZ_new','X','Y','Z_s','Z_sb','y') |
---|
263 | |
---|
264 | % save netcdf |
---|
265 | Data.ListVarName={'coord_x','coord_y','dZ'}; |
---|
266 | Data.VarDimName={'coord_x','coord_y',{'coord_y','coord_x'}}; |
---|
267 | Data.VarAttribute{1}.Role='coord_x'; |
---|
268 | Data.VarAttribute{1}.unit='cm'; |
---|
269 | Data.VarAttribute{2}.Role='coord_y'; |
---|
270 | Data.VarAttribute{2}.unit='cm'; |
---|
271 | Data.VarAttribute{3}.Role='scalar'; |
---|
272 | Data.VarAttribute{3}.unit='cm'; |
---|
273 | Data.coord_x=[coord_x(1) coord_x(end)]; |
---|
274 | Data.coord_y=[y(1) y(end)]; |
---|
275 | Data.dZ=dZ_mesh'; |
---|
276 | struct2nc(fullfile(DirOut,'dZ.nc'),Data) |
---|
277 | |
---|
278 | function F=phys_scan(X,y) |
---|
279 | F=(9.4*10^(-7)*y.^2-3.09*10^(-4)*y+0.07).*X +(-0.001023*y.^2+0.469*y+186.9); |
---|
280 | |
---|
281 | function Fz=phys_scanz(Z,y) |
---|
282 | Fz=(-1.4587*10^(-5)*y.^2 + 0.001072*y+0.0833).*Z; %+(-2.1*10^(-6)*x.^2+5.1*10^(-4)*x+0.0735).*Z; |
---|
283 | |
---|
284 | |
---|
285 | |
---|