Changeset 867 for trunk/src/series


Ignore:
Timestamp:
Feb 12, 2015, 9:31:47 PM (10 years ago)
Author:
sommeria
Message:

python option added in series and bug corrections

Location:
trunk/src/series
Files:
1 added
3 edited

Legend:

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

    r810 r867  
    136136for iview=1:NbView
    137137    if ~exist(filecell{iview,1}','file')
    138         msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
     138        disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
    139139        return
    140140    end
     
    155155    diff_time=max(max(diff(time)));
    156156    if diff_time>0
    157         msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)])
     157        disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
    158158    end   
    159159end
     
    176176    FileExtOut='.nc';% write result as .nc files for netcdf inputs
    177177else
    178     msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
     178    disp_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
    179179    return
    180180end
    181181if NbView==2 && ~isequal(CheckImage{1},CheckImage{2})
    182     msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
     182    disp_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun)
    183183    return
    184184end
     
    216216% index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice
    217217nbfiles=0;
    218 nbmissing=0;
     218% nbmissing=0;
    219219
    220220%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
     
    275275            [Field,errormsg]=proj_field(Field,Param.ProjObject);
    276276            if ~isempty(errormsg)
    277                 msgbox_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg])
     277                disp_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg],checkrun)
    278278                return
    279279            end
     
    289289            DataOut=Field;%default
    290290            DataOut.Conventions='uvmat'; %suppress Conventions='uvmat/civdata' for civ input files
    291             for ivar=1:length(Field.ListVarName)
     291            errorvar=zeros(numel(Field.ListVarName));%index of errorflag associated to each variable
     292            for ivar=1:numel(Field.ListVarName)
    292293                VarName=Field.ListVarName{ivar};
    293                 DataOut.(VarName)=double(DataOut.(VarName));
    294             end
    295         else   %current field
    296             for ivar=1:length(Field.ListVarName)
    297                 VarName=Field.ListVarName{ivar};
    298                 sizmean=size(DataOut.(VarName));
    299                 siz=size(Field.(VarName));
    300                 if ~isequal(DataOut.(VarName),0)&& ~isequal(siz,sizmean)
    301                     disp_uvmat('ERROR',['unequal size of input field ' VarName ', need to project  on a grid'],checkrun)
    302                     return
     294                DataOut.(VarName)=zeros(size(DataOut.(VarName)));% initiate each field to zero
     295                NbData.(VarName)=zeros(size(DataOut.(VarName)));% initiate the nbre of good data to zero
     296                for iivar=1:length(Field.VarAttribute)
     297                    if isequal(Field.VarDimName{iivar},Field.VarDimName{ivar})&& isfield(Field.VarAttribute{iivar},'Role')...
     298                            && strcmp(Field.VarAttribute{iivar}.Role,'errorflag')
     299                        errorvar(ivar)=iivar; % index of the errorflag variable corresponding to ivar
     300                    end
     301                end
     302            end
     303            DataOut.ListVarName(errorvar(errorvar~=0))=[]; %remove errorflag from result
     304            DataOut.VarDimName(errorvar(errorvar~=0))=[]; %remove errorflag from result
     305            DataOut.VarAttribute(errorvar(errorvar~=0))=[]; %remove errorflag from result
     306        end   %current field
     307        for ivar=1:length(DataOut.ListVarName)
     308            VarName=Field.ListVarName{ivar};
     309            sizmean=size(DataOut.(VarName));
     310            siz=size(Field.(VarName));
     311            if ~isequal(DataOut.(VarName),0)&& ~isequal(siz,sizmean)
     312                disp_uvmat('ERROR',['unequal size of input field ' VarName ', need to project  on a grid'],checkrun)
     313                return
     314            else
     315                if errorvar(ivar)==0
     316                    check_bad=isnan(Field.(VarName));%=0 for NaN data values, 1 else
    303317                else
    304                     DataOut.(VarName)=DataOut.(VarName)+ double(Field.(VarName)); % update the sum
     318                    check_bad=isnan(Field.(VarName)) | Field.(Field.ListVarName{errorvar(ivar)})~=0;%=0 for NaN or error flagged data values, 1 else
    305319                end
     320                Field.(VarName)(check_bad)=0; %set to zero NaN or data marked by error flag
     321                DataOut.(VarName)=DataOut.(VarName)+ double(Field.(VarName)); % update the sum
     322                NbData.(VarName)=NbData.(VarName)+ ~check_bad;% records the number of data for each point
    306323            end
    307324        end
     
    315332for ivar=1:length(Field.ListVarName)
    316333    VarName=Field.ListVarName{ivar};
    317     DataOut.(VarName)=DataOut.(VarName)/nbfiles; % normalize the mean
    318 end
     334    DataOut.(VarName)=DataOut.(VarName)./NbData.(VarName); % normalize the mean
     335end
     336nbmissing=NbField-nbfiles;
    319337if nbmissing~=0
    320     msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])
     338    disp_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'],checkrun)
    321339end
    322340if isempty(time) % time is read from files
  • trunk/src/series/merge_proj.m

    r857 r867  
    196196    FileExtOut='.nc'; %netcdf output
    197197end
    198 NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series
     198%NomTypeOut=NomType;% output file index will indicate the first and last ref index in the series
    199199RootFileOut=RootFile{1};
    200200for iview=2:NbView
     
    403403end
    404404errormsg='';
    405 MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
     405MergeData=Data{1};% merged field= first field by default, reproduces the global attributes of the first field
    406406NbView=length(Data);
    407 if NbView==1
    408     return
     407if NbView==1% if there is only one field, just reproduce it in MergeData
     408    return 
    409409end
    410410
     
    419419    if NbDim(icell)~=1 % skip field cells which are of dim 1
    420420        switch CellInfo{icell}.CoordType
    421             case 'scattered'  %case of input fields with unstructured coordinates: just concacene data
     421            case 'scattered'  %case of input fields with unstructured coordinates: just concatene data
    422422                for ivar=CellInfo{icell}.VarIndex %  indices of the selected variables in the list FieldData.ListVarName
    423423                    VarName=Data{1}.ListVarName{ivar};
    424                     %MergeData=Data{1};% merged field= first field by default, reproduces the glabal attributes of the first field
    425424                    for iview=2:NbView
    426425                        MergeData.(VarName)=[MergeData.(VarName); Data{iview}.(VarName)];
     
    431430                if isfield(CellInfo{icell},'VarIndex_errorflag') && ~isempty(CellInfo{icell}.VarIndex_errorflag)
    432431                    FFName=Data{1}.ListVarName{CellInfo{icell}.VarIndex_errorflag};% name of errorflag variable
     432                    MergeData.ListVarName(CellInfo{icell}.VarIndex_errorflag)=[];%remove error flag variable in MergeData (will use NaN instead)
     433                    MergeData.VarDimName(CellInfo{icell}.VarIndex_errorflag)=[];
     434                    MergeData.VarAttribute(CellInfo{icell}.VarIndex_errorflag)=[];
    433435                end
    434436                % select good data on each view
     
    441443                            check_bad=isnan(Data{iview}.(VarName)) | Data{iview}.(FFName)~=0;%=0 for NaN or error flagged data values, 1 else
    442444                        end
    443                         Data{iview}.(VarName)(check_bad)=0; %set to zero NaN or masked data
     445                        Data{iview}.(VarName)(check_bad)=0; %set to zero NaN or data marked by error flag
    444446                        if iview==1
    445                             MergeData.(VarName)=Data{1}.(VarName);% correct the field of MergeData
     447                            %MergeData.(VarName)=Data{1}.(VarName);% initiate MergeData with the first field
    446448                            NbAver=~check_bad;% initiate NbAver: the nbre of good data for each point
    447449                        elseif size(Data{iview}.(VarName))~=size(MergeData.(VarName))
    448450                            errormsg='sizes of the input matrices do not agree, need to interpolate on a common grid using a projection object';
    449451                            return
    450                         else     
    451                          
    452                             MergeData.(VarName)=MergeData.(VarName) + Data{iview}.(VarName);%add data
     452                        else                             
     453                            MergeData.(VarName)=MergeData.(VarName) +double(Data{iview}.(VarName));%add data
    453454                            NbAver=NbAver + ~check_bad;% add 1 for good data, 0 else
    454455                        end
    455456                    end
    456457                    MergeData.(VarName)(NbAver~=0)=MergeData.(VarName)(NbAver~=0)./NbAver(NbAver~=0);% take average of defined data at each point
     458                    MergeData.(VarName)(NbAver==0)=NaN;% set to NaN the points with no good data
    457459                end
    458460        end
    459         if isempty(FFName)
    460             FFName='FF';
    461         end
    462         MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data
    463         MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data
     461%         if isempty(FFName)
     462%             FFName='FF';
     463%         end
     464%         MergeData.(FFName)(NbAver~=0)=0;% flag to 1 undefined summed data
     465%         MergeData.(FFName)(NbAver==0)=1;% flag to 1 undefined summed data
    464466    end
    465467end
  • trunk/src/series/time_series.m

    r810 r867  
    207207%% Set field names and velocity types
    208208InputFields{1}=[];%default (case of images)
     209if nbview==2
     210    InputFields{2}=[];%default (case of images)
     211end
    209212if isfield(Param,'InputFields')
    210213    InputFields{1}=Param.InputFields;
    211 end
    212 if nbview==2
    213     InputFields{2}=[];%default (case of images)
    214     if isfield(Param,'InputFields')
    215         InputFields{2}=Param.InputFields{1};%default
     214    if nbview==2
     215        InputFields{2}=Param.InputFields;%default
    216216        if isfield(Param.InputFields,'FieldName_1')
    217217            InputFields{2}.FieldName=Param.InputFields.FieldName_1;
Note: See TracChangeset for help on using the changeset viewer.