Ignore:
Timestamp:
Mar 25, 2021, 9:37:04 AM (3 years ago)
Author:
sommeria
Message:

phys_polar debugged

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/sliding_average.m

    r1093 r1094  
    2525%             .RUN =0 for GUI input, =1 for function activation
    2626%             .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
     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
    3030%                     .TransformPath:   path  of the selected transform function
    3131%    .InputFields: sub structure describing the input fields withfields
     
    3434%              .FieldName_1: name of the second field in case of two input series
    3535%              .VelType_1: velocity type of the second field in case of two input series
    36 %              .Coord_y: name of y coordinate variable
     36%             uvmat .Coord_y: name of y coordinate variable
    3737%              .Coord_x: name of x coordinate variable
    3838%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
    3939%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    40 
    4140%=======================================================================
    4241% Copyright 2008-2021, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
     
    6261if isstruct(Param) && isequal(Param.Action.RUN,0)
    6362    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)
     63    ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to mseriesax (options 'off'/'on', 'off' by default)
    6564    ParamOut.NbSlice=1; %nbre of slices ('off' by default)
    6665    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
    6766    ParamOut.FieldName='one';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
    6867    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',
    7069    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
    7170    ParamOut.OutputDirExt='.tfilter';%set the output dir extension
     
    122121        return
    123122    end
    124     [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
     123    [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});900
    125124    FileType{iview}=FileInfo{iview}.FileType;
    126125    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
     
    138137if size(time,1)>1
    139138    diff_time=max(max(diff(time)));
    140     if diff_time>0
     139    if diff_time>0series
    141140        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
    142141    end   
     
    177176
    178177%% Set field names and velocity types
    179 InputFields{1}=[];%default (case of images)
     178InputFields{1}=[];%default (case of images)series
    180179if isfield(Param,'InputFields')
    181180    InputFields{1}=Param.InputFields;
     
    187186%% initialisation
    188187T=24.2; %main wave period
     188t0=3; % time for motion start (torus at its maximum x)
    189189NbPeriod=2; %number of periods for the sliding average
    190190omega=2*pi/T;
     191amplitude=2.5; %oscillation amplitude
     192Lscale=15;%diameter of the torus, length scale for normalisation
     193Uscale=amplitude*omega;
    191194
    192195DataOut.ListGlobalAttribute= {'Conventions','Time'};
    193196DataOut.Conventions='uvmat';
    194 DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','DUDXsin','DUDYsin','DVDXsin','DVDYsin','Ustokes','Vstokes'};
     197DataOut.ListVarName={'coord_y','coord_x','Umean','Vmean','Ucos','Vcos','DUDXsin','DUDXcos','DUDYsin','DVDXsin','DVDXcos'...
     198    ,'DVDYsin','Ustokes','Vstokes'};
    195199DataOut.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'}};
    197202
    198203%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
     
    207212Time_end=Data.Time;
    208213dt=(Time_end-Time_1)/(NbField-1); %time interval
    209 NpTime=round(NbPeriod*T/dt+1)
    210 
     214NpTime=round(NbPeriod*T/dt+1);
     215
     216OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
     217RootFileOut=RootFile{1};
     218NomTypeOut='_1';
    211219%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
    212220disp('loop for filtering started')
     
    219227    [Field,tild,errormsg] = read_field(filecell{1,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
    220228   
    221     %%%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
     229    %%%%%%%%%%% MAIN RUNNING OPERATIONS  %%%%%%%%%%%%
    222230    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;
    225233        npy=numel(DataOut.coord_y);
    226234        npx=numel(DataOut.coord_x);
     
    229237        Ucos=zeros(NpTime,npy,npx);
    230238        Vcos=zeros(NpTime,npy,npx);
     239        DUDXcos=zeros(NpTime,npy,npx);
    231240        DUDXsin=zeros(NpTime,npy,npx);
    232241        DUDYsin=zeros(NpTime,npy,npx);
     242        DVDXcos=zeros(NpTime,npy,npx);
    233243        DVDXsin=zeros(NpTime,npy,npx);
    234244        DVDYsin=zeros(NpTime,npy,npx);
    235245    end
    236       Time(index)=Field.Time;
     246    Time(index)=Field.Time-t0;%time from the start of the motion
    237247    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)-(NpTime-1)*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)-(NpTime-1)*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
    264282    % writing the result file as netcdf file
    265     if index-round(NpTime/2)>=1
    266         OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomType{1},index-round(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
     291end
     292   
Note: See TracChangeset for help on using the changeset viewer.