Ignore:
Timestamp:
Jan 16, 2012, 12:51:23 AM (12 years ago)
Author:
sommeria
Message:

fgunctions under series adapted to the renovated GUI series

File:
1 edited

Legend:

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

    r340 r374  
    11%'time_series': extract a time series, used with series.fig
    22%------------------------------------------------------------------------
    3 % function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series)
     3% function GUI_input=time_series(Param)
    44%
    55%OUTPUT
     
    88%INPUT:
    99%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
    10 %num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
     10%i2_series: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
    1111%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
    1212%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
    1313%Series: Matlab structure containing information set by the series interface
    1414%
    15 function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series)
     15function GUI_input=time_series(Param)
    1616
    1717%% requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
    18 if ~exist('num_i1','var')
     18if ~exist('Param','var')
    1919    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
    2020        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
     
    3333end
    3434
    35 %------------------------------------------------------
    36 hseries=guidata(Series.hseries);%handles in the GUI series
    37 WaitbarPos=get(hseries.waitbar_frame,'Position'); %position of the waitbar frame
     35%% input parameters
     36% read the xml file for batch case
     37if ischar(Param) && ~isempty(find(regexp('Param','.xml$')))
     38    Param=xml2struct(Param);
     39else %  RUN case: parameters introduced as the input structure Param
     40    hseries=guidata(Param.hseries);%handles of the GUI series
     41    WaitbarPos=get(hseries.waitbar_frame,'Position');
     42end
     43[filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
     44
     45
     46%% coordinate transform or other user defined transform (TODO: case BATCH ?)
     47transform_fct='';%default
     48if isfield(Param,'transform_fct') % transform function handle
     49    transform_fct=Param.transform_fct;
     50end
    3851
    3952%% projection object
     
    5164end
    5265
    53 %% root names: transform input to cell in case of a single input series
    54 if ischar(Series.RootPath)
    55     Series.RootPath={Series.RootPath};
    56     Series.RootFile={Series.RootFile};
    57     Series.SubDir={Series.SubDir};
    58     Series.FileExt={Series.FileExt};
    59     Series.NomType={Series.NomType};
    60     num_i1={num_i1};
    61     num_i2={num_i2};
    62     num_j1={num_j1};
    63     num_j2={num_j2};
    64 end
    65 ext=Series.FileExt{1};
     66%% features of the input fields
     67    RootPath=Param.InputTable(:,1);
     68    RootFile=Param.InputTable(:,3);
     69    SubDir=Param.InputTable(:,2);
     70    NomType=Param.InputTable(:,4);
     71    FileExt=Param.InputTable(:,5);
     72ext=FileExt{1};
    6673form=imformats(ext(2:end));%test valid Matlab image formats
    67 nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series
     74nbfield=size(i1_series{1},1)*size(i1_series{1},2); %number of fields in the time series
    6875
    6976%% determine image type
    7077hhh=which('mmreader');
    7178testnetcdf=0;
    72 nbview=length(Series.RootPath);%Number of input series: this function  accepts only one or two input file series (sub_field is used in the latter case)
     79nbview=length(RootPath);%Number of input series: this function  accepts only one or two input file series (sub_field is used in the latter case)
    7380for iview=1:nbview
    74     if isequal(Series.FileExt{iview},'.nc')||isequal(Series.FileExt{iview},'.cdf')
     81    if isequal(FileExt{iview},'.nc')||isequal(FileExt{iview},'.cdf')
    7582        FileType{iview}='netcdf';
    7683        testnetcdf=1;
    77     elseif isequal(lower(Series.FileExt{iview}),'.avi')
     84    elseif isequal(lower(FileExt{iview}),'.avi')
    7885        if ~isequal(hhh,'')%&& mmreader.isPlatformSupported()
    79             MovieObject{iview}=mmreader(fullfile(Series.RootPath{iview},[Series.RootFile{iview} Series.FileExt{iview}]));
     86            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
    8087            FileType{iview}='movie';
    8188        else
    8289            FileType{iview}='avi';
    8390        end
    84     elseif isequal(lower(Series.FileExt{iview}),'.vol')
     91    elseif isequal(lower(FileExt{iview}),'.vol')
    8592        FileType{iview}='vol';
    8693    else
    87        form=imformats(Series.FileExt{iview}(2:end));
     94       form=imformats(FileExt{iview}(2:end));
    8895       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
    89            if isequal(Series.NomType{iview},'*');
     96           if isequal(NomType{iview},'*');
    9097               FileType{iview}='multimage';
    9198           else
     
    95102    end
    96103end
    97 filebase{1}=fullfile(Series.RootPath{1},Series.RootFile{1});
     104filebase{1}=fullfile(RootPath{1},RootFile{1});
    98105
    99106%% number of slices
    100 NbSlice=Series.NbSlice;
     107NbSlice=Param.NbSlice;
    101108
    102109%% Field and velocity type (the same for the two views)
    103 if isfield(Series,'Field')
    104     FieldName=Series.Field;%the same set of fields for all views
    105 else
    106     FieldName={''};
    107 end
    108 if isequal(FieldName,{''}) && testnetcdf
     110FieldName={''};
     111
     112if isfield(Param,'InputFields')&&isfield(Param.InputFields,'FieldMenu') 
     113    FieldName=Param.InputFields.FieldMenu;%the same set of fields for all views
     114    VelType{1}=Param.InputFields.VelTypeMenu;
     115end
     116if isempty(FieldName) && testnetcdf
    109117    msgbox_uvmat('ERROR','A field must be defined as input')
    110118    return
    111119end
    112 if isequal(FieldName,{'get_field...'})
     120if isequal(FieldName,'get_field...')
    113121    hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
    114122    if numel(hget_field)>1
    115123        delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld
    116124    elseif isempty(hget_field)
    117        filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),Series.FileExt{1},Series.NomType{1},1,num_i2{1}(1),num_j2{1}(1),Series.SubDir{1});
     125        filename=filecell{1,1};
     126      % filename=name_generator(filebase{1},i1_series{1}(1),j1_series{1}(1),FileExt{1},NomType{1},1,i2_series{1}(1),num_j2{1}(1),SubDir{1});
    118127       idetect(iview)=exist(filename,'file');
    119128       hget_field=get_field(filename);
     
    123132    if isempty(SubField)
    124133        delete(hget_field)
    125        filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),Series.FileExt{1},Series.NomType{1},1,num_i2{1}(1),num_j2{1}(1),Series.SubDir{1});
     134        filename=filecell{1,1};
     135       %filename=name_generator(filebase{1},i1_series{1}(1),j1_series{1}(1),FileExt{1},NomType{1},1,i2_series{1}(1),j2_series{1}(1),SubDir{1});
    126136        hget_field=get_field(filename);
    127137        SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
     
    135145    testcivx=isequal(FileType{1},'netcdf');
    136146end
    137 VelType_str=get(hseries.VelTypeMenu,'String');
    138 VelType_val=get(hseries.VelTypeMenu,'Value');
    139 VelType{1}=VelType_str{VelType_val};
    140 if nbview==2
    141     VelType_str=get(hseries.VelTypeMenu_1,'String');
    142     VelType_val=get(hseries.VelTypeMenu_1,'Value');
    143     VelType{2}=VelType_str{VelType_val};
    144 end
     147% VelType_str=get(hseries.VelTypeMenu,'String');
     148% VelType_val=get(hseries.VelTypeMenu,'Value');
     149% VelType{1}=VelType_str{VelType_val};
     150% if nbview==2
     151%     VelType_str=get(hseries.VelTypeMenu_1,'String');
     152%     VelType_val=get(hseries.VelTypeMenu_1,'Value');
     153%     VelType{2}=VelType_str{VelType_val};
     154% end
    145155
    146156%% Calibration data and timing: read the ImaDoc files
     
    152162for iview=1:nbview%Loop on views
    153163    XmlData{iview}=[];%default
    154     filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview});
     164    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
    155165    if exist([filebase{iview} '.xml'],'file')
    156166        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']);
     
    218228%%  Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
    219229subdir_result='time_series';
    220 pathdir=fullfile(Series.RootPath{1},subdir_result);
     230pathdir=fullfile(RootPath{1},subdir_result);
    221231while exist(pathdir,'dir')
    222232    subdir_result=[subdir_result '.0'];
    223     pathdir=fullfile(Series.RootPath{1},subdir_result);
     233    pathdir=fullfile(RootPath{1},subdir_result);
    224234end
    225235[m1,m2,m3]=mkdir(pathdir);
     
    233243end
    234244filebase_out=filebase{1};
    235 NomTypeOut=nomtype2pair(Series.NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
    236 
    237 %% coordinate transform or other user defined transform
    238 transform_fct=[];%default
    239 if isfield(Series,'transform_fct')
    240     transform_fct=Series.transform_fct;
    241 end
     245 i21=i1_series{end}(end);
     246 if ~isempty(i2_series{end})
     247     i21=i2_series{end}(end)-i1_series{1}(1);
     248 end
     249 j21=1;
     250 if ~isempty(j1_series{1})
     251     j21=j1_series{end}(end);
     252      if ~isempty(j2_series{end})
     253          j21=j2_series{end}(end)-j21;
     254      end
     255 end
     256NomTypeOut=nomtype2pair(NomType{1},i21,j21);
     257
    242258
    243259%% velocity type
     
    264280            % loop on views (in case of multiple input series)
    265281            for iview=1:nbview
    266                 filename=name_generator(filebase{iview},...
    267                     num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),Series.SubDir{iview});
     282                filename=filecell{iview,ifile};
     283               % filename=name_generator(filebase{iview},...
     284                %    i1_series{iview}(ifile),j1_series{iview}(ifile),FileExt{iview},NomType{iview},1,i2_series{iview}(ifile),j2_series{iview}(ifile),SubDir{iview});
    268285                if exist(filename,'file')
    269286                    try
     
    274291                            switch FileType{iview}
    275292                                case 'movie'
    276                                     A=read(MovieObject{iview},num_i1{iview}(ifile));
     293                                    A=read(MovieObject{iview},i1_series{iview}(ifile));
    277294                                case 'avi'
    278                                     mov=aviread(filename,num_i1{iview}(ifile));
     295                                    mov=aviread(filename,i1_series{iview}(ifile));
    279296                                    A=frame2im(mov(1));
    280297                                case 'vol'
    281298                                    A=imread(filename);
    282299                                case 'multimage'
    283                                     A=imread(filename,num_i1{iview}(ifile));
     300                                    A=imread(filename,i1_series{iview}(ifile));
    284301                                case 'image'
    285302                                    A=imread(filename);
     
    308325                        end
    309326                        if ~isempty(NbSlice_calib)  % z index
    310                             Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
     327                            Data{iview}.ZIndex=mod(i1_series{iview}(ifile)-1,NbSlice_calib{1})+1;
    311328                        end
    312329                    catch ME
     
    397414                            if isequal(ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
    398415                                if isempty(VarVal)
    399                                     msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
     416                                    msgbox_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(ifile))])
    400417                                    return
    401418                                end
     
    423440                        RecordData.Time(filecounter,1)=ifile;%default
    424441                    end
    425                 else % time from ImaDoc prevails
    426                     RecordData.Time(filecounter,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2;
     442                else % time from ImaDoc prevails  TODO: correct
     443                  %  RecordData.Time(filecounter,1)=time{1}(i1_series{1})(ifile),j1_series{1}(ifile))+time(end,i2_series{end}(ifile),j2_series{end}(ifile)))/2;
     444                  RecordData.Time(filecounter,1)=i1_series{1}(ifile);% TODO : generalise
    427445                end
    428446               
     
    472490    end
    473491    RecordData.VarDimName=[{'Time'} RecordData.VarDimName];
    474     RecordData.Action=Series.Action;%name of the processing programme
     492    RecordData.Action=Param.Action;%name of the processing programme
    475493    test_time=diff(RecordData.Time)>0;% test that the readed time is increasing (not constant)
    476494    if ~test_time
     
    484502   
    485503    %name of result file
    486     [filemean]=...
    487         name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),subdir_result);
     504   % [filemean]=...
     505    %    name_generator(filebase_out,i1_series{1}(i_slice),j1_series{1}(i_slice),'.nc','_i1-i2_j1-j2',1,i2_series{end}(ifile),j2_series{end}(ifile),subdir_result);
     506    filemean=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},'.nc','_1',i1_series{1}(i_slice));
    488507    errormsg=struct2nc(filemean,RecordData); %save result file
    489508    if isempty(errormsg)
Note: See TracChangeset for help on using the changeset viewer.