[751] | 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 | [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1}); |
---|
| 106 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
| 107 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
| 108 | if ~isempty(j1_series{iview}) |
---|
| 109 | frame_index{iview}=j1_series{iview}; |
---|
| 110 | else |
---|
| 111 | frame_index{iview}=i1_series{iview}; |
---|
| 112 | end |
---|
| 113 | end |
---|
| 114 | |
---|
| 115 | %% calibration data and timing: read the ImaDoc files |
---|
| 116 | XmlData=[]; |
---|
| 117 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
| 118 | if size(time,1)>1 |
---|
| 119 | diff_time=max(max(diff(time))); |
---|
| 120 | if diff_time>0 |
---|
| 121 | msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
---|
| 122 | end |
---|
| 123 | end |
---|
| 124 | |
---|
| 125 | %% coordinate transform or other user defined transform |
---|
| 126 | transform_fct='';%default |
---|
| 127 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
| 128 | addpath(Param.FieldTransform.TransformPath) |
---|
| 129 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
| 130 | rmpath(Param.FieldTransform.TransformPath) |
---|
| 131 | end |
---|
| 132 | |
---|
| 133 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
| 134 | % EDIT FROM HERE |
---|
| 135 | |
---|
| 136 | %% check the validity of input file types |
---|
| 137 | if CheckImage{1} |
---|
| 138 | FileExtOut='.png'; % write result as .png images for image inputs |
---|
| 139 | elseif CheckNc{1} |
---|
| 140 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
| 141 | else |
---|
| 142 | msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}]) |
---|
| 143 | return |
---|
| 144 | end |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | %% settings for the output file |
---|
| 148 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
---|
| 149 | first_i=i1_series{1}(1); |
---|
| 150 | last_i=i1_series{1}(end); |
---|
| 151 | if isempty(j1_series{1})% if there is no second index j |
---|
| 152 | first_j=1;last_j=1; |
---|
| 153 | else |
---|
| 154 | first_j=j1_series{1}(1); |
---|
| 155 | last_j=j1_series{1}(end); |
---|
| 156 | end |
---|
| 157 | |
---|
| 158 | %% Set field names and velocity types |
---|
| 159 | InputFields{1}=[];%default (case of images) |
---|
| 160 | if isfield(Param,'InputFields') |
---|
| 161 | InputFields{1}=Param.InputFields; |
---|
| 162 | end |
---|
| 163 | |
---|
| 164 | nbfiles=0; |
---|
| 165 | nbmissing=0; |
---|
| 166 | |
---|
| 167 | %initialisation |
---|
| 168 | DataOut.ListGlobalAttribute= {'Conventions'}; |
---|
| 169 | DataOut.Conventions= 'uvmat'; |
---|
| 170 | DataOut.ListVarName={'coord_y', 'coord_x' ,'UMean' , 'VMean','u2Mean','v2Mean','u2Mean_1','v2Mean_1','uvMean','Counter'}; |
---|
| 171 | 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'},... |
---|
| 172 | {'coord_y','coord_x'},{'coord_y','coord_x'}}; |
---|
| 173 | DataOut.UMean=0; |
---|
| 174 | DataOut.VMean=0; |
---|
| 175 | DataOut.u2Mean=0; |
---|
| 176 | DataOut.v2Mean=0; |
---|
| 177 | DataOut.u2Mean_1=0; |
---|
| 178 | DataOut.v2Mean_1=0; |
---|
| 179 | DataOut.uvMean=0; |
---|
| 180 | DataOut.Counter=0; |
---|
| 181 | U2Mean=0; |
---|
| 182 | V2Mean=0; |
---|
| 183 | UVMean=0; |
---|
| 184 | U2Mean_1=0; |
---|
| 185 | V2Mean_1=0; |
---|
[761] | 186 | Counter_1=0; |
---|
| 187 | |
---|
[751] | 188 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
| 189 | for index=1:NbField |
---|
| 190 | update_waitbar(WaitbarHandle,index/NbField) |
---|
| 191 | if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
| 192 | disp('program stopped by user') |
---|
| 193 | break |
---|
| 194 | end |
---|
| 195 | [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); |
---|
| 196 | |
---|
| 197 | %%%%%%%%%%%% MAIN RUNNING OPERATIONS %%%%%%%%%%%% |
---|
| 198 | if index==1 %first field |
---|
| 199 | |
---|
| 200 | DataOut.coord_y=Field.coord_y; |
---|
| 201 | DataOut.coord_x=Field.coord_x; |
---|
| 202 | Uprev=Field.U; |
---|
| 203 | Vprev=Field.V; |
---|
[761] | 204 | FFprev=Field.FF; |
---|
[751] | 205 | end |
---|
[761] | 206 | FF=isnan(Field.U);%|Field.U<-60|Field.U>30;% threshold on U |
---|
[751] | 207 | DataOut.Counter=DataOut.Counter+ (~FF);% add 1 to the couter for non NaN point |
---|
[761] | 208 | Counter_1=Counter_1+(~FF & ~FFprev); |
---|
[751] | 209 | Field.U(FF)=0;% set to 0 the nan values |
---|
| 210 | Field.V(FF)=0; |
---|
| 211 | DataOut.UMean=DataOut.UMean+Field.U; %increment the sum |
---|
| 212 | DataOut.VMean=DataOut.VMean+Field.V; %increment the sum |
---|
| 213 | U2Mean=U2Mean+(Field.U).*(Field.U); %increment the U squared sum |
---|
| 214 | V2Mean=V2Mean+(Field.V).*(Field.V); %increment the V squared sum |
---|
| 215 | UVMean=UVMean+(Field.U).*(Field.V); %increment the sum |
---|
| 216 | U2Mean_1=U2Mean_1+(Field.U).*Uprev; %increment the U squared sum |
---|
| 217 | V2Mean_1=V2Mean_1+(Field.V).*Vprev; %increment the V squared sum |
---|
| 218 | Uprev=Field.U; %store for next iteration |
---|
| 219 | Vprev=Field.V; |
---|
[761] | 220 | FFprev=FF; |
---|
[751] | 221 | end |
---|
| 222 | %%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%% |
---|
| 223 | |
---|
| 224 | DataOut.Counter(DataOut.Counter==0)=1;% put counter to 1 when it is zero |
---|
| 225 | DataOut.UMean=DataOut.UMean./DataOut.Counter; % normalize the mean |
---|
| 226 | DataOut.VMean=DataOut.VMean./DataOut.Counter; % normalize the mean |
---|
| 227 | U2Mean=U2Mean./DataOut.Counter; % normalize the mean |
---|
| 228 | V2Mean=V2Mean./DataOut.Counter; % normalize the mean |
---|
| 229 | UVMean=UVMean./DataOut.Counter; % normalize the mean |
---|
[761] | 230 | U2Mean_1=U2Mean_1./Counter_1; % normalize the mean |
---|
| 231 | V2Mean_1=V2Mean_1./Counter_1; % normalize the mean |
---|
[751] | 232 | DataOut.u2Mean=U2Mean-DataOut.UMean.*DataOut.UMean; % normalize the mean |
---|
| 233 | DataOut.v2Mean=V2Mean-DataOut.VMean.*DataOut.VMean; % normalize the mean |
---|
| 234 | DataOut.uvMean=UVMean-DataOut.UMean.*DataOut.VMean; % normalize the mean \ |
---|
| 235 | DataOut.u2Mean_1=U2Mean_1-DataOut.UMean.*DataOut.UMean; % normalize the mean |
---|
| 236 | DataOut.v2Mean_1=V2Mean_1-DataOut.VMean.*DataOut.VMean; % normalize the mean |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | %% calculate the profiles |
---|
| 240 | % npx=numel(DataOut.coord_x); |
---|
| 241 | % band=ceil(npx/5) :floor(4*npx/5);% keep only the central band |
---|
| 242 | % for ivar=3:numel(DataOut.ListVarName)-1 |
---|
| 243 | % VarName=DataOut.ListVarName{ivar};% name of the variable |
---|
| 244 | % DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Profile']}];%append the name of the profile variable |
---|
| 245 | % DataOut.VarDimName=[DataOut.VarDimName {'coord_y'}]; |
---|
| 246 | % DataOut.([VarName 'Profile'])=mean(DataOut.(VarName)(:,band),2); %take the mean profile of U, excluding the edges |
---|
| 247 | % end |
---|
| 248 | |
---|
| 249 | %% writing the result file as netcdf file |
---|
| 250 | OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j); |
---|
| 251 | %case of netcdf input file , determine global attributes |
---|
| 252 | errormsg=struct2nc(OutputFile,DataOut); %save result file |
---|
| 253 | if isempty(errormsg) |
---|
| 254 | disp([OutputFile ' written']); |
---|
| 255 | else |
---|
| 256 | disp(['error in writting result file: ' errormsg]) |
---|
| 257 | end |
---|
| 258 | |
---|
| 259 | |
---|
| 260 | %% open the result file with uvmat (in RUN mode) |
---|
| 261 | if checkrun |
---|
| 262 | uvmat(OutputFile)% open the last result file with uvmat |
---|
| 263 | end |
---|