[1139] | 1 | %'test_patch_tps': test the optimum value for the spline smmoothing function used in civ_series |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % Method: |
---|
| 4 | %open a netcdf file with civ results. |
---|
| 5 | |
---|
| 6 | % function ParamOut=test_patch_tps (Param) |
---|
| 7 | % |
---|
| 8 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 9 | % |
---|
| 10 | %OUTPUT |
---|
| 11 | % ParamOut: sets input parameters when the function is selected, not activated(input Param.Action.RUN=0),=[] when the function is running |
---|
| 12 | % |
---|
| 13 | %INPUT: |
---|
| 14 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
| 15 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
| 16 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
---|
| 17 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
---|
| 18 | % |
---|
| 19 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
---|
| 20 | % see the current structure Param) |
---|
| 21 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
| 22 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
| 23 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
| 24 | % .OutputDirExt: directory extension for data outputs |
---|
| 25 | % .Action: .ActionName: name of the current activated function |
---|
| 26 | % .ActionPath: path of the current activated function |
---|
| 27 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
---|
| 28 | % .RUN =0 for GUI input, =1 for function activation |
---|
| 29 | % .RunMode='local','background', 'cluster': type of function use |
---|
| 30 | % |
---|
| 31 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
| 32 | % .InputFields: sub structure describing the input fields withfields |
---|
| 33 | % .FieldName: name(s) of the field |
---|
| 34 | % .VelType: velocity type |
---|
| 35 | |
---|
| 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 37 | |
---|
| 38 | %======================================================================= |
---|
| 39 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
| 40 | % http://www.legi.grenoble-inp.fr |
---|
| 41 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr |
---|
| 42 | % |
---|
| 43 | % This file is part of the toolbox UVMAT. |
---|
| 44 | % |
---|
| 45 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 46 | % it under the terms of the GNU General Public License as published |
---|
| 47 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 48 | % or (at your option) any later version. |
---|
| 49 | % |
---|
| 50 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 51 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 52 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 53 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 54 | %======================================================================= |
---|
| 55 | |
---|
| 56 | function ParamOut=test_patch_tps (Param) |
---|
| 57 | |
---|
| 58 | %%%%%%%%%%%%%%%%% INPUT PREPARATION MODE (no RUN) %%%%%%%%%%%%%%%%% |
---|
| 59 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
---|
| 60 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
| 61 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
| 62 | ParamOut.NbSlice='off'; % edit box nbre of slices made active |
---|
| 63 | ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 64 | ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
| 65 | ParamOut.FieldTransform = 'off';%can use a transform function |
---|
| 66 | ParamOut.ProjObject='off';%cannot use projection object(option 'off'/'on', |
---|
| 67 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
---|
| 68 | ParamOut.OutputDirExt='.test_patch';%set the output dir extension |
---|
| 69 | 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 |
---|
| 70 | |
---|
| 71 | %% root input file(s) and type |
---|
| 72 | % check the existence of the first file in the series |
---|
| 73 | first_j=[];% note that the function will propose to cover the whole range of indices |
---|
| 74 | if isfield(Param.IndexRange,'MinIndex_j'); first_j=Param.IndexRange.MinIndex_j; end |
---|
| 75 | last_j=[]; |
---|
| 76 | if isfield(Param.IndexRange,'MaxIndex_j'); last_j=Param.IndexRange.MaxIndex_j; end |
---|
| 77 | PairString=''; |
---|
| 78 | if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end |
---|
| 79 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString); |
---|
| 80 | FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},... |
---|
| 81 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2); |
---|
| 82 | if ~exist(FirstFileName,'file') |
---|
| 83 | msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist']) |
---|
| 84 | return |
---|
| 85 | else |
---|
| 86 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,PairString); |
---|
| 87 | LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},... |
---|
| 88 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2); |
---|
| 89 | if ~exist(FirstFileName,'file') |
---|
| 90 | msgbox_uvmat('WARNING',['the last input file ' LastFileName ' does not exist']) |
---|
| 91 | end |
---|
| 92 | end |
---|
| 93 | |
---|
| 94 | %% check the validity of input file types |
---|
| 95 | Data=nc2struct(FirstFileName,[]); |
---|
| 96 | if isfield(Data,'CivStage') |
---|
| 97 | switch Data.CivStage |
---|
| 98 | case {1,2} |
---|
| 99 | CivStage='civ1'; |
---|
| 100 | MaxDiff=1.5; SubDomainSize=250; FieldSmooth=10; %default |
---|
| 101 | case 3 |
---|
| 102 | CivStage='civ1'; |
---|
| 103 | MaxDiff=Data.Patch1_MaxDiff; |
---|
| 104 | SubDomainSize=Data.Patch1_SubDomainSize; |
---|
| 105 | FieldSmooth=Data.Patch1_FieldSmooth; |
---|
| 106 | case {4,5} |
---|
| 107 | CivStage='civ2'; |
---|
[1142] | 108 | MaxDiff=1.5; SubDomainSize=250; FieldSmooth=5; %default |
---|
[1139] | 109 | case 6 |
---|
| 110 | CivStage='civ2'; |
---|
| 111 | MaxDiff=Data.Patch2_MaxDiff; |
---|
| 112 | SubDomainSize=Data.Patch2_SubDomainSize; |
---|
| 113 | FieldSmooth=Data.Patch2_FieldSmooth; |
---|
| 114 | end |
---|
| 115 | else |
---|
| 116 | msgbox_uvmat('ERROR',['invalid file type input: ' FileType ' not a civ data']) |
---|
| 117 | return |
---|
| 118 | end |
---|
| 119 | |
---|
| 120 | %% numbers of fields |
---|
| 121 | incr_j=1;%default |
---|
| 122 | if isfield(Param.IndexRange,'incr_j')&&~isempty(Param.IndexRange.incr_j) |
---|
| 123 | incr_j=Param.IndexRange.incr_j; |
---|
| 124 | end |
---|
| 125 | if isempty(first_j)||isempty(last_j) |
---|
| 126 | nbfield_j=1; |
---|
| 127 | else |
---|
| 128 | nbfield_j=numel(first_j:incr_j:last_j);%nb of fields for the j index (bursts or volume slices) |
---|
| 129 | end |
---|
| 130 | first_i=1;last_i=1;incr_i=1;%default |
---|
| 131 | if isfield(Param.IndexRange,'MinIndex_i'); first_i=Param.IndexRange.MinIndex_i; end |
---|
| 132 | if isfield(Param.IndexRange,'MaxIndex_i'); last_i=Param.IndexRange.MaxIndex_i; end |
---|
| 133 | if isfield(Param.IndexRange,'incr_i')&&~isempty(Param.IndexRange.incr_i) |
---|
| 134 | incr_i=Param.IndexRange.incr_i; |
---|
| 135 | end |
---|
| 136 | nbfield_i=numel(first_i:incr_i:last_i);%nb of fields for the i index (bursts or volume slices) |
---|
| 137 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
| 138 | |
---|
| 139 | %% setting of intput parameters |
---|
| 140 | ListParam={'CivStage';'FieldSmooth';'MaxDiff';'SubDomainSize'}; |
---|
| 141 | DefaultValue={CivStage;FieldSmooth;MaxDiff;SubDomainSize}; |
---|
| 142 | if isfield(Param,'ActionInput') |
---|
| 143 | ParamIn=Param.ActionInput; |
---|
| 144 | else |
---|
| 145 | ParamIn=[]; |
---|
| 146 | end |
---|
| 147 | [ParamOut.ActionInput,errormsg] = set_param_input(ListParam,DefaultValue,ParamIn); |
---|
| 148 | if ~isempty(errormsg) |
---|
| 149 | msgbox_uvmat('ERROR',errormsg) |
---|
| 150 | end |
---|
| 151 | return |
---|
| 152 | end |
---|
| 153 | %%%%%%%%%%%%%%%%% STOP HERE FOR PAMETER INPUT MODE %%%%%%%%%%%%%%%%% |
---|
| 154 | |
---|
| 155 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 156 | checkrun=1; |
---|
| 157 | RUNHandle=[]; |
---|
| 158 | WaitbarHandle=[]; |
---|
| 159 | if ischar(Param) |
---|
| 160 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 161 | checkrun=0; |
---|
| 162 | else |
---|
| 163 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 164 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
| 165 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
| 166 | end |
---|
| 167 | |
---|
| 168 | %% input preparation |
---|
| 169 | RootPath=Param.InputTable{:,1}; |
---|
| 170 | RootFile=Param.InputTable{:,3}; |
---|
| 171 | NomType=Param.InputTable{:,4}; |
---|
| 172 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
| 173 | % if ~isempty(hdisp),delete(hdisp),end; |
---|
| 174 | %%%%%%%%%%%% |
---|
| 175 | % The cell array filecell is the list of input file names, while |
---|
| 176 | % filecell{iview,fileindex}: |
---|
| 177 | % iview: line in the table corresponding to a given file series |
---|
| 178 | % fileindex: file index within the file series, |
---|
| 179 | % 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 |
---|
| 180 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
| 181 | %%%%%%%%%%%% |
---|
| 182 | |
---|
| 183 | %% output file naming |
---|
| 184 | FileExtOut='.nc'; % write result as .png images for image inputsFileInfo.FileType='image' |
---|
| 185 | NomTypeOut=NomType; |
---|
| 186 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
| 187 | OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device); |
---|
| 188 | RootFileOut=RootFile; |
---|
| 189 | |
---|
| 190 | %% file index parameters |
---|
| 191 | |
---|
| 192 | Param.InputFields.VelType=Param.ActionInput.CivStage; |
---|
| 193 | SubDomainSize=Param.ActionInput.SubDomainSize; |
---|
| 194 | MaxDiff=Param.ActionInput.MaxDiff; |
---|
| 195 | FieldSmooth=(Param.ActionInput.FieldSmooth)*[0.1 0.2 0.5 1 2 5 10];%scan the smoothing param from 1/10 to 10 current value |
---|
| 196 | NbSmooth=numel(FieldSmooth); |
---|
| 197 | for irho=1:NbSmooth |
---|
| 198 | str=num2str(FieldSmooth(irho)); |
---|
| 199 | str=regexprep(str,'\.','p'); |
---|
[1141] | 200 | Ustr{irho}=['U_' str]; |
---|
| 201 | Vstr{irho}=['V_' str]; |
---|
[1139] | 202 | Xstr{irho}=['X_' str]; |
---|
| 203 | Ystr{irho}=['Y_' str]; |
---|
[1141] | 204 | Dimstr{irho}='NbVec'; |
---|
[1139] | 205 | str_i{irho}=str; |
---|
| 206 | end |
---|
| 207 | |
---|
| 208 | %% Prepare the structure of output netcdf file |
---|
[1142] | 209 | DataOut.ListGlobalAttribute={'CivStage','SubDomainSize','MaxDiff','CoordUnit'}; |
---|
[1139] | 210 | DataOut.CivStage=Param.InputFields.VelType; |
---|
[1142] | 211 | DataOut.SubDomainSize=SubDomainSize; |
---|
| 212 | DataOut.MaxDiff=MaxDiff; |
---|
| 213 | DataOut.CoordUnit='pixel'; |
---|
| 214 | DataOut.ListVarName=[{'FieldSmooth','Diff_rms','NbExclude','X','Y'} Ustr Vstr] ; |
---|
| 215 | DataOut.VarDimName=[{'FieldSmooth','FieldSmooth','FieldSmooth','NbVec','NbVec'} Dimstr Dimstr]; |
---|
[1141] | 216 | DataOut.VarAttribute{4}.Role='falseflag'; |
---|
[1139] | 217 | DataOut.FieldSmooth=FieldSmooth; |
---|
| 218 | |
---|
| 219 | %% MAIN LOOP |
---|
| 220 | for index=1:1%numel(filecell) |
---|
| 221 | Data=read_field(filecell{1,index},'civdata',Param.InputFields); |
---|
[1143] | 222 | ind_good=find(Data.FF==0|Data.FF==20|Data.FF==2);%keep good civ data, and also the ones excluded by the criterium of discrepancy betwween smoothed and raw fields (FF=2 or 20 (old convention)) |
---|
[1139] | 223 | NbGood=numel(ind_good); |
---|
| 224 | Xin=Data.X(ind_good); |
---|
| 225 | Yin=Data.Y(ind_good); |
---|
| 226 | Uin=Data.U(ind_good); |
---|
| 227 | Vin=Data.V(ind_good); |
---|
[1141] | 228 | tic |
---|
[1139] | 229 | for irho=1:NbSmooth |
---|
| 230 | [SubRange,NbCentres,Coord_tps,U_tps,V_tps,~,U_smooth, V_smooth,~,FFres]=... |
---|
| 231 | filter_tps([Xin Yin],Uin,Vin,[],SubDomainSize,FieldSmooth(irho),MaxDiff); |
---|
| 232 | if irho==1 |
---|
[1141] | 233 | DataOut.FF=zeros(size(Xin)); |
---|
| 234 | DataOut.X=Xin; |
---|
| 235 | DataOut.Y=Yin; |
---|
| 236 | figure(1) |
---|
| 237 | cla |
---|
| 238 | scatter(Xin,Yin,1) |
---|
[1139] | 239 | for irec=1:size(SubRange,3) |
---|
| 240 | rectangle('Position',[SubRange(:,1,irec)' SubRange(:,2,irec)'-SubRange(:,1,irec)']) |
---|
[1141] | 241 | end |
---|
[1139] | 242 | title('subdomains for thin shell splines (tps)') |
---|
| 243 | end |
---|
| 244 | ind_good=find(FFres==0); |
---|
[1141] | 245 | ind_false=find(FFres~=0); |
---|
[1139] | 246 | U_Diff=Uin(ind_good)-U_smooth(ind_good); |
---|
| 247 | V_Diff=Vin(ind_good)-V_smooth(ind_good); |
---|
| 248 | DataOut.Diff_rms(irho)=sqrt(mean(U_Diff.*U_Diff+V_Diff.*V_Diff)/2); |
---|
| 249 | DataOut.NbExclude(irho)=(NbGood-numel(ind_good))/NbGood; |
---|
[1142] | 250 | U_smooth(ind_false)=NaN; |
---|
| 251 | V_smooth(ind_false)=NaN; |
---|
[1141] | 252 | DataOut.(['U_' str_i{irho}])=U_smooth; |
---|
| 253 | DataOut.(['V_' str_i{irho}])=V_smooth; |
---|
[1139] | 254 | end |
---|
[1141] | 255 | time=toc |
---|
[1139] | 256 | OutputFile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,FileExtOut,NomTypeOut,i1_series{1}(index),[],j1_series{1}(index),j2_series{1}(index)) |
---|
| 257 | errormsg=struct2nc(OutputFile,DataOut) |
---|
| 258 | end |
---|
[1141] | 259 | figure |
---|
[1139] | 260 | semilogx(FieldSmooth,DataOut.Diff_rms,'b',FieldSmooth,DataOut.NbExclude,'r',FieldSmooth,0.1*ones(size(FieldSmooth)),'m') |
---|
| 261 | grid on |
---|
| 262 | title( [filecell{1,1} ':' Param.InputFields.VelType]) |
---|
[1141] | 263 | legend({'rms vel. diff. ' ;' ratio excluded vectors';'recommended diff'},'Location','northwest') |
---|
[1139] | 264 | xlabel('smoothing parameter') |
---|
| 265 | ylabel('rms (pixels) and exclusion ratio') |
---|
[1141] | 266 | OutputFig=fullfile(OutputPath,OutputDir,'plot_rms_diff.png') |
---|
| 267 | saveas(2,OutputFig) |
---|
[1139] | 268 | |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | |
---|
| 273 | |
---|
| 274 | |
---|