Changeset 693 for trunk/src


Ignore:
Timestamp:
Oct 29, 2013, 12:28:57 PM (10 years ago)
Author:
sommeria
Message:

bug repaired geometry_calib/Detect grid, + corrections in get_field

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/geometry_calib.m

    r682 r693  
    5050% Edit the above text to modify the response to help geometry_calib
    5151
    52 % Last Modified by GUIDE v2.5 02-Sep-2013 16:47:27
     52% Last Modified by GUIDE v2.5 29-Oct-2013 06:46:10
    5353
    5454% Begin initialization code - DO NOT edit
     
    114114set(handles.Copy,'Position',[151 Height-394 120 30])%  rank 6
    115115set(handles.CLEAR_PTS,'Position',[297 Height-394 120 30])%  rank 6
     116set(handles.ClearLine,'Position',[297 Height-364 120 30])%  rank 6
    116117set(handles.phys_title,'Position',[38 Height-426 125 20])%  rank 7
    117118set(handles.CoordUnit,'Position',[151 Height-426 120 30])%  rank 7
     
    230231    Data=get(handles.ListCoord,'Data');
    231232    Data(:,6)=zeros(size(Data,1),1);
    232     Data(index,6)=1;% indicate in the list the point with max deviation (possible mistake)
     233    Data(index,6)=-1;% indicate in the list the point with max deviation (possible mistake)
    233234    set(handles.ListCoord,'Data',Data)% indicate in the list the point with max deviation (possible mistake)
    234235    figure(handles.geometry_calib)
     
    881882huvmat=findobj(allchild(0),'Name','uvmat');
    882883UvData=get(huvmat,'UserData');
    883 A=UvData.Field.A;
     884A=UvData.Field.A;%currently displayed image
    884885npxy=size(A);
    885886X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
    886887Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
    887888
    888 %calculate transform matrices for plane projection
     889%calculate transform matrices for plane projection: rectangle assumed to be viewed in perspective
    889890% reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren
    890891B = [ X Y ones(size(X)) zeros(4,3)        -X.*corners_X -Y.*corners_X ...
     
    898899
    899900% transform grid image into 'phys' coordinates
    900 GeometryCalib.CalibrationType='linear';
     901GeometryCalib.CalibrationType='3D_linear';
    901902GeometryCalib.fx_fy=[1 1];
    902903GeometryCalib.Tx_Ty_Tz=[Amat(1,3) Amat(2,3) 1];
     
    918919DataOut=phys(Data,Calib);
    919920rmpath(fullfile(path_UVMAT,'transform_field'))
    920 Amod=DataOut.A;
     921Amod=DataOut.A;% current imgage expressed in 'phys' coord
    921922Rangx=DataOut.AX;
    922923Rangy=DataOut.AY;
     
    936937ind_range_y=ceil(abs(GeometryCalib.R(2,2)*CalibData.grid.Dy/3));% range of search of image ma around each point obtained by linear interpolation from the marked points
    937938nbpoints=size(T,1);
     939%lokk for image maxima around each expected pgrid point
    938940for ipoint=1:nbpoints
    939941    i0=1+round((T(ipoint,1)-Rangx(1))/Dx);%round(Xpx(ipoint));
     
    962964    Delta(ipoint,2)=(y_shift+ind_y_max+j0min-j0-1)*Dy;
    963965end
    964 Tmod=T(:,(1:2))+Delta;
    965 [Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2));
    966 % for ipoint=1:nbpoints
    967 %      Coord{ipoint,1}=num2str(T(ipoint,1),4);%display coordiantes with 4 digits
    968 %      Coord{ipoint,2}=num2str(T(ipoint,2),4);%display coordiantes with 4 digits
    969 %      Coord{ipoint,3}=num2str(T(ipoint,3),4);%display coordiantes with 4 digits;
    970 %      Coord{ipoint,4}=num2str(Xpx(ipoint),4);%display coordiantes with 4 digits
    971 %      Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digits
    972 % end
     966Tmod=T(:,(1:2))+Delta;% 'phys' coordinates of the detected points
     967Tmod(:,2)=flipdim(Tmod(:,2),1);% inverse the order of y coordinates
     968[Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2));% image coordinates of the detected points
    973969Coord=[T Xpx Ypx zeros(size(T,1),1)];
    974970set(handles.ListCoord,'Data',Coord)
     
    12501246    Data=get(handles.ListCoord,'Data');
    12511247    Data(:,6)=zeros(size(Data,1),1);
    1252     Data(iline,6)=1;% mark the selected line
     1248    Data(iline,6)=-1;% mark the selected line
    12531249    set(handles.ListCoord,'Data',Data)
    12541250    update_calib_marker(Data(iline,:))
     
    13401336    set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range])
    13411337end
     1338
     1339%------------------------------------------------------------------------
     1340% --- Executes on button press in ClearLine: remove the selected line in the table Coord
     1341%------------------------------------------------------------------------
     1342function ClearLine_Callback(hObject, eventdata, handles)
     1343
     1344Coord=get(handles.ListCoord,'Data');
     1345ind=find(Coord(:,6));%find the marker '-' for line selection
     1346if isempty(ind)
     1347    msgbox_uvmat('WARNING','no line suppressed, select a line in the table')
     1348else
     1349    answer=msgbox_uvmat('INPUT_Y-N',['suppress line ' num2str(ind) '?']);
     1350    if isequal(answer,'Yes')
     1351Coord(:,6)=zeros(size(Coord,1),1);% desactivate the current line mark
     1352Coord(ind,:)=[];
     1353PLOT_Callback(hObject,eventdata,handles)
     1354set(handles.APPLY,'BackgroundColor',[1 0 1])
     1355set(handles.ListCoord,'Data',Coord);
     1356    end
     1357end
  • trunk/src/get_field.m

    r675 r693  
    3434function varargout = get_field(varargin)
    3535
    36 % Last Modified by GUIDE v2.5 09-Jun-2013 11:15:54
     36% Last Modified by GUIDE v2.5 23-Oct-2013 23:44:17
    3737
    3838% Begin initialization code - DO NOT EDIT
     
    9797        check_singleton(idim)=isequal(Field.DimValue(dim_index),1);%check_singleton=1 for singleton
    9898    end
    99     Field.Check0D(ilist)=(isequal(check_singleton,ones(1,NbDim)));% =1 if the variable reduces to a single value
     99    Field.Check0D(ilist)=(isequal(check_singleton,ones(1,NbDim)))||(~isequal(Field.VarType(ilist),4)&&~isequal(Field.VarType(ilist),5));% =1 if the variable reduces to a single value
    100100    if ~Field.Check0D(ilist)
    101101    Field.Display.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);% eliminate singletons in the list of variable dimensions
     
    137137end
    138138if Field.MaxDim>=2
    139     ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}];% the time can be chosen as a dim index
     139    ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'matrix index'}];% the time can be chosen as a dim index
    140140end
    141141
     
    144144    time_index=find(strcmp(ParamIn.TimeAttrName,Field.Display.ListGlobalAttribute),1);
    145145else
    146     time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);
     146    time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% look for global attribute containing name 'Time'
    147147end
    148148if ~isempty(time_index)
     
    517517%% set default coord selection
    518518if numel(find(test_coord))>3
     519     SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
     520    if numel(SwitchVarIndexTime)<3
     521        SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index'];
     522        set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime)
     523    end
    519524    set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
     525    SwitchVarIndexTime_Callback([], [], handles)
    520526end
    521527if numel(var_component)<2
     
    554560        set(handles.TimeName,'Value',1)
    555561        set(handles.TimeName,'String',ListTime)
    556     case 'dim index'
     562    case 'matrix index'
    557563        if numel(find(test_coord))<3
    558564            ListTime={''};
     
    579585test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
    580586dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable
    581 for ilist=1:numel(Field.Display.VarDimName)
    582     dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
    583     if isequal(dimnames,dim_var)
    584         test_component(ilist)=1;
    585     elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable
    586         test_coord(ilist)=1;
     587CheckDimensionX=get(handles.CheckDimensionX,'Value');
     588CheckDimensionY=get(handles.CheckDimensionY,'Value');
     589if ~CheckDimensionX  || ~CheckDimensionY
     590    %look for coordinate variables among the other variables
     591    for ilist=1:numel(Field.Display.VarDimName)
     592        dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
     593        if isequal(dimnames,dim_var)
     594            test_component(ilist)=1;% the listed variable has the same dimension as the selected scalar-> possibly chosen as unstructured coordinate
     595        elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var), 1))%variable ilist is a 1D array which can be coordinate variable
     596            test_coord(ilist)=1;
     597        end
    587598    end
    588599end
     
    593604%% set default coord selection
    594605if numel(find(test_coord))>3
     606    SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String');
     607    if numel(SwitchVarIndexTime)<3
     608        SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index'];
     609        set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime)
     610    end
    595611    set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time
     612    SwitchVarIndexTime_Callback([], [], handles)
    596613end
    597614% if numel(var_component)<2
     
    623640    end
    624641end
    625 set(handles.Coord_x,'Value',coord_val(1))
    626 set(handles.Coord_y,'Value',coord_val(2))
    627 set(handles.Coord_y,'String',ListCoord)
    628 set(handles.Coord_x,'String',ListCoord)
    629 
     642if  CheckDimensionX
     643    set(handles.Coord_x,'Value',2)
     644    set(handles.Coord_x,'String',dim_var')
     645else
     646    set(handles.Coord_x,'Value',coord_val(1))
     647    set(handles.Coord_x,'String',ListCoord)
     648end
     649if  CheckDimensionY
     650    set(handles.Coord_y,'Value',1)
     651    set(handles.Coord_y,'String',dim_var')
     652else
     653    set(handles.Coord_y,'Value',coord_val(2))
     654    set(handles.Coord_y,'String',ListCoord)
     655end
    630656
    631657%% set list of time coordinates
     
    871897        end
    872898        set(handles.TimeName, 'String',TimeVarName)
    873     case 'dim index'% TimeName menu represents the available dimensions
    874         set(handles.TimeName, 'Visible','on')
    875         TimeVarName=Field.Display.SingleDimName;
    876         List=get(handles.TimeName,'String');
    877         option=List{get(handles.TimeName,'Value')};
    878         ind=find(strcmp(option,TimeVarName));
    879         if isempty(ind)
    880             set(handles.TimeName, 'Value',1);
    881         else
    882             set(handles.TimeName, 'Value',ind);
    883         end
    884         set(handles.TimeName, 'String',TimeVarName)
     899    case 'matrix_index'% TimeName menu represents the available dimensions
     900        set(handles.TimeName, 'Visible','on')     
     901        set(handles.TimeName, 'Value',1);
     902        set(handles.TimeName, 'String',Field.Display.ListDimName)
    885903end
    886904
     
    920938    end
    921939end
     940
     941% --- Executes on button press in CheckDimensionY.
     942function CheckDimensionX_Callback(hObject, eventdata, handles)
     943FieldList=get(handles.FieldOption,'String');
     944FieldOption=FieldList{get(handles.FieldOption,'Value')};
     945switch FieldOption
     946    case '1D plot'
     947       
     948    case 'scalar'
     949       scalar_Callback(hObject, eventdata, handles)
     950    case 'vectors'
     951end
     952
     953% --- Executes on button press in CheckDimensionY.
     954function CheckDimensionY_Callback(hObject, eventdata, handles)
     955FieldList=get(handles.FieldOption,'String');
     956FieldOption=FieldList{get(handles.FieldOption,'Value')};
     957switch FieldOption
     958    case '1D plot'
     959       
     960    case 'scalar'
     961       scalar_Callback(hObject, eventdata, handles)
     962    case 'vectors'
     963end
     964% hObject    handle to CheckDimensionY (see GCBO)
     965% eventdata  reserved - to be defined in a future version of MATLAB
     966% handles    structure with handles and user data (see GUIDATA)
     967
     968% Hint: get(hObject,'Value') returns toggle state of CheckDimensionY
  • trunk/src/mouse_motion.m

    r682 r693  
    418418                    Data=get(h_ListCoord,'Data');
    419419                    Data(:,6)=zeros(size(Data,1),1);
    420                     Data(index_point,6)=1;%mrk the point on the GUI geometry_calib
     420                    Data(index_point,6)=-1;%mrk the point on the GUI geometry_calib
    421421                    set(h_ListCoord,'Data',Data);
    422422                    hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
  • trunk/src/nc2struct.m

    r648 r693  
    1313%                    .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)                         
    1414%                    .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
    15 %                  ListDimName=list of dimension (added information, not requested for field description)
    16 %                  DimValue= vlalues of dimensions (added information, not requested for field description)
     15%                  .ListDimName=list of dimension (added information, not requested for field description)
     16%                  .DimValue= vlalues of dimensions (added information, not requested for field description)
     17%                  .VarType= integers giving the type of variable as coded by netcdf= 2 for char, =4 for single,=( for double
    1718%         .Txt: error message
    1819%  var_detect: vector with same length as the cell array ListVarName, = 1 for each detected variable and 0 else.
     
    166167    for ncvar=1:nvars %loop on the variables of the netcdf file
    167168        %get name, type, dimensions and attribute numbers of each variable
    168         [ListVarNameNetcdf{ncvar},xtype,dimids{ncvar},nbatt(ncvar)] = netcdf.inqVar(nc,ncvar-1);
     169        [ListVarNameNetcdf{ncvar},xtype(ncvar),dimids{ncvar},nbatt(ncvar)] = netcdf.inqVar(nc,ncvar-1);
    169170    end 
    170171    testmulti=0;
     
    221222            end
    222223            try
    223             if ischar(valuestr)
    224                % valuestr=regexprep(valuestr,{'\\','\/','\.','\-',' '},{'_','_','_','_','_'});%remove  '\','.' or '-' if exists
    225                 eval(['Data.VarAttribute{ivar}.' attname '=''' valuestr ''';'])
    226             elseif isempty(valuestr)
    227                 eval(['Data.VarAttribute{ivar}.' attname '=[];'])
    228             elseif isnumeric(valuestr)
    229                 eval(['Data.VarAttribute{ivar}.' attname '=valuestr;'])
     224             if isempty(valuestr)
     225                Data.VarAttribute{ivar}.(attname)=valuestr;
    230226            end
    231227            catch ME
     
    233229                display(valuestr)
    234230                display(ME.message)         
    235                 eval(['Data.VarAttribute{ivar}.atrr_' num2str(iatt) '=''not read'';'])
     231                Data.VarAttribute{ivar}.(['atrr_' num2str(iatt)])='not read';
    236232            end
    237233        end
     
    255251                if var_dim{ivar}(end)==TimeDimIndex% if the last dim of the variable is the time
    256252                    slice_length=prod(var_dim{ivar}(1:end-1));
    257                     Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1),TimeIndex*slice_length,slice_length); %read the variable data
     253                    Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1,TimeIndex*slice_length,slice_length)); %read the variable data
    258254                    CheckSub=1;
    259255                end
    260256            end
    261257            if ~CheckSub
    262                 Data.(VarName)=double(netcdf.getVar(nc,var_index(ivar)-1)); %read the whole variable data
    263             end
    264         end
    265     end
     258                Data.(VarName)=netcdf.getVar(nc,var_index(ivar)-1); %read the whole variable data
     259                if xtype(var_index(ivar))==5
     260                Data.(VarName)=double(Data.(VarName)); %transform to double for single pecision
     261                end
     262            end
     263        end
     264    end
     265    Data.VarType=xtype(var_index);
    266266   
    267267    %%  -------- close fle-----------
  • trunk/src/read_field.m

    r684 r693  
    2020%     .ColorVar: variable used for vector color
    2121%     .Npx, .Npy: nbre of pixels along x and y (used for .vol input files)
     22%     .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'num'   
    2223% num: frame number for movies
    2324%
  • trunk/src/uvmat.m

    r690 r693  
    23522352    if strcmp(TimeName,'civdata')||strcmp(TimeName,'civx')
    23532353        abstime=Field{1}.Time;
    2354     elseif ~isempty(regexp(TimeName,'^att:'))||~isempty(regexp(TimeName,'^dim:'))||~isempty(regexp(TimeName,'^var:'))
     2354    elseif ~isempty(regexp(TimeName,'^att:'))||~isempty(regexp(TimeName,'^var:'))
    23552355        abstime=Field{1}.(TimeName(5:end));%the time is an attribute or variale selected by get_file
     2356    elseif ~isempty(regexp(TimeName,'^dim:'))
     2357        abstime=str2num(get(handles.i1,'String'));
    23562358    end
    23572359    if isfield(Field{1},'Dt')
     
    31273129            XName=GetFieldData.Coordinates.Coord_x;
    31283130            TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
    3129             if strcmp(TimeNameStr,'file index')
    3130                 set(handles.TimeName,'String','');
    3131             else
    3132                 set(handles.TimeName,'String',[TimeNameStr(1:3) ':' GetFieldData.Time.TimeName]);
    3133             end
    3134             if strcmp(TimeNameStr,'variable')||strcmp(TimeNameStr,'dim index')% we scan a variable index, not a file index
    3135                 set(handles.NomType,'String','*')
    3136                 set(handles.RootFile,FileName)
    3137             end
    3138             %     set(handles.TimeValue,'String' SwitchVarIndexTime
     3131            switch TimeNameStr
     3132                case 'file index'
     3133                    set(handles.TimeName,'String','');
     3134                case 'attribute'
     3135                    set(handles.TimeName,'String',['att:' GetFieldData.Time.TimeName]);
     3136                case 'variable'
     3137                    set(handles.TimeName,'String',['var:' GetFieldData.Time.TimeName])
     3138                    set(handles.NomType,'String','*')
     3139                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
     3140                    set(handles.FileIndex,'String','')
     3141                    ParamIn.TimeVarName=GetFieldData.Time.TimeName;
     3142                case 'matrix_index'
     3143                    set(handles.TimeName,'String',['dim:' GetFieldData.Time.TimeName]);
     3144                    set(handles.NomType,'String','*')
     3145                    set(handles.RootFile,'String',[get(handles.RootFile,'String') get(handles.FileIndex,'String')])
     3146                    set(handles.FileIndex,'String','')
     3147                    ParamIn.TimeDimName=GetFieldData.Time.TimeName;
     3148            end
    31393149            set(handles.Coord_x,'String',XName)
    31403150            if ischar(YName)
Note: See TracChangeset for help on using the changeset viewer.