[1157] | 1 | %'sliding_average': calculate the time correlation function at each point |
---|
[1090] | 2 | %------------------------------------------------------------------------ |
---|
[1157] | 3 | % function ParamOut=turb_correlation_time(Param) |
---|
[1090] | 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) |
---|
[1114] | 18 | % .InputTable: cell of input file names, (several5.804 lines for multiple input) |
---|
[1090] | 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 |
---|
[1094] | 27 | % 900 |
---|
| 28 | % .IndexRange: set the file or frame indices on which the action must be performseriesed |
---|
| 29 | % .FieldTransform: .TransformName: name of the select39ed transform function |
---|
[1090] | 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 |
---|
[1094] | 36 | % uvmat .Coord_y: name of y coordinate variable |
---|
[1090] | 37 | % .Coord_x: name of x coordinate variable |
---|
| 38 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 40 | %======================================================================= |
---|
[1157] | 41 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[1090] | 42 | % http://www.legi.grenoble-inp.fr |
---|
[1157] | 43 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
[1090] | 44 | % |
---|
| 45 | % This file is part of the toolbox UVMAT. |
---|
| 46 | % |
---|
| 47 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 48 | % it under the terms of the GNU General Public License as published |
---|
| 49 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 50 | % or (at your option) any later version. |
---|
| 51 | % |
---|
| 52 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 53 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 54 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 55 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 56 | %======================================================================= |
---|
| 57 | |
---|
| 58 | function ParamOut=sliding_average(Param) |
---|
| 59 | |
---|
| 60 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName |
---|
| 61 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
---|
| 62 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
[1094] | 63 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to mseriesax (options 'off'/'on', 'off' by default) |
---|
[1090] | 64 | ParamOut.NbSlice=1; %nbre of slices ('off' by default) |
---|
| 65 | ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
| 66 | ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
[1157] | 67 | ParamOut.FieldTransform = 'off';%can use a transform function |
---|
[1094] | 68 | ParamOut.ProjObject='off';%can use projection object39(option 'off'/'on', |
---|
[1090] | 69 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
---|
| 70 | ParamOut.OutputDirExt='.tfilter';%set the output dir extension |
---|
[1157] | 71 | 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 |
---|
| 72 | |
---|
| 73 | %% check the first input file in the series |
---|
| 74 | first_j=[];% |
---|
| 75 | if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end |
---|
| 76 | PairString=''; |
---|
| 77 | if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end |
---|
| 78 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString); |
---|
| 79 | FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},... |
---|
| 80 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2); |
---|
| 81 | if exist(FirstFileName,'file') |
---|
| 82 | FileInfo=get_file_info(FirstFileName); |
---|
| 83 | if ~(isfield(FileInfo,'FileType')&& strcmp(FileInfo.FileType,'netcdf')) |
---|
| 84 | msgbox_uvmat('ERROR','this fct works only on netcdf files (fields projected on a grid, notraw civ data)') |
---|
| 85 | return |
---|
| 86 | end |
---|
| 87 | else |
---|
| 88 | msgbox_uvmat('ERROR',['the input file ' FirstFileName ' does not exist']) |
---|
| 89 | return |
---|
| 90 | end |
---|
| 91 | |
---|
| 92 | %% setting of intput parameters |
---|
| 93 | % answer = msgbox_uvmat('INPUT_MENU','select the variables to filter',ListVarName'); |
---|
| 94 | % ParamOut.ListVarName=ListVarName(answer); |
---|
| 95 | answer = msgbox_uvmat('INPUT_TXT','set the filering window length','3'); |
---|
| 96 | ParamOut.WindowLength=str2double(answer); |
---|
| 97 | |
---|
| 98 | % [ParamOut.ActionInput,errormsg] = set_param_input(ListParam,DefaultValue,ParamIn); |
---|
| 99 | % if ~isempty(errormsg) |
---|
| 100 | % msgbox_uvmat('ERROR',errormsg) |
---|
| 101 | % end |
---|
| 102 | % [ParamOut,errormsg] = set_param_input(ListParam,DefaultValue,ParamIn); |
---|
[1090] | 103 | return |
---|
| 104 | end |
---|
| 105 | |
---|
| 106 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
---|
| 107 | ParamOut=[];%default output |
---|
| 108 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 109 | checkrun=1; |
---|
| 110 | if ischar(Param) |
---|
| 111 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 112 | checkrun=0; |
---|
| 113 | end |
---|
| 114 | |
---|
| 115 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 116 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
| 117 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
| 118 | |
---|
| 119 | %% define the directory for result file (with path=RootPath{1}) |
---|
| 120 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
| 121 | |
---|
| 122 | %% root input file(s) name, type and index series |
---|
| 123 | RootPath=Param.InputTable(:,1); |
---|
| 124 | RootFile=Param.InputTable(:,3); |
---|
| 125 | SubDir=Param.InputTable(:,2); |
---|
| 126 | NomType=Param.InputTable(:,4); |
---|
| 127 | FileExt=Param.InputTable(:,5); |
---|
| 128 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
| 129 | %%%%%%%%%%%% |
---|
| 130 | % The cell array filecell is the list of input file names, while |
---|
| 131 | % filecell{iview,fileindex}: |
---|
| 132 | % iview: line in the table corresponding to a given file series |
---|
| 133 | % fileindex: file index within the file series, |
---|
| 134 | % 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 |
---|
| 135 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
| 136 | %%%%%%%%%%%% NbView=1 : a single input series |
---|
| 137 | NbView=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 138 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 139 | NbField_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 140 | NbField=NbField_j*NbField_i; %total number of fields |
---|
| 141 | |
---|
| 142 | %% determine the file type on each line from the first input file |
---|
| 143 | ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'}; |
---|
| 144 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
| 145 | for iview=1:NbView |
---|
| 146 | if ~exist(filecell{iview,1}','file') |
---|
| 147 | msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist']) |
---|
| 148 | return |
---|
| 149 | end |
---|
[1095] | 150 | [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1}); |
---|
[1090] | 151 | FileType{iview}=FileInfo{iview}.FileType; |
---|
| 152 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
| 153 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
| 154 | if ~isempty(j1_series{iview}) |
---|
| 155 | frame_index{iview}=j1_series{iview}; |
---|
| 156 | else |
---|
| 157 | frame_index{iview}=i1_series{iview}; |
---|
| 158 | end |
---|
| 159 | end |
---|
| 160 | |
---|
| 161 | %% calibration data and timing: read the ImaDoc files |
---|
| 162 | XmlData=[]; |
---|
| 163 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
| 164 | if size(time,1)>1 |
---|
| 165 | diff_time=max(max(diff(time))); |
---|
[1095] | 166 | if diff_time>0 |
---|
[1090] | 167 | msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
---|
| 168 | end |
---|
| 169 | end |
---|
| 170 | |
---|
| 171 | %% coordinate transform or other user defined transform |
---|
| 172 | transform_fct='';%default |
---|
| 173 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
| 174 | addpath(Param.FieldTransform.TransformPath) |
---|
| 175 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
| 176 | rmpath(Param.FieldTransform.TransformPath) |
---|
| 177 | end |
---|
| 178 | |
---|
| 179 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
| 180 | % EDIT FROM HERE |
---|
| 181 | |
---|
| 182 | %% check the validity of input file types |
---|
| 183 | if CheckImage{1} |
---|
| 184 | FileExtOut='.png'; % write result as .png images for image inputs |
---|
| 185 | elseif CheckNc{1} |
---|
| 186 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
| 187 | else |
---|
| 188 | msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}]) |
---|
| 189 | return |
---|
| 190 | end |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | %% settings for the output file |
---|
| 194 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
---|
| 195 | first_i=i1_series{1}(1); |
---|
| 196 | last_i=i1_series{1}(end); |
---|
| 197 | if isempty(j1_series{1})% if there is no second index j |
---|
| 198 | first_j=1;last_j=1; |
---|
| 199 | else |
---|
| 200 | first_j=j1_series{1}(1); |
---|
| 201 | last_j=j1_series{1}(end); |
---|
| 202 | end |
---|
| 203 | |
---|
| 204 | %% Set field names and velocity types |
---|
[1094] | 205 | InputFields{1}=[];%default (case of images)series |
---|
[1090] | 206 | if isfield(Param,'InputFields') |
---|
| 207 | InputFields{1}=Param.InputFields; |
---|
[1119] | 208 | end |
---|
[1090] | 209 | |
---|
| 210 | nbfiles=0; |
---|
| 211 | nbmissing=0; |
---|
| 212 | |
---|
[1157] | 213 | %% initialisation output data |
---|
[1090] | 214 | |
---|
[1157] | 215 | DataOut.ListGlobalAttribute= {'Conventions'}; |
---|
[1090] | 216 | DataOut.Conventions='uvmat'; |
---|
[1157] | 217 | DataOut.ListVarName={'Time','coord_y','coord_x','Ufilter','Vfilter'}; |
---|
| 218 | DataOut.VarDimName={'Time','coord_y','coord_x',{'Time','coord_y','coord_x'},{'Time','coord_y','coord_x'}}; |
---|
[1090] | 219 | |
---|
| 220 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
| 221 | % First get time % |
---|
| 222 | [Data,tild,errormsg]=nc2struct(filecell{1,1}); |
---|
| 223 | Time_1=Data.Time; |
---|
| 224 | if ~isempty(errormsg) |
---|
| 225 | disp_uvmat('ERROR',errormsg,checkrun) |
---|
| 226 | return |
---|
| 227 | end |
---|
[1157] | 228 | [Data,tild,errormsg]=nc2struct(filecell{1,2}); |
---|
| 229 | Time_2=Data.Time; |
---|
| 230 | dt=(Time_2-Time_1); %time interval |
---|
| 231 | NpTime=21; %Nbre de champ pour la moyenne glissante (choisir impair) |
---|
[1090] | 232 | |
---|
[1096] | 233 | OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device)); |
---|
[1094] | 234 | RootFileOut=RootFile{1}; |
---|
| 235 | NomTypeOut='_1'; |
---|
[1090] | 236 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
| 237 | disp('loop for filtering started') |
---|
| 238 | for index=1:NbField |
---|
| 239 | update_waitbar(WaitbarHandle,index/NbField) |
---|
| 240 | if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
| 241 | disp('program stopped by user') |
---|
| 242 | break |
---|
| 243 | end |
---|
[1114] | 244 | [Field,tild,~] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); |
---|
[1090] | 245 | |
---|
[1094] | 246 | %%%%%%%%%%% MAIN RUNNING OPERATIONS %%%%%%%%%%%% |
---|
[1090] | 247 | if index==1 %first field |
---|
[1157] | 248 | DataOut.coord_x=Field.coord_x; |
---|
| 249 | DataOut.coord_y=Field.coord_y; |
---|
[1090] | 250 | npy=numel(DataOut.coord_y); |
---|
| 251 | npx=numel(DataOut.coord_x); |
---|
[1157] | 252 | Ufilter=zeros(NpTime,npy,npx); |
---|
| 253 | Vfilter=zeros(NpTime,npy,npx); |
---|
[1090] | 254 | end |
---|
[1157] | 255 | Time(index)=Field.Time;%time |
---|
| 256 | Ufilter=circshift(Ufilter,[-1 0 0]); %shift U by ishift along the first index |
---|
| 257 | Vfilter=circshift(Vfilter,[-1 0 0]); %shift U by ishift along the first index |
---|
| 258 | Ufilter(end,:,:)=Field.U; |
---|
| 259 | Vfilter(end,:,:)=Field.V; |
---|
| 260 | DataOut.Time=(Time(index)-(NpTime-1)*dt/2);%mid time |
---|
| 261 | DataOut.Ufilter=squeeze(nanmean(Ufilter,1)); |
---|
| 262 | DataOut.Vfilter=squeeze(nanmean(Vfilter,1)); |
---|
| 263 | |
---|
[1094] | 264 | |
---|
[1090] | 265 | % writing the result file as netcdf file |
---|
[1157] | 266 | i1=i1_series{1}(index)-ceil(NpTime/2); |
---|
[1094] | 267 | OutputFile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeOut,i1); |
---|
| 268 | errormsg=struct2nc(OutputFile, DataOut); |
---|
| 269 | if isempty(errormsg) |
---|
| 270 | disp([OutputFile ' written']) |
---|
| 271 | else |
---|
| 272 | disp(errormsg) |
---|
[1090] | 273 | end |
---|
| 274 | end |
---|
[1094] | 275 | |
---|