Changeset 590 for trunk/src/series


Ignore:
Timestamp:
Mar 16, 2013, 4:33:29 PM (12 years ago)
Author:
sommeria
Message:

ima_levels: bug correction
check_peaklock: adapated to new conventions, not finished

Location:
trunk/src/series
Files:
2 edited

Legend:

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

    r583 r590  
    1 %%-------------------------------------------------------
    2 % --- Executes on button press in peaklocking. TODO: UPDATE
    3 %-------------------------------------------------
    4 function peaklocking(handles)
     1% 'check_peaklocking': estimte peaklocking error in a civ field series TODO: UPDATE
     2%------------------------------------------------------------------------
     3% function ParamOut=check_peaklocking(Param)
     4%
     5%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
     6%
     7% This function is used in four modes by the GUI series:
     8%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     9%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     10%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     11%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     12%
     13% This function is used in four modes by the GUI series:
     14%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     15%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     16%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     17%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     18%
     19%OUTPUT
     20% GUI_input=list of options in the GUI series.fig needed for the function
     21%
     22%INPUT:
     23% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
     24% In batch mode, Param is the name of the corresponding xml file containing the same information
     25% In the absence of input (as activated when the current Action is selected
     26% in series), the function ouput GUI_input set the activation of the needed GUI elements
     27%
     28% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     29%    .InputTable: cell of input file names, (several lines for multiple input)
     30%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
     31%    .OutputSubDir: name of the subdirectory for data outputs
     32%    .OutputDirExt: directory extension for data outputs
     33%    .Action: .ActionName: name of the current activated function
     34%             .ActionPath:   path of the current activated function
     35%    .IndexRange: set the file or frame indices on which the action must be performed
     36%    .FieldTransform: .TransformName: name of the selected transform function
     37%                     .TransformPath:   path  of the selected transform function
     38%                     .TransformHandle: corresponding function handle
     39%    .InputFields: sub structure describing the input fields withfields
     40%              .FieldName: name of the field
     41%              .VelType: velocity type
     42%              .FieldName_1: name of the second field in case of two input series
     43%              .VelType_1: velocity type of the second field in case of two input series
     44%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
     45%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     46function  ParamOut=check_peaklocking(Param)
     47
     48%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
     49if ~exist('Param','var') % case with no input parameter
     50    ParamOut={'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     51        'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
     52        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     53        'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     54        'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     55        'FieldTransform'; 'off';...%can use a transform function
     56        'ProjObject';'on';...%can use projection object(option 'off'/'on',
     57        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
     58        'OutputDirExt';'.pklock';...%set the output dir extension
     59               ''};
     60        return
     61end
     62
     63%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
     64%% select different modes,  RUN, parameter input, BATCH
     65% BATCH  case: read the xml file for batch case
     66if ischar(Param)
     67        Param=xml2struct(Param);
     68        checkrun=0;
     69% RUN case: parameters introduced as the input structure Param
     70else
     71    hseries=guidata(Param.hseries);%handles of the GUI series
     72    if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
     73        checkrun=1;% will only search interactive input parameters (preparation of BATCH mode)
     74    else
     75        checkrun=2; % indicate the RUN option is used
     76    end
     77end
     78ParamOut=Param; %default output
     79OutputDir=[Param.OutputSubDir Param.OutputDirExt];
     80
     81%% root input file(s) and type
     82RootPath=Param.InputTable(:,1);
     83RootFile=Param.InputTable(:,3);
     84SubDir=Param.InputTable(:,2);
     85NomType=Param.InputTable(:,4);
     86FileExt=Param.InputTable(:,5);
     87[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     88%%%%%%%%%%%%
     89% The cell array filecell is the list of input file names, while
     90% filecell{iview,fileindex}:
     91%        iview: line in the table corresponding to a given file series
     92%        fileindex: file index within  the file series,
     93% 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
     94% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
     95%%%%%%%%%%%%
     96NbSlice=1;%default
     97if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
     98    NbSlice=Param.IndexRange.NbSlice;
     99end
     100nbview=1;%number of input file series (lines in InputTable)
     101nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     102nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     103nbfield=nbfield_j*nbfield_i; %total number of fields
     104nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     105nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     106
     107%determine the file type on each line from the first input file
     108ImageTypeOptions={'image','multimage','mmreader','video'};
     109NcTypeOptions={'netcdf','civx','civdata'};
     110for iview=1:nbview
     111    if ~exist(filecell{iview,1}','file')
     112        displ_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
     113        return
     114    end
     115    [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
     116    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
     117    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
     118    if ~isempty(j1_series{iview})
     119        frame_index{iview}=j1_series{iview};
     120    else
     121        frame_index{iview}=i1_series{iview};
     122    end
     123end
     124
     125%% calibration data and timing: read the ImaDoc files
     126%none
     127
     128%% coordinate transform or other user defined transform
     129% none
     130
     131%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     132 % EDIT FROM HERE
     133
     134%% check the validity of  ctinput file types
     135%none
     136
     137%% Set field names and velocity types
     138InputFields{1}=[];%default (case of images)
     139if isfield(Param,'InputFields')
     140    InputFields{1}=Param.InputFields;
     141end
     142% only one input fieldseries
     143
     144%% Initiate output fields
     145%initiate the output structure as a copy of the first input one (reproduce fields)
     146[DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
     147if ~isempty(errormsg)
     148    displ_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun)
     149    return
     150end
     151time_1=[];
     152if isfield(DataOut,'Time')
     153    time_1=DataOut.Time(1);
     154end
     155if CheckNc{iview}
     156    if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
     157        DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
     158    end
     159    DataOut.Conventions='uvmat';
     160    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
     161    ActionKey='Action';
     162    while isfield(DataOut,ActionKey)
     163        ActionKey=[ActionKey '_1'];
     164    end
     165    DataOut.(ActionKey)=Param.Action;
     166    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
     167    if isfield(DataOut,'Time')
     168        DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
     169    end
     170end
     171
     172%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
     173index_slice=1:nbfield;% select the file indices
     174for index=index_slice
     175    if checkrun
     176        update_waitbar(hseries.Waitbar,index/(nbfield))
     177        stopstate=get(hseries.RUN,'BusyAction');
     178    else
     179        stopstate='queue';
     180    end
     181    if isequal(stopstate,'queue')% enable STOP command
     182        Data=cell(1,nbview);%initiate the set Data;
     183        nbtime=0;
     184        dt=[];
     185        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
     186        for iview=1:nbview
     187            % reading input file(s)
     188            [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
     189            if ~isempty(errormsg)
     190                errormsg=['time_series / read_field / ' errormsg];
     191                display(errormsg)
     192                break
     193            end
     194            if ~isempty(NbSlice_calib)
     195                Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
     196            end
     197        end
     198        if isempty(errormsg)
     199            Field=Data{1}; % default input field structure
     200            % coordinate transform (or other user defined transform)
     201            % none
     202           
     203            %field projection on an object
     204            if Param.CheckObject
     205                [Field,errormsg]=proj_field(Field,Param.ProjObject);
     206                if ~isempty(errormsg)
     207                    msgbox_uvmat('ERROR',['time_series / proj_field / ' errormsg])
     208                    return
     209                end
     210            end
     211            nbfile=nbfile+1;
     212           
     213            % initiate the time series at the first iteration
     214            if nbfile==1
     215                % stop program if the first field reading is in error
     216                if ~isempty(errormsg)
     217                    displ_uvmat('ERROR',['time_series / sub_field / ' errormsg],checkrun)
     218                    return
     219                end
     220                DataOut=Field;%default
     221                DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots
     222                nbvar=length(Field.ListVarName);
     223                if nbvar==0
     224                    displ_uvmat('ERROR','no input variable selected',checkrun)
     225                    return
     226                end
     227                testsum=2*ones(1,nbvar);%initiate flag for action on each variable
     228                if isfield(Field,'VarAttribute') % look for coordinate and flag variables
     229                    for ivar=1:nbvar
     230                        if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
     231                            var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
     232                            if isequal(var_role,'errorflag')
     233                                displ_uvmat('ERROR','do not handle error flags in time series',checkrun)
     234                                return
     235                            end
     236                            if isequal(var_role,'warnflag')
     237                                testsum(ivar)=0;  % not recorded variable
     238                                eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable
     239                            end
     240                            if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
     241                                    isequal(var_role,'coord_z')|isequal(var_role,'coord')
     242                                testsum(ivar)=1; %constant coordinates, record without time evolution
     243                            end
     244                        end
     245                        % check whether the variable ivar is a dimension variable
     246                        DimCell=Field.VarDimName{ivar};
     247                        if ischar(DimCell)
     248                            DimCell={DimCell};
     249                        end
     250                        if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
     251                            testsum(ivar)=1;
     252                        end
     253                    end
     254                end
     255                for ivar=1:nbvar
     256                    if testsum(ivar)==2
     257                        eval(['DataOut.' Field.ListVarName{ivar} '=[];'])
     258                    end
     259                end
     260                DataOut.ListVarName=[{'Time'} DataOut.ListVarName];
     261            end
     262           
     263            % add data to the current field
     264            for ivar=1:length(Field.ListVarName)
     265                VarName=Field.ListVarName{ivar};
     266                VarVal=Field.(VarName);
     267                if testsum(ivar)==2% test for recorded variable
     268                    if isempty(errormsg)
     269                        if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
     270                            if isempty(VarVal)
     271                                displ_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(index))],checkrun)
     272                                return
     273                            end
     274                            VarVal=mean(VarVal,1);
     275                        end
     276                        VarVal=shiftdim(VarVal,-1); %shift dimension
     277                        DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series
     278                    else
     279                        DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error
     280                    end
     281                elseif testsum(ivar)==1% variable representing fixed coordinates
     282                    VarInit=DataOut.(VarName);
     283                    if isempty(errormsg) && ~isequal(VarVal,VarInit)
     284                        displ_uvmat('ERROR',['time series requires constant coordinates ' VarName],checkrun)
     285                        return
     286                    end
     287                end
     288            end
     289           
     290            % record the time:
     291            if isempty(time)% time not set by xml filer(s)
     292                if isfield(Data{1},'Time')
     293                    DataOut.Time(nbfile,1)=Field.Time;
     294                else
     295                    DataOut.Time(nbfile,1)=index;%default
     296                end
     297            else % time from ImaDoc prevails  TODO: correct
     298                DataOut.Time(nbfile,1)=time(index);%
     299            end
     300           
     301            % record the number of missing input fields
     302            if ~isempty(errormsg)
     303                nbmissing=nbmissing+1;
     304                display(['index=' num2str(index) ':' errormsg])
     305            end
     306        end
     307    end
     308end
     309%%%%%%% END OF LOOP WITHIN A SLICE
     310
     311%remove time for global attributes if exists
     312Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute));
     313if ~isempty(Time_index)
     314    DataOut.ListGlobalAttribute(Time_index)=[];
     315end
     316DataOut.Conventions='uvmat';
     317for ivar=1:numel(DataOut.ListVarName)
     318    VarName=DataOut.ListVarName{ivar};
     319    eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons
     320end
     321
     322% add time dimension
     323for ivar=1:length(Field.ListVarName)
     324    DimCell=Field.VarDimName(ivar);
     325    if testsum(ivar)==2%variable used as time series
     326        DataOut.VarDimName{ivar}=[{'Time'} DimCell];
     327    elseif testsum(ivar)==1
     328        DataOut.VarDimName{ivar}=DimCell;
     329    end
     330end
     331indexremove=find(~testsum);
     332if ~isempty(indexremove)
     333    DataOut.ListVarName(1+indexremove)=[];
     334    DataOut.VarDimName(indexremove)=[];
     335    if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs
     336        DataOut.Role(1+indexremove)=[];
     337    end
     338end
     339
     340%shift variable attributes
     341if isfield(DataOut,'VarAttribute')
     342    DataOut.VarAttribute=[{[]} DataOut.VarAttribute];
     343end
     344DataOut.VarDimName=[{'Time'} DataOut.VarDimName];
     345DataOut.Action=Param.Action;%name of the processing programme
     346test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant)
     347if ~test_time
     348    DataOut.Time=1:filecounter;
     349end
     350
     351% display nbmissing
     352if ~isequal(nbmissing,0)
     353    displ_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun)
     354end
     355
     356%name of result file
     357OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]);
     358errormsg=struct2nc(OutputFile,DataOut); %save result file
     359if isempty(errormsg)
     360    display([OutputFile ' written'])
     361else
     362    displ_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun)
     363end
     364
     365return
     366
     367%%%%%%%%%%%%%%%%%%  END%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    5368%evaluation of peacklocking errors
    6369%use splinhist: give spline coeff cc for a smooth histo (call spline4)
  • trunk/src/series/ima_levels.m

    r551 r590  
    161161    end
    162162    if isequal(stopstate,'queue') % enable STOP command
    163         if ~isempty(j1_series)
     163        if ~isempty(j1_series)&&~isequal(j1_series,{[]})
    164164            j1=j1_series{1}(ifile);
    165165        end
     
    172172        A=levels(A);
    173173        filename_new=fullfile_uvmat(RootPath{1},OutputSubDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
    174 %         OutputFile=fullfile_uvmat(RootPath{1},OutputSubDir,RootFile{1},FileExtOut,NomType{1},i1,i2,j1,j2);
    175174        imwrite(A,filename_new)
    176175        display([filename_new ' written'])
Note: See TracChangeset for help on using the changeset viewer.