Ignore:
Timestamp:
Jun 17, 2012, 10:52:04 PM (12 years ago)
Author:
sommeria
Message:

merg_i_j transformed to the new standards.
Various improvements

File:
1 edited

Legend:

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

    r454 r457  
    11%'aver_stat': calculate field average, used with series.fig
     2% this function can be used as a template for applying a global operation (here averaging) on a series of input fields
    23%------------------------------------------------------------------------
    3 % function GUI_input=aver_stat(Param)
     4% function ParamOut=aver_stat(Param)
    45%
    56%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
     7%
     8% This function is used in four modes by the GUI series:
     9%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     10%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     11%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     12%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     13%
     14% This function is used in four modes by the GUI series:
     15%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     16%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     17%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     18%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     19%
    620%OUTPUT
    721% GUI_input=list of options in the GUI series.fig needed for the function
     
    3246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    3347
    34 function GUI_input=aver_stat(Param)
     48function ParamOut=aver_stat(Param)
    3549
    3650%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
    3751if ~exist('Param','var') % case with no input parameter
    38     GUI_input={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
     52    ParamOut={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
    3953        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     54        'WholeIndexRange';'off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
    4055        'NbSlice';'on'; ...%nbre of slices ('off' by default)
    4156        'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     
    5065
    5166%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
    52 %% get input parameters, file names and indices
     67%% select different modes,  RUN, parameter input, BATCH
    5368% BATCH  case: read the xml file for batch case
    54 if ischar(Param) && ~isempty(find(regexp(Param,'.xml$')))
    55     Param=xml2struct(Param);
    56     checkrun=0;
    57 % RUN case: parameters introduced as the input structure Param 
    58 else
     69ParamOut=Param; %default output
     70if ischar(Param)
     71    if strcmp(Param,'input?')
     72        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
     73    else
     74        Param=xml2struct(Param);
     75        checkrun=0;
     76    end
     77% RUN case: parameters introduced as the input structure Param
     78else
    5979    hseries=guidata(Param.hseries);%handles of the GUI series
    6080    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
    61     checkrun=1; % indicate the RUN option is used
    62 end
     81    checkrun=2; % indicate the RUN option is used
     82end
     83
     84%% root input file(s) and type
     85RootPath=Param.InputTable(:,1);
     86RootFile=Param.InputTable(:,3);
     87SubDir=Param.InputTable(:,2);
     88NomType=Param.InputTable(:,4);
     89FileExt=Param.InputTable(:,5);
     90
    6391% get the set of input file names (cell array filecell), and the lists of
    6492% input file or frame indices i1_series,i2_series,j1_series,j2_series
    65 
    6693[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    67 
    6894% filecell{iview,fileindex}: cell array representing the list of file names
    6995%        iview: line in the table corresponding to a given file series
     
    7298% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
    7399% set of frame indices used for movie or multimage input
    74 
    75 
    76 %% root input file(s) and type
    77 RootPath=Param.InputTable(:,1);
    78 RootFile=Param.InputTable(:,3);
    79 SubDir=Param.InputTable(:,2);
    80 NomType=Param.InputTable(:,4);
    81 FileExt=Param.InputTable(:,5);
    82 
    83100% numbers of slices and file indices
     101
    84102NbSlice=1;%default
    85 if isfield(Param.IndexRange,'NbSlice')
     103if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
    86104    NbSlice=Param.IndexRange.NbSlice;
    87105end
    88106nbview=numel(i1_series);%number of input file series (lines in InputTable)
    89 nbfield_j=size(i1_series{1},1); %nb of consecutive fields for the j index (bursts or volume slices)
    90 nbfield_i=size(i1_series{1},2); %nb of consecutive fields for the i index
    91 nbfield=nbfield_j*nbfield_i; %total number of files or frames
     107nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     108nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     109nbfield=nbfield_j*nbfield_i; %total number of fields
    92110nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
    93111nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     
    96114ImageTypeOptions={'image','multimage','mmreader','video'};
    97115NcTypeOptions={'netcdf','civx','civdata'};
    98    
    99116for iview=1:nbview
    100117    if ~exist(filecell{iview,1}','file')
     
    117134itime=0;
    118135NbSlice_calib={};
     136XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
    119137for iview=1:nbview%Loop on views
    120     XmlData{iview}=[];%default
    121     filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
    122     if exist([filebase{iview} '.xml'],'file')
    123         [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
    124         if isfield(XmlData{iview},'Time')
    125             itime=itime+1;
    126             timecell{itime}=XmlData{iview}.Time;
    127         end
    128         if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
    129             NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
    130             if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
    131                 msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    132             end
    133         end
    134     elseif exist([filebase{iview} '.civ'],'file')
    135         [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
     138    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
     139    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
     140    if ~exist(filexml,'file')
     141        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
     142        if ~exist(filexml,'file')
     143            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
     144            if ~exist(filexml,'file')
     145                filexml='';
     146            end
     147        end
     148    end
     149    if ~isempty(filexml)
     150        [XmlData{iview},error]=imadoc2struct(filexml);
     151    end
     152    if isfield(XmlData{iview},'Time')
    136153        itime=itime+1;
    137         timecell{itime}=time;
    138         XmlData{iview}.Time=time;
    139         GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
    140         GeometryCalib.Tx=0;
    141         GeometryCalib.Ty=0;
    142         GeometryCalib.Tz=1;
    143         GeometryCalib.dpx=1;
    144         GeometryCalib.dpy=1;
    145         GeometryCalib.sx=1;
    146         GeometryCalib.Cx=0;
    147         GeometryCalib.Cy=0;
    148         GeometryCalib.f=1;
    149         GeometryCalib.kappa1=0;
    150         GeometryCalib.CoordUnit='cm';
    151         XmlData{iview}.GeometryCalib=GeometryCalib;
    152         if error==1
    153             msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
     154        timecell{itime}=XmlData{iview}.Time;
     155    end
     156    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
     157        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     158        if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
     159            msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
    154160        end
    155161    end
     
    182188    end   
    183189end
    184 if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file'
     190if size(time,2) < i2_series{1}(end) ||( ~isempty(j2_series{1}) && size(time,3) < j2_series{1}(end))% time array absent or too short in ImaDoc xml file'
    185191    time=[];
    186192end
     
    283289       
    284290        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
    285         index
    286291        for iview=1:nbview
    287292            % reading input file(s)
     
    369374        msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])
    370375    end
    371     if isempty(time) % time read from files  prevails
     376    if isempty(time) % time is read from files 
    372377        if isfield(Field,'Time')
    373378            time_end=Field.Time(1);%last time read
     
    377382            end
    378383        end
    379     else  % time from ImaDoc prevails
    380         DataOut.Time=time(1,i1_series{1}(1),j1_series{1}(1));
     384    else  % time from ImaDoc prevails if it exists
     385        j1=1;%default
     386        if ~isempty(j1_series{1})
     387            j1=j1_series{1};
     388        end
     389        DataOut.Time=time(1,i1_series{1}(1),j1filexml);
    381390        DataOut.Time_end=time(end,i1_series{end}(end),j1_series{end}(end));
    382391    end
Note: See TracChangeset for help on using the changeset viewer.