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/merge_proj.m

    r447 r457  
    1 
    2 
    3 
    4 
    5 
    6 %'merge_proj': project and concatene fields, used with series.fig
     1%'merge_proj': project and concatene fieldsmerge_proj
     2% can be used as a template for applying an operation (here projection and concateantion) on each field of an input series
    73%------------------------------------------------------------------------
    8 % function GUI_input=merge_proj(Param)
     4% function GUI_config=merge_proj(Param)
     5%------------------------------------------------------------------------
     6
     7%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
    98%
     9% This function is used in four modes by the GUI series:
     10%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     11%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     12%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     13%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     14%
     15% This function is used in four modes by the GUI series:
     16%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
     17%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
     18%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced.
     19%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
     20%
     21%OUTPUT
     22% GUI_input=list of options in the GUI series.fig needed for the function
     23%
     24%INPUT:
     25% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
     26% In batch mode, Param is the name of the corresponding xml file containing the same information
     27% In the absence of input (as activated when the current Action is selected
     28% in series), the function ouput GUI_input set the activation of the needed GUI elements
     29%
     30% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
     31%    .InputTable: cell of input file names, (several lines for multiple input)
     32%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
     33%    .OutputSubDir: name of the subdirectory for data outputs
     34%    .OutputDir: directory for data outputs, including path
     35%    .Action: .ActionName: name of the current activated function
     36%             .ActionPath:   path of the current activated function
     37%    .IndexRange: set the file or frame indices on which the action must be performed
     38%    .FieldTransform: .TransformName: name of the selected transform function
     39%                     .TransformPath:   path  of the selected transform function
     40%                     .TransformHandle: corresponding function handle
     41%    .InputFields: sub structure describing the input fields withfields
     42%              .FieldName: name of the field
     43%              .VelType: velocity type
     44%              .FieldName_1: name of the second field in case of two input series
     45%              .VelType_1: velocity type of the second field in case of two input series
     46%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
     47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     48
     49function GUI_input=merge_proj(Param)
     50
     51%% set the input elements needed on the GUI series when the action is selected in the menu ActionName
     52if ~exist('Param','var') % case with no input parameter
     53    GUI_input={'NbViewMax';2;...% max nbre of input file series (default='' , no limitation)
     54        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
     55        'NbSlice';'on'; ...%nbre of slices ('off' by default)
     56        'VelType';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
     57        'FieldName';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
     58        'FieldTransform'; 'on';...%can use a transform function
     59        'ProjObject';'on';...%can use projection object(option 'off'/'on',
     60        'Mask';'on';...%can use mask option   (option 'off'/'on', 'off' by default)
     61        'OutputDirExt';'.proj';...%set the output dir extension
     62               ''};
     63        return
     64end
     65
     66%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     67%% select different modes,  RUN, parameter input, BATCH
     68% BATCH  case: read the xml file for batch case
     69if ischar(Param)
     70    if strcmp(Param,'input?')
     71        checkrun=1;% will inly search input parameters (preparation of BATCH mode)
     72    else
     73        Param=xml2struct(Param);
     74        checkrun=0;
     75    end
     76% RUN case: parameters introduced as the input structure Param
     77else
     78    hseries=guidata(Param.hseries);%handles of the GUI series
     79    WaitbarPos=get(hseries.waitbar_frame,'Position');%position of the waitbar on the GUI series
     80    checkrun=2; % indicate the RUN option is used
     81end
     82
     83%% root input file(s) and type
     84RootPath=Param.InputTable(:,1);
     85RootFile=Param.InputTable(:,3);
     86SubDir=Param.InputTable(:,2);
     87NomType=Param.InputTable(:,4);
     88FileExt=Param.InputTable(:,5);
     89
     90% get the set of input file names (cell array filecell), and the lists of
     91% input file or frame indices i1_series,i2_series,j1_series,j2_series
     92[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     93% filecell{iview,fileindex}: cell array representing the list of file names
     94%        iview: line in the table corresponding to a given file series
     95%        fileindex: file index within  the file series,
     96% 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
     97% i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
     98% set of frame indices used for movie or multimage input
     99% numbers of slices and file indices
     100
     101NbSlice=1;%default
     102if isfield(Param.IndexRange,'NbSlice')
     103    NbSlice=Param.IndexRange.NbSlice;
     104end
     105nbview=numel(i1_series);%number of input file series (lines in InputTable)
     106nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
     107nbfield_i=size(i1_series{1},2); %nb of fields for the i index
     108nbfield=nbfield_j*nbfield_i; %total number of fields
     109nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
     110nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
     111
     112%determine the file type on each line from the first input file
     113ImageTypeOptions={'image','multimage','mmreader','video'};%allowed input file types(images)
     114
     115[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
     116CheckImage{1}=~isempty(find(strcmp(FileType,ImageTypeOptions)));% =1 for images
     117if ~isempty(j1_series{1})
     118    frame_index{1}=j1_series{1};
     119else
     120    frame_index{1}=i1_series{1};
     121end
     122
     123%% calibration data and timing: read the ImaDoc files
     124mode=''; %default
     125timecell={};
     126itime=0;
     127NbSlice_calib={};
     128for iview=1:nbview%Loop on views
     129    XmlData{iview}=[];%default
     130    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
     131    if exist([filebase{iview} '.xml'],'file')
     132        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
     133        if isfield(XmlData{iview},'Time')
     134            itime=itime+1;
     135            timecell{itime}=XmlData{iview}.Time;
     136        end
     137        if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
     138            NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
     139            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
     140                msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
     141            end
     142        end
     143    elseif exist([filebase{iview} '.civ'],'file')
     144        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
     145        itime=itime+1;
     146        timecell{itime}=time;
     147        XmlData{iview}.Time=time;
     148        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
     149        GeometryCalib.Tx=0;
     150        GeometryCalib.Ty=0;
     151        GeometryCalib.Tz=1;
     152        GeometryCalib.dpx=1;
     153        GeometryCalib.dpy=1;
     154        GeometryCalib.sx=1;
     155        GeometryCalib.Cx=0;
     156        GeometryCalib.Cy=0;
     157        GeometryCalib.f=1;
     158        GeometryCalib.kappa1=0;
     159        GeometryCalib.CoordUnit='cm';
     160        XmlData{iview}.GeometryCalib=GeometryCalib;
     161        if error==1
     162            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
     163        end
     164    end
     165end
     166
     167%% check coincidence in time for several input file series
     168multitime=0;
     169if isempty(timecell)
     170    time=[];
     171elseif length(timecell)==1
     172    time=timecell{1};
     173elseif length(timecell)>1
     174    multitime=1;
     175    for icell=1:length(timecell)
     176        if ~isequal(size(timecell{icell}),size(timecell{1}))
     177            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
     178            time=timecell{1};
     179            multitime=0;
     180            break
     181        end
     182    end
     183end
     184if multitime
     185    for icell=1:length(timecell)
     186        time(icell,:,:)=timecell{icell};
     187    end
     188    diff_time=max(max(diff(time)));
     189    if diff_time>0
     190        msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
     191    end   
     192end
     193if size(time,2) < i2_series{1}(end) || size(time,3) < j2_series{1}(end)% time array absent or too short in ImaDoc xml file'
     194    time=[];
     195end
     196
     197%% coordinate transform or other user defined transform
     198transform_fct='';%default
     199if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'TransformHandle')
     200    transform_fct=Param.FieldTransform.TransformHandle;
     201end
     202%%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
     203 % EDIT FROM HERE
     204
     205%% check the validity of  input file types
     206if CheckImage{1}
     207    FileExtOut='.png'; % write result as .png images for image inputs
     208elseif CheckNc{1}
     209    FileExtOut='.nc';% write result as .nc files for netcdf inputs
     210else
     211    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
     212    return
     213end
     214if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
     215        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
     216    return
     217end
     218NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
     219if NbSlice~=nbfield_j
     220    answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
     221    if ~strcmp(answer,'Yes')
     222        return
     223    end
     224end
     225
     226%% Set field names and velocity types
     227InputFields{1}=[];%default (case of images)
     228if isfield(Param,'InputFields')
     229    InputFields{1}=Param.InputFields;
     230end
     231if nbview==2
     232    InputFields{2}=[];%default (case of images)
     233    if isfield(Param,'InputFields')
     234        InputFields{2}=Param.InputFields{1};%default
     235        if isfield(Param.InputFields,'FieldName_1')
     236            InputFields{2}.FieldName=Param.InputFields.FieldName_1;
     237            if isfield(Param.InputFields,'VelType_1')
     238                InputFields{2}.VelType=Param.InputFields.VelType_1;
     239            end
     240        end
     241    end
     242end
     243
     244%% Initiate output fields
     245%initiate the output structure as a copy of the first input one (reproduce fields)
     246[DataOut,ParamOut,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1);
     247if ~isempty(errormsg)
     248    msgbox_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg])
     249    return
     250end
     251time_1=[];
     252if isfield(DataOut,'Time')
     253    time_1=DataOut.Time(1);
     254end
     255if CheckNc{iview}
     256    if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute))
     257        DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute];
     258    end
     259    DataOut.Conventions='uvmat';
     260    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}];
     261    ActionKey='Action';
     262    while isfield(DataOut,ActionKey)
     263        ActionKey=[ActionKey '_1'];
     264    end
     265    DataOut.(ActionKey)=Param.Action;
     266    DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}];
     267    if isfield(DataOut,'Time')
     268        DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}];
     269    end
     270end
     271
     272%% MAIN LOOP ON SLICES
     273%%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
     274for i_slice=1:NbSlice
     275    index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice
     276    nbfiles=0;
     277    nbmissing=0;
     278   
     279   %initiate result fields
     280   for ivar=1:length(DataOut.ListVarName)
     281       DataOut.(DataOut.ListVarName{ivar})=0; % initialise all fields to zero
     282   end
     283
     284    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
     285    for index=index_slice
     286        if checkrun
     287            update_waitbar(hseries.waitbar_frame,WaitbarPos,index/(nbfield))
     288            stopstate=get(hseries.RUN,'BusyAction');
     289        else
     290            stopstate='queue';
     291        end
    10292%OUTPUT
    11293% GUI_input=list of options in the GUI series.fig needed for the function
     
    15297%  or name of the xml file containing these parameters (BATCH case)
    16298%
    17 function GUI_input=merge_proj(Param)
    18 
    19 %requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    20 if ~exist('Param','var')
    21     GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
    22         'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
    23         'RootFile';'on';... %root input file name ('on' by default)
    24         'FileExt';'on';... %input file extension ('on' by default)
    25         'NomType';'on';...%type of file indexing ('on' by default)
    26         'NbSlice';'on'; ...%nbre of slices ('off' by default)
    27         'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
    28         'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
    29         'CoordType';'on';...%can use a transform function 'off' by default
    30         'GetObject';'on';...%can use projection object ,'off' by default
    31         'OutputDirExt';'.proj';...
    32         %'GetMask';'on'...%can use mask option   ,'off' by default
    33         %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter
    34                ''};
    35     return %exit the function
    36 end
    37 
    38 %% input parameters:
    39 % read the xml file for batch case
    40 if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
    41     Param=xml2struct(Param);
    42 else % RUN case : parameters introduced as the input structure Param
    43     hseries=guidata(Param.hseries);%handles of the GUI series
    44     WaitbarPos=get(hseries.waitbar_frame,'Position');% info for the waitbar
    45 end
    46 [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
    47 
    48 %% coordinate transform or other user defined transform
    49 transform_fct='';%default
    50 if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'fct_handle')
    51     transform_fct=Param.FieldTransform.fct_handle;
    52 end
     299
    53300
    54301%% projection object
Note: See TracChangeset for help on using the changeset viewer.