Changeset 871 for trunk/src/proj_field.m


Ignore:
Timestamp:
Feb 16, 2015, 12:15:23 AM (6 years ago)
Author:
sommeria
Message:

histo improved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/proj_field.m

    r869 r871  
    11%'proj_field': projects the field on a projection object
    22%--------------------------------------------------------------------------
    3 %  function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
     3%  function [ProjData,errormsg]=proj_field(FieldData,ObjectData,VarMesh)
    44%
    55% OUTPUT:
     
    8282%=======================================================================
    8383
    84 function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
     84function [ProjData,errormsg]=proj_field(FieldData,ObjectData,VarMesh)
    8585errormsg='';%default
    8686ProjData=[];
     
    110110    case {'polygon','rectangle','ellipse'}
    111111        if isequal(ObjectData.ProjMode,'inside')||isequal(ObjectData.ProjMode,'outside')
    112             [ProjData,errormsg] = proj_patch(FieldData,ObjectData);
     112            if ~exist('VarMesh','var')
     113                VarMesh=[];
     114            end
     115            [ProjData,errormsg] = proj_patch(FieldData,ObjectData,VarMesh);
    113116        else
    114117            [ProjData,errormsg] = proj_line(FieldData,ObjectData);
     
    342345%-----------------------------------------------------------------
    343346%project in a patch
    344 function  [ProjData,errormsg]=proj_patch(FieldData,ObjectData)%%
     347function  [ProjData,errormsg]=proj_patch(FieldData,ObjectData,VarMesh)%%
    345348%-------------------------------------------------------------------
    346349[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
     
    365368
    366369CoordMesh=zeros(1,numel(FieldData.ListVarName));
     370%VarMesh=nan(1,numel(FieldData.ListVarName));
     371% MinValue=nan(1,numel(FieldData.ListVarName));
     372% MaxValue=nan(1,numel(FieldData.ListVarName));
    367373if isfield (FieldData,'VarAttribute')
    368374    for iattr=1:length(FieldData.VarAttribute)%initialization of variable attribute values
     
    373379            CoordMesh(iattr)=FieldData.VarAttribute{iattr}.CoordMesh;
    374380        end
     381%         if isfield(FieldData.VarAttribute{iattr},'Mesh')
     382%             VarMesh(iattr)=FieldData.VarAttribute{iattr}.Mesh;
     383%         end
     384%         if isfield(FieldData.VarAttribute{iattr},'MinValue')
     385%             VarMesh(iattr)=FieldData.VarAttribute{iattr}.MinValue;
     386%         end
     387%         if isfield(FieldData.VarAttribute{iattr},'MaxValue')
     388%             VarMesh(iattr)=FieldData.VarAttribute{iattr}.MaxValue;
     389%         end
    375390    end
    376391end
     
    496511    end
    497512    indsel=find(testin);
     513    nbvar=0;
     514    VarSize=zeros(size(VarIndex));
    498515    for ivar=VarIndex
    499516        VarName=FieldData.ListVarName{ivar};
    500         ProjData.([VarName 'Mean'])=mean(double(FieldData.(VarName)(indsel,:))); % take the mean in the selected region, for each color component
     517        ProjData.([VarName 'Mean'])=mean(double(FieldData.(VarName)(indsel,:))); % take the mean in the selected region, for each co
    501518        ProjData.([VarName 'Min'])=min(double(FieldData.(VarName)(indsel,:))); % take the min in the selected region , for each color component
    502         ProjData.([VarName 'Max'])=max(double(FieldData.(VarName)(indsel,:))); % take the max in the selected region , for each color component
    503         if isequal(CoordMesh(ivar),0)
    504             [ProjData.([VarName 'Histo']),ProjData.(VarName)]=hist(double(FieldData.(VarName)(indsel,:,:)),100); % default histogram with 100 bins
     519        ProjData.([VarName 'Max'])=max(double(FieldData.(VarName)(indsel,:))); % take the max in the selected region , for each color co
     520        nbvar=nbvar+1;
     521        VarSize(nbvar)=mean((ProjData.([VarName 'Max'])-ProjData.([VarName 'Min']))/100);
     522    end
     523    if  isempty(VarMesh) || isnan(VarMesh) % mesh not specified as input, estimate from the bounds
     524        VarMesh=mean(VarSize);
     525        ord=10^(floor(log10(VarMesh)));%order of magnitude
     526        if VarMesh/ord >=5
     527            VarMesh=5*ord;
     528        elseif VarMesh/ord >=2
     529            VarMesh=2*ord;
    505530        else
    506             ProjData.(VarName)=ProjData.([VarName 'Min'])+CoordMesh(ivar)/2:CoordMesh(ivar):ProjData.([VarName 'Max']); % list of bin values
    507             ProjData.([VarName 'Histo'])=hist(double(FieldData.(VarName)(indsel,:)),ProjData.(VarName)); % histogram at predefined bin positions
    508         end
     531            VarMesh=ord;
     532        end
     533    end
     534    for ivar=VarIndex
     535        VarName=FieldData.ListVarName{ivar};
     536        LowBound=VarMesh*ceil(ProjData.([VarName 'Min'])/VarMesh);
     537        UpperBound=VarMesh*floor(ProjData.([VarName 'Max'])/VarMesh);
     538        ProjData.(VarName)=LowBound:VarMesh:UpperBound; % list of bin values
     539        ProjData.([VarName 'Histo'])=hist(double(FieldData.(VarName)(indsel,:)),ProjData.(VarName)); % histogram at predefined bin positions
    509540        ProjData.ListVarName=[ProjData.ListVarName {VarName} {[VarName 'Histo']} {[VarName 'Mean']} {[VarName 'Min']} {[VarName 'Max']}];
    510541        if test_Amat && testcolor
     
    513544            ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName} {'one'} {'one'} {'one'}];
    514545        end
     546        VarAttribute_var=[];
    515547        if isfield(FieldData,'VarAttribute')&& numel(FieldData.VarAttribute)>=ivar
    516             ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute{ivar} {[]} {[]} {[]} {[]}];
    517         end
     548            VarAttribute_var=FieldData.VarAttribute{ivar};
     549        end
     550      %  VarAttribute_var.Role='coord_x';% the variable is now used as an absissa
     551        VarAttribute_histo.Role='histo';
     552        ProjData.VarAttribute=[ProjData.VarAttribute {VarAttribute_var} {VarAttribute_histo} {[]} {[]} {[]}];
    518553    end
    519554end
Note: See TracChangeset for help on using the changeset viewer.