Ignore:
Timestamp:
Apr 21, 2023, 11:01:06 AM (18 months ago)
Author:
sommeria
Message:

various updates

File:
1 edited

Legend:

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

    r1121 r1122  
    200200DataVol.Time=0; %TO UPDATE
    201201DataVol.ListVarName={'coord_x','coord_y','coord_z','A'};
    202 DataVol.VarDimName={'coord_x','coord_y','coord_z',{'coord_z','coord_y','coord_x'}};
     202DataVol.VarDimName={'coord_x','coord_y','coord_z',{'coord_y','coord_x','coord_z'}};
    203203DataVol.VarAttribute{1}.Role='coord_x';
    204204DataVol.VarAttribute{2}.Role='coord_y';
     
    257257
    258258for index_i=1:NbField_i
    259     AMerge=zeros(NbField_j,numel(DataVol.coord_y),numel(DataVol.coord_x));
     259   
    260260    for index_j=1:NbField_j
    261261        index_j
     
    268268
    269269        %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
    270         Data=cell(1,NbView);%initiate the set Data
     270       
    271271        timeread=zeros(1,NbView);
    272         for iview=1:NbView
     272%         for iview=1:NbView
    273273            %% reading input file(s)
    274             [Data{iview},tild,errormsg] = read_field(filecell{iview,index_j},FileType{iview},ParamIn{iview},frame_index{iview}(index_j));
     274            [Data,tild,errormsg] = read_field(filecell{1,index_j},FileType{1},ParamIn{1},frame_index{1}(index_j));
    275275            if ~isempty(errormsg)
    276276                disp_uvmat('ERROR',['ERROR in merge_proj/read_field/' errormsg],checkrun)
    277277                return
    278278            end
    279             ListVar=Data{iview}.ListVarName;
     279            Data.A=Data.A(1:4:end,1:4:end);% reduce the mage size
     280            ListVar=Data.ListVarName;
     281            %reduce the image size
    280282            for ilist=1:numel(ListVar)
    281                 Data{iview}.(ListVar{ilist})=double(Data{iview}.(ListVar{ilist}));% transform all fields in double before all operations
     283                Data.(ListVar{ilist})=double(Data.(ListVar{ilist}));% transform all fields in double before all operations
    282284            end
    283285            % get the time defined in the current file if not already defined from the xml file
    284             if ~isempty(time) && isfield(Data{iview},'Time')
    285                 timeread(iview)=Data{iview}.Time;
     286            if ~isempty(time) && isfield(Data,'Time')
     287                timeread(iview)=Data.Time;
    286288            end
    287             Data{iview}.ZIndex=index_j;
    288             [X,Y]=meshgrid(DataVol.coord_x,DataVol.coord_y);%grid in physical coordinates
    289             Data{iview}=proj_plane(Data{iview},XmlData{iview},X,Y); %project on the common x,y plane
     289            Data.ZIndex=index_j;
     290            [X,Y,Z]=meshgrid(DataVol.coord_x,DataVol.coord_y,DataVol.coord_z);%grid in physical coordinates
     291            %Data{iview}=proj_plane(Data{iview},XmlData{iview},X,Y); %project on the common x,y plane
     292
     293        if index_j==1
     294            AMerge=zeros(size(Data.A,1),size(Data.A,2),NbField_j);
    290295        end
    291         % merge the NbView fields only to merge views from several cameras)
    292 
    293         %     [MergeData,errormsg]=merge_field(ProjData);
    294         %     if ~isempty(errormsg)
    295         %         disp_uvmat('ERROR',errormsg,checkrun);
    296         %         return
    297         %     end
    298         AMerge(index_j,:,:)=Data{iview}.A;
     296        AMerge(:,:,index_j)=Data.A;
    299297
    300298        %%%%%%%%%%%%%%%% END LOOP FOR VOLUME SCAN %%%%%%%%%%%%%%%%
    301299    end
    302300    %interpolate on the vertical grid
    303     Z=zeros(1,NbField_j);
    304     for j_index=1:numel(DataVol.coord_y)
    305         for i_index=1:numel(DataVol.coord_x)
    306             for ZIndex=1:NbField_j
    307             Z(ZIndex)=Zpos(XmlData{iview},ZIndex,X(j_index,i_index),Y(j_index,i_index));
    308             end
    309             DataVol.A(:,j_index,i_index) = interp1(Z,AMerge(:,j_index,i_index),DataVol.coord_z);
    310         end
    311     end
     301    DataVol.A=proj_volume(AMerge,XmlData{1},X,Y,Z);
     302%     Z=zeros(1,NbField_j);
     303%     for j_index=1:numel(DataVol.coord_y)
     304%         for i_index=1:numel(DataVol.coord_x)
     305%             for ZIndex=1:NbField_j
     306%             Z(ZIndex)=Zpos(XmlData{iview},ZIndex,X(j_index,i_index),Y(j_index,i_index));
     307%             end
     308%             DataVol.A(:,j_index,i_index) = interp1(Z,AMerge(:,j_index,i_index),DataVol.coord_z);
     309%         end
     310%     end
    312311    error=struct2nc(OutputFile,DataVol)%save result file
    313312
    314 
    315     %     if index==1
    316     %         TimeData.ListGlobalAttribute={'Conventions','Project','CoordUnit','TimeUnit','ZPos','Time'};
    317     %         TimeData.Conventions='uvmat';
    318     %         TimeData.Project='2016_Circumpolar';
    319     %         TimeData.CoordUnit='cm';
    320     %         TimeData.TimeUnit='s';
    321     % %         TimeData.ZPos=ZPos;
    322     %         TimeData.ListVarName={'radius','azimuth','U','V','curl','div'};
    323     %         TimeData.VarDimName={'radius','azimuth',{'radius','azimuth'},{'radius','azimuth'}...
    324     %             {'radius','azimuth'},{'radius','azimuth'}};
    325     %         TimeData.VarAttribute{1}.Role='';
    326     %         TimeData.VarAttribute{2}.Role='';
    327     %         TimeData.VarAttribute{3}.Role='vector_x';
    328     %         TimeData.VarAttribute{4}.Role='vector_y';
    329     %         TimeData.VarAttribute{5}.Role='scalar';
    330     %         TimeData.VarAttribute{6}.Role='scalar';
    331     %
    332     %     end
    333     %
    334     %         %% append data to the netcdf file for next iterations
    335     %
    336     %
    337     %             error=struct2nc(OutputFile,TimeData);%save result file
    338     %         if isempty(error)
    339     %             disp(['output file ' OutputFile ' written'])
    340     %         else
    341     %             disp(error)
    342     %         end
    343     %             ellapsed_time=toc(tstart);
    344     %     disp(['ellapsed time since start ' num2str(ellapsed_time/60,2) ' minutes'])
    345313end
    346314
     
    426394end
    427395
     396
     397function ZIndex=XYZtoIndex(XmlData,X,Y,Z)% Z positions corresponding to X,Y positions
     398Zp=Z-XmlData.Slice.SliceCoord(1,3);
     399DZ=XmlData.Slice.SliceCoord(end,3)-XmlData.Slice.SliceCoord(1,3)/(size(XmlData.Slice.SliceCoord,1)-1);
     400if DZ~=0
     401ZIndex=(Z-XmlData.Slice.SliceCoord(1,3))/DZ+1;% Z=XmlData.SliceCoord(1,3)+(ZIndex-1)*DZ
     402end
     403% effect of angular deviation
     404SliceAngleMax=XmlData.Slice.SliceAngle(end,:)-XmlData.Slice.SliceAngle(1,:);
     405normAxe=norm(SliceAngleMax);
     406if normAxe>0 % case of angle scan
     407a=-SliceAngleMax(2)/normAxe;
     408b=-SliceAngleMax(1)/normAxe;
     409c=-a*XmlData.Slice.SliceCoord(1,1)+b*XmlData.Slice.SliceCoord(1,2);%equation of the axis ax+by+c=0
     410DNormal=norm(a*X+b*Y+c);
     411Ang=atand(Zp./DNormal);
     412ZIndex=ZIndex+Ang-norm(XmlData.Slice.SliceAngle(1,:))+1;
     413end
     414
     415%------------------------------------------------------------
     416% proj_volume: poject each image on a common grid given by coord_x and coord_y
     417function A=proj_volume(AMerge,XmlData,X,Y,Z)
     418
     419A=[]; %default output
     420
     421%% initial image coordinates
     422[npy,npx,npz]=size(AMerge);
     423xima=0.5:npx-0.5;%image coordinates of corners
     424%yima=npy-0.5:-1:0.5;
     425yima=0.5:npy-0.5;
     426zima=0.5:npz-0.5;
     427[XIMA_init,YIMA_init,ZIMA_init]=meshgrid(xima,yima,zima);%grid of initial image in px coordinates
     428
     429%% projected coordinates
     430ZIndex=XYZtoIndex(XmlData,X,Y,Z);% Z positions correspoonding to X,Y positions
     431
     432%% interpolation on the new grid
     433[XIMA,YIMA]=px_XYZ(XmlData.GeometryCalib,XmlData.Slice,X,Y,Z);% image coordinates for each point in the real
     434A=interp3(XIMA_init,YIMA_init,ZIMA_init,AMerge,XIMA,YIMA,ZIndex);
     435
     436
     437
    428438% proj_plane: poject each image on a common grid given by coord_x and coord_y
    429439function DataOut=proj_plane(DataIn,XmlData,X,Y)
Note: See TracChangeset for help on using the changeset viewer.