Changeset 535


Ignore:
Timestamp:
Sep 3, 2012, 2:02:13 PM (8 years ago)
Author:
sommeria
Message:

various bugs fixed, in particular patch projection with color images

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_field_cells.m

    r530 r535  
    5555
    5656function [CellInfo,NbDim,errormsg]=find_field_cells(Data)
    57 % CellVarIndex={};
    58 % CellInfo={}
     57
    5958NbDim=0;
    60 % CellVarType=[];
    61 errormsg=[];
     59errormsg='';
    6260if ~isfield(Data,'ListVarName'), errormsg='the list of variables .ListVarName is missing';return;end
    6361if ~isfield(Data,'VarDimName'), errormsg='the list of dimensions .VarDimName is missing';return;end
    6462nbvar=numel(Data.ListVarName);%number of field variables
    6563if ~isequal(numel(Data.VarDimName),nbvar), errormsg='.ListVarName and .VarDimName have unequal length';return;end
    66 if isfield(Data,'ListDimName')&& isfield(Data,'DimValue')&&isequal(numel(Data.ListDimName),numel(Data.DimValue))
    67     check_dim=1;% dimensions of data defined, data not needed for this function
    68 else
    69     check_dim=0;
    70     for ilist=1:numel(Data.ListVarName)
    71         if ~isfield(Data,Data.ListVarName{ilist})
    72             errormsg=['missing variable ' Data.ListVarName{ilist}];
    73             return
    74         end
    75     end
    76 end
    77 icell=0;
    78 
    79 % NbDim=[];
    80 % VarDimIndex=[];
    81 % VarDimName={};
     64% check the existence of variable data
     65check_var=1;
     66for ilist=1:numel(Data.ListVarName)
     67    if ~isfield(Data,Data.ListVarName{ilist})
     68        check_var=0;% dimensions of data defined, data not needed for this function
     69        break
     70    end
     71end
     72if ~check_var &&  ~(isfield(Data,'ListDimName')&& isfield(Data,'DimValue')&&isequal(numel(Data.ListDimName),numel(Data.DimValue)))
     73    errormsg=['missing variable or values of dimensions' Data.ListVarName{ilist}];
     74    return
     75end
     76
    8277
    8378%% role of variables and list of requested operations
     
    127122            CellInfo{icell}.CoordIndex=ivar_coord_x(icell);
    128123            % size of coordinate var
    129             if check_dim
     124            if check_var
     125                CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)}));
     126            else
    130127                for idim=1:numel(DimCell)
    131128                 check_index= strcmp(DimCell{idim},Data.ListDimName);
     
    133130                end
    134131                CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize);
    135             else
    136                 CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)}));
    137132            end
    138133            ind_y=find(strcmp('coord_y',Role(VarIndex)));
     
    157152
    158153%% look for tps coordinates
    159 ivar_remain=find(~check_select);
     154ivar_remain=find(~check_select);% indices of remaining variables (not already selected)
    160155check_coord_tps= strcmp('coord_tps',Role(~check_select));
    161 ivar_tps=ivar_remain(check_coord_tps);
     156ivar_tps=ivar_remain(check_coord_tps);% variable indices corresponding to tps coordinates
    162157for icell_tps=1:numel(ivar_tps)
    163     DimCell=Data.VarDimName{ivar_tps(icell_tps)};
    164     icell=numel(CellInfo)+icell_tps;
    165     CellInfo{icell}.CoordIndex=ivar_tps(icell);
     158    DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable
     159    icell=numel(CellInfo)+icell_tps; % new field cell index
     160    CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the  tps coordinate variable
    166161    CellInfo{icell}.VarIndex_subrange_tps=[];
    167162    CellInfo{icell}.VarIndex_nbsites_tps=[];
     
    182177    CellInfo{icell}.CoordType='tps';
    183178    CellInfo{icell}.VarIndex=find(check_cell);
    184     if check_dim
     179    if check_var
     180        NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
     181        CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3);
     182    else
    185183        check_index_1= strcmp(DimCell{1},Data.ListDimName);
    186184        check_index_2= strcmp(DimCell{2},Data.ListDimName);
     
    188186        NbDim(icell)=Data.DimValue(check_index_2);
    189187        CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3);
    190     else
    191         NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
    192         CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3);
    193188    end
    194189    check_select=check_select|check_cell;
    195190end
    196191
    197 %% look for dimension variables and corresponding gridded data
    198 ivar_remain=find(~check_select);
     192%% look for coordinate variables and corresponding gridded data:
     193% coordinate variables are variables associated with a single dimension, defining the coordinate values
     194% two cases: 1)the coordiante variable represents the set of coordiante values
     195%            2)the coordinate variable contains only two elements, representing the coordinate bounds for the dimension with the same name as the cordinate
     196ivar_remain=find(~check_select);% indices of remaining variables, not already taken into account
     197ListVarName=Data.ListVarName(~check_select);%list of remaining variables
    199198VarDimName=Data.VarDimName(~check_select);%dimensions of remaining variables
    200 check_coord= cellfun(@numel,VarDimName)==1|cellfun(@ischar,VarDimName)==1;% find variables with a single dimension
    201 ListCoordIndex=ivar_remain(check_coord);
    202 ListCoordName=Data.ListVarName(ListCoordIndex);
    203 ListDimName=Data.VarDimName(ListCoordIndex);
    204 %remove redondant values
     199check_coord= cellfun(@numel,VarDimName)==1|cellfun(@ischar,VarDimName)==1;% find remaining variables with a single dimension
     200ListCoordIndex=ivar_remain(check_coord);% indices of remaining variables with a single dimension
     201ListCoordName=Data.ListVarName(ListCoordIndex);% corresponding names of remaining variables with a single dimension
     202ListDimName=Data.VarDimName(ListCoordIndex);% dimension names of remaining variables with a single dimension
     203
     204%remove redondant variables -> keep only one variable per dimension
    205205check_keep=logical(ones(size(ListDimName)));
    206206for idim=1:numel(ListDimName)
    207     prev_ind=strcmp(ListDimName{idim},ListDimName(1:idim-1));
     207    prev_ind=strcmp(ListDimName{idim},ListDimName(1:idim-1));% check whether the dimension is already taken into account
    208208    if ~isempty(prev_ind)
    209         if strcmp(ListCoordName{idim},ListDimName{idim}) %coordinate variable
     209        if strcmp(ListCoordName{idim},ListDimName{idim}) %variable with the same name as the coordinate taken in priority
    210210            check_keep(prev_ind)=0;
    211211        else
     
    214214    end
    215215end
    216 ListCoordIndex=ListCoordIndex(check_keep);
    217 ListCoordName=ListCoordName(check_keep);
    218 ListDimName=ListDimName(check_keep);
    219 
    220 CoordSize=[];
     216ListCoordIndex=ListCoordIndex(check_keep);% list of coordinate variable indices
     217ListCoordName=ListCoordName(check_keep);% list of coordinate variable names
     218ListDimName=ListDimName(check_keep);% list of coordinate dimension names
     219
     220% determine dimension sizes
     221CoordSize=zeros(size(ListCoordIndex));
    221222for ilist=1:numel(ListCoordIndex)
    222223    if iscell(ListDimName{ilist})
    223224        ListDimName(ilist)=ListDimName{ilist};%transform cell to string
    224225    end
    225     if check_dim% if the list of dimensions is directly defined
    226         check_index= strcmp(ListDimName{ilist},Data.ListDimName);
    227         DimValue=Data.DimValue(check_index);
     226    if check_var% if the list of dimensions has been directly defined, no variable data available
     227        CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));% number of elements in the variable corresponding to the dimension #ilist
    228228    else
    229         DimValue=numel(Data.(ListCoordName{ilist}));
    230     end
    231     if DimValue==2% case of uniform grid coordinate defined by lower and upper bounds only
    232         ListDimName{ilist}=ListCoordName{ilist};% look for dimensions with name equal to coordinate for
    233         if check_dim
    234             check_index= strcmp(ListCoordName{ilist},Data.ListDimName);
    235             CoordSize(ilist)=Data.DimValue(check_index);
    236         else
    237             CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));
    238         end
    239     else
    240         CoordSize(ilist)=DimValue;
    241     end
    242 end
     229        check_index= strcmp(ListDimName{ilist},Data.ListDimName);% find the  index in the list of dimensions
     230        CoordSize(ilist)=Data.DimValue(check_index);% find the  corresponding dimension value
     231    end
     232    if CoordSize(ilist)==2% case of uniform grid coordinate defined by lower and upper bounds only
     233        ListDimName{ilist}=ListCoordName{ilist};% replace the dimension name by the coordinate variable name
     234%         if check_var
     235%             check_index= strcmp(ListCoordName{ilist},Data.ListDimName);
     236%             CoordSize(ilist)=Data.DimValue(check_index);
     237%         else
     238%             CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));
     239% %         end
     240%     else
     241%         CoordSize(ilist)=DimValue;
     242    end
     243end
     244
     245% group the remaining variables in cells sharing the same coordinate variables
    243246NewCellInfo={};
    244247NewCellDimIndex={};
    245248NewNbDim=[];
    246 for ivardim=1:numel(VarDimName) % loop on the list of remaining variables
    247     DimCell=VarDimName{ivardim};% dimension names of the current variable
     249for ivardim=1:numel(VarDimName) % loop at the list of remaining variables
     250    DimCell=VarDimName{ivardim};% dimension names of the current variable 
    248251    if ischar(DimCell), DimCell={DimCell}; end %transform char to cell if needed
    249252    DimIndices=[];
    250253    for idim=1:numel(DimCell)
    251         ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of coord dimensions
     254        ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of coordinate variables
    252255        if ~isempty(ind_dim)
    253256            DimIndices=[DimIndices ind_dim]; %update the list of coord dimensions included in DimCell
    254         end
    255     end
     257            if check_var && CoordSize(ind_dim)==2 % determine the size of the coordinate in case of coordiante variable limited to lower and upper bounds
     258                if isvector(Data.(ListVarName{ivardim})) || iscolumn(Data.(ListVarName{ivardim}))
     259                    if numel(Data.(ListVarName{ivardim}))>2
     260                        CoordSize(ind_dim)=numel(Data.(ListVarName{ivardim}));
     261                    end
     262                else
     263                    CoordSize(ind_dim)=size(Data.(ListVarName{ivardim}),idim);
     264                end
     265            end
     266        end
     267    end
     268    % look for cells of variables with the same coordinate variables
    256269    check_previous=0;
    257270    for iprev=1:numel(NewCellInfo)
     
    262275        end
    263276    end
     277    % create a new cell if no previous one contains the coordinate variables
    264278    if ~check_previous
    265279        nbcell=numel(NewCellInfo)+1;
  • trunk/src/plot_field.m

    r530 r535  
    270270Data={};
    271271for icell=1:length(CellInfo)
    272     VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list data.ListVarName
     272   
     273    % select types of  variables to be projected
     274    ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
     275    check_proj=false(size(FieldData.ListVarName));
     276    for ilist=1:numel(ListProj)
     277        if isfield(CellInfo{icell},ListProj{ilist})
     278            check_proj(CellInfo{icell}.(ListProj{ilist}))=1;
     279        end
     280    end
     281    VarIndex=find(check_proj);
     282    %
     283    %     VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list data.ListVarName
     284    %     for ivar=1:length(VarIndex)
     285    %         checkancillary=0;
     286    %         if length(FieldData.VarAttribute)>=VarIndex(ivar)
     287    %             VarAttribute=FieldData.VarAttribute{VarIndex(ivar)};
     288    %             if isfield(VarAttribute,'Role')&&(strcmp(VarAttribute.Role,'ancillary')||strcmp(VarAttribute.Role,'coord_tps')...
     289    %                     ||strcmp(VarAttribute.Role,'vector_x_tps')||strcmp(VarAttribute.Role,'vector_y_tps'))
     290    %                 checkancillary=1;
     291    %             end
     292    %         end
     293    %         if ~checkancillary% does not display variables with attribute '.Role=ancillary'
    273294    for ivar=1:length(VarIndex)
    274         checkancillary=0;
    275         if length(FieldData.VarAttribute)>=VarIndex(ivar)
    276             VarAttribute=FieldData.VarAttribute{VarIndex(ivar)};
    277             if isfield(VarAttribute,'Role')&&(strcmp(VarAttribute.Role,'ancillary')||strcmp(VarAttribute.Role,'coord_tps')...
    278                     ||strcmp(VarAttribute.Role,'vector_x_tps')||strcmp(VarAttribute.Role,'vector_y_tps'))
    279                 checkancillary=1;
    280             end
    281         end
    282 %         if ~checkancillary% does not display variables with attribute '.Role=ancillary'
    283             VarName=FieldData.ListVarName{VarIndex(ivar)};
    284             VarValue=FieldData.(VarName);
    285             Data =[Data [{VarName}; num2cell(VarValue)]];
    286             if size(VarValue,1)~=1
    287                 VarValue=VarValue';% put the different values on a line
    288             end
    289             if size(VarValue,1)==1
    290             txt=[VarName '=' num2str(VarValue)];
    291             txt_cell=[txt_cell;{txt}];
    292             end
    293 %         end
     295    VarName=FieldData.ListVarName{VarIndex(ivar)};
     296    VarValue=FieldData.(VarName);
     297    if iscolumn(VarValue)
     298        VarValue=VarValue';% put the different values on a line
     299    end
     300    if numel(VarValue)>1 && numel(VarValue)<10
     301        for ind=1:numel(VarValue)
     302            VarNameCell{1,ind}=[VarName '_' num2str(ilist)];
     303        end
     304    else
     305        VarNameCell={VarName};
     306    end
     307    if numel(VarValue)<10
     308        Data =[Data [VarNameCell; num2cell(VarValue)]];
     309    else
     310        Data =[Data [VarNameCell; {['size ' num2str(size(VarValue))]}]];
     311    end
     312    if size(VarValue,1)==1
     313        txt=[VarName '=' num2str(VarValue)];
     314        txt_cell=[txt_cell;{txt}];
     315    end
    294316    end
    295317end
  • trunk/src/uvmat.m

    r534 r535  
    293293    display_file_name(handles,inputfile)
    294294    %%%%%%%
    295     testinputfield=1;
    296295end
    297296
     
    24042403%% get bounds and mesh (needed  to propose default options for projection objects)
    24052404if NbDim>1
    2406     CoordMax=zeros(1,numel(imax));
    2407     CoordMin=zeros(1,numel(imax));
     2405    CoordMax=zeros(numel(imax),NbDim);
     2406    CoordMin=zeros(numel(imax),NbDim);
     2407    Mesh=zeros(numel(imax),NbDim);
    24082408    for ind=1:numel(imax)
    24092409        XName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)};
    24102410        YName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)};
    2411         CoordMax(ind,1)=max(max(UvData.Field.(XName)));
    2412         CoordMin(ind,1)=min(min(UvData.Field.(XName)));
    2413         CoordMax(ind,2)=max(max(UvData.Field.(YName)));
    2414         CoordMin(ind,2)=min(min(UvData.Field.(YName)));
     2411        CoordMax(ind,NbDim)=max(max(UvData.Field.(XName)));
     2412        CoordMin(ind,NbDim)=min(min(UvData.Field.(XName)));
     2413        CoordMax(ind,NbDim-1)=max(max(UvData.Field.(YName)));
     2414        CoordMin(ind,NbDim-1)=min(min(UvData.Field.(YName)));
    24152415        %         test_x=1;%test for unstructured coordinates
    24162416        if NbDim==3
    24172417            ZName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)};
    2418             CoordMax(imax(ind),3)=max(max(UvData.Field.(ZName)));
    2419             CoordMin(ind,3)=min(min(UvData.Field.(ZName)));
     2418            CoordMax(imax(ind),1)=max(max(UvData.Field.(ZName)));
     2419            CoordMin(ind,1)=min(min(UvData.Field.(ZName)));
    24202420        end
    24212421       
     
    24232423           
    24242424            case 'scattered' %unstructured coordinates
    2425                 NbPoints(ind)=CellInfo{imax(ind)}.CoordSize;% nbre of points
    2426                 Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim)
     2425                NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points
     2426                Mesh(ind,:)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim)
    24272427            case 'grid'%structured coordinate
    2428                 NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points
    2429                 Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./NbPoints);
    2430                
     2428                NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction
     2429                Mesh(ind,:)=min((CoordMax(ind,:)-CoordMin(ind,:))./(NbPoints-1));               
    24312430        end
    24322431    end
     
    25252524    % main projection object (uvmat display)
    25262525    list_object=get(handles.ListObject_1,'String');
    2527     if isequal(list_object,{''})%refresh list of objects if the menu is empty
     2526    if isequal(list_object,{''})||isequal(list_object,' ')%refresh list of objects if the menu is empty
    25282527        set(handles.ListObject,'Value',1)
    25292528        set(handles.ListObject,'String',{'plane'})
Note: See TracChangeset for help on using the changeset viewer.