| 1 | %'aver_stat': calculate Reynolds steress components over time series |
|---|
| 2 | %------------------------------------------------------------------------ |
|---|
| 3 | % function ParamOut=turb_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 | |
|---|
| 41 | function ParamOut=turb_stat(Param) |
|---|
| 42 | |
|---|
| 43 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName |
|---|
| 44 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
|---|
| 45 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
|---|
| 46 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
|---|
| 47 | ParamOut.NbSlice='off'; %nbre of slices ('off' by default) |
|---|
| 48 | ParamOut.VelType='one';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
|---|
| 49 | ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
|---|
| 50 | ParamOut.FieldTransform = 'on';%can use a transform function |
|---|
| 51 | ParamOut.ProjObject='off';%can use projection object(option 'off'/'on', |
|---|
| 52 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
|---|
| 53 | ParamOut.OutputDirExt='.staturb';%set the output dir extension |
|---|
| 54 | 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 |
|---|
| 55 | % filecell=get_file_series(Param);%check existence of the first input file |
|---|
| 56 | % if ~exist(filecell{1,1},'file') |
|---|
| 57 | % msgbox_uvmat('WARNING','the first input file does not exist') |
|---|
| 58 | % end |
|---|
| 59 | return |
|---|
| 60 | end |
|---|
| 61 | |
|---|
| 62 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
|---|
| 63 | ParamOut=[];%default output |
|---|
| 64 | %% read input parameters from an xml file if input is a file name (batch mode) |
|---|
| 65 | checkrun=1; |
|---|
| 66 | if ischar(Param) |
|---|
| 67 | Param=xml2struct(Param);% read Param as input file (batch case) |
|---|
| 68 | checkrun=0; |
|---|
| 69 | end |
|---|
| 70 | hseries=findobj(allchild(0),'Tag','series'); |
|---|
| 71 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
|---|
| 72 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
|---|
| 73 | |
|---|
| 74 | %% define the directory for result file (with path=RootPath{1}) |
|---|
| 75 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
|---|
| 76 | |
|---|
| 77 | %% root input file(s) name, type and index series |
|---|
| 78 | RootPath=Param.InputTable(:,1); |
|---|
| 79 | RootFile=Param.InputTable(:,3); |
|---|
| 80 | SubDir=Param.InputTable(:,2); |
|---|
| 81 | NomType=Param.InputTable(:,4); |
|---|
| 82 | FileExt=Param.InputTable(:,5); |
|---|
| 83 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
|---|
| 84 | %%%%%%%%%%%% |
|---|
| 85 | % The cell array filecell is the list of input file names, while |
|---|
| 86 | % filecell{iview,fileindex}: |
|---|
| 87 | % iview: line in the table corresponding to a given file series |
|---|
| 88 | % fileindex: file index within the file series, |
|---|
| 89 | % 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 |
|---|
| 90 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
|---|
| 91 | %%%%%%%%%%%% NbView=1 : a single input series |
|---|
| 92 | NbView=numel(i1_series);%number of input file series (lines in InputTable) |
|---|
| 93 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
|---|
| 94 | NbField_i=size(i1_series{1},2); %nb of fields for the i index |
|---|
| 95 | NbField=NbField_j*NbField_i; %total number of fields |
|---|
| 96 | |
|---|
| 97 | %% determine the file type on each line from the first input file |
|---|
| 98 | ImageTypeOptions={'image','multimage','mmreader','video'}; |
|---|
| 99 | NcTypeOptions={'netcdf','civx','civdata'}; |
|---|
| 100 | for iview=1:NbView |
|---|
| 101 | if ~exist(filecell{iview,1}','file') |
|---|
| 102 | msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist']) |
|---|
| 103 | return |
|---|
| 104 | end |
|---|
| 105 | [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1}); |
|---|
| 106 | FileType{iview}=FileInfo{iview}.FileType; |
|---|
| 107 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
|---|
| 108 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
|---|
| 109 | if ~isempty(j1_series{iview}) |
|---|
| 110 | frame_index{iview}=j1_series{iview}; |
|---|
| 111 | else |
|---|
| 112 | frame_index{iview}=i1_series{iview}; |
|---|
| 113 | end |
|---|
| 114 | end |
|---|
| 115 | |
|---|
| 116 | %% calibration data and timing: read the ImaDoc files |
|---|
| 117 | XmlData=[]; |
|---|
| 118 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
|---|
| 119 | if size(time,1)>1 |
|---|
| 120 | diff_time=max(max(diff(time))); |
|---|
| 121 | if diff_time>0 |
|---|
| 122 | msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
|---|
| 123 | end |
|---|
| 124 | end |
|---|
| 125 | |
|---|
| 126 | %% coordinate transform or other user defined transform |
|---|
| 127 | transform_fct='';%default |
|---|
| 128 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
|---|
| 129 | addpath(Param.FieldTransform.TransformPath) |
|---|
| 130 | transform_fct=str2func(Param.FieldTransform.TransformName); |
|---|
| 131 | rmpath(Param.FieldTransform.TransformPath) |
|---|
| 132 | end |
|---|
| 133 | |
|---|
| 134 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
|---|
| 135 | % EDIT FROM HERE |
|---|
| 136 | |
|---|
| 137 | %% check the validity of input file types |
|---|
| 138 | if CheckImage{1} |
|---|
| 139 | FileExtOut='.png'; % write result as .png images for image inputs |
|---|
| 140 | elseif CheckNc{1} |
|---|
| 141 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
|---|
| 142 | else |
|---|
| 143 | msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}]) |
|---|
| 144 | return |
|---|
| 145 | end |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | %% settings for the output file |
|---|
| 149 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
|---|
| 150 | first_i=i1_series{1}(1); |
|---|
| 151 | last_i=i1_series{1}(end); |
|---|
| 152 | if isempty(j1_series{1})% if there is no second index j |
|---|
| 153 | first_j=1;last_j=1; |
|---|
| 154 | else |
|---|
| 155 | first_j=j1_series{1}(1); |
|---|
| 156 | last_j=j1_series{1}(end); |
|---|
| 157 | end |
|---|
| 158 | |
|---|
| 159 | %% Set field names and velocity types |
|---|
| 160 | InputFields{1}=[];%default (case of images) |
|---|
| 161 | if isfield(Param,'InputFields') |
|---|
| 162 | InputFields{1}=Param.InputFields; |
|---|
| 163 | end |
|---|
| 164 | |
|---|
| 165 | nbfiles=0; |
|---|
| 166 | nbmissing=0; |
|---|
| 167 | |
|---|
| 168 | %initialisation |
|---|
| 169 | DataOut.ListGlobalAttribute= {'Conventions'}; |
|---|
| 170 | DataOut.Conventions= 'uvmat'; |
|---|
| 171 | DataOut.ListVarName={'coord_y', 'coord_x' ,'UMean' , 'VMean','u2Mean','v2Mean','u2Mean_1','v2Mean_1','uvMean','Counter'}; |
|---|
| 172 | DataOut.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},... |
|---|
| 173 | {'coord_y','coord_x'},{'coord_y','coord_x'}}; |
|---|
| 174 | DataOut.UMean=0; |
|---|
| 175 | DataOut.VMean=0; |
|---|
| 176 | DataOut.u2Mean=0; |
|---|
| 177 | DataOut.v2Mean=0; |
|---|
| 178 | DataOut.u2Mean_1=0; |
|---|
| 179 | DataOut.v2Mean_1=0; |
|---|
| 180 | DataOut.uvMean=0; |
|---|
| 181 | DataOut.Counter=0; |
|---|
| 182 | U2Mean=0; |
|---|
| 183 | V2Mean=0; |
|---|
| 184 | UVMean=0; |
|---|
| 185 | U2Mean_1=0; |
|---|
| 186 | V2Mean_1=0; |
|---|
| 187 | Counter_1=0; |
|---|
| 188 | |
|---|
| 189 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
|---|
| 190 | for index=1:NbField |
|---|
| 191 | update_waitbar(WaitbarHandle,index/NbField) |
|---|
| 192 | if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
|---|
| 193 | disp('program stopped by user') |
|---|
| 194 | break |
|---|
| 195 | end |
|---|
| 196 | [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); |
|---|
| 197 | |
|---|
| 198 | %%%%%%%%%%%% MAIN RUNNING OPERATIONS %%%%%%%%%%%% |
|---|
| 199 | if index==1 %first field |
|---|
| 200 | |
|---|
| 201 | DataOut.coord_y=Field.coord_y; |
|---|
| 202 | DataOut.coord_x=Field.coord_x; |
|---|
| 203 | Uprev=Field.U; |
|---|
| 204 | Vprev=Field.V; |
|---|
| 205 | FFprev=Field.FF; |
|---|
| 206 | end |
|---|
| 207 | FF=isnan(Field.U);%|Field.U<-60|Field.U>30;% threshold on U |
|---|
| 208 | DataOut.Counter=DataOut.Counter+ (~FF);% add 1 to the couter for non NaN point |
|---|
| 209 | Counter_1=Counter_1+(~FF & ~FFprev); |
|---|
| 210 | Field.U(FF)=0;% set to 0 the nan values |
|---|
| 211 | Field.V(FF)=0; |
|---|
| 212 | DataOut.UMean=DataOut.UMean+Field.U; %increment the sum |
|---|
| 213 | DataOut.VMean=DataOut.VMean+Field.V; %increment the sum |
|---|
| 214 | U2Mean=U2Mean+(Field.U).*(Field.U); %increment the U squared sum |
|---|
| 215 | V2Mean=V2Mean+(Field.V).*(Field.V); %increment the V squared sum |
|---|
| 216 | UVMean=UVMean+(Field.U).*(Field.V); %increment the sum |
|---|
| 217 | U2Mean_1=U2Mean_1+(Field.U).*Uprev; %increment the U squared sum |
|---|
| 218 | V2Mean_1=V2Mean_1+(Field.V).*Vprev; %increment the V squared sum |
|---|
| 219 | Uprev=Field.U; %store for next iteration |
|---|
| 220 | Vprev=Field.V; |
|---|
| 221 | FFprev=FF; |
|---|
| 222 | end |
|---|
| 223 | %%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%% |
|---|
| 224 | |
|---|
| 225 | DataOut.Counter(DataOut.Counter==0)=1;% put counter to 1 when it is zero |
|---|
| 226 | DataOut.UMean=DataOut.UMean./DataOut.Counter; % normalize the mean |
|---|
| 227 | DataOut.VMean=DataOut.VMean./DataOut.Counter; % normalize the mean |
|---|
| 228 | U2Mean=U2Mean./DataOut.Counter; % normalize the mean |
|---|
| 229 | V2Mean=V2Mean./DataOut.Counter; % normalize the mean |
|---|
| 230 | UVMean=UVMean./DataOut.Counter; % normalize the mean |
|---|
| 231 | U2Mean_1=U2Mean_1./Counter_1; % normalize the mean |
|---|
| 232 | V2Mean_1=V2Mean_1./Counter_1; % normalize the mean |
|---|
| 233 | DataOut.u2Mean=U2Mean-DataOut.UMean.*DataOut.UMean; % normalize the mean |
|---|
| 234 | DataOut.v2Mean=V2Mean-DataOut.VMean.*DataOut.VMean; % normalize the mean |
|---|
| 235 | DataOut.uvMean=UVMean-DataOut.UMean.*DataOut.VMean; % normalize the mean \ |
|---|
| 236 | DataOut.u2Mean_1=U2Mean_1-DataOut.UMean.*DataOut.UMean; % normalize the mean |
|---|
| 237 | DataOut.v2Mean_1=V2Mean_1-DataOut.VMean.*DataOut.VMean; % normalize the mean |
|---|
| 238 | |
|---|
| 239 | |
|---|
| 240 | %% calculate the profiles |
|---|
| 241 | % npx=numel(DataOut.coord_x); |
|---|
| 242 | % band=ceil(npx/5) :floor(4*npx/5);% keep only the central band |
|---|
| 243 | % for ivar=3:numel(DataOut.ListVarName)-1 |
|---|
| 244 | % VarName=DataOut.ListVarName{ivar};% name of the variable |
|---|
| 245 | % DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Profile']}];%append the name of the profile variable |
|---|
| 246 | % DataOut.VarDimName=[DataOut.VarDimName {'coord_y'}]; |
|---|
| 247 | % DataOut.([VarName 'Profile'])=mean(DataOut.(VarName)(:,band),2); %take the mean profile of U, excluding the edges |
|---|
| 248 | % end |
|---|
| 249 | |
|---|
| 250 | %% writing the result file as netcdf file |
|---|
| 251 | OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j); |
|---|
| 252 | %case of netcdf input file , determine global attributes |
|---|
| 253 | errormsg=struct2nc(OutputFile,DataOut); %save result file |
|---|
| 254 | if isempty(errormsg) |
|---|
| 255 | disp([OutputFile ' written']); |
|---|
| 256 | else |
|---|
| 257 | disp(['error in writting result file: ' errormsg]) |
|---|
| 258 | end |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | %% open the result file with uvmat (in RUN mode) |
|---|
| 262 | if checkrun |
|---|
| 263 | uvmat(OutputFile)% open the last result file with uvmat |
|---|
| 264 | end |
|---|