source: trunk/src/series/turb_stat.m @ 751

Last change on this file since 751 was 751, checked in by sommeria, 10 years ago

add aver_synchro (field analysis at different frequencies) and turb_stat

File size: 11.5 KB
Line 
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
41function ParamOut=turb_stat(Param)
42
43%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
44if 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
60end
61
62%%%%%%%%%%%%  STANDARD PART  %%%%%%%%%%%%
63ParamOut=[];%default output
64%% read input parameters from an xml file if input is a file name (batch mode)
65checkrun=1;
66if ischar(Param)
67    Param=xml2struct(Param);% read Param as input file (batch case)
68    checkrun=0;
69end
70hseries=findobj(allchild(0),'Tag','series');
71RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
72WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
73
74%% define the directory for result file (with path=RootPath{1})
75OutputDir=[Param.OutputSubDir Param.OutputDirExt];
76   
77%% root input file(s) name, type and index series
78RootPath=Param.InputTable(:,1);
79RootFile=Param.InputTable(:,3);
80SubDir=Param.InputTable(:,2);
81NomType=Param.InputTable(:,4);
82FileExt=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
92NbView=numel(i1_series);%number of input file series (lines in InputTable)
93NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
94NbField_i=size(i1_series{1},2); %nb of fields for the i index
95NbField=NbField_j*NbField_i; %total number of fields
96
97%% determine the file type on each line from the first input file
98ImageTypeOptions={'image','multimage','mmreader','video'};
99NcTypeOptions={'netcdf','civx','civdata'};
100for 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
113end
114
115%% calibration data and timing: read the ImaDoc files
116XmlData=[];
117[XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
118if 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   
123end
124
125%% coordinate transform or other user defined transform
126transform_fct='';%default
127if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
128    addpath(Param.FieldTransform.TransformPath)
129    transform_fct=str2func(Param.FieldTransform.TransformName);
130    rmpath(Param.FieldTransform.TransformPath)
131end
132
133%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
134 % EDIT FROM HERE
135
136%% check the validity of  input file types
137if CheckImage{1}
138    FileExtOut='.png'; % write result as .png images for image inputs
139elseif CheckNc{1}
140    FileExtOut='.nc';% write result as .nc files for netcdf inputs
141else
142    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
143    return
144end
145
146
147%% settings for the output file
148NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
149first_i=i1_series{1}(1);
150last_i=i1_series{1}(end);
151if isempty(j1_series{1})% if there is no second index j
152    first_j=1;last_j=1;
153else
154    first_j=j1_series{1}(1);
155    last_j=j1_series{1}(end);
156end
157
158%% Set field names and velocity types
159InputFields{1}=[];%default (case of images)
160if isfield(Param,'InputFields')
161    InputFields{1}=Param.InputFields;
162end
163
164nbfiles=0;
165nbmissing=0;
166
167%initialisation
168DataOut.ListGlobalAttribute= {'Conventions'};
169DataOut.Conventions= 'uvmat';
170DataOut.ListVarName={'coord_y', 'coord_x' ,'UMean' , 'VMean','u2Mean','v2Mean','u2Mean_1','v2Mean_1','uvMean','Counter'};
171DataOut.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'}};
173DataOut.UMean=0;
174DataOut.VMean=0;
175DataOut.u2Mean=0;
176DataOut.v2Mean=0;
177DataOut.u2Mean_1=0;
178DataOut.v2Mean_1=0;
179DataOut.uvMean=0;
180DataOut.Counter=0;
181U2Mean=0;
182V2Mean=0;
183UVMean=0;
184U2Mean_1=0;
185V2Mean_1=0;
186checkgrid=0;% test for a structured grid for input field
187%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
188for index=1:NbField
189    update_waitbar(WaitbarHandle,index/NbField)
190    if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
191        disp('program stopped by user')
192        break
193    end
194    [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
195
196    %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
197    if index==1 %first field
198       
199        DataOut.coord_y=Field.coord_y;
200        DataOut.coord_x=Field.coord_x;
201        Uprev=Field.U;
202        Vprev=Field.V;
203    end
204    FF=isnan(Field.U)|Field.U<-60|Field.U>30;% threshold on U
205    DataOut.Counter=DataOut.Counter+ (~FF);% add 1 to the couter for non NaN point
206    Field.U(FF)=0;% set to 0 the nan values
207    Field.V(FF)=0;
208    DataOut.UMean=DataOut.UMean+Field.U; %increment the sum
209    DataOut.VMean=DataOut.VMean+Field.V; %increment the sum
210    U2Mean=U2Mean+(Field.U).*(Field.U); %increment the U squared sum
211    V2Mean=V2Mean+(Field.V).*(Field.V); %increment the V squared sum
212    UVMean=UVMean+(Field.U).*(Field.V); %increment the sum
213    U2Mean_1=U2Mean_1+(Field.U).*Uprev; %increment the U squared sum
214    V2Mean_1=V2Mean_1+(Field.V).*Vprev; %increment the V squared sum
215    Uprev=Field.U; %store for next iteration
216    Vprev=Field.V;
217end
218%%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
219
220DataOut.Counter(DataOut.Counter==0)=1;% put counter to 1 when it is zero
221DataOut.UMean=DataOut.UMean./DataOut.Counter; % normalize the mean
222DataOut.VMean=DataOut.VMean./DataOut.Counter; % normalize the mean
223U2Mean=U2Mean./DataOut.Counter; % normalize the mean
224V2Mean=V2Mean./DataOut.Counter; % normalize the mean
225UVMean=UVMean./DataOut.Counter; % normalize the mean
226U2Mean_1=U2Mean_1./DataOut.Counter; % normalize the mean
227V2Mean_1=V2Mean_1./DataOut.Counter; % normalize the mean
228DataOut.u2Mean=U2Mean-DataOut.UMean.*DataOut.UMean; % normalize the mean
229DataOut.v2Mean=V2Mean-DataOut.VMean.*DataOut.VMean; % normalize the mean
230DataOut.uvMean=UVMean-DataOut.UMean.*DataOut.VMean; % normalize the mean \
231DataOut.u2Mean_1=U2Mean_1-DataOut.UMean.*DataOut.UMean; % normalize the mean
232DataOut.v2Mean_1=V2Mean_1-DataOut.VMean.*DataOut.VMean; % normalize the mean
233
234
235%% calculate the profiles
236% npx=numel(DataOut.coord_x);
237% band=ceil(npx/5) :floor(4*npx/5);% keep only the central band
238% for ivar=3:numel(DataOut.ListVarName)-1
239%     VarName=DataOut.ListVarName{ivar};% name of the variable
240%     DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Profile']}];%append the name of the profile variable
241%     DataOut.VarDimName=[DataOut.VarDimName {'coord_y'}];
242%    DataOut.([VarName 'Profile'])=mean(DataOut.(VarName)(:,band),2); %take the mean profile of U, excluding the edges
243% end
244
245%% writing the result file as netcdf file
246OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j);
247 %case of netcdf input file , determine global attributes
248 errormsg=struct2nc(OutputFile,DataOut); %save result file
249 if isempty(errormsg)
250     disp([OutputFile ' written']);
251 else
252     disp(['error in writting result file: ' errormsg])
253 end
254
255
256%% open the result file with uvmat (in RUN mode)
257if checkrun
258    uvmat(OutputFile)% open the last result file with uvmat
259end
Note: See TracBrowser for help on using the repository browser.