1 | %'aver_stat': calculate Reynolds stress 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 | %======================================================================= |
---|
42 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
43 | % http://www.legi.grenoble-inp.fr |
---|
44 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.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 | |
---|
59 | function ParamOut=LIF_proj(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='off'; %nbre of slices ('on' if needed as input, fixed value e.g. 1, 'off' by default) |
---|
66 | ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
67 | ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
68 | ParamOut.FieldTransform = 'off';%can use a transform function |
---|
69 | ParamOut.ProjObject='off';%can use projection object(option 'off'/'on', |
---|
70 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
---|
71 | ParamOut.OutputDirExt='.lif_proj';%set the output dir extension |
---|
72 | ParamOut.OutputFileMode='NbInput';% '=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 | if ~strcmp(Param.InputTable{1,5},'.png') |
---|
78 | msgbox_uvmat('ERROR','put .png image in first input line'); |
---|
79 | end |
---|
80 | if ~strcmp(Param.InputTable{2,5},'.nc') |
---|
81 | msgbox_uvmat('ERROR','put .nc file (mproj) in second input line'); |
---|
82 | end |
---|
83 | return |
---|
84 | end |
---|
85 | |
---|
86 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
---|
87 | ParamOut=[];%default output |
---|
88 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
89 | checkrun=1; |
---|
90 | if ischar(Param) |
---|
91 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
92 | checkrun=0; |
---|
93 | end |
---|
94 | hseries=findobj(allchild(0),'Tag','series'); |
---|
95 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
96 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
97 | |
---|
98 | %% root input file(s) name, type and index series |
---|
99 | RootPath=Param.InputTable(:,1); |
---|
100 | RootFile=Param.InputTable(:,3); |
---|
101 | SubDir=Param.InputTable(:,2); |
---|
102 | NomType=Param.InputTable(:,4); |
---|
103 | FileExt=Param.InputTable(:,5); |
---|
104 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
105 | %%%%%%%%%%%% |
---|
106 | % The cell array filecell is the list of input file names, while |
---|
107 | % filecell{iview,fileindex}: |
---|
108 | % iview: line in the table corresponding to a given file series |
---|
109 | % fileindex: file index within the file series, |
---|
110 | % 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 |
---|
111 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
112 | %%%%%%%%%%%% NbView=1 : a single input series |
---|
113 | NbView=numel(i1_series);%number of input file series (lines in InputTable) |
---|
114 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
115 | NbField_i=size(i1_series{1},2); %nb of fields for the i index |
---|
116 | NbField=NbField_j*NbField_i; %total number of fields |
---|
117 | |
---|
118 | %% determine the file type on each line from the first input file |
---|
119 | |
---|
120 | |
---|
121 | %% calibration data and timing: read the ImaDoc files |
---|
122 | XmlData=[]; |
---|
123 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
124 | if size(time,1)>1 |
---|
125 | diff_time=max(max(diff(time))); |
---|
126 | if diff_time>0 |
---|
127 | msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
---|
128 | end |
---|
129 | end |
---|
130 | |
---|
131 | %% coordinate transform or other user defined transform |
---|
132 | transform_fct='';%default |
---|
133 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
134 | addpath(Param.FieldTransform.TransformPath) |
---|
135 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
136 | rmpath(Param.FieldTransform.TransformPath) |
---|
137 | end |
---|
138 | |
---|
139 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
140 | % EDIT FROM HERE |
---|
141 | |
---|
142 | %% settings for the output file |
---|
143 | first_i=i1_series{1}(1); |
---|
144 | last_i=i1_series{1}(end); |
---|
145 | if isempty(j1_series{1})% if there is no second index j |
---|
146 | first_j=1;last_j=1; |
---|
147 | else |
---|
148 | first_j=j1_series{1}(1); |
---|
149 | last_j=j1_series{1}(end); |
---|
150 | end |
---|
151 | |
---|
152 | %% Set field names and velocity types |
---|
153 | InputFields{1}=[];%default (case of images) |
---|
154 | if isfield(Param,'InputFields') |
---|
155 | InputFields{1}=Param.InputFields; |
---|
156 | end |
---|
157 | |
---|
158 | nbfiles=0; |
---|
159 | nbmissing=0; |
---|
160 | |
---|
161 | RootPathOut=fullfile(Param.OutputPath,Param.Experiment,Param.Device); |
---|
162 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
163 | |
---|
164 | interval=Param.IndexRange.incr_i% statistics is done taking into account the input index increment |
---|
165 | |
---|
166 | %% |
---|
167 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
168 | |
---|
169 | ind_first=Param.IndexRange.first_i; |
---|
170 | for index_i=ind_first:interval:Param.IndexRange.last_i |
---|
171 | if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
172 | disp('program stopped by user') |
---|
173 | break |
---|
174 | end |
---|
175 | % read teh netcdf file with velocity data (after vel3C) |
---|
176 | InputFile=fullfile_uvmat(RootPath{2},SubDir{2},RootFile{2},FileExt{2},NomType{2},index_i) |
---|
177 | [Field,tild,errormsg] = nc2struct(InputFile); |
---|
178 | Field.ListVarName=[Field.ListVarName {'C'}];% add image intensity to the list of fields |
---|
179 | Field.VarDimName=[Field.VarDimName {{'coord_y','coord_x'}}];% same dimension as for the projected velocity data |
---|
180 | Dx=(Field.coord_x(end)-Field.coord_x(1))/(numel(Field.coord_x)-1);%mesh of the projected velocity data |
---|
181 | Dy=(Field.coord_y(end)-Field.coord_y(1))/(numel(Field.coord_y)-1); |
---|
182 | %read the two images of the pair |
---|
183 | InputFile_1=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},index_i,[],first_j); |
---|
184 | [Ima,tild,errormsg] = read_field(InputFile_1,'image'); |
---|
185 | InputFile_2=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},index_i,[],last_j); |
---|
186 | B=imread(InputFile_2); |
---|
187 | Ima.A=Ima.A+B; % take the sum of the two images of the pair corresponding to the PIV data |
---|
188 | |
---|
189 | [A_out,Rangx,Rangy]=phys_ima(Ima.A,XmlData{1},1);%transfor to phys coordinates |
---|
190 | pixel_x=(Rangx(2)-Rangx(1))/size(A_out,2);% phys size of a pixel |
---|
191 | pixel_y=(Rangy(1)-Rangy(2))/size(A_out,1); |
---|
192 | Npfilt_x=round(Dx/(2*pixel_x)); |
---|
193 | Npfilt_y=round(Dy/(2*pixel_y)); |
---|
194 | ix=-Npfilt_x:Npfilt_x; |
---|
195 | iy=-Npfilt_y:Npfilt_y; |
---|
196 | fct2_x=cos(ix*pi/(2*(Npfilt_x-1))); |
---|
197 | fct2_y=cos(iy*pi/(2*(Npfilt_y-1))); |
---|
198 | %definition of the cos shape matrix filter |
---|
199 | |
---|
200 | Mfiltre=fct2_y'*fct2_x; |
---|
201 | Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter |
---|
202 | A_out=filter2(Mfiltre,A_out);%filtered image |
---|
203 | ind_x=round((Field.coord_x-Rangx(1))/pixel_x)+1; |
---|
204 | first_ind_x=find(ind_x>=1,1); |
---|
205 | last_ind_x=find(ind_x>size(A_out,2),1)-1; |
---|
206 | ind_x=ind_x(first_ind_x:last_ind_x); |
---|
207 | ind_y=round((Rangy(1)-Field.coord_y)/pixel_y)+1; |
---|
208 | last_ind_y=find(ind_y<1,1)-1; |
---|
209 | if isempty(last_ind_y) |
---|
210 | last_ind_y=numel(ind_y); |
---|
211 | end |
---|
212 | first_ind_y=find(ind_y<=size(A_out,1),1); |
---|
213 | if isempty(first_ind_y) |
---|
214 | first_ind_y=1; |
---|
215 | end |
---|
216 | ind_y=ind_y(first_ind_y:last_ind_y); |
---|
217 | Field.C=NaN(numel(Field.coord_y),numel(Field.coord_x)); |
---|
218 | Field.C(first_ind_y:last_ind_y,first_ind_x:last_ind_x)=A_out(ind_y,ind_x);%image values at positions of the PIV data |
---|
219 | |
---|
220 | %% writing the result file as netcdf file |
---|
221 | |
---|
222 | OutputFile=fullfile_uvmat(RootPathOut,OutputDir,RootFile{1},'.nc',NomType{2},index_i); |
---|
223 | %case of netcdf input file , determine global attributes |
---|
224 | errormsg=struct2nc(OutputFile,Field); %save result file |
---|
225 | if isempty(errormsg) |
---|
226 | disp([OutputFile ' written']); |
---|
227 | else |
---|
228 | disp(['error in writting result file: ' errormsg]) |
---|
229 | end |
---|
230 | |
---|
231 | end |
---|
232 | |
---|
233 | |
---|