[751] | 1 | %'aver_stat': calculate field average over a time series |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function ParamOut=aver_stat(Param) |
---|
| 4 | % |
---|
| 5 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 6 | % |
---|
| 7 | %OUTPUT |
---|
| 8 | % ParamOut: sets options in the GUI series.fig needed for the function |
---|
| 9 | % |
---|
| 10 | %INPUT: |
---|
| 11 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
| 12 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
| 13 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
---|
| 14 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
---|
| 15 | % |
---|
| 16 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
---|
| 17 | % see the current structure Param) |
---|
| 18 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
| 19 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
| 20 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
| 21 | % .OutputDirExt: directory extension for data outputs |
---|
| 22 | % .Action: .ActionName: name of the current activated function |
---|
| 23 | % .ActionPath: path of the current activated function |
---|
| 24 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
---|
| 25 | % .RUN =0 for GUI input, =1 for function activation |
---|
| 26 | % .RunMode='local','background', 'cluster': type of function use |
---|
| 27 | % |
---|
| 28 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
| 29 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
| 30 | % .TransformPath: path of the selected transform function |
---|
| 31 | % .InputFields: sub structure describing the input fields withfields |
---|
| 32 | % .FieldName: name(s) of the field |
---|
| 33 | % .VelType: velocity type |
---|
| 34 | % .FieldName_1: name of the second field in case of two input series |
---|
| 35 | % .VelType_1: velocity type of the second field in case of two input series |
---|
| 36 | % .Coord_y: name of y coordinate variable |
---|
| 37 | % .Coord_x: name of x coordinate variable |
---|
| 38 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 40 | |
---|
[810] | 41 | %======================================================================= |
---|
[1107] | 42 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[810] | 43 | % http://www.legi.grenoble-inp.fr |
---|
| 44 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 45 | % |
---|
| 46 | % This file is part of the toolbox UVMAT. |
---|
| 47 | % |
---|
| 48 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 49 | % it under the terms of the GNU General Public License as published |
---|
| 50 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 51 | % or (at your option) any later version. |
---|
| 52 | % |
---|
| 53 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 54 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 55 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 56 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 57 | %======================================================================= |
---|
| 58 | |
---|
[751] | 59 | function ParamOut=aver_synchro(Param) |
---|
| 60 | |
---|
| 61 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName |
---|
| 62 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
---|
| 63 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
| 64 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
| 65 | ParamOut.NbSlice='on'; %nbre of slices ('off' by default) |
---|
| 66 | ParamOut.VelType='two';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 67 | ParamOut.FieldName='two';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
| 68 | ParamOut.FieldTransform = 'on';%can use a transform function |
---|
| 69 | ParamOut.ProjObject='on';%can use projection object(option 'off'/'on', |
---|
| 70 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
---|
| 71 | ParamOut.OutputDirExt='.synchro';%set the output dir extension |
---|
| 72 | 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 |
---|
| 73 | % filecell=get_file_series(Param);%check existence of the first input file |
---|
| 74 | % if ~exist(filecell{1,1},'file') |
---|
| 75 | % msgbox_uvmat('WARNING','the first input file does not exist') |
---|
| 76 | % end |
---|
| 77 | def={'26'}; |
---|
| 78 | if isfield (Param,'ActionInput')&& isfield(Param.ActionInput,'WavePeriod') |
---|
| 79 | def=Param.ActionInput.WavePeriod; |
---|
| 80 | |
---|
| 81 | def={num2str(def)}; |
---|
| 82 | end |
---|
| 83 | prompt={'wave period'}; |
---|
| 84 | dlgTitle='primary period'; |
---|
| 85 | lineNo=1; |
---|
| 86 | answer=inputdlg(prompt,dlgTitle,lineNo,def); |
---|
| 87 | ParamOut.ActionInput.WavePeriod=str2num(answer{1}); |
---|
| 88 | return |
---|
| 89 | end |
---|
| 90 | |
---|
| 91 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
---|
| 92 | ParamOut=[];%default output |
---|
| 93 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 94 | checkrun=1; |
---|
| 95 | if ischar(Param) |
---|
| 96 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 97 | checkrun=0; |
---|
| 98 | end |
---|
| 99 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 100 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
| 101 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
| 102 | |
---|
| 103 | %% define the directory for result file (with path=RootPath{1}) |
---|
| 104 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
| 105 | |
---|
| 106 | %% root input file(s) name, type and index series |
---|
| 107 | RootPath=Param.InputTable(:,1); |
---|
| 108 | RootFile=Param.InputTable(:,3); |
---|
| 109 | SubDir=Param.InputTable(:,2); |
---|
| 110 | NomType=Param.InputTable(:,4); |
---|
| 111 | FileExt=Param.InputTable(:,5); |
---|
| 112 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
[784] | 113 | FileInfo=get_file_info(filecell{1,1}); |
---|
[783] | 114 | FileType=FileInfo.FileType; |
---|
[751] | 115 | %%%%%%%%%%%% |
---|
| 116 | % The cell array filecell is the list of input file names, while |
---|
| 117 | % filecell{iview,fileindex}: |
---|
| 118 | % iview: line in the table corresponding to a given file series |
---|
| 119 | % fileindex: file index within the file series, |
---|
| 120 | % 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 |
---|
| 121 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
| 122 | %%%%%%%%%%%% |
---|
| 123 | nbview=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 124 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 125 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 126 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
| 127 | |
---|
| 128 | %% determine the input file type |
---|
| 129 | % if ~strcmp(FileType{1},'netcdf') |
---|
| 130 | % displ_uvmat('ERROR','netcdf file series with field projected on a regular mesh must be put as input') |
---|
| 131 | % return |
---|
| 132 | % end |
---|
| 133 | |
---|
| 134 | %% calibration data and timing: read the ImaDoc files |
---|
| 135 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
| 136 | % if size(time,1)>1 |
---|
| 137 | % diff_time=max(max(diff(time))); |
---|
| 138 | % if diff_time>0 |
---|
| 139 | % msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
---|
| 140 | % end |
---|
| 141 | % end |
---|
| 142 | |
---|
| 143 | %% coordinate transform or other user defined transform |
---|
| 144 | transform_fct='';%default |
---|
| 145 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
| 146 | addpath(Param.FieldTransform.TransformPath) |
---|
| 147 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
| 148 | rmpath(Param.FieldTransform.TransformPath) |
---|
| 149 | end |
---|
| 150 | |
---|
| 151 | %% settings for the output file |
---|
| 152 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
---|
| 153 | first_i=i1_series{1}(1); |
---|
| 154 | last_i=i1_series{1}(end); |
---|
| 155 | if isempty(j1_series{1})% if there is no second index j |
---|
| 156 | first_j=1;last_j=1; |
---|
| 157 | else |
---|
| 158 | first_j=j1_series{1}(1); |
---|
| 159 | last_j=j1_series{1}(end); |
---|
| 160 | end |
---|
| 161 | |
---|
| 162 | %% Set field names and velocity types |
---|
| 163 | InputFields{1}=[];%default (case of images) |
---|
| 164 | if isfield(Param,'InputFields') |
---|
| 165 | InputFields{1}=Param.InputFields; |
---|
| 166 | end |
---|
| 167 | |
---|
| 168 | % for i_slice=1:NbSlice |
---|
| 169 | % index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice |
---|
| 170 | nbfiles=0; |
---|
| 171 | nbmissing=0; |
---|
| 172 | MeanU=0; |
---|
| 173 | MeanV=0; |
---|
| 174 | MinU=0; |
---|
| 175 | MaxU=0; |
---|
| 176 | MinV=0; |
---|
| 177 | MaxV=0; |
---|
| 178 | vec_X=0; |
---|
| 179 | vec_Y=0; |
---|
| 180 | vec_U=0; %initiate the sum |
---|
| 181 | vec_V=0; |
---|
| 182 | cos1_U=0; |
---|
| 183 | cos1_V=0; |
---|
| 184 | sin1_U=0; |
---|
| 185 | sin1_V=0; |
---|
| 186 | cos2_U=0; |
---|
| 187 | cos2_V=0; |
---|
| 188 | sin2_U=0; |
---|
| 189 | sin2_V=0; |
---|
| 190 | cos3_U=0; |
---|
[1079] | 191 | |
---|
[751] | 192 | cos3_V=0; |
---|
| 193 | sin3_U=0; |
---|
| 194 | sin3_V=0; |
---|
| 195 | cossub_U=0; |
---|
| 196 | cossub_V=0; |
---|
| 197 | sinsub_U=0; |
---|
| 198 | sigma1=2*pi/Param.ActionInput.WavePeriod;%primary wave frequency |
---|
| 199 | sigma2=4*pi/Param.ActionInput.WavePeriod;%harmonic 2 |
---|
| 200 | sigma3=6*pi/Param.ActionInput.WavePeriod;%harmonic 3 |
---|
| 201 | sigma_sub=pi/Param.ActionInput.WavePeriod;%subharmonic |
---|
| 202 | sinsub_V=0; |
---|
[974] | 203 | NbField=0; |
---|
[751] | 204 | vec_C=0; |
---|
| 205 | |
---|
| 206 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
| 207 | for index=1:nbfield |
---|
[974] | 208 | index |
---|
[751] | 209 | update_waitbar(WaitbarHandle,index/nbfield) |
---|
| 210 | if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
| 211 | disp('program stopped by user') |
---|
| 212 | break |
---|
| 213 | end |
---|
| 214 | |
---|
| 215 | % reading input file(s) |
---|
| 216 | [Data,tild,errormsg] = read_field(filecell{1,index},FileType,InputFields{1}); |
---|
| 217 | if ~isempty(errormsg) |
---|
| 218 | displ_uvmat('ERROR',['error of input reading: ' errormsg],checkrun); |
---|
| 219 | break |
---|
| 220 | end |
---|
| 221 | if ~isempty(NbSlice_calib) |
---|
| 222 | Data.ZIndex=mod(i1_series{1}(index)-1,NbSlice_calib{1})+1;%Zindex for phys transform |
---|
| 223 | end |
---|
| 224 | %update average |
---|
[974] | 225 | FF=isnan(Data.U)|isnan(Data.V);% chceck NaN values |
---|
| 226 | Data.U(FF)=0;% set to zero the NaN values |
---|
| 227 | Data.V(FF)=0; |
---|
| 228 | NbField=NbField+~FF;%count the NaN values |
---|
[751] | 229 | MeanU=MeanU+Data.U; |
---|
| 230 | MeanV=MeanV+Data.V; |
---|
| 231 | MaxU=(MaxU>=Data.U).*MaxU+(MaxU<Data.U).*Data.U; |
---|
| 232 | MinU=(MinU<=Data.U).*MinU+(MinU>Data.U).*Data.U; |
---|
| 233 | MaxV=(MaxV>=Data.V).*MaxV+(MaxV<Data.V).*Data.V; |
---|
| 234 | MinV=(MinV<=Data.V).*MinV+(MinV>Data.V).*Data.V; |
---|
| 235 | cos1_U=cos1_U+Data.U*cos(Data.Time*sigma1); |
---|
| 236 | cos1_V=cos1_V+Data.V*cos(Data.Time*sigma1); |
---|
| 237 | sin1_U=sin1_U+Data.U*sin(Data.Time*sigma1); |
---|
| 238 | sin1_V=sin1_V+Data.V*sin(Data.Time*sigma1); |
---|
| 239 | cos2_U=cos2_U+Data.U*cos(Data.Time*sigma2); |
---|
| 240 | cos2_V=cos2_V+Data.V*cos(Data.Time*sigma2); |
---|
| 241 | sin2_U=sin2_U+Data.U*sin(Data.Time*sigma2); |
---|
| 242 | sin2_V=sin2_V+Data.V*sin(Data.Time*sigma2); |
---|
| 243 | cos3_U=cos3_U+Data.U*cos(Data.Time*sigma3); |
---|
| 244 | cos3_V=cos3_V+Data.V*cos(Data.Time*sigma3); |
---|
| 245 | sin3_U=sin3_U+Data.U*sin(Data.Time*sigma3); |
---|
| 246 | sin3_V=sin3_V+Data.V*sin(Data.Time*sigma3); |
---|
| 247 | cossub_U=cossub_U+Data.U*cos(Data.Time*sigma_sub); |
---|
| 248 | cossub_V=cossub_V+Data.V*cos(Data.Time*sigma_sub); |
---|
| 249 | sinsub_U=sinsub_U+Data.U*sin(Data.Time*sigma_sub); |
---|
| 250 | sinsub_V=sinsub_V+Data.V*sin(Data.Time*sigma_sub); |
---|
| 251 | |
---|
| 252 | |
---|
| 253 | end |
---|
| 254 | |
---|
| 255 | %%%%%%%%%%%%%%%%%%%%%%%% |
---|
[787] | 256 | Data.ListVarName={'coord_x','coord_y','MeanU','MeanV','cos1_U','cos1_V','a1_U','a1_V','a2_U','a2_V','a3_U','a3_V','asub_U','asub_V',... |
---|
[974] | 257 | 'phase1_U','phase1_V','phase2_U','phase2_V','phase3_U','phase3_V','phasesub_U','phasesub_V'}; |
---|
[751] | 258 | %Data.ListVarName=[{'coord_y','coord_x'} Data.ListVarName]; |
---|
| 259 | %Data.VarDimName={'coord_y', 'coord_x'}; |
---|
[787] | 260 | for ilist=1:numel(Data.ListVarName)-2 |
---|
| 261 | Data.VarDimName{ilist+2}={'coord_y','coord_x'}; |
---|
| 262 | % Data.VarDimName{ilist}='nb_vectors'; |
---|
[751] | 263 | end |
---|
[974] | 264 | Data.MeanU=MeanU./NbField; |
---|
| 265 | Data.MeanV=MeanV./NbField; |
---|
| 266 | cos1_U=cos1_U./NbField; |
---|
| 267 | cos1_V=cos1_V./NbField; |
---|
| 268 | sin1_U=sin1_U./NbField; |
---|
| 269 | sin1_V=sin1_V./NbField; |
---|
| 270 | cos2_U=cos2_U./NbField; |
---|
| 271 | cos2_V=cos2_V./NbField; |
---|
| 272 | sin2_U=sin2_U./NbField; |
---|
| 273 | sin2_V=sin2_V./NbField; |
---|
| 274 | cos3_U=cos3_U./NbField; |
---|
| 275 | cos3_V=cos3_V./NbField; |
---|
| 276 | sin3_U=sin3_U./NbField; |
---|
| 277 | sin3_V=sin3_V./NbField; |
---|
| 278 | cossub_U=cossub_U./NbField; |
---|
| 279 | cossub_V=cossub_V./NbField; |
---|
| 280 | sinsub_U=sinsub_U./NbField; |
---|
| 281 | sinsub_V=sinsub_V./NbField; |
---|
| 282 | Data.cos1_U=cos1_U; |
---|
| 283 | Data.cos1_V=cos1_V; |
---|
| 284 | Data.a1_U=sqrt(2)*sqrt(cos1_U.*cos1_U+sin1_U.*sin1_U); |
---|
| 285 | Data.a1_V=-sqrt(2)*sqrt(cos1_V.*cos1_V+sin1_V.*sin1_V); |
---|
[751] | 286 | Data.a2_U=sqrt(2)*sqrt(cos2_U.*cos2_U+sin2_U.*sin2_U); |
---|
| 287 | Data.a2_V=-sqrt(2)*sqrt(cos2_V.*cos2_V+sin2_V.*sin2_V); |
---|
| 288 | Data.a3_U=sqrt(2)*sqrt(cos3_U.*cos3_U+sin3_U.*sin3_U); |
---|
| 289 | Data.a3_V=-sqrt(2)*sqrt(cos3_V.*cos3_V+sin3_V.*sin3_V); |
---|
| 290 | Data.asub_U=sqrt(2)*sqrt(cossub_U.*cossub_U+sinsub_U.*sinsub_U); |
---|
| 291 | Data.asub_V=-sqrt(2)*sqrt(cossub_V.*cossub_V+sinsub_V.*sinsub_V); |
---|
[974] | 292 | % clear i |
---|
[751] | 293 | Data.phase1_U=(angle(cos1_U+i*sin1_U)); |
---|
[974] | 294 | |
---|
[751] | 295 | Data.phase1_V=angle(cos1_V+i*sin1_V); |
---|
| 296 | Data.phase2_U=(angle(cos2_U+i*sin2_U)); |
---|
| 297 | Data.phase2_V=(angle(cos2_V+i*sin2_V)); |
---|
| 298 | Data.phase3_U=(angle(cos3_U+i*sin3_U)); |
---|
| 299 | Data.phase3_V=(angle(cos3_V+i*sin3_V)); |
---|
| 300 | Data.phasesub_U=(angle(cossub_U+i*sinsub_U)); |
---|
| 301 | Data.phasesub_V=(angle(cossub_V+i*sinsub_V)); |
---|
| 302 | |
---|
| 303 | %% write the results |
---|
| 304 | OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},'.nc','',1); |
---|
[787] | 305 | errormsg=struct2nc(OutputFile,Data);% write the output file |
---|
| 306 | if isempty(errormsg) |
---|
| 307 | disp_uvmat('CONFIRMATION',[OutputFile ' successfully written'],checkrun) |
---|
| 308 | else |
---|
| 309 | disp_uvmat('ERROR',errormsg,checkrun) |
---|
| 310 | end |
---|
| 311 | |
---|
[751] | 312 | |
---|
| 313 | %% open the result file with uvmat (in RUN mode) |
---|
| 314 | % if checkrun |
---|
| 315 | % uvmat(OutputFile)% open the last result file with uvmat |
---|
| 316 | % end |
---|
[810] | 317 | '#### THE END ####' |
---|