Changeset 1094 for trunk/src/series/sliding_average.m
 Timestamp:
 Mar 25, 2021, 9:37:04 AM (3 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/series/sliding_average.m
r1093 r1094 25 25 % .RUN =0 for GUI input, =1 for function activation 26 26 % .RunMode='local','background', 'cluster': type of function use 27 % 28 % .IndexRange: set the file or frame indices on which the action must be perform ed29 % .FieldTransform: .TransformName: name of the select ed transform function27 % 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 30 30 % .TransformPath: path of the selected transform function 31 31 % .InputFields: sub structure describing the input fields withfields … … 34 34 % .FieldName_1: name of the second field in case of two input series 35 35 % .VelType_1: velocity type of the second field in case of two input series 36 % .Coord_y: name of y coordinate variable36 % uvmat .Coord_y: name of y coordinate variable 37 37 % .Coord_x: name of x coordinate variable 38 38 % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) 39 39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 40 41 40 %======================================================================= 42 41 % Copyright 20082021, LEGI UMR 5519 / CNRS UGA GINP, Grenoble, France … … 62 61 if isstruct(Param) && isequal(Param.Action.RUN,0) 63 62 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 m ax (options 'off'/'on', 'off' by default)63 ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to mseriesax (options 'off'/'on', 'off' by default) 65 64 ParamOut.NbSlice=1; %nbre of slices ('off' by default) 66 65 ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) 67 66 ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) 68 67 ParamOut.FieldTransform = 'on';%can use a transform function 69 ParamOut.ProjObject='off';%can use projection object (option 'off'/'on',68 ParamOut.ProjObject='off';%can use projection object39(option 'off'/'on', 70 69 ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) 71 70 ParamOut.OutputDirExt='.tfilter';%set the output dir extension … … 122 121 return 123 122 end 124 [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1}); 123 [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});900 125 124 FileType{iview}=FileInfo{iview}.FileType; 126 125 CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images … … 138 137 if size(time,1)>1 139 138 diff_time=max(max(diff(time))); 140 if diff_time>0 139 if diff_time>0series 141 140 msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) 142 141 end … … 177 176 178 177 %% Set field names and velocity types 179 InputFields{1}=[];%default (case of images) 178 InputFields{1}=[];%default (case of images)series 180 179 if isfield(Param,'InputFields') 181 180 InputFields{1}=Param.InputFields; … … 187 186 %% initialisation 188 187 T=24.2; %main wave period 188 t0=3; % time for motion start (torus at its maximum x) 189 189 NbPeriod=2; %number of periods for the sliding average 190 190 omega=2*pi/T; 191 amplitude=2.5; %oscillation amplitude 192 Lscale=15;%diameter of the torus, length scale for normalisation 193 Uscale=amplitude*omega; 191 194 192 195 DataOut.ListGlobalAttribute= {'Conventions','Time'}; 193 196 DataOut.Conventions='uvmat'; 194 DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','DUDXsin','DUDYsin','DVDXsin','DVDYsin','Ustokes','Vstokes'}; 197 DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','DUDXsin','DUDXcos','DUDYsin','DVDXsin','DVDXcos'... 198 ,'DVDYsin','Ustokes','Vstokes'}; 195 199 DataOut.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},... 196 {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'}}; 200 {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'},... 201 {'coord_y','coord_x'},{'coord_y','coord_x'},{'coord_y','coord_x'}}; 197 202 198 203 %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% … … 207 212 Time_end=Data.Time; 208 213 dt=(Time_endTime_1)/(NbField1); %time interval 209 NpTime=round(NbPeriod*T/dt+1) 210 214 NpTime=round(NbPeriod*T/dt+1); 215 216 OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device); 217 RootFileOut=RootFile{1}; 218 NomTypeOut='_1'; 211 219 %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% 212 220 disp('loop for filtering started') … … 219 227 [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); 220 228 221 %%%%%%%%%%% %MAIN RUNNING OPERATIONS %%%%%%%%%%%%229 %%%%%%%%%%% MAIN RUNNING OPERATIONS %%%%%%%%%%%% 222 230 if index==1 %first field 223 DataOut.coord_x=Field.coord_x ;224 DataOut.coord_y=Field.coord_y ;231 DataOut.coord_x=Field.coord_x/Lscale; 232 DataOut.coord_y=Field.coord_y/Lscale; 225 233 npy=numel(DataOut.coord_y); 226 234 npx=numel(DataOut.coord_x); … … 229 237 Ucos=zeros(NpTime,npy,npx); 230 238 Vcos=zeros(NpTime,npy,npx); 239 DUDXcos=zeros(NpTime,npy,npx); 231 240 DUDXsin=zeros(NpTime,npy,npx); 232 241 DUDYsin=zeros(NpTime,npy,npx); 242 DVDXcos=zeros(NpTime,npy,npx); 233 243 DVDXsin=zeros(NpTime,npy,npx); 234 244 DVDYsin=zeros(NpTime,npy,npx); 235 245 end 236 Time(index)=Field.Time;246 Time(index)=Field.Timet0;%time from the start of the motion 237 247 Umean=circshift(Umean,[1 0 0]); %shift U by ishift along the first index 238 Vmean=circshift(Vmean,[1 0 0]); %shift U by ishift along the first index 239 Ucos=circshift(Ucos,[1 0 0]); %shift U by ishift along the first index 240 Vcos=circshift(Vcos,[1 0 0]); %shift U by ishift along the first index 241 DUDXsin=circshift(DUDXsin,[1 0 0]); 242 DUDYsin=circshift(DUDYsin,[1 0 0]); 243 DVDXsin=circshift(DVDXsin,[1 0 0]); 244 DVDYsin=circshift(DVDYsin,[1 0 0]); 245 Umean(end,:,:)=Field.U; 246 Vmean(end,:,:)=Field.V; 247 Ucos(end,:,:)=Field.U*cos(omega*Time(index)); 248 Vcos(end,:,:)=Field.V*cos(omega*Time(index)); 249 DUDXsin(end,:,:)=Field.DUDX*sin(omega*Time(index)); 250 DUDYsin(end,:,:)=Field.DUDY*sin(omega*Time(index)); 251 DVDXsin(end,:,:)=Field.DVDX*sin(omega*Time(index)); 252 DVDYsin(end,:,:)=Field.DVDY*sin(omega*Time(index)); 253 DataOut.Time=Time(index)(NpTime1)*dt/2; 254 DataOut.Umean=squeeze(nanmean(Umean,1)); 255 DataOut.Vmean=squeeze(nanmean(Vmean,1)); 256 DataOut.Ucos=2*squeeze(nanmean(Ucos,1)); 257 DataOut.Vcos=2*squeeze(nanmean(Vcos,1)); 258 DataOut.DUDXsin=2*squeeze(nanmean(DUDXsin,1)); 259 DataOut.DUDYsin=2*squeeze(nanmean(DUDYsin,1)); 260 DataOut.DVDXsin=2*squeeze(nanmean(DVDXsin,1)); 261 DataOut.DVDYsin=2*squeeze(nanmean(DVDYsin,1)); 262 DataOut.Ustokes=(1/omega)*(DataOut.Ucos.*DataOut.DUDXsin+DataOut.Vcos.*DataOut.DUDYsin); 263 DataOut.Vstokes=(1/omega)*(DataOut.Ucos.*DataOut.DVDXsin+DataOut.Vcos.*DataOut.DVDYsin); 248 Vmean=circshift(Vmean,[1 0 0]); %shift U by ishift along the first index 249 Ucos=circshift(Ucos,[1 0 0]); %shift U by ishift along the first index 250 Vcos=circshift(Vcos,[1 0 0]); %shift U by ishift along the first index 251 DUDXcos=circshift(DUDXcos,[1 0 0]); 252 DUDXsin=circshift(DUDXsin,[1 0 0]); 253 DUDYsin=circshift(DUDYsin,[1 0 0]); 254 DVDXcos=circshift(DVDXcos,[1 0 0]); 255 DVDXsin=circshift(DVDXsin,[1 0 0]); 256 DVDYsin=circshift(DVDYsin,[1 0 0]); 257 Umean(end,:,:)=Field.U; 258 Vmean(end,:,:)=Field.V; 259 Ucos(end,:,:)=Field.U*cos(omega*Time(index)); 260 Vcos(end,:,:)=Field.V*cos(omega*Time(index)); 261 DUDXcos(end,:,:)=Field.DUDX*cos(omega*Time(index)); 262 DUDXsin(end,:,:)=Field.DUDX*sin(omega*Time(index)); 263 DUDYsin(end,:,:)=Field.DUDY*sin(omega*Time(index));% ParamOut=[];%default output 264 265 DVDXcos(end,:,:)=Field.DVDX*cos(omega*Time(index)); 266 DVDXsin(end,:,:)=Field.DVDX*sin(omega*Time(index)); 267 DVDYsin(end,:,:)=Field.DVDY*sin(omega*Time(index)); 268 DataOut.Time=(Time(index)(NpTime1)*dt/2)/T;%time inperiods from the beginning of the oscillation (torus at max abscissa) 269 DataOut.Umean=(1/Uscale)*squeeze(nanmean(Umean,1)); 270 DataOut.Vmean=(1/Uscale)*squeeze(nanmean(Vmean,1)); 271 DataOut.Ucos=2*squeeze(nanmean(Ucos,1)); 272 DataOut.Vcos=2*squeeze(nanmean(Vcos,1)); 273 DataOut.DUDXcos=2*squeeze(nanmean(DUDXcos,1)); 274 DataOut.DUDXsin=2*squeeze(nanmean(DUDXsin,1)); 275 DataOut.DUDYsin=2*squeeze(nanmean(DUDYsin,1)); 276 DataOut.DVDXcos=2*squeeze(nanmean(DVDXcos,1)); 277 DataOut.DVDXsin=2*squeeze(nanmean(DVDXsin,1)); 278 DataOut.DVDYsin=2*squeeze(nanmean(DVDYsin,1)); 279 DataOut.Ustokes=(1/omega)*(1/Uscale)*(DataOut.Ucos.*DataOut.DUDXsin+DataOut.Vcos.*DataOut.DUDYsin); 280 DataOut.Vstokes=(1/omega)*(1/Uscale)*(DataOut.Ucos.*DataOut.DVDXsin+DataOut.Vcos.*DataOut.DVDYsin); 281 264 282 % writing the result file as netcdf file 265 if indexround(NpTime/2)>=1 266 OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomType{1},indexround(NpTime/2)); 267 %case of netcdf input file , determine global attributes 268 errormsg=struct2nc(OutputFile,DataOut); %save result file 269 if isempty(errormsg) 270 disp([OutputFile ' written']); 271 else 272 disp(['error in writting result file: ' errormsg]) 273 end 274 end 275 end 276 %%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%% 277 283 i1=i1_series{1}(index); 284 OutputFile=fullfile_uvmat(OutputPath,OutputDir,RootFileOut,'.nc',NomTypeOut,i1); 285 errormsg=struct2nc(OutputFile, DataOut); 286 if isempty(errormsg) 287 disp([OutputFile ' written']) 288 else 289 disp(errormsg) 290 end 291 end 292
Note: See TracChangeset
for help on using the changeset viewer.