Changeset 670


Ignore:
Timestamp:
Jul 17, 2013, 8:01:15 AM (11 years ago)
Author:
sommeria
Message:

merge_proj corrected to combine masked fields

File:
1 edited

Legend:

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

    r668 r670  
    129129    diff_time=max(max(diff(time)));
    130130    if diff_time>0
    131         disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
     131        disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time) ': time of first series chosen in result'],checkrun)
    132132    end   
    133133end
     
    341341    return
    342342end
    343 MergeData=Data{1};%default
    344343error=0;
    345344NbView=length(Data);
     
    347346    return
    348347end
     348MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
    349349
    350350%% group the variables (fields of 'Data') in cells of variables with the same dimensions
    351351[CellInfo,NbDim,errormsg]=find_field_cells(Data{1});
     352
    352353%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
    353 % CellVarIndex=cells of variable index arrays
    354354for icell=1:length(CellInfo)
    355     if NbDim(icell)==1
    356         continue% skip field cells which are of dim 1
    357     end
    358     VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
    359 %     VarType=VarTypeCell{icell};
    360     ivar_X=CellInfo{icell}.CoordIndex(1);
    361     ivar_Y=CellInfo{icell}.CoordIndex(2);
    362 %     ivar_Y=VarType.coord_y;
    363     ivar_FF=CellInfo{icell}.VarIndex_errorflag;
    364     if isempty(ivar_X)
    365         test_grid=1;%test for input data on regular grid (e.g. image)coordinates
    366     else
    367         if length(ivar_Y)~=1
    368                 disp_uvmat('ERROR','y coordinate missing in proj_field.m',checkrun)
    369                 return
    370         end
    371         test_grid=0;
    372     end
    373     %case of input fields with unstructured coordinates
    374     if isequal(CellInfo{icell}.CoordType,'scattered')
    375         for ivar=VarIndex
    376             VarName=MergeData.ListVarName{ivar};
    377             for iview=1:NbView
    378                 MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)];
    379             end
    380         end
    381     %case of fields defined on a structured  grid
    382     else 
    383         testFF=0;
    384         for iview=2:NbView
    385             for ivar=VarIndex
    386                 VarName=MergeData.ListVarName{ivar};
    387                 if isfield(MergeData,'VarAttribute')
    388                     if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag')
    389                         testFF=1;
     355    if NbDim(icell)~=1 % skip field cells which are of dim 1
     356        switch CellInfo{icell}.CoordType
     357            case 'scattered'  %case of input fields with unstructured coordinates: just concacene data
     358                for ivar=CellInfo{icell}.VarIndex %  indices of the selected variables in the list FieldData.ListVarName
     359                    VarName=Data{1}.ListVarName{ivar};
     360                    %MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
     361                    for iview=2:NbView
     362                        MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)];
    390363                    end
    391364                end
    392                 MergeData.(VarName)=MergeData.(VarName) + Data{iview}.(VarName);
    393             end
    394         end
    395         if testFF
    396             nbaver=NbView-MergeData.FF;
    397             indgood=find(nbaver>0);
    398             for ivar=VarIndex
    399                 VarName=MergeData.ListVarName{ivar};
    400                 MergeData.(VarName)(indgood)=double(MergeData.(VarName)(indgood))./nbaver(indgood);
    401             end
    402         else
    403             for ivar=VarIndex
    404                 VarName=MergeData.ListVarName{ivar};
    405                 MergeData.(VarName)=double(MergeData.(VarName))./NbView;
    406             end   
    407         end
    408     end
    409 end
     365            case 'grid'        %case of fields defined on a structured  grid
     366                FFName='';
     367                if ~isempty(CellInfo{icell}.VarIndex_errorflag)
     368                    FFName=Data{1}.ListVarName{CellInfo{icell}.VarIndex_errorflag};% name of errorflag variable
     369                end
     370                % select good data on each view
     371                for ivar=CellInfo{icell}.VarIndex  %  indices of the selected variables in the list FieldData.ListVarName
     372                    VarName=Data{1}.ListVarName{ivar};
     373                    for iview=1:NbView
     374                        if isempty(FFName)
     375                            check_bad=isnan(Data{iview}.(VarName));%=0 for NaN data values, 1 else
     376                        else
     377                            check_bad=isnan(Data{iview}.(VarName)) | Data{iview}.(FFName)~=0;%=0 for NaN or error flagged data values, 1 else
     378                        end
     379                        Data{iview}.(VarName)(check_bad)=0; %set to zero NaN or masked data
     380                        if iview==1
     381                            MergeData.(VarName)=Data{1}.(VarName);% correct the field of MergeData
     382                            NbAver=~check_bad;% initiate NbAver: the nbre of good data for each point
     383                        else
     384                            MergeData.(VarName)=MergeData.(VarName) + Data{iview}.(VarName);%add data
     385                            NbAver=NbAver + ~check_bad;% add 1 for good data, 0 else
     386                        end
     387                    end
     388                    MergeData.(VarName)(NbAver~=0)=MergeData.(VarName)(NbAver~=0)./NbAver(NbAver~=0);% take average of defined data at each point
     389                end
     390        end
     391        if isempty(FFName)
     392            FFName='FF';
     393        end
     394        MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data
     395        MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data
     396    end
     397end
     398
    410399
    411400   
Note: See TracChangeset for help on using the changeset viewer.