[1090] | 1 | %'turb_correlation_time': calculate the time correlation function at each point |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function ParamOut=turb_correlation_time(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 |
---|
[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 | %======================================================================= |
---|
[1093] | 41 | % Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[1090] | 42 | % http://www.legi.grenoble-inp.fr |
---|
| 43 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 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) |
---|
| 67 | ParamOut.FieldTransform = 'on';%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 |
---|
| 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 | % filecell=get_file_series(Param);%check existence of the first input file |
---|
| 73 | % if ~exist(filecell{1,1},'file') |
---|
| 74 | % msgbox_uvmat('WARNING','the first input file does not exist') |
---|
| 75 | % end |
---|
| 76 | return |
---|
| 77 | end |
---|
| 78 | |
---|
| 79 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
---|
| 80 | ParamOut=[];%default output |
---|
| 81 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
| 82 | checkrun=1; |
---|
| 83 | if ischar(Param) |
---|
| 84 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
| 85 | checkrun=0; |
---|
| 86 | end |
---|
| 87 | |
---|
| 88 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 89 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
| 90 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
| 91 | |
---|
| 92 | %% define the directory for result file (with path=RootPath{1}) |
---|
| 93 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
| 94 | |
---|
| 95 | %% root input file(s) name, type and index series |
---|
| 96 | RootPath=Param.InputTable(:,1); |
---|
| 97 | RootFile=Param.InputTable(:,3); |
---|
| 98 | SubDir=Param.InputTable(:,2); |
---|
| 99 | NomType=Param.InputTable(:,4); |
---|
| 100 | FileExt=Param.InputTable(:,5); |
---|
| 101 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
| 102 | %%%%%%%%%%%% |
---|
| 103 | % The cell array filecell is the list of input file names, while |
---|
| 104 | % filecell{iview,fileindex}: |
---|
| 105 | % iview: line in the table corresponding to a given file series |
---|
| 106 | % fileindex: file index within the file series, |
---|
| 107 | % 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 |
---|
| 108 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
| 109 | %%%%%%%%%%%% NbView=1 : a single input series |
---|
| 110 | NbView=numel(i1_series);%number of input file series (lines in InputTable) |
---|
| 111 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
| 112 | NbField_i=size(i1_series{1},2); %nb of fields for the i index |
---|
| 113 | NbField=NbField_j*NbField_i; %total number of fields |
---|
| 114 | |
---|
| 115 | %% determine the file type on each line from the first input file |
---|
| 116 | ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'}; |
---|
| 117 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
| 118 | for iview=1:NbView |
---|
| 119 | if ~exist(filecell{iview,1}','file') |
---|
| 120 | msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist']) |
---|
| 121 | return |
---|
| 122 | end |
---|
[1095] | 123 | [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1}); |
---|
[1090] | 124 | FileType{iview}=FileInfo{iview}.FileType; |
---|
| 125 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
| 126 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
| 127 | if ~isempty(j1_series{iview}) |
---|
| 128 | frame_index{iview}=j1_series{iview}; |
---|
| 129 | else |
---|
| 130 | frame_index{iview}=i1_series{iview}; |
---|
| 131 | end |
---|
| 132 | end |
---|
| 133 | |
---|
| 134 | %% calibration data and timing: read the ImaDoc files |
---|
| 135 | XmlData=[]; |
---|
| 136 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
| 137 | if size(time,1)>1 |
---|
| 138 | diff_time=max(max(diff(time))); |
---|
[1095] | 139 | if diff_time>0 |
---|
[1090] | 140 | msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
---|
| 141 | end |
---|
| 142 | end |
---|
| 143 | |
---|
| 144 | %% coordinate transform or other user defined transform |
---|
| 145 | transform_fct='';%default |
---|
| 146 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
| 147 | addpath(Param.FieldTransform.TransformPath) |
---|
| 148 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
| 149 | rmpath(Param.FieldTransform.TransformPath) |
---|
| 150 | end |
---|
| 151 | |
---|
| 152 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
| 153 | % EDIT FROM HERE |
---|
| 154 | |
---|
| 155 | %% check the validity of input file types |
---|
| 156 | if CheckImage{1} |
---|
| 157 | FileExtOut='.png'; % write result as .png images for image inputs |
---|
| 158 | elseif CheckNc{1} |
---|
| 159 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
| 160 | else |
---|
| 161 | msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}]) |
---|
| 162 | return |
---|
| 163 | end |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | %% settings for the output file |
---|
| 167 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
---|
| 168 | first_i=i1_series{1}(1); |
---|
| 169 | last_i=i1_series{1}(end); |
---|
| 170 | if isempty(j1_series{1})% if there is no second index j |
---|
| 171 | first_j=1;last_j=1; |
---|
| 172 | else |
---|
| 173 | first_j=j1_series{1}(1); |
---|
| 174 | last_j=j1_series{1}(end); |
---|
| 175 | end |
---|
| 176 | |
---|
| 177 | %% Set field names and velocity types |
---|
[1094] | 178 | InputFields{1}=[];%default (case of images)series |
---|
[1090] | 179 | if isfield(Param,'InputFields') |
---|
| 180 | InputFields{1}=Param.InputFields; |
---|
| 181 | end |
---|
| 182 | |
---|
| 183 | nbfiles=0; |
---|
| 184 | nbmissing=0; |
---|
| 185 | |
---|
| 186 | %% initialisation |
---|
[1096] | 187 | char_index=regexp(SubDir{1},'waves_L1_'); |
---|
| 188 | switch(SubDir{1}(char_index+9)) |
---|
| 189 | case '1' |
---|
| 190 | amplitude=2.5 %oscillation amplitude |
---|
| 191 | T=24.46; |
---|
| 192 | t0=3 ;% dt=0.5 s, torus at its max x at the beginning of motion, i0=7 |
---|
| 193 | case '2' |
---|
| 194 | amplitude=5 %oscillation amplitude |
---|
| 195 | T=24.47; |
---|
| 196 | t0=8.5; % dt=1/3 s -> image index of starting motion = 26, % torus at its max x at the beginning of motion |
---|
| 197 | case '3' |
---|
| 198 | amplitude=10 %oscillation amplitude |
---|
| 199 | T=24.45; |
---|
| 200 | t0=6.5-T/2;% dt=0.25, torus at its minimum x at the beginning of motion |
---|
| 201 | case '4' |
---|
| 202 | amplitude=15 %oscillation amplitude |
---|
| 203 | T=24.48; |
---|
| 204 | t0=3.4; %dt=0.2 -> i0=18 image index of starting motion, % torus at its max x at the beginning of motion |
---|
| 205 | end |
---|
[1090] | 206 | NbPeriod=2; %number of periods for the sliding average |
---|
[1097] | 207 | omega=2*2*pi/T;%harmonic |
---|
[1094] | 208 | Lscale=15;%diameter of the torus, length scale for normalisation |
---|
| 209 | Uscale=amplitude*omega; |
---|
[1090] | 210 | |
---|
| 211 | DataOut.ListGlobalAttribute= {'Conventions','Time'}; |
---|
| 212 | DataOut.Conventions='uvmat'; |
---|
[1095] | 213 | DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','Usin','Vsin','DUDXsin','DUDXcos','DUDYsin','DVDXsin','DVDXcos'... |
---|
[1094] | 214 | ,'DVDYsin','Ustokes','Vstokes'}; |
---|
[1090] | 215 | DataOut.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},... |
---|
[1094] | 216 | {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},... |
---|
[1095] | 217 | {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'}}; |
---|
[1090] | 218 | |
---|
| 219 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
| 220 | % First get time % |
---|
| 221 | [Data,tild,errormsg]=nc2struct(filecell{1,1}); |
---|
| 222 | Time_1=Data.Time; |
---|
| 223 | if ~isempty(errormsg) |
---|
| 224 | disp_uvmat('ERROR',errormsg,checkrun) |
---|
| 225 | return |
---|
| 226 | end |
---|
| 227 | [Data,tild,errormsg]=nc2struct(filecell{1,end}); |
---|
| 228 | Time_end=Data.Time; |
---|
| 229 | dt=(Time_end-Time_1)/(NbField-1); %time interval |
---|
[1094] | 230 | NpTime=round(NbPeriod*T/dt+1); |
---|
[1090] | 231 | |
---|
[1096] | 232 | OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device)); |
---|
[1094] | 233 | RootFileOut=RootFile{1}; |
---|
| 234 | NomTypeOut='_1'; |
---|
[1090] | 235 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
| 236 | disp('loop for filtering started') |
---|
| 237 | for index=1:NbField |
---|
| 238 | update_waitbar(WaitbarHandle,index/NbField) |
---|
| 239 | if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
| 240 | disp('program stopped by user') |
---|
| 241 | break |
---|
| 242 | end |
---|
| 243 | [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); |
---|
| 244 | |
---|
[1094] | 245 | %%%%%%%%%%% MAIN RUNNING OPERATIONS %%%%%%%%%%%% |
---|
[1090] | 246 | if index==1 %first field |
---|
[1094] | 247 | DataOut.coord_x=Field.coord_x/Lscale; |
---|
| 248 | DataOut.coord_y=Field.coord_y/Lscale; |
---|
[1090] | 249 | npy=numel(DataOut.coord_y); |
---|
| 250 | npx=numel(DataOut.coord_x); |
---|
| 251 | Umean=zeros(NpTime,npy,npx); |
---|
| 252 | Vmean=zeros(NpTime,npy,npx); |
---|
| 253 | Ucos=zeros(NpTime,npy,npx); |
---|
| 254 | Vcos=zeros(NpTime,npy,npx); |
---|
[1095] | 255 | Usin=zeros(NpTime,npy,npx); |
---|
| 256 | Vsin=zeros(NpTime,npy,npx); |
---|
[1094] | 257 | DUDXcos=zeros(NpTime,npy,npx); |
---|
[1090] | 258 | DUDXsin=zeros(NpTime,npy,npx); |
---|
| 259 | DUDYsin=zeros(NpTime,npy,npx); |
---|
[1094] | 260 | DVDXcos=zeros(NpTime,npy,npx); |
---|
[1090] | 261 | DVDXsin=zeros(NpTime,npy,npx); |
---|
| 262 | DVDYsin=zeros(NpTime,npy,npx); |
---|
| 263 | end |
---|
[1094] | 264 | Time(index)=Field.Time-t0;%time from the start of the motion |
---|
[1090] | 265 | Umean=circshift(Umean,[-1 0 0]); %shift U by ishift along the first index |
---|
[1094] | 266 | Vmean=circshift(Vmean,[-1 0 0]); %shift U by ishift along the first index |
---|
| 267 | Ucos=circshift(Ucos,[-1 0 0]); %shift U by ishift along the first index |
---|
| 268 | Vcos=circshift(Vcos,[-1 0 0]); %shift U by ishift along the first index |
---|
[1095] | 269 | Usin=circshift(Usin,[-1 0 0]); %shift U by ishift along the first index |
---|
| 270 | Vsin=circshift(Vsin,[-1 0 0]); %shift U by ishift along the first index |
---|
[1094] | 271 | DUDXcos=circshift(DUDXcos,[-1 0 0]); |
---|
| 272 | DUDXsin=circshift(DUDXsin,[-1 0 0]); |
---|
| 273 | DUDYsin=circshift(DUDYsin,[-1 0 0]); |
---|
| 274 | DVDXcos=circshift(DVDXcos,[-1 0 0]); |
---|
| 275 | DVDXsin=circshift(DVDXsin,[-1 0 0]); |
---|
| 276 | DVDYsin=circshift(DVDYsin,[-1 0 0]); |
---|
| 277 | Umean(end,:,:)=Field.U; |
---|
| 278 | Vmean(end,:,:)=Field.V; |
---|
| 279 | Ucos(end,:,:)=Field.U*cos(omega*Time(index)); |
---|
| 280 | Vcos(end,:,:)=Field.V*cos(omega*Time(index)); |
---|
[1095] | 281 | Usin(end,:,:)=Field.U*sin(omega*Time(index)); |
---|
| 282 | Vsin(end,:,:)=Field.V*sin(omega*Time(index)); |
---|
[1094] | 283 | DUDXcos(end,:,:)=Field.DUDX*cos(omega*Time(index)); |
---|
| 284 | DUDXsin(end,:,:)=Field.DUDX*sin(omega*Time(index)); |
---|
| 285 | DUDYsin(end,:,:)=Field.DUDY*sin(omega*Time(index));% ParamOut=[];%default output |
---|
| 286 | |
---|
| 287 | DVDXcos(end,:,:)=Field.DVDX*cos(omega*Time(index)); |
---|
| 288 | DVDXsin(end,:,:)=Field.DVDX*sin(omega*Time(index)); |
---|
| 289 | DVDYsin(end,:,:)=Field.DVDY*sin(omega*Time(index)); |
---|
| 290 | DataOut.Time=(Time(index)-(NpTime-1)*dt/2)/T;%time inperiods from the beginning of the oscillation (torus at max abscissa) |
---|
| 291 | DataOut.Umean=(1/Uscale)*squeeze(nanmean(Umean,1)); |
---|
| 292 | DataOut.Vmean=(1/Uscale)*squeeze(nanmean(Vmean,1)); |
---|
[1095] | 293 | DataOut.Ucos=2*(1/Uscale)*squeeze(nanmean(Ucos,1)); |
---|
| 294 | DataOut.Vcos=2*(1/Uscale)*squeeze(nanmean(Vcos,1)); |
---|
| 295 | DataOut.Usin=2*(1/Uscale)*squeeze(nanmean(Usin,1)); |
---|
| 296 | DataOut.Vsin=2*(1/Uscale)*squeeze(nanmean(Vsin,1)); |
---|
[1094] | 297 | DataOut.DUDXcos=2*squeeze(nanmean(DUDXcos,1)); |
---|
| 298 | DataOut.DUDXsin=2*squeeze(nanmean(DUDXsin,1)); |
---|
| 299 | DataOut.DUDYsin=2*squeeze(nanmean(DUDYsin,1)); |
---|
| 300 | DataOut.DVDXcos=2*squeeze(nanmean(DVDXcos,1)); |
---|
| 301 | DataOut.DVDXsin=2*squeeze(nanmean(DVDXsin,1)); |
---|
| 302 | DataOut.DVDYsin=2*squeeze(nanmean(DVDYsin,1)); |
---|
| 303 | DataOut.Ustokes=(1/omega)*(1/Uscale)*(DataOut.Ucos.*DataOut.DUDXsin+DataOut.Vcos.*DataOut.DUDYsin); |
---|
| 304 | DataOut.Vstokes=(1/omega)*(1/Uscale)*(DataOut.Ucos.*DataOut.DVDXsin+DataOut.Vcos.*DataOut.DVDYsin); |
---|
| 305 | |
---|
[1090] | 306 | % writing the result file as netcdf file |
---|
[1094] | 307 | i1=i1_series{1}(index); |
---|
| 308 | OutputFile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeOut,i1); |
---|
| 309 | errormsg=struct2nc(OutputFile, DataOut); |
---|
| 310 | if isempty(errormsg) |
---|
| 311 | disp([OutputFile ' written']) |
---|
| 312 | else |
---|
| 313 | disp(errormsg) |
---|
[1090] | 314 | end |
---|
| 315 | end |
---|
[1094] | 316 | |
---|