[204] | 1 | %'proj_field': projects the field on a projection object
|
---|
| 2 | %--------------------------------------------------------------------------
|
---|
| 3 | % function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
|
---|
| 4 | %
|
---|
| 5 | % OUTPUT:
|
---|
| 6 | % ProjData structure containing the fields of the input field FieldData,
|
---|
| 7 | % transmitted or projected on the object, plus the additional fields
|
---|
| 8 | % .UMax, .UMin, .VMax, .VMin: min and max of velocity components in a domain
|
---|
| 9 | % .UMean,VMean: mean of the velocity components in a domain
|
---|
| 10 | % .AMin, AMax: min and max of a scalar
|
---|
| 11 | % .AMean: mean of a scalar in a domain
|
---|
| 12 | % .NbPix;
|
---|
| 13 | % .DimName= names of the matrix dimensions (matlab cell)
|
---|
| 14 | % .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}];
|
---|
| 15 | % .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName;
|
---|
| 16 | %
|
---|
| 17 | %INPUT
|
---|
| 18 | % ObjectData: structure characterizing the projection object
|
---|
| 19 | % .Style : style of projection object
|
---|
| 20 | % .ProjMode=type of projection ;
|
---|
| 21 | % .CoordType: 'px' or 'phys' type of coordinates defining the object position
|
---|
| 22 | % .Phi angle of rotation (=0 by default)
|
---|
| 23 | % .ProjAngle=angle of projection;
|
---|
| 24 | % .DX,.DY,.DZ=increments along each coordinate
|
---|
| 25 | % .Coord(nbpoints,3): set of coordinates defining the object position;
|
---|
| 26 |
|
---|
| 27 | %FieldData: data of the field to be projected on the projection object, with optional fields
|
---|
| 28 | % .Txt: error message, transmitted to the projection
|
---|
| 29 | % .CoordType: 'px' or 'phys' type of coordinates of the field, must be the same as for the projection object, transmitted
|
---|
| 30 | % .Mesh: typical distance between data points (used for mouse action or display), transmitted
|
---|
| 31 | % .CoordUnit, .TimeUnit, .dt: transmitted
|
---|
| 32 | % standardised description of fields, nc-formated Matlab structure with fields:
|
---|
| 33 | % .ListGlobalAttribute: cell listing the names of the global attributes
|
---|
| 34 | % .Att_1,Att_2... : values of the global attributes
|
---|
| 35 | % .ListVarName: cell listing the names of the variables
|
---|
| 36 | % .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
|
---|
| 37 | % .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
|
---|
| 38 | % The variables are grouped in 'fields', made of a set of variables with common dimensions (using the function find_field_indices)
|
---|
| 39 | % The variable attribute 'Role' is used to define the role for plotting:
|
---|
| 40 | % Role = 'scalar': (default) represents a scalar field
|
---|
| 41 | % = 'coord': represents a set of unstructured coordinates, whose
|
---|
| 42 | % space dimension is given by the last array dimension (called 'NbDim').
|
---|
| 43 | % = 'coord_x', 'coord_y', 'coord_z': represents a separate set of
|
---|
| 44 | % unstructured coordinate x, y or z
|
---|
| 45 | % = 'vector': represents a vector field whose number of components
|
---|
| 46 | % is given by the last dimension (called 'NbDim')
|
---|
| 47 | % = 'vector_x', 'vector_y', 'vector_z' :represents the x, y or z component of a vector
|
---|
| 48 | % = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
|
---|
| 49 | % = 'errorflag': provides an error flag marking false data,
|
---|
| 50 | % default=0, no error. Different non zero values can represent different criteria of elimination.
|
---|
| 51 | %
|
---|
| 52 | % Default role of variables (by name)
|
---|
| 53 | % vector field:
|
---|
| 54 | % .X,.Y: position of the velocity vectors, projected on the object
|
---|
| 55 | % .U, .V, .W: velocity components, projected on the object
|
---|
| 56 | % .C, .CName: scalar associated to the vector
|
---|
| 57 | % .F : equivalent to 'warnflag'
|
---|
| 58 | % .FF: equivalent to 'errorflag'
|
---|
| 59 | % scalar field or image:
|
---|
| 60 | % .AName: name of a scalar (to be calculated from velocity fields after projection), transmitted
|
---|
| 61 | % .A: scalar, projected on the object
|
---|
| 62 | % .AX, .AY: positions for the scalar
|
---|
| 63 | % case of a structured grid: A is a dim 2 matrix and .AX=[first last] (length 2 vector) represents the first and last abscissa of the grid
|
---|
| 64 | % case of an unstructured scalar: A is a vector, AX and AY the corresponding coordinates
|
---|
| 65 | %
|
---|
| 66 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 67 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
|
---|
| 68 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 69 | % This file is part of the toolbox UVMAT.
|
---|
| 70 | %
|
---|
| 71 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 72 | % it under the terms of the GNU General Public License as published by
|
---|
| 73 | % the Free Software Foundation; either version 2 of the License, or
|
---|
| 74 | % (at your option) any later version.
|
---|
| 75 | %
|
---|
| 76 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 77 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 78 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 79 | % GNU General Public License (file UVMAT/COPYING.txt) for more details.
|
---|
| 80 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 81 |
|
---|
| 82 | function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
|
---|
[206] | 83 | errormsg='';%default
|
---|
| 84 | %% case of no projection (object is used only as graph display)
|
---|
[204] | 85 | if isfield(ObjectData,'ProjMode') && (isequal(ObjectData.ProjMode,'none')||isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'))
|
---|
| 86 | ProjData=[];
|
---|
| 87 | return
|
---|
| 88 | end
|
---|
[206] | 89 |
|
---|
| 90 | %% in the absence of object Style or projection mode, or object coordinaes, the input field is just tranfered without change
|
---|
[204] | 91 | if ~isfield(ObjectData,'Style')||~isfield(ObjectData,'ProjMode')
|
---|
| 92 | ProjData=FieldData;
|
---|
| 93 | return
|
---|
| 94 | end
|
---|
| 95 | if ~isfield(ObjectData,'Coord')
|
---|
| 96 | if strcmp(ObjectData.Style,'plane')
|
---|
| 97 | ObjectData.Coord=[0 0 0];%default
|
---|
| 98 | else
|
---|
| 99 | ProjData=FieldData;
|
---|
| 100 | return
|
---|
| 101 | end
|
---|
| 102 | end
|
---|
| 103 |
|
---|
| 104 | %% OBSOLETE
|
---|
| 105 | if isfield(ObjectData,'XMax') && ~isempty(ObjectData.XMax)
|
---|
| 106 | ObjectData.RangeX(1)=ObjectData.XMax;
|
---|
| 107 | end
|
---|
| 108 | if isfield(ObjectData,'XMin') && ~isempty(ObjectData.XMin)
|
---|
| 109 | ObjectData.RangeX(2)=ObjectData.XMin;
|
---|
| 110 | end
|
---|
| 111 | if isfield(ObjectData,'YMax') && ~isempty(ObjectData.YMax)
|
---|
| 112 | ObjectData.RangeY(1)=ObjectData.YMax;
|
---|
| 113 | end
|
---|
| 114 | if isfield(ObjectData,'YMin') && ~isempty(ObjectData.YMin)
|
---|
| 115 | ObjectData.RangeY(2)=ObjectData.YMin;
|
---|
| 116 | end
|
---|
| 117 | if isfield(ObjectData,'ZMax') && ~isempty(ObjectData.ZMax)
|
---|
| 118 | ObjectData.RangeZ(1)=ObjectData.ZMax;
|
---|
| 119 | end
|
---|
| 120 | if isfield(ObjectData,'ZMin') && ~isempty(ObjectData.ZMin)
|
---|
| 121 | ObjectData.RangeZ(2)=ObjectData.ZMin;
|
---|
| 122 | end
|
---|
| 123 | %%%%%%%%%%
|
---|
| 124 |
|
---|
| 125 | %% apply projection depending on the object style
|
---|
| 126 | switch ObjectData.Style
|
---|
| 127 | case 'points'
|
---|
| 128 | [ProjData,errormsg]=proj_points(FieldData,ObjectData);
|
---|
| 129 | case {'line','polyline'}
|
---|
| 130 | [ProjData,errormsg] = proj_line(FieldData,ObjectData);
|
---|
| 131 | case {'polygon','rectangle','ellipse'}
|
---|
| 132 | if isequal(ObjectData.ProjMode,'inside')||isequal(ObjectData.ProjMode,'outside')
|
---|
| 133 | [ProjData,errormsg] = proj_patch(FieldData,ObjectData);
|
---|
| 134 | else
|
---|
| 135 | [ProjData,errormsg] = proj_line(FieldData,ObjectData);
|
---|
| 136 | end
|
---|
| 137 | case 'plane'
|
---|
| 138 | [ProjData,errormsg] = proj_plane(FieldData,ObjectData);
|
---|
| 139 | case 'volume'
|
---|
| 140 | [ProjData,errormsg] = proj_volume(FieldData,ObjectData);
|
---|
| 141 | end
|
---|
| 142 |
|
---|
| 143 | %-----------------------------------------------------------------
|
---|
| 144 | %project on a set of points
|
---|
| 145 | function [ProjData,errormsg]=proj_points(FieldData,ObjectData)%%
|
---|
| 146 | %-------------------------------------------------------------------
|
---|
| 147 |
|
---|
| 148 | siz=size(ObjectData.Coord);
|
---|
| 149 | width=0;
|
---|
| 150 | if isfield(ObjectData,'Range')
|
---|
| 151 | width=ObjectData.Range(1,2);
|
---|
| 152 | end
|
---|
| 153 | if isfield(ObjectData,'RangeX')&&~isempty(ObjectData.RangeX)
|
---|
| 154 | width=max(ObjectData.RangeX);
|
---|
| 155 | end
|
---|
| 156 | if isfield(ObjectData,'RangeY')&&~isempty(ObjectData.RangeY)
|
---|
| 157 | width=max(width,max(ObjectData.RangeY));
|
---|
| 158 | end
|
---|
| 159 | if isfield(ObjectData,'RangeZ')&&~isempty(ObjectData.RangeZ)
|
---|
| 160 | width=max(width,max(ObjectData.RangeZ));
|
---|
| 161 | end
|
---|
| 162 | if isequal(ObjectData.ProjMode,'projection')
|
---|
| 163 | if width==0
|
---|
| 164 | errormsg='projection range around points needed';
|
---|
| 165 | return
|
---|
| 166 | end
|
---|
| 167 | elseif ~isequal(ObjectData.ProjMode,'interp')
|
---|
| 168 | errormsg=(['ProjMode option ' ObjectData.ProjMode ' not available in proj_field']);
|
---|
| 169 | return
|
---|
| 170 | end
|
---|
| 171 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
| 172 | ProjData.NbDim=0;
|
---|
| 173 | %ProjData.ListDimName= {'nb_points'};
|
---|
| 174 | %ProjData.DimValue=siz(1); %nbre of projection points
|
---|
| 175 |
|
---|
| 176 |
|
---|
| 177 | % idimvar=0;
|
---|
| 178 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 179 | if ~isempty(errormsg)
|
---|
| 180 | errormsg=['error in proj_field/proj_points:' errormsg];
|
---|
| 181 | return
|
---|
| 182 | end
|
---|
| 183 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
| 184 | % CellVarIndex=cells of variable index arrays
|
---|
| 185 | % ivar_new=0; % index of the current variable in the projected field
|
---|
| 186 | % icoord=0;
|
---|
| 187 | for icell=1:length(CellVarIndex)
|
---|
| 188 | if NbDim(icell)==1
|
---|
| 189 | continue
|
---|
| 190 | end
|
---|
| 191 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 192 | VarType=VarTypeCell{icell};
|
---|
| 193 | ivar_X=VarType.coord_x;
|
---|
| 194 | ivar_Y=VarType.coord_y;
|
---|
| 195 | ivar_Z=VarType.coord_z;
|
---|
| 196 | % ivar_U=VarType.vector_x;
|
---|
| 197 | % ivar_V=VarType.vector_y;
|
---|
| 198 | % ivar_W=VarType.vector_z;
|
---|
| 199 | % ivar_C=VarType.scalar ;
|
---|
| 200 | ivar_Anc=VarType.ancillary;
|
---|
| 201 | % test_anc=zeros(size(VarIndex));
|
---|
| 202 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
| 203 | ivar_F=VarType.warnflag;
|
---|
| 204 | ivar_FF=VarType.errorflag;
|
---|
| 205 | VarIndex([ivar_X ivar_Y ivar_Z ivar_Anc ivar_F ivar_FF])=[];% not projected variables removed frlom list
|
---|
| 206 | if isempty(ivar_X)
|
---|
| 207 | test_grid=1;%test for input data on regular grid (e.g. image)coordinates
|
---|
| 208 |
|
---|
| 209 | else
|
---|
[213] | 210 | if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1
|
---|
[204] | 211 | errormsg='multiple coordinate input in proj_field.m';
|
---|
| 212 | return
|
---|
| 213 | end
|
---|
| 214 | if length(ivar_Y)~=1
|
---|
| 215 | errormsg='y coordinate not defined in proj_field.m';
|
---|
| 216 | return
|
---|
| 217 | end
|
---|
| 218 | test_grid=0;
|
---|
| 219 | end
|
---|
| 220 | ProjData.ListVarName={'Y','X','NbVal'};
|
---|
| 221 | ProjData.VarDimName={'nb_points','nb_points','nb_points'};
|
---|
| 222 | ProjData.VarAttribute{1}.Role='ancillary';
|
---|
| 223 | ProjData.VarAttribute{2}.Role='ancillary';
|
---|
| 224 | ProjData.VarAttribute{3}.Role='ancillary';
|
---|
| 225 | for ivar=VarIndex
|
---|
| 226 | VarName=FieldData.ListVarName{ivar};
|
---|
| 227 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
| 228 | ProjData.VarDimName=[ProjData.VarDimName {'nb_points'}];
|
---|
| 229 | end
|
---|
| 230 | if ~test_grid
|
---|
| 231 | eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';'])
|
---|
| 232 | eval(['coord_y=FieldData.' FieldData.ListVarName{ivar_Y} ';'])
|
---|
| 233 | test3D=0;% TEST 3D CASE : NOT COMPLETED , 3D CASE : NOT COMPLETED
|
---|
| 234 | if length(ivar_Z)==1
|
---|
| 235 | eval(['coord_z=FieldData.' FieldData.ListVarName{ivar_Z} ';'])
|
---|
| 236 | test3D=1;
|
---|
| 237 | end
|
---|
[213] | 238 | if length(ivar_F)>1 || length(ivar_FF)>1
|
---|
[204] | 239 | msgbox_uvmat('ERROR','multiple flag input in proj_field.m')
|
---|
| 240 | return
|
---|
| 241 | end
|
---|
| 242 | for ipoint=1:siz(1)
|
---|
| 243 | Xpoint=ObjectData.Coord(ipoint,:);
|
---|
| 244 | distX=coord_x-Xpoint(1);
|
---|
| 245 | distY=coord_y-Xpoint(2);
|
---|
| 246 | dist=distX.*distX+distY.*distY;
|
---|
| 247 | indsel=find(dist<width*width);
|
---|
| 248 | ProjData.X(ipoint,1)=Xpoint(1);
|
---|
| 249 | ProjData.Y(ipoint,1)=Xpoint(2);
|
---|
| 250 | if isequal(length(ivar_FF),1)
|
---|
| 251 | FFName=FieldData.ListVarName{ivar_FF};
|
---|
| 252 | eval(['FF=FieldData.' FFName '(indsel);'])
|
---|
[215] | 253 | %ind_indsel=find(~FF);
|
---|
| 254 | indsel=indsel(~FF);
|
---|
[204] | 255 | end
|
---|
| 256 | ProjData.NbVal(ipoint,1)=length(indsel);
|
---|
| 257 | for ivar=VarIndex
|
---|
| 258 | VarName=FieldData.ListVarName{ivar};
|
---|
| 259 | if isempty(indsel)
|
---|
| 260 | eval(['ProjData.' VarName '(ipoint,1)=NaN;'])
|
---|
| 261 | else
|
---|
| 262 | eval(['Var=FieldData.' VarName '(indsel);'])
|
---|
| 263 | eval(['ProjData.' VarName '(ipoint,1)=mean(Var);'])
|
---|
| 264 | if isequal(ObjectData.ProjMode,'interp')
|
---|
| 265 | eval(['ProjData.' VarName '(ipoint,1)=griddata_uvmat(coord_x(indsel),coord_y(indsel),Var,Xpoint(1),Xpoint(2)))';])
|
---|
| 266 | end
|
---|
| 267 | end
|
---|
| 268 | end
|
---|
| 269 | end
|
---|
| 270 | else
|
---|
| 271 | %DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
|
---|
| 272 | %case of structured coordinates
|
---|
| 273 | if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
|
---|
| 274 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
| 275 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
| 276 | eval(['AX=FieldData.' AXName ';']);% set of x positions
|
---|
| 277 | eval(['AY=FieldData.' AYName ';']);% set of y positions
|
---|
| 278 | AName=FieldData.ListVarName{VarIndex(1)};
|
---|
| 279 | eval(['A=FieldData.' AName ';']);% scalar
|
---|
| 280 | npxy=size(A);
|
---|
| 281 |
|
---|
| 282 | % % nbcolor=1; %default
|
---|
| 283 | % for idim=1:length(ListDimName)
|
---|
| 284 | % DimName=ListDimName{idim};
|
---|
| 285 | % if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
|
---|
| 286 | % nbcolor=npxy(idim);
|
---|
| 287 | % DimIndices(idim)=[];
|
---|
| 288 | % npxy(idim)=[];
|
---|
| 289 | % end
|
---|
| 290 | % if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
|
---|
| 291 | % DimIndices(idim)=[];
|
---|
| 292 | % npxy(idim)=[];
|
---|
| 293 | % end
|
---|
| 294 | % end
|
---|
| 295 | ind_1=find(npxy==1);
|
---|
| 296 | %DimIndices(ind_1)=[]; %suppress singleton dimensions
|
---|
| 297 | % indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
|
---|
| 298 | %NbDim=length(DimIndices)%number of space dimensions
|
---|
| 299 | NbDim=numel(VarType.coord);
|
---|
| 300 | Coord_z=[];
|
---|
| 301 | Coord_y=[];
|
---|
| 302 | Coord_x=[];
|
---|
| 303 | for idim=1:NbDim %loop on space dimensions
|
---|
| 304 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
| 305 | test_coord(idim)=0;%test for defined coordinates, =0 by default
|
---|
| 306 | %ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
|
---|
| 307 | ivar=VarType.coord(idim);
|
---|
| 308 | % if ~isequal(ivar,0)% a variable corresponds to the current dimension
|
---|
| 309 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
|
---|
| 310 | if numel(Coord{idim})==2
|
---|
| 311 | DCoord_min(idim)= (Coord{idim}(2)-Coord{idim}(1))/(npxy(idim)-1);
|
---|
| 312 | else
|
---|
| 313 | DCoord=diff(Coord{idim});
|
---|
| 314 | DCoord_min(idim)=min(DCoord);
|
---|
| 315 | DCoord_max=max(DCoord);
|
---|
| 316 | test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
| 317 | test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
|
---|
| 318 | if ~isequal(test_direct(idim),test_direct_min)
|
---|
| 319 | errormsg=['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'];
|
---|
| 320 | return
|
---|
| 321 | end
|
---|
| 322 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
| 323 | test_coord(idim)=1;
|
---|
| 324 | end
|
---|
| 325 | % else % no variable associated with the first dimension, look fo variable attributes Coord_1, _2 or _3
|
---|
| 326 | % Coord_i_str=['Coord_' num2str(idim)];
|
---|
| 327 | % DCoord_min(idim)=1;%default
|
---|
| 328 | % Coord{idim}=[0.5 npxy(idim)];
|
---|
| 329 | % test_direct(idim)=1;
|
---|
| 330 | % end
|
---|
| 331 | end
|
---|
| 332 | DX=DCoord_min(2);
|
---|
| 333 | DY=DCoord_min(1);
|
---|
| 334 | for ipoint=1:siz(1)
|
---|
| 335 | xwidth=width/(abs(DX));
|
---|
| 336 | ywidth=width/(abs(DY));
|
---|
| 337 | i_min=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5-xwidth); %minimum index of the selected region
|
---|
| 338 | i_min=max(1,i_min);%restrict to field limit
|
---|
| 339 | i_plus=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5+xwidth);
|
---|
| 340 | i_plus=min(npxy(2),i_plus); %restrict to field limit
|
---|
| 341 | j_min=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY-ywidth+0.5);
|
---|
| 342 | j_min=max(1,j_min);
|
---|
| 343 | j_plus=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY+ywidth+0.5);
|
---|
| 344 | j_plus=min(npxy(1),j_plus);
|
---|
| 345 | ProjData.X(ipoint,1)=ObjectData.Coord(ipoint,1);
|
---|
| 346 | ProjData.Y(ipoint,1)=ObjectData.Coord(ipoint,2);
|
---|
| 347 | i_int=(i_min:i_plus);
|
---|
| 348 | j_int=(j_min:j_plus);
|
---|
| 349 | ProjData.NbVal(ipoint,1)=length(j_int)*length(i_int);
|
---|
| 350 | if isempty(i_int) || isempty(j_int)
|
---|
| 351 | for ivar=VarIndex
|
---|
| 352 | eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=NaN;']);
|
---|
| 353 | end
|
---|
| 354 | errormsg=['no data points in the selected projection range ' num2str(width) ];
|
---|
| 355 | else
|
---|
| 356 | %TODO: introduce circle in the selected subregion
|
---|
| 357 | %[I,J]=meshgrid([1:j_int],[1:i_int]);
|
---|
| 358 | for ivar=VarIndex
|
---|
| 359 | eval(['Avalue=FieldData.' FieldData.ListVarName{ivar} '(j_int,i_int,:);']);
|
---|
| 360 | eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=mean(mean(Avalue));']);
|
---|
| 361 | end
|
---|
| 362 | end
|
---|
| 363 | end
|
---|
| 364 | end
|
---|
| 365 | end
|
---|
| 366 | end
|
---|
| 367 |
|
---|
| 368 | %-----------------------------------------------------------------
|
---|
| 369 | %project in a patch
|
---|
| 370 | function [ProjData,errormsg]=proj_patch(FieldData,ObjectData)%%
|
---|
| 371 | %-------------------------------------------------------------------
|
---|
| 372 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
| 373 |
|
---|
| 374 | objectfield=fieldnames(ObjectData);
|
---|
| 375 | widthx=0;
|
---|
| 376 | widthy=0;
|
---|
| 377 | if isfield(ObjectData,'RangeX')&~isempty(ObjectData.RangeX)
|
---|
| 378 | widthx=max(ObjectData.RangeX);
|
---|
| 379 | end
|
---|
| 380 | if isfield(ObjectData,'RangeY')&~isempty(ObjectData.RangeY)
|
---|
| 381 | widthy=max(ObjectData.RangeY);
|
---|
| 382 | end
|
---|
| 383 |
|
---|
| 384 | %A REVOIR, GENERALISER: UTILISER proj_line
|
---|
| 385 | ProjData.NbDim=1;
|
---|
| 386 | ProjData.ListVarName={};
|
---|
| 387 | ProjData.VarDimName={};
|
---|
| 388 | ProjData.VarAttribute={};
|
---|
| 389 |
|
---|
| 390 | Mesh=zeros(1,numel(FieldData.ListVarName));
|
---|
| 391 | if isfield (FieldData,'VarAttribute')
|
---|
| 392 | %ProjData.VarAttribute=FieldData.VarAttribute;%list of variable attribute names
|
---|
| 393 | for iattr=1:length(FieldData.VarAttribute)%initialization of variable attribute values
|
---|
| 394 | % ProjData.VarAttribute{iattr}={};
|
---|
| 395 | if isfield(FieldData.VarAttribute{iattr},'Unit')
|
---|
| 396 | unit{iattr}=FieldData.VarAttribute{iattr}.Unit;
|
---|
| 397 | end
|
---|
| 398 | if isfield(FieldData.VarAttribute{iattr},'Mesh')
|
---|
| 399 | Mesh(iattr)=FieldData.VarAttribute{iattr}.Mesh;
|
---|
| 400 | end
|
---|
| 401 | end
|
---|
| 402 | end
|
---|
| 403 |
|
---|
| 404 | %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
| 405 | testfalse=0;
|
---|
| 406 | ListIndex={};
|
---|
| 407 | % DimVarIndex=0;%initilise list of indices for dimension variables
|
---|
| 408 | idimvar=0;
|
---|
| 409 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 410 | if ~isempty(errormsg)
|
---|
| 411 | errormsg=['error in proj_field/proj_patch:' errormsg];
|
---|
| 412 | return
|
---|
| 413 | end
|
---|
| 414 |
|
---|
| 415 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
| 416 | dimcounter=0;
|
---|
| 417 | for icell=1:length(CellVarIndex)
|
---|
| 418 | testX=0;
|
---|
| 419 | testY=0;
|
---|
| 420 | test_Amat=0;
|
---|
| 421 | testfalse=0;
|
---|
| 422 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 423 | VarType=VarTypeCell{icell};
|
---|
| 424 | % DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
|
---|
| 425 | if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2
|
---|
| 426 | continue
|
---|
| 427 | end
|
---|
| 428 | testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);
|
---|
| 429 | testfalse=~isempty(VarType.errorflag);
|
---|
| 430 | testproj(VarIndex)=zeros(size(VarIndex));%default
|
---|
| 431 | testproj(VarType.scalar)=1;
|
---|
| 432 | testproj(VarType.vector_x)=1;
|
---|
| 433 | testproj(VarType.vector_y)=1;
|
---|
| 434 | testproj(VarType.vector_z)=1;
|
---|
| 435 | testproj(VarType.image)=1;
|
---|
| 436 | testproj(VarType.color)=1;
|
---|
| 437 | VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
|
---|
| 438 | if testX %case of unstructured coordinates
|
---|
| 439 | eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');'])
|
---|
| 440 | for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag]
|
---|
| 441 | VarName=FieldData.ListVarName{ivar};
|
---|
| 442 | eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);'])
|
---|
| 443 | end
|
---|
| 444 | XName=FieldData.ListVarName{VarType.coord_x};
|
---|
| 445 | YName=FieldData.ListVarName{VarType.coord_y};
|
---|
| 446 | eval(['coord_x=FieldData.' XName ';'])
|
---|
| 447 | eval(['coord_y=FieldData.' YName ';'])
|
---|
| 448 | end
|
---|
| 449 | if testfalse
|
---|
| 450 | FFName=FieldData.ListVarName{VarType.errorflag};
|
---|
| 451 | eval(['errorflag=FieldData.' FFName ';'])
|
---|
| 452 | end
|
---|
| 453 | % image or 2D matrix
|
---|
| 454 | if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
|
---|
| 455 | test_Amat=1;% test for image or 2D matrix
|
---|
| 456 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
| 457 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
| 458 | eval(['AX=FieldData.' AXName ';'])% x coordinate
|
---|
| 459 | eval(['AY=FieldData.' AYName ';'])% y coordinate
|
---|
| 460 | VarName=FieldData.ListVarName{VarIndex(1)};
|
---|
| 461 | eval(['DimValue=size(FieldData.' VarName ');'])
|
---|
| 462 | if length(AX)==2
|
---|
| 463 | AX=linspace(AX(1),AX(end),DimValue(2));
|
---|
| 464 | end
|
---|
| 465 | if length(AY)==2
|
---|
| 466 | AY=linspace(AY(1),AY(end),DimValue(1));
|
---|
| 467 | end
|
---|
| 468 | % for idim=1:length(DimValue)
|
---|
| 469 | % Coord_i_str=['Coord_' num2str(idim)];
|
---|
| 470 | % DCoord_min(idim)=1;%default
|
---|
| 471 | % Coord{idim}=[0.5 DimValue(idim)];
|
---|
| 472 | % test_direct(idim)=1;
|
---|
| 473 | % end
|
---|
| 474 | % AX=linspace(Coord{2}(1),Coord{2}(2),DimValue(2));
|
---|
| 475 | % AY=linspace(Coord{1}(1),Coord{1}(2),DimValue(1)); %TODO : 3D case
|
---|
| 476 | testcolor=find(numel(DimValue)==3);
|
---|
| 477 | if length(DimValue)==3
|
---|
| 478 | testcolor=1;
|
---|
| 479 | npxy(3)=3;
|
---|
| 480 | else
|
---|
| 481 | testcolor=0;
|
---|
| 482 | npxy(3)=1;
|
---|
| 483 | end
|
---|
| 484 | [Xi,Yi]=meshgrid(AX,AY);
|
---|
| 485 | npxy(1)=length(AY);
|
---|
| 486 | npxy(2)=length(AX);
|
---|
| 487 | Xi=reshape(Xi,npxy(1)*npxy(2),1);
|
---|
| 488 | Yi=reshape(Yi,npxy(1)*npxy(2),1);
|
---|
| 489 | for ivar=1:length(VarIndex)
|
---|
| 490 | VarName=FieldData.ListVarName{VarIndex(ivar)};
|
---|
| 491 | eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',npxy(1)*npxy(2),npxy(3));']); % keep only non false vectors
|
---|
| 492 | end
|
---|
| 493 | end
|
---|
| 494 | %select the indices in the range of action
|
---|
| 495 | testin=[];%default
|
---|
| 496 | if isequal(ObjectData.Style,'rectangle')
|
---|
| 497 | % if ~isfield(ObjectData,'RangeX')|~isfield(ObjectData,'RangeY')
|
---|
| 498 | % errormsg='rectangle half sides RangeX and RangeY needed'
|
---|
| 499 | % return
|
---|
| 500 | % end
|
---|
| 501 | if testX
|
---|
| 502 | distX=abs(coord_x-ObjectData.Coord(1,1));
|
---|
| 503 | distY=abs(coord_y-ObjectData.Coord(1,2));
|
---|
| 504 | testin=distX<widthx & distY<widthy;
|
---|
| 505 | elseif test_Amat
|
---|
| 506 | distX=abs(Xi-ObjectData.Coord(1,1));
|
---|
| 507 | distY=abs(Yi-ObjectData.Coord(1,2));
|
---|
| 508 | testin=distX<widthx & distY<widthy;
|
---|
| 509 | end
|
---|
| 510 | elseif isequal(ObjectData.Style,'polygon')
|
---|
| 511 | if testX
|
---|
| 512 | testin=inpolygon(coord_x,coord_y,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
|
---|
| 513 | elseif test_Amat
|
---|
| 514 | testin=inpolygon(Xi,Yi,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
|
---|
| 515 | else%calculate the scalar
|
---|
| 516 | testin=[]; %A REVOIR
|
---|
| 517 | end
|
---|
| 518 | elseif isequal(ObjectData.Style,'ellipse')
|
---|
| 519 | X2Max=widthx*widthx;
|
---|
| 520 | Y2Max=(widthy)*(widthy);
|
---|
| 521 | if testX
|
---|
| 522 | distX=(coord_x-ObjectData.Coord(1,1));
|
---|
| 523 | distY=(coord_y-ObjectData.Coord(1,2));
|
---|
| 524 | testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
|
---|
| 525 | elseif test_Amat %case of usual 2x2 matrix
|
---|
| 526 | distX=(Xi-ObjectData.Coord(1,1));
|
---|
| 527 | distY=(Yi-ObjectData.Coord(1,2));
|
---|
| 528 | testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
|
---|
| 529 | end
|
---|
| 530 | end
|
---|
| 531 | %selected indices
|
---|
| 532 | if isequal(ObjectData.ProjMode,'outside')
|
---|
| 533 | testin=~testin;
|
---|
| 534 | end
|
---|
| 535 | if testfalse
|
---|
| 536 | testin=testin & (errorflag==0); % keep only non false vectors
|
---|
| 537 | end
|
---|
| 538 | indsel=find(testin);
|
---|
| 539 | for ivar=VarIndex
|
---|
| 540 | if testproj(ivar)
|
---|
| 541 | VarName=FieldData.ListVarName{ivar};
|
---|
| 542 | eval(['ProjData.' VarName 'Mean=mean(mean(double(FieldData.' VarName '(indsel,:))));']); % keep only non false vectors
|
---|
| 543 | eval(['ProjData.' VarName 'Min=min(min(double(FieldData.' VarName '(indsel,:))));']); % keep only non false vectors
|
---|
| 544 | eval(['ProjData.' VarName 'Max=max(max(double(FieldData.' VarName '(indsel,:))));']); % keep only non false vectors
|
---|
| 545 | if isequal(Mesh(ivar),0)
|
---|
| 546 | eval(['[ProjData.' VarName 'Histo,ProjData.' VarName ']=hist(double(FieldData.' VarName '(indsel,:)),100);']); % default histogram with 100 bins
|
---|
| 547 | else
|
---|
| 548 | eval(['ProjData.' VarName '=(ProjData.' VarName 'Min+Mesh(ivar)/2:Mesh(ivar):ProjData.' VarName 'Max);']); % list of bin values
|
---|
| 549 | eval(['ProjData.' VarName 'Histo=hist(double(FieldData.' VarName '(indsel,:)),ProjData.' VarName ');']); % histogram at predefined bin positions
|
---|
| 550 | end
|
---|
| 551 | ProjData.ListVarName=[ProjData.ListVarName {VarName} {[VarName 'Histo']} {[VarName 'Mean']} {[VarName 'Min']} {[VarName 'Max']}];
|
---|
| 552 | if test_Amat && testcolor
|
---|
| 553 | ProjData.VarDimName=[ProjData.VarDimName {VarName} {{VarName,'rgb'}} {'rgb'}];%{{'nb_point','rgb'}};
|
---|
| 554 | else
|
---|
| 555 | ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName} {'nbpoint'} {'nbpoint'} {'nbpoint'}];
|
---|
| 556 | end
|
---|
| 557 | ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute{ivar} {[]} {[]} {[]} {[]}];
|
---|
| 558 | end
|
---|
| 559 | end
|
---|
| 560 | % if test_Amat & testcolor
|
---|
| 561 | % %ProjData.ListDimName=[ProjData.ListDimName {'rgb'}];
|
---|
| 562 | % % ProjData.DimValue=[ProjData.DimValue 3];
|
---|
| 563 | % % ProjData.VarDimIndex={[1 2]};
|
---|
| 564 | % ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName,'rgb'}];%{{'nb_point','rgb'}};
|
---|
| 565 | % ProjData.VarDimName
|
---|
| 566 | % end
|
---|
| 567 | end
|
---|
| 568 |
|
---|
| 569 |
|
---|
| 570 | %-----------------------------------------------------------------
|
---|
| 571 | %project on a line
|
---|
| 572 | % AJOUTER flux,circul,error
|
---|
| 573 | function [ProjData,errormsg] = proj_line(FieldData, ObjectData)
|
---|
| 574 | %-----------------------------------------------------------------
|
---|
| 575 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);%transfer global attributes
|
---|
| 576 | if ~isempty(errormsg)
|
---|
| 577 | return
|
---|
| 578 | end
|
---|
| 579 | ProjData.NbDim=1;
|
---|
| 580 | %initialisation of the input parameters and defaultoutput
|
---|
| 581 | ProjMode='projection';%direct projection on the line by default
|
---|
| 582 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
| 583 | ProjAngle=90; %90 degrees projection by default
|
---|
| 584 | if isfield(FieldData,'ProjAngle'),ProjAngle=ObjectData.ProjAngle; end;
|
---|
| 585 | width=0;%default width of the projection band
|
---|
| 586 | if isfield(ObjectData,'Range')&size(ObjectData.Range,2)>=2
|
---|
| 587 | width=abs(ObjectData.Range(1,2));
|
---|
| 588 | end
|
---|
| 589 | if isfield(ObjectData,'RangeY')
|
---|
| 590 | width=max(ObjectData.RangeY);
|
---|
| 591 | end
|
---|
| 592 |
|
---|
| 593 | % default output
|
---|
| 594 | errormsg=[];%default
|
---|
| 595 | Xline=[];
|
---|
| 596 | flux=0;
|
---|
| 597 | circul=0;
|
---|
| 598 | liny=ObjectData.Coord(:,2);
|
---|
| 599 | siz_line=size(ObjectData.Coord);
|
---|
| 600 | if siz_line(1)<2
|
---|
| 601 | return% line needs at least 2 points to be defined
|
---|
| 602 | end
|
---|
| 603 | testfalse=0;
|
---|
| 604 | ListIndex={};
|
---|
| 605 |
|
---|
| 606 | %angles of the polyline and boundaries of action
|
---|
| 607 | dlinx=diff(ObjectData.Coord(:,1));
|
---|
| 608 | dliny=diff(ObjectData.Coord(:,2));
|
---|
| 609 | theta=angle(dlinx+i*dliny);%angle of each segment
|
---|
| 610 | theta(siz_line(1))=theta(siz_line(1)-1);
|
---|
| 611 | % determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'filter')
|
---|
| 612 | if isequal(ProjMode,'projection') || isequal(ProjMode,'filter')
|
---|
| 613 | xsup(1)=ObjectData.Coord(1,1)-width*sin(theta(1));
|
---|
| 614 | xinf(1)=ObjectData.Coord(1,1)+width*sin(theta(1));
|
---|
| 615 | ysup(1)=ObjectData.Coord(1,2)+width*cos(theta(1));
|
---|
| 616 | yinf(1)=ObjectData.Coord(1,2)-width*cos(theta(1));
|
---|
| 617 | for ip=2:siz_line(1)
|
---|
| 618 | xsup(ip)=ObjectData.Coord(ip,1)-width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
| 619 | xinf(ip)=ObjectData.Coord(ip,1)+width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
| 620 | ysup(ip)=ObjectData.Coord(ip,2)+width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
| 621 | yinf(ip)=ObjectData.Coord(ip,2)-width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
| 622 | end
|
---|
| 623 | end
|
---|
| 624 |
|
---|
| 625 | %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
| 626 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 627 | if ~isempty(errormsg)
|
---|
| 628 | errormsg=['error in proj_field/proj_line:' errormsg];
|
---|
| 629 | return
|
---|
| 630 | end
|
---|
| 631 |
|
---|
| 632 | % loop on variable cells with the same space dimension
|
---|
| 633 | ProjData.ListVarName={};
|
---|
| 634 | ProjData.VarDimName={};
|
---|
| 635 | for icell=1:length(CellVarIndex)
|
---|
| 636 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 637 | VarType=VarTypeCell{icell}; %types of variables
|
---|
| 638 | if NbDim(icell)~=2% proj_line acts only on fields of space dimension 2, TODO: check 3D case
|
---|
| 639 | continue
|
---|
| 640 | end
|
---|
| 641 | testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates
|
---|
| 642 | testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);% test for vectors
|
---|
| 643 | testfalse=~isempty(VarType.errorflag);% test for error flag
|
---|
| 644 | testproj(VarIndex)=zeros(size(VarIndex));% test =1 for simply projected variables, default =0
|
---|
| 645 | %=0 for vector components, treated separately
|
---|
| 646 | testproj(VarType.scalar)=1;
|
---|
| 647 | testproj(VarType.image)=1;
|
---|
| 648 | testproj(VarType.color)=1;
|
---|
| 649 | VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
|
---|
| 650 | if testU
|
---|
| 651 | VarIndex=[VarIndex VarType.vector_x VarType.vector_y];%append u and v at the end of the list of variables
|
---|
| 652 | end
|
---|
| 653 | %identify vector components
|
---|
| 654 | if testU
|
---|
| 655 | UName=FieldData.ListVarName{VarType.vector_x};
|
---|
| 656 | VName=FieldData.ListVarName{VarType.vector_y};
|
---|
| 657 | eval(['vector_x=FieldData.' UName ';'])
|
---|
| 658 | eval(['vector_y=FieldData.' VName ';'])
|
---|
| 659 | end
|
---|
| 660 | %identify error flag
|
---|
| 661 | if testfalse
|
---|
| 662 | FFName=FieldData.ListVarName{VarType.errorflag};
|
---|
| 663 | eval(['errorflag=FieldData.' FFName ';'])
|
---|
| 664 | end
|
---|
| 665 | % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
|
---|
| 666 | if testX
|
---|
| 667 | if ~isequal(ProjMode,'interp')
|
---|
| 668 | if width==0
|
---|
| 669 | errormsg='range of the projection object is missing';
|
---|
| 670 | return
|
---|
| 671 | else
|
---|
| 672 | lambda=2/(width*width); %smoothing factor used for filter: weight exp(-2) at distance width from the line
|
---|
| 673 | end
|
---|
| 674 | end
|
---|
| 675 | if ~isequal(ProjMode,'projection')
|
---|
| 676 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
| 677 | DX=abs(ObjectData.DX);%mesh of interpolation points along the line
|
---|
| 678 | else
|
---|
| 679 | errormsg='DX missing';
|
---|
| 680 | return
|
---|
| 681 | end
|
---|
| 682 | end
|
---|
| 683 | XName= FieldData.ListVarName{VarType.coord_x};
|
---|
| 684 | YName= FieldData.ListVarName{VarType.coord_y};
|
---|
| 685 | eval(['coord_x=FieldData.' XName ';'])
|
---|
| 686 | eval(['coord_y=FieldData.' YName ';'])
|
---|
| 687 | end
|
---|
| 688 | %initiate projection
|
---|
| 689 | for ivar=1:length(VarIndex)
|
---|
| 690 | ProjLine{ivar}=[];
|
---|
| 691 | end
|
---|
| 692 | XLine=[];
|
---|
| 693 | linelengthtot=0;
|
---|
| 694 |
|
---|
| 695 | % circul=0;
|
---|
| 696 | % flux=0;
|
---|
| 697 | %%%%%%% % A FAIRE CALCULER MEAN DES QUANTITES %%%%%%
|
---|
| 698 | %case of unstructured coordinates
|
---|
| 699 | if testX
|
---|
| 700 | for ip=1:siz_line(1)-1 %Loop on the segments of the polyline
|
---|
| 701 | linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip));
|
---|
| 702 | %select the vector indices in the range of action
|
---|
| 703 | if testfalse
|
---|
| 704 | flagsel=(errorflag==0); % keep only non false vectors
|
---|
| 705 | else
|
---|
| 706 | flagsel=ones(size(coord_x));
|
---|
| 707 | end
|
---|
| 708 | if isequal(ProjMode,'projection') | isequal(ProjMode,'filter')
|
---|
| 709 | flagsel=flagsel & ((coord_y -yinf(ip))*(xinf(ip+1)-xinf(ip))>(coord_x-xinf(ip))*(yinf(ip+1)-yinf(ip))) ...
|
---|
| 710 | & ((coord_y -ysup(ip))*(xsup(ip+1)-xsup(ip))<(coord_x-xsup(ip))*(ysup(ip+1)-ysup(ip))) ...
|
---|
| 711 | & ((coord_y -yinf(ip+1))*(xsup(ip+1)-xinf(ip+1))>(coord_x-xinf(ip+1))*(ysup(ip+1)-yinf(ip+1))) ...
|
---|
| 712 | & ((coord_y -yinf(ip))*(xsup(ip)-xinf(ip))<(coord_x-xinf(ip))*(ysup(ip)-yinf(ip)));
|
---|
| 713 | end
|
---|
| 714 | indsel=find(flagsel);%indsel =indices of good vectors
|
---|
| 715 | X_sel=coord_x(indsel);
|
---|
| 716 | Y_sel=coord_y(indsel);
|
---|
| 717 | nbvar=0;
|
---|
| 718 | for iselect=1:numel(VarIndex)-2*testU
|
---|
| 719 | VarName=FieldData.ListVarName{VarIndex(iselect)};
|
---|
| 720 | eval(['ProjVar{iselect}=FieldData.' VarName '(indsel);']);%scalar value
|
---|
| 721 | end
|
---|
| 722 | if testU
|
---|
| 723 | ProjVar{numel(VarIndex)-1}=cos(theta(ip))*vector_x(indsel)+sin(theta(ip))*vector_y(indsel);% longitudinal component
|
---|
| 724 | ProjVar{numel(VarIndex)}=-sin(theta(ip))*vector_x(indsel)+cos(theta(ip))*vector_y(indsel);%transverse component
|
---|
| 725 | end
|
---|
| 726 | if isequal(ProjMode,'projection')
|
---|
| 727 | sintheta=sin(theta(ip));
|
---|
| 728 | costheta=cos(theta(ip));
|
---|
| 729 | Xproj=(X_sel-ObjectData.Coord(ip,1))*costheta + (Y_sel-ObjectData.Coord(ip,2))*sintheta; %projection on the line
|
---|
| 730 | [Xproj,indsort]=sort(Xproj);
|
---|
| 731 | for ivar=1:numel(ProjVar)
|
---|
| 732 | if ~isempty(ProjVar{ivar})
|
---|
| 733 | ProjVar{ivar}=ProjVar{ivar}(indsort);
|
---|
| 734 | end
|
---|
| 735 | end
|
---|
| 736 | elseif isequal(ProjMode,'interp') %linear interpolation:
|
---|
| 737 | npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
|
---|
[206] | 738 | Xproj=linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint);
|
---|
[204] | 739 | xreg=cos(theta(ip))*Xproj+ObjectData.Coord(ip,1);
|
---|
| 740 | yreg=sin(theta(ip))*Xproj+ObjectData.Coord(ip,2);
|
---|
| 741 | for ivar=1:numel(ProjVar)
|
---|
| 742 | if ~isempty(ProjVar{ivar})
|
---|
| 743 | ProjVar{ivar}=griddata_uvmat(X_sel,Y_sel,ProjVar{ivar},xreg,yreg);
|
---|
| 744 | end
|
---|
| 745 | end
|
---|
| 746 | elseif isequal(ProjMode,'filter') %filtering
|
---|
| 747 | npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
|
---|
[213] | 748 | Xproj=linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint);
|
---|
[204] | 749 | siz=size(X_sel);
|
---|
[215] | 750 | xregij=cos(theta(ip))*ones(siz(1),1)*Xproj+ObjectData.Coord(ip,1);
|
---|
| 751 | yregij=sin(theta(ip))*ones(siz(1),1)*Xproj+ObjectData.Coord(ip,2);
|
---|
| 752 | xij=X_sel*ones(1,npoint);
|
---|
| 753 | yij=Y_sel*ones(1,npoint);
|
---|
[204] | 754 | Aij=exp(-lambda*((xij-xregij).*(xij-xregij)+(yij-yregij).*(yij-yregij)));
|
---|
[215] | 755 | norm=Aij'*ones(siz(1),1);
|
---|
[204] | 756 | for ivar=1:numel(ProjVar)
|
---|
| 757 | if ~isempty(ProjVar{ivar})
|
---|
[215] | 758 | ProjVar{ivar}=Aij'*ProjVar{ivar}./norm;
|
---|
[204] | 759 | end
|
---|
| 760 | end
|
---|
| 761 | end
|
---|
| 762 | %prolongate the total record
|
---|
| 763 | for ivar=1:numel(ProjVar)
|
---|
| 764 | if ~isempty(ProjVar{ivar})
|
---|
| 765 | ProjLine{ivar}=[ProjLine{ivar}; ProjVar{ivar}];
|
---|
| 766 | end
|
---|
| 767 | end
|
---|
| 768 | XLine=[XLine ;(Xproj+linelengthtot)];%along line abscissa
|
---|
| 769 | linelengthtot=linelengthtot+linelength;
|
---|
| 770 | % circul=circul+(sum(U_sel))*linelength/npoint;
|
---|
| 771 | % flux=flux+(sum(V_sel))*linelength/npoint;
|
---|
| 772 | end
|
---|
| 773 | ProjData.X=XLine';
|
---|
| 774 | cur_index=1;
|
---|
| 775 | ProjData.ListVarName=[ProjData.ListVarName {XName}];
|
---|
| 776 | ProjData.VarDimName=[ProjData.VarDimName {XName}];
|
---|
| 777 | ProjData.VarAttribute{1}.long_name='abscissa along line';
|
---|
| 778 | for iselect=1:numel(VarIndex)
|
---|
| 779 | VarName=FieldData.ListVarName{VarIndex(iselect)};
|
---|
| 780 | eval(['ProjData.' VarName '=ProjLine{iselect};'])
|
---|
| 781 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
| 782 | ProjData.VarDimName=[ProjData.VarDimName {XName}];
|
---|
| 783 | ProjData.VarAttribute{iselect}=FieldData.VarAttribute{VarIndex(iselect)};
|
---|
| 784 | if strcmp(ProjMode,'projection')
|
---|
| 785 | ProjData.VarAttribute{iselect}.Role='discrete';
|
---|
| 786 | else
|
---|
| 787 | ProjData.VarAttribute{iselect}.Role='continuous';
|
---|
| 788 | end
|
---|
| 789 | end
|
---|
| 790 |
|
---|
| 791 | %case of structured coordinates
|
---|
| 792 | elseif numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
|
---|
| 793 | if ~isequal(ObjectData.Style,'line')% exclude polyline
|
---|
| 794 | errormsg=['no projection available on ' ObjectData.Style 'for structured coordinates']; %
|
---|
| 795 | else
|
---|
| 796 | test_Amat=1;%image or 2D matrix
|
---|
| 797 | test_interp2=0;%default
|
---|
| 798 | % if ~isempty(VarType.coord_y)
|
---|
| 799 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
| 800 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
| 801 | eval(['AX=FieldData.' AXName ';']);% set of x positions
|
---|
| 802 | eval(['AY=FieldData.' AYName ';']);% set of y positions
|
---|
| 803 | AName=FieldData.ListVarName{VarIndex(1)};
|
---|
| 804 | eval(['A=FieldData.' AName ';']);% scalar
|
---|
| 805 | npxy=size(A);
|
---|
| 806 | npx=npxy(2);
|
---|
| 807 | npy=npxy(1);
|
---|
| 808 | if numel(AX)==2
|
---|
| 809 | DX=(AX(2)-AX(1))/(npx-1);
|
---|
| 810 | else
|
---|
| 811 | DX_vec=diff(AX);
|
---|
| 812 | DX=max(DX_vec);
|
---|
| 813 | DX_min=min(DX_vec);
|
---|
| 814 | if (DX-DX_min)>0.0001*abs(DX)
|
---|
| 815 | test_interp2=1;
|
---|
| 816 | DX=DX_min;
|
---|
| 817 | end
|
---|
| 818 | end
|
---|
| 819 | if numel(AY)==2
|
---|
| 820 | DY=(AY(2)-AY(1))/(npy-1);
|
---|
| 821 | else
|
---|
| 822 | DY_vec=diff(AY);
|
---|
| 823 | DY=max(DY_vec);
|
---|
| 824 | DY_min=min(DY_vec);
|
---|
| 825 | if (DY-DY_min)>0.0001*abs(DY)
|
---|
| 826 | test_interp2=1;
|
---|
| 827 | DY=DY_min;
|
---|
| 828 | end
|
---|
| 829 | end
|
---|
| 830 | AXI=linspace(AX(1),AX(end), npx);%set of x positions for the interpolated input data
|
---|
| 831 | AYI=linspace(AY(1),AY(end), npy);%set of x positions for the interpolated input data
|
---|
| 832 | if isfield(ObjectData,'DX')
|
---|
| 833 | DXY_line=ObjectData.DX;%mesh on the projection line
|
---|
| 834 | else
|
---|
| 835 | DXY_line=sqrt(abs(DX*DY));% mesh on the projection line
|
---|
| 836 | end
|
---|
| 837 | dlinx=ObjectData.Coord(2,1)-ObjectData.Coord(1,1);
|
---|
| 838 | dliny=ObjectData.Coord(2,2)-ObjectData.Coord(1,2);
|
---|
| 839 | linelength=sqrt(dlinx*dlinx+dliny*dliny);
|
---|
| 840 | theta=angle(dlinx+i*dliny);%angle of the line
|
---|
| 841 | if isfield(FieldData,'RangeX')
|
---|
| 842 | XMin=min(FieldData.RangeX);%shift of the origin on the line
|
---|
| 843 | else
|
---|
| 844 | XMin=0;
|
---|
| 845 | end
|
---|
| 846 | eval(['ProjData.' AXName '=linspace(XMin,XMin+linelength,linelength/DXY_line+1);'])%abscissa of the new pixels along the line
|
---|
| 847 | y=linspace(-width,width,2*width/DXY_line+1);%ordintes of the new pixels (coordinate across the line)
|
---|
| 848 | eval(['npX=length(ProjData.' AXName ');'])
|
---|
| 849 | npY=length(y); %TODO: utiliser proj_grid
|
---|
| 850 | eval(['[X,Y]=meshgrid(ProjData.' AXName ',y);'])%grid in the line coordinates
|
---|
| 851 | XIMA=ObjectData.Coord(1,1)+(X-XMin)*cos(theta)-Y*sin(theta);
|
---|
| 852 | YIMA=ObjectData.Coord(1,2)+(X-XMin)*sin(theta)+Y*cos(theta);
|
---|
| 853 | XIMA=(XIMA-AX(1))/DX+1;% index of the original image along x
|
---|
| 854 | YIMA=(YIMA-AY(1))/DY+1;% index of the original image along y
|
---|
| 855 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
| 856 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
| 857 | flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
|
---|
| 858 | ind_in=find(flagin);
|
---|
| 859 | ind_out=find(~flagin);
|
---|
| 860 | ICOMB=(XIMA-1)*npy+YIMA;
|
---|
| 861 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
| 862 | nbcolor=1; %color images
|
---|
| 863 | if numel(npxy)==2
|
---|
| 864 | nbcolor=1;
|
---|
| 865 | elseif length(npxy)==3
|
---|
| 866 | nbcolor=npxy(3);
|
---|
| 867 | else
|
---|
| 868 | errormsg='multicomponent field not projected';
|
---|
| 869 | display(errormsg)
|
---|
| 870 | return
|
---|
| 871 | end
|
---|
| 872 | nbvar=length(ProjData.ListVarName);% number of var from previous cells
|
---|
| 873 | ProjData.ListVarName=[ProjData.ListVarName {AXName}];
|
---|
| 874 | ProjData.VarDimName=[ProjData.VarDimName {AXName}];
|
---|
| 875 | for ivar=VarIndex
|
---|
| 876 | VarName{ivar}=FieldData.ListVarName{ivar};
|
---|
| 877 | if test_interp2% interpolate on new grid
|
---|
| 878 | eval(['FieldData.' VarName{ivar} '=interp2(FieldData.' AXName ',FieldData.' AYName ',FieldData.' VarName{ivar} ',AXI,AYI'');']) %TO TEST
|
---|
| 879 | end
|
---|
| 880 | eval(['vec_A=reshape(squeeze(FieldData.' VarName{ivar} '),npx*npy,nbcolor);']) %put the original image in colum
|
---|
| 881 | if nbcolor==1
|
---|
| 882 | vec_B(ind_in)=vec_A(ICOMB);
|
---|
| 883 | vec_B(ind_out)=zeros(size(ind_out));
|
---|
| 884 | A_out=reshape(vec_B,npY,npX);
|
---|
| 885 | eval(['ProjData.' VarName{ivar} '=((sum(A_out,1)/npY))'';']);
|
---|
| 886 | elseif nbcolor==3
|
---|
[213] | 887 | vec_B(ind_in,1:3)=vec_A(ICOMB,:);
|
---|
[204] | 888 | vec_B(ind_out,1)=zeros(size(ind_out));
|
---|
| 889 | vec_B(ind_out,2)=zeros(size(ind_out));
|
---|
| 890 | vec_B(ind_out,3)=zeros(size(ind_out));
|
---|
| 891 | A_out=reshape(vec_B,npY,npX,nbcolor);
|
---|
| 892 | eval(['ProjData.' VarName{ivar} '=squeeze(sum(A_out,1)/npY);']);
|
---|
| 893 | end
|
---|
| 894 | ProjData.ListVarName=[ProjData.ListVarName VarName{ivar} ];
|
---|
| 895 | ProjData.VarDimName=[ProjData.VarDimName {AXName}];%to generalize with the initial name of the x coordinate
|
---|
| 896 | ProjData.VarAttribute{ivar}.Role='continuous';% for plot with continuous line
|
---|
| 897 | end
|
---|
| 898 | if testU
|
---|
| 899 | eval(['vector_x =ProjData.' VarName{VarType.vector_x} ';'])
|
---|
| 900 | eval(['vector_y =ProjData.' VarName{VarType.vector_y} ';'])
|
---|
| 901 | eval(['ProjData.' VarName{VarType.vector_x} '=cos(theta)*vector_x+sin(theta)*vector_y;'])
|
---|
| 902 | eval(['ProjData.' VarName{VarType.vector_y} '=-sin(theta)*vector_x+cos(theta)*vector_y;'])
|
---|
| 903 | end
|
---|
| 904 | ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line';
|
---|
| 905 | if nbcolor==3
|
---|
| 906 | ProjData.VarDimName{end}={AXName,'rgb'};
|
---|
| 907 | end
|
---|
| 908 | end
|
---|
| 909 | end
|
---|
| 910 | end
|
---|
| 911 |
|
---|
| 912 | % %shotarter case for horizontal or vertical line (A FAIRE
|
---|
| 913 | % % Rangx=[0.5 npx-0.5];%image coordiantes of corners
|
---|
| 914 | % % Rangy=[npy-0.5 0.5];
|
---|
| 915 | % % if isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib
|
---|
| 916 | % % Rangx=Rangx/Calib.Pxcmx;
|
---|
| 917 | % % Rangy=Rangy/Calib.Pxcmy;
|
---|
| 918 | % % else
|
---|
| 919 | % % [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[0 0]);%case of translations without rotation and quadratic deformation
|
---|
| 920 | % % [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[0 0]);
|
---|
| 921 | % % end
|
---|
| 922 | %
|
---|
| 923 | % % test_scal=0;%default% 3- 'UserData':(get(handles.Tag,'UserData')
|
---|
| 924 |
|
---|
| 925 |
|
---|
| 926 | %-----------------------------------------------------------------
|
---|
| 927 | %project on a plane
|
---|
| 928 | % AJOUTER flux,circul,error
|
---|
| 929 | function [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
|
---|
| 930 | %-----------------------------------------------------------------
|
---|
| 931 |
|
---|
| 932 | %% initialisation of the input parameters of the projection plane
|
---|
| 933 | ProjMode='projection';%direct projection by default
|
---|
| 934 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
| 935 |
|
---|
| 936 | %axis origin
|
---|
| 937 | if isempty(ObjectData.Coord)
|
---|
| 938 | ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
|
---|
| 939 | ObjectData.Coord(1,2)=0;
|
---|
| 940 | ObjectData.Coord(1,3)=0;
|
---|
| 941 | end
|
---|
| 942 |
|
---|
| 943 | %rotation angles
|
---|
[206] | 944 | PlaneAngle=[0 0 0];
|
---|
| 945 | norm_plane=[0 0 1];
|
---|
| 946 | cos_om=1;
|
---|
| 947 | sin_om=0;
|
---|
[227] | 948 | test90x=0;%=1 for 90 degree rotation alround x axis
|
---|
| 949 | test90y=0;%=1 for 90 degree rotation alround y axis
|
---|
[206] | 950 | if isfield(ObjectData,'Angle')&& isequal(size(ObjectData.Angle),[1 3])&& ~isequal(ObjectData.Angle,[0 0 0])
|
---|
[227] | 951 | test90y=isequal(ObjectData.Angle,[0 90 0]);
|
---|
[212] | 952 | PlaneAngle=(pi/180)*ObjectData.Angle;
|
---|
[206] | 953 | om=norm(PlaneAngle);%norm of rotation angle in radians
|
---|
| 954 | OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
|
---|
[212] | 955 | cos_om=cos(om);
|
---|
| 956 | sin_om=sin(om);
|
---|
[206] | 957 | coeff=OmAxis(3)*(1-cos_om);
|
---|
| 958 | %components of the unity vector norm_plane normal to the projection plane
|
---|
| 959 | norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
|
---|
| 960 | norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
|
---|
| 961 | norm_plane(3)=OmAxis(3)*coeff+cos_om;
|
---|
[204] | 962 | end
|
---|
[227] | 963 | testangle=~isequal(PlaneAngle,[0 0 0]);% && ~test90y && ~test90x;%=1 for slanted plane
|
---|
| 964 |
|
---|
[206] | 965 | % Phi=0;%default
|
---|
| 966 | % Theta=0;
|
---|
| 967 | % Psi=0;
|
---|
| 968 | % if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
|
---|
| 969 | % Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
|
---|
| 970 | % end
|
---|
| 971 | % if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
|
---|
| 972 | % Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
|
---|
| 973 | % end
|
---|
| 974 | % if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
|
---|
| 975 | % Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
|
---|
| 976 | % end
|
---|
[204] | 977 |
|
---|
| 978 | %components of the unity vector normal to the projection plane
|
---|
[206] | 979 | % NormVec_X=-sin(Phi)*sin(Theta);
|
---|
| 980 | % NormVec_Y=cos(Phi)*sin(Theta);
|
---|
| 981 | % NormVec_Z=cos(Theta);
|
---|
[204] | 982 |
|
---|
| 983 | %mesh sizes DX and DY
|
---|
| 984 | DX=0;
|
---|
| 985 | DY=0; %default
|
---|
| 986 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
| 987 | DX=abs(ObjectData.DX);%mesh of interpolation points
|
---|
| 988 | end
|
---|
| 989 | if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
|
---|
| 990 | DY=abs(ObjectData.DY);%mesh of interpolation points
|
---|
| 991 | end
|
---|
| 992 | if ~strcmp(ProjMode,'projection') && (DX==0||DY==0)
|
---|
| 993 | errormsg='DX or DY missing';
|
---|
| 994 | display(errormsg)
|
---|
| 995 | return
|
---|
| 996 | end
|
---|
| 997 |
|
---|
| 998 | %extrema along each axis
|
---|
| 999 | testXMin=0;
|
---|
| 1000 | testXMax=0;
|
---|
| 1001 | testYMin=0;
|
---|
| 1002 | testYMax=0;
|
---|
| 1003 | if isfield(ObjectData,'RangeX')
|
---|
| 1004 | XMin=min(ObjectData.RangeX);
|
---|
| 1005 | XMax=max(ObjectData.RangeX);
|
---|
| 1006 | testXMin=XMax>XMin;
|
---|
| 1007 | testXMax=1;
|
---|
| 1008 | end
|
---|
| 1009 | if isfield(ObjectData,'RangeY')
|
---|
| 1010 | YMin=min(ObjectData.RangeY);
|
---|
| 1011 | YMax=max(ObjectData.RangeY);
|
---|
| 1012 | testYMin=YMax>YMin;
|
---|
| 1013 | testYMax=1;
|
---|
| 1014 | end
|
---|
| 1015 | width=0;%default width of the projection band
|
---|
| 1016 | if isfield(ObjectData,'RangeZ')
|
---|
| 1017 | width=max(ObjectData.RangeZ);
|
---|
| 1018 | end
|
---|
| 1019 |
|
---|
| 1020 | % initiate Matlab structure for physical field
|
---|
| 1021 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
| 1022 | ProjData.NbDim=2;
|
---|
| 1023 | ProjData.ListVarName={};
|
---|
| 1024 | ProjData.VarDimName={};
|
---|
| 1025 | if ~isequal(DX,0)&& ~isequal(DY,0)
|
---|
| 1026 | ProjData.Mesh=sqrt(DX*DY);%define typical data mesh, useful for mouse selection in plots
|
---|
| 1027 | elseif isfield(FieldData,'Mesh')
|
---|
| 1028 | ProjData.Mesh=FieldData.Mesh;
|
---|
| 1029 | end
|
---|
| 1030 |
|
---|
| 1031 | error=0;%default
|
---|
| 1032 | flux=0;
|
---|
| 1033 | testfalse=0;
|
---|
| 1034 | ListIndex={};
|
---|
| 1035 |
|
---|
| 1036 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 1037 | %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
| 1038 | %-----------------------------------------------------------------
|
---|
| 1039 | idimvar=0;
|
---|
[206] | 1040 |
|
---|
[204] | 1041 | [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 1042 | if ~isempty(errormsg)
|
---|
| 1043 | errormsg=['error in proj_field/proj_plane:' errormsg];
|
---|
| 1044 | return
|
---|
| 1045 | end
|
---|
| 1046 |
|
---|
| 1047 | % LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
| 1048 | % CellVarIndex=cells of variable index arrays
|
---|
| 1049 | ivar_new=0; % index of the current variable in the projected field
|
---|
| 1050 | icoord=0;
|
---|
| 1051 | nbcoord=0;%number of added coordinate variables brought by projection
|
---|
| 1052 | nbvar=0;
|
---|
| 1053 | for icell=1:length(CellVarIndex)
|
---|
| 1054 | NbDim=NbDimVec(icell);
|
---|
| 1055 | if NbDim<2
|
---|
| 1056 | continue
|
---|
| 1057 | end
|
---|
| 1058 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 1059 | VarType=VarTypeCell{icell};
|
---|
| 1060 | ivar_X=VarType.coord_x;
|
---|
| 1061 | ivar_Y=VarType.coord_y;
|
---|
| 1062 | ivar_Z=VarType.coord_z;
|
---|
| 1063 | ivar_U=VarType.vector_x;
|
---|
| 1064 | ivar_V=VarType.vector_y;
|
---|
| 1065 | ivar_W=VarType.vector_z;
|
---|
| 1066 | ivar_C=VarType.scalar ;
|
---|
| 1067 | ivar_Anc=VarType.ancillary;
|
---|
| 1068 | test_anc=zeros(size(VarIndex));
|
---|
| 1069 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
| 1070 | ivar_F=VarType.warnflag;
|
---|
| 1071 | ivar_FF=VarType.errorflag;
|
---|
| 1072 | testX=~isempty(ivar_X) && ~isempty(ivar_Y);
|
---|
| 1073 | DimCell=FieldData.VarDimName{VarIndex(1)};
|
---|
| 1074 | if ischar(DimCell)
|
---|
| 1075 | DimCell={DimCell};%name of dimensions
|
---|
| 1076 | end
|
---|
[227] | 1077 |
|
---|
| 1078 | %% case of input fields with unstructured coordinates
|
---|
[204] | 1079 | if testX
|
---|
| 1080 | XName=FieldData.ListVarName{ivar_X};
|
---|
| 1081 | YName=FieldData.ListVarName{ivar_Y};
|
---|
| 1082 | eval(['coord_x=FieldData.' XName ';'])
|
---|
| 1083 | eval(['coord_y=FieldData.' YName ';'])
|
---|
| 1084 | if length(ivar_Z)==1
|
---|
| 1085 | ZName=FieldData.ListVarName{ivar_Z};
|
---|
| 1086 | eval(['coord_z=FieldData.' ZName ';'])
|
---|
| 1087 | end
|
---|
[227] | 1088 |
|
---|
[204] | 1089 | % translate initial coordinates
|
---|
| 1090 | coord_x=coord_x-ObjectData.Coord(1,1);
|
---|
| 1091 | coord_y=coord_y-ObjectData.Coord(1,2);
|
---|
| 1092 | if ~isempty(ivar_Z)
|
---|
| 1093 | coord_z=coord_z-ObjectData.Coord(1,3);
|
---|
| 1094 | end
|
---|
| 1095 |
|
---|
| 1096 | % selection of the vectors in the projection range (3D case)
|
---|
| 1097 | if length(ivar_Z)==1 && width > 0
|
---|
| 1098 | %components of the unitiy vector normal to the projection plane
|
---|
[227] | 1099 | fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane
|
---|
[204] | 1100 | indcut=find(abs(fieldZ) <= width);
|
---|
[206] | 1101 | size(indcut)
|
---|
[204] | 1102 | for ivar=VarIndex
|
---|
| 1103 | VarName=FieldData.ListVarName{ivar};
|
---|
[227] | 1104 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
| 1105 | % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
|
---|
[204] | 1106 | end
|
---|
| 1107 | coord_x=coord_x(indcut);
|
---|
| 1108 | coord_y=coord_y(indcut);
|
---|
| 1109 | coord_z=coord_z(indcut);
|
---|
| 1110 | end
|
---|
[227] | 1111 |
|
---|
| 1112 | %rotate coordinates if needed:
|
---|
| 1113 | if testangle && ~test90y && ~test90x;%=1 for slanted plane
|
---|
| 1114 | % coord_X=coord_x;
|
---|
| 1115 | % coord_Y=coord_y;
|
---|
| 1116 | % if ~isequal(Theta,0)
|
---|
| 1117 | % coord_Y=coord_Y *cos(Theta);
|
---|
| 1118 | % end
|
---|
| 1119 | % else
|
---|
[204] | 1120 | coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
|
---|
| 1121 | coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
|
---|
[227] | 1122 | % end
|
---|
| 1123 | % if ~isempty(ivar_Z)
|
---|
[204] | 1124 | coord_Y=coord_Y+coord_z *sin(Theta);
|
---|
[227] | 1125 | % end
|
---|
| 1126 | % if testangle
|
---|
| 1127 | coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
|
---|
| 1128 | coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
|
---|
[206] | 1129 | else
|
---|
| 1130 | coord_X=coord_x;
|
---|
| 1131 | coord_Y=coord_y;
|
---|
[204] | 1132 | end
|
---|
| 1133 |
|
---|
| 1134 | %restriction to the range of x and y if imposed
|
---|
| 1135 | testin=ones(size(coord_X)); %default
|
---|
| 1136 | testbound=0;
|
---|
| 1137 | if testXMin
|
---|
| 1138 | testin=testin & (coord_X >= XMin);
|
---|
| 1139 | testbound=1;
|
---|
| 1140 | end
|
---|
| 1141 | if testXMax
|
---|
| 1142 | testin=testin & (coord_X <= XMax);
|
---|
| 1143 | testbound=1;
|
---|
| 1144 | end
|
---|
| 1145 | if testYMin
|
---|
| 1146 | testin=testin & (coord_Y >= YMin);
|
---|
| 1147 | testbound=1;
|
---|
| 1148 | end
|
---|
| 1149 | if testYMin
|
---|
| 1150 | testin=testin & (coord_Y <= YMax);
|
---|
| 1151 | testbound=1;
|
---|
| 1152 | end
|
---|
| 1153 | if testbound
|
---|
| 1154 | indcut=find(testin);
|
---|
| 1155 | for ivar=VarIndex
|
---|
| 1156 | VarName=FieldData.ListVarName{ivar};
|
---|
[227] | 1157 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
[204] | 1158 | end
|
---|
| 1159 | coord_X=coord_X(indcut);
|
---|
| 1160 | coord_Y=coord_Y(indcut);
|
---|
| 1161 | if length(ivar_Z)==1
|
---|
| 1162 | coord_Z=coord_Z(indcut);
|
---|
| 1163 | end
|
---|
| 1164 | end
|
---|
| 1165 | % different cases of projection
|
---|
| 1166 | if isequal(ObjectData.ProjMode,'projection')
|
---|
| 1167 | %the list of dimension
|
---|
| 1168 | %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions
|
---|
| 1169 | %ProjData.DimValue=[ProjData.
|
---|
[227] | 1170 | %length(coord_X)];
|
---|
| 1171 |
|
---|
[204] | 1172 | for ivar=VarIndex %transfer variables to the projection plane
|
---|
| 1173 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1174 | if ivar==ivar_X %x coordinate
|
---|
| 1175 | eval(['ProjData.' VarName '=coord_X;'])
|
---|
| 1176 | elseif ivar==ivar_Y % y coordinate
|
---|
| 1177 | eval(['ProjData.' VarName '=coord_Y;'])
|
---|
| 1178 | elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
|
---|
| 1179 | eval(['ProjData.' VarName '=FieldData.' VarName ';'])
|
---|
| 1180 | end
|
---|
[227] | 1181 | if isempty(ivar_Z) || ivar~=ivar_Z
|
---|
[204] | 1182 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1183 | ProjData.VarDimName=[ProjData.VarDimName DimCell];
|
---|
| 1184 | nbvar=nbvar+1;
|
---|
| 1185 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
| 1186 | ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
|
---|
| 1187 | end
|
---|
| 1188 | end
|
---|
[227] | 1189 | end
|
---|
[204] | 1190 | elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
|
---|
[206] | 1191 | coord_x_proj=XMin:DX:XMax;
|
---|
| 1192 | coord_y_proj=YMin:DY:YMax;
|
---|
[204] | 1193 | DimCell={'coord_y','coord_x'};
|
---|
| 1194 | ProjData.ListVarName={'coord_y','coord_x'};
|
---|
[227] | 1195 | ProjData.VarDimName={'coord_y','coord_x'};
|
---|
| 1196 | nbcoord=2;
|
---|
[204] | 1197 | ProjData.coord_y=[YMin YMax];
|
---|
| 1198 | ProjData.coord_x=[XMin XMax];
|
---|
| 1199 | if isempty(ivar_X), ivar_X=0; end;
|
---|
| 1200 | if isempty(ivar_Y), ivar_Y=0; end;
|
---|
| 1201 | if isempty(ivar_Z), ivar_Z=0; end;
|
---|
| 1202 | if isempty(ivar_U), ivar_U=0; end;
|
---|
| 1203 | if isempty(ivar_V), ivar_V=0; end;
|
---|
| 1204 | if isempty(ivar_W), ivar_W=0; end;
|
---|
| 1205 | if isempty(ivar_F), ivar_F=0; end;
|
---|
| 1206 | if isempty(ivar_FF), ivar_FF=0; end;
|
---|
| 1207 | if ~isequal(ivar_FF,0)
|
---|
| 1208 | VarName_FF=FieldData.ListVarName{ivar_FF};
|
---|
| 1209 | eval(['indsel=find(FieldData.' VarName_FF '==0);'])
|
---|
| 1210 | coord_X=coord_X(indsel);
|
---|
| 1211 | coord_Y=coord_Y(indsel);
|
---|
| 1212 | end
|
---|
| 1213 | FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
|
---|
| 1214 | testFF=0;
|
---|
| 1215 | for ivar=VarIndex
|
---|
| 1216 | VarName=FieldData.ListVarName{ivar};
|
---|
[227] | 1217 | if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)
|
---|
[204] | 1218 | ivar_new=ivar_new+1;
|
---|
| 1219 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
| 1220 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1221 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
| 1222 | ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
| 1223 | end
|
---|
| 1224 | if ~isequal(ivar_FF,0)
|
---|
| 1225 | eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
|
---|
| 1226 | end
|
---|
| 1227 | eval(['ProjData.' VarName '=griddata_uvmat(double(coord_X),double(coord_Y),double(FieldData.' VarName '),coord_x_proj,coord_y_proj'');'])
|
---|
| 1228 | eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
|
---|
| 1229 | FFlag= isnan(varline); %detect undefined values NaN
|
---|
| 1230 | indnan=find(FFlag);
|
---|
| 1231 | if~isempty(indnan)
|
---|
| 1232 | varline(indnan)=zeros(size(indnan));
|
---|
| 1233 | eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
|
---|
| 1234 | FF(indnan)=ones(size(indnan));
|
---|
| 1235 | testFF=1;
|
---|
| 1236 | end
|
---|
| 1237 | if ivar==ivar_U
|
---|
| 1238 | ivar_U=ivar_new;
|
---|
| 1239 | end
|
---|
| 1240 | if ivar==ivar_V
|
---|
| 1241 | ivar_V=ivar_new;
|
---|
| 1242 | end
|
---|
| 1243 | if ivar==ivar_W
|
---|
| 1244 | ivar_W=ivar_new;
|
---|
| 1245 | end
|
---|
| 1246 | end
|
---|
| 1247 | end
|
---|
| 1248 | if testFF
|
---|
| 1249 | ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
|
---|
| 1250 | ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
|
---|
[227] | 1251 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
[204] | 1252 | ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
|
---|
| 1253 | end
|
---|
| 1254 | end
|
---|
| 1255 |
|
---|
[227] | 1256 | %% case of input fields defined on a structured grid
|
---|
[204] | 1257 | else
|
---|
[227] | 1258 | 'TESTproj'
|
---|
| 1259 | VarName=FieldData.ListVarName{VarIndex(1)}%get the first variable of the cell to get the input matrix dimensions
|
---|
[204] | 1260 | eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
|
---|
[227] | 1261 | DimValue(DimValue==1)=[];%remove singleton dimensions
|
---|
[204] | 1262 | NbDim=numel(DimValue);%update number of space dimensions
|
---|
| 1263 | nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
|
---|
| 1264 | if NbDim>=3
|
---|
| 1265 | if NbDim>3
|
---|
| 1266 | errormsg='matrices with more than 3 dimensions not handled';
|
---|
| 1267 | return
|
---|
| 1268 | else
|
---|
| 1269 | VarType.coord
|
---|
| 1270 | if numel(find(VarType.coord))==2% the third matrix dimension does not correspond to a space coordinate
|
---|
| 1271 | nbcolor=DimValue(3);
|
---|
| 1272 | DimValue(3)=[]; %number of 'color' components updated
|
---|
| 1273 | NbDim=2;% space dimension set to 2
|
---|
| 1274 | end
|
---|
| 1275 | end
|
---|
| 1276 | end
|
---|
[227] | 1277 | testangle
|
---|
| 1278 | if testangle% TODO modify name also in case of origin shift in x or y
|
---|
| 1279 | AYName='Y';
|
---|
| 1280 | AXName='X';
|
---|
| 1281 | count=0;
|
---|
| 1282 | %modify coordinate names if they are already used
|
---|
| 1283 | while ~(isempty(find(strcmp('AXName',ProjData.ListVarName),1)) && isempty(find(strcmp('AYName',ProjData.ListVarName),1)))
|
---|
| 1284 | count=count+1;
|
---|
| 1285 | AYName=[AYName '_' num2str(count)];
|
---|
| 1286 | AXName=[AXName '_' num2str(count)];
|
---|
| 1287 | end
|
---|
| 1288 | else
|
---|
| 1289 | AYName=FieldData.ListVarName{VarType.coord(NbDim-1)}%name of input x coordinate (name preserved on projection)
|
---|
| 1290 | AXName=FieldData.ListVarName{VarType.coord(NbDim)}%name of input y coordinate (name preserved on projection)
|
---|
| 1291 | end
|
---|
[204] | 1292 | eval(['AX=FieldData.' AXName ';'])
|
---|
| 1293 | eval(['AY=FieldData.' AYName ';'])
|
---|
| 1294 | ListDimName=FieldData.VarDimName{VarIndex(1)};
|
---|
[227] | 1295 | ProjData.ListVarName=[ProjData.ListVarName {AYName} {AXName}]; %TODO: check if it already exists in Projdata (several cells)
|
---|
| 1296 | ProjData.VarDimName=[ProjData.VarDimName {AYName} {AXName}];
|
---|
[204] | 1297 | Coord_z=[];
|
---|
| 1298 | Coord_y=[];
|
---|
[227] | 1299 | Coord_x=[];
|
---|
| 1300 |
|
---|
[204] | 1301 | for idim=1:NbDim %loop on space dimensions
|
---|
| 1302 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
| 1303 | ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension
|
---|
| 1304 | if ~isequal(ivar,0)% a variable corresponds to the dimension #idim
|
---|
| 1305 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
|
---|
| 1306 | if numel(Coord{idim})==2 %input array defined on a regular grid
|
---|
[227] | 1307 | DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
|
---|
[204] | 1308 | else
|
---|
| 1309 | DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
|
---|
| 1310 | DCoord_min(idim)=min(DCoord);
|
---|
| 1311 | DCoord_max=max(DCoord);
|
---|
[227] | 1312 | % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
| 1313 | if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000)
|
---|
[204] | 1314 | msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'])
|
---|
[227] | 1315 | return
|
---|
| 1316 | end
|
---|
[204] | 1317 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
| 1318 | end
|
---|
| 1319 | test_direct(idim)=(DCoord_min(idim)>0);
|
---|
| 1320 | else % no variable associated with the dimension #idim, the coordinate value is set equal to the matrix index by default
|
---|
| 1321 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
| 1322 | DCoord_min(idim)=1;%default
|
---|
| 1323 | Coord{idim}=[0.5 DimValue(idim)-0.5];
|
---|
| 1324 | test_direct(idim)=1;
|
---|
| 1325 | end
|
---|
| 1326 | end
|
---|
| 1327 | if DY==0
|
---|
| 1328 | DY=abs(DCoord_min(NbDim-1));
|
---|
| 1329 | end
|
---|
[227] | 1330 | npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol
|
---|
[204] | 1331 | if DX==0
|
---|
| 1332 | DX=abs(DCoord_min(NbDim));
|
---|
| 1333 | end
|
---|
[227] | 1334 | npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol
|
---|
[213] | 1335 | for idim=1:NbDim
|
---|
[204] | 1336 | if test_interp(idim)
|
---|
| 1337 | DimValue(idim)=1+round(abs(Coord{idim}(end)-Coord{idim}(1))/abs(DCoord_min(idim)));%nbre of points after possible interpolation on a regular gri
|
---|
| 1338 | end
|
---|
[227] | 1339 | end
|
---|
[204] | 1340 | Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY);
|
---|
| 1341 | test_direct_y=test_direct(NbDim-1);
|
---|
| 1342 | Coord_x=linspace(Coord{NbDim}(1),Coord{NbDim}(end),npX);
|
---|
| 1343 | test_direct_x=test_direct(NbDim);
|
---|
| 1344 | DAX=DCoord_min(NbDim);
|
---|
[227] | 1345 | DAY=DCoord_min(NbDim-1);
|
---|
[204] | 1346 | minAX=min(Coord_x);
|
---|
| 1347 | maxAX=max(Coord_x);
|
---|
| 1348 | minAY=min(Coord_y);
|
---|
| 1349 | maxAY=max(Coord_y);
|
---|
| 1350 | xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
|
---|
| 1351 | ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
|
---|
[206] | 1352 | xcor_new=xcorner*cos_om+ycorner*sin_om;%coord new frame
|
---|
| 1353 | ycor_new=-xcorner*sin_om+ycorner*cos_om;
|
---|
[204] | 1354 | if ~testXMax
|
---|
| 1355 | XMax=max(xcor_new);
|
---|
| 1356 | end
|
---|
| 1357 | if ~testXMin
|
---|
| 1358 | XMin=min(xcor_new);
|
---|
| 1359 | end
|
---|
| 1360 | if ~testYMax
|
---|
| 1361 | YMax=max(ycor_new);
|
---|
| 1362 | end
|
---|
| 1363 | if ~testYMin
|
---|
| 1364 | YMin=min(ycor_new);
|
---|
| 1365 | end
|
---|
| 1366 | DXinit=(maxAX-minAX)/(DimValue(NbDim)-1);
|
---|
| 1367 | DYinit=(maxAY-minAY)/(DimValue(NbDim-1)-1);
|
---|
| 1368 | if DX==0
|
---|
| 1369 | DX=DXinit;
|
---|
| 1370 | end
|
---|
| 1371 | if DY==0
|
---|
| 1372 | DY=DYinit;
|
---|
| 1373 | end
|
---|
| 1374 | if NbDim==3
|
---|
| 1375 | DZ=(Coord{1}(end)-Coord{1}(1))/(DimValue(1)-1);
|
---|
| 1376 | if ~test_direct(1)
|
---|
| 1377 | DZ=-DZ;
|
---|
| 1378 | end
|
---|
| 1379 | Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
|
---|
| 1380 | test_direct_z=test_direct(1);
|
---|
| 1381 | end
|
---|
| 1382 | npX=floor((XMax-XMin)/DX+1);
|
---|
[227] | 1383 | npY=floor((YMax-YMin)/DY+1);
|
---|
[204] | 1384 | if test_direct_y
|
---|
| 1385 | coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
|
---|
| 1386 | else
|
---|
| 1387 | coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
|
---|
| 1388 | end
|
---|
| 1389 | if test_direct_x
|
---|
| 1390 | coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
|
---|
| 1391 | else
|
---|
| 1392 | coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
|
---|
[227] | 1393 | end
|
---|
[204] | 1394 | % case with no rotation and interpolation
|
---|
[206] | 1395 | if isequal(ProjMode,'projection') && ~testangle
|
---|
[204] | 1396 | if ~testXMin && ~testXMax && ~testYMin && ~testYMax && NbDim==2
|
---|
[227] | 1397 | ProjData=FieldData;
|
---|
[204] | 1398 | else
|
---|
| 1399 | indY=NbDim-1;
|
---|
| 1400 | if test_direct(indY)
|
---|
| 1401 | min_indy=ceil((YMin-Coord{indY}(1))/DYinit)+1;
|
---|
| 1402 | max_indy=floor((YMax-Coord{indY}(1))/DYinit)+1;
|
---|
| 1403 | Ybound(1)=Coord{indY}(1)+DYinit*(min_indy-1);
|
---|
| 1404 | Ybound(2)=Coord{indY}(1)+DYinit*(max_indy-1);
|
---|
| 1405 | else
|
---|
| 1406 | min_indy=ceil((Coord{indY}(1)-YMax)/DYinit)+1;
|
---|
| 1407 | max_indy=floor((Coord{indY}(1)-YMin)/DYinit)+1;
|
---|
| 1408 | Ybound(2)=Coord{indY}(1)-DYinit*(max_indy-1);
|
---|
| 1409 | Ybound(1)=Coord{indY}(1)-DYinit*(min_indy-1);
|
---|
[227] | 1410 | end
|
---|
[204] | 1411 | if test_direct(NbDim)==1
|
---|
| 1412 | min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1;
|
---|
| 1413 | max_indx=floor((XMax-Coord{NbDim}(1))/DXinit)+1;
|
---|
| 1414 | Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
|
---|
| 1415 | Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
|
---|
| 1416 | else
|
---|
| 1417 | min_indx=ceil((Coord{NbDim}(1)-XMax)/DXinit)+1;
|
---|
| 1418 | max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1;
|
---|
| 1419 | Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
|
---|
[227] | 1420 |
|
---|
| 1421 |
|
---|
[204] | 1422 | Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
|
---|
| 1423 | end
|
---|
| 1424 | min_indy=max(min_indy,1);% deals with margin (bound lower than the first index)
|
---|
| 1425 | min_indx=max(min_indx,1);
|
---|
[227] | 1426 |
|
---|
| 1427 | if test90y
|
---|
| 1428 | 'TEST3D'
|
---|
| 1429 | ind_new=[3 2 1];
|
---|
| 1430 | DimCell=DimCell(ind_new);
|
---|
| 1431 | DimValue=DimValue(ind_new);
|
---|
| 1432 | DimCell(1)=[]; %suppress x variable
|
---|
| 1433 | DimValue(1)=[];
|
---|
| 1434 | iz=ceil((ObjectData.Coord(1,1)-Coord{3}(1))/DX)+1;
|
---|
| 1435 | for ivar=VarIndex
|
---|
| 1436 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1437 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1438 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1439 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
| 1440 | eval(['size(FieldData.' VarName ')'])
|
---|
| 1441 | eval(['ProjData.' VarName '=permute(FieldData.' VarName ',ind_new)'])% permute x and z indices for 90 degree rotation
|
---|
| 1442 | eval(['size(ProjData.' VarName ')'])
|
---|
| 1443 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
[204] | 1444 | end
|
---|
[227] | 1445 | eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
|
---|
| 1446 | eval(['ProjData.' AXName '=[Coord{1}(end),Coord{1}(1)];']) %record the new (projected ) x coordinates
|
---|
| 1447 | else
|
---|
[204] | 1448 | if NbDim==3
|
---|
[227] | 1449 | DimCell(1)=[]; %suppress z variable
|
---|
| 1450 | DimValue(1)=[];
|
---|
| 1451 | if test_direct(1)
|
---|
| 1452 | iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
|
---|
| 1453 | else
|
---|
| 1454 | iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;
|
---|
| 1455 | end
|
---|
[204] | 1456 | end
|
---|
[227] | 1457 | max_indy=min(max_indy,DimValue(1));%introduce bounds in y and x indices
|
---|
| 1458 | max_indx=min(max_indx,DimValue(2));
|
---|
| 1459 | for ivar=VarIndex% loop on non coordinate variables
|
---|
| 1460 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1461 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1462 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1463 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
|
---|
| 1464 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
|
---|
| 1465 | end
|
---|
| 1466 | if NbDim==3
|
---|
| 1467 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']);
|
---|
| 1468 | else
|
---|
| 1469 | eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']);
|
---|
| 1470 | end
|
---|
| 1471 | end
|
---|
| 1472 | eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
|
---|
| 1473 | eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates
|
---|
| 1474 | end
|
---|
[204] | 1475 | end
|
---|
| 1476 | else % case with rotation and/or interpolation
|
---|
| 1477 | if NbDim==2 %2D case
|
---|
| 1478 | [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
|
---|
[212] | 1479 | XIMA=ObjectData.Coord(1,1)+(X)*cos(PlaneAngle(3))-Y*sin(PlaneAngle(3));%corresponding coordinates in the original image
|
---|
| 1480 | YIMA=ObjectData.Coord(1,2)+(X)*sin(PlaneAngle(3))+Y*cos(PlaneAngle(3));
|
---|
[204] | 1481 | XIMA=(XIMA-minAX)/DXinit+1;% image index along x
|
---|
| 1482 | YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
|
---|
| 1483 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
| 1484 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
[227] | 1485 | flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
|
---|
[204] | 1486 | if isequal(ObjectData.ProjMode,'filter')
|
---|
| 1487 | npx_filter=ceil(abs(DX/DAX));
|
---|
| 1488 | npy_filter=ceil(abs(DY/DAY));
|
---|
| 1489 | Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
|
---|
| 1490 | test_filter=1;
|
---|
| 1491 | else
|
---|
| 1492 | test_filter=0;
|
---|
| 1493 | end
|
---|
| 1494 | eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
|
---|
| 1495 | eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates
|
---|
| 1496 | for ivar=VarIndex
|
---|
| 1497 | VarName=FieldData.ListVarName{ivar};
|
---|
[227] | 1498 | if test_interp(1) || test_interp(2)%interpolate on a regular grid
|
---|
| 1499 | eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
|
---|
[204] | 1500 | end
|
---|
| 1501 | %filter the field (image) if option 'filter' is used
|
---|
[227] | 1502 | if test_filter
|
---|
| 1503 | Aclass=class(FieldData.A);
|
---|
| 1504 | eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
|
---|
| 1505 | if ~isequal(Aclass,'double')
|
---|
| 1506 | eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
|
---|
| 1507 | end
|
---|
[204] | 1508 | end
|
---|
[227] | 1509 | eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
|
---|
[206] | 1510 | %ind_in=find(flagin);
|
---|
[204] | 1511 | ind_out=find(~flagin);
|
---|
| 1512 | ICOMB=(XIMA-1)*DimValue(1)+YIMA;
|
---|
| 1513 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
[227] | 1514 | vec_B(flagin,1:nbcolor)=vec_A(ICOMB,:);
|
---|
[204] | 1515 | for icolor=1:nbcolor
|
---|
| 1516 | vec_B(ind_out,icolor)=zeros(size(ind_out));
|
---|
| 1517 | end
|
---|
| 1518 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1519 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1520 | if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
|
---|
| 1521 | ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
[227] | 1522 | end
|
---|
[204] | 1523 | eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
|
---|
| 1524 | end
|
---|
[227] | 1525 | ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
|
---|
[204] | 1526 | ProjData.ListVarName=[ProjData.ListVarName 'FF'];
|
---|
| 1527 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1528 | ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
|
---|
[227] | 1529 | elseif ~testangle
|
---|
| 1530 | % unstructured z coordinate
|
---|
| 1531 | test_sup=(Coord{1}>=ObjectData.Coord(1,3));
|
---|
| 1532 | iz_sup=find(test_sup);
|
---|
| 1533 | iz=iz_sup(1);
|
---|
| 1534 | if iz>=1 & iz<=npz
|
---|
| 1535 | %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
|
---|
| 1536 | %ProjData.DimValue=[ProjData.DimValue npY npX];
|
---|
| 1537 | for ivar=VarIndex
|
---|
| 1538 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1539 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1540 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
| 1541 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
| 1542 | %TODO : do a vertical average for a thick plane
|
---|
| 1543 | if test_interp(2) || test_interp(3)
|
---|
| 1544 | eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
|
---|
[204] | 1545 | end
|
---|
| 1546 | end
|
---|
| 1547 | end
|
---|
[227] | 1548 | else
|
---|
| 1549 | errormsg='projection of structured coordinates on oblique plane not yet implemented';
|
---|
| 1550 | %TODO: use interp3
|
---|
| 1551 | return
|
---|
[204] | 1552 | end
|
---|
| 1553 | end
|
---|
| 1554 | end
|
---|
[227] | 1555 |
|
---|
[204] | 1556 | %% projection of velocity components in the rotated coordinates
|
---|
[206] | 1557 | if testangle && length(ivar_U)==1
|
---|
[204] | 1558 | if isempty(ivar_V)
|
---|
| 1559 | msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
|
---|
| 1560 | return
|
---|
| 1561 | end
|
---|
| 1562 | UName=FieldData.ListVarName{ivar_U};
|
---|
[227] | 1563 | VName=FieldData.ListVarName{ivar_V};
|
---|
[212] | 1564 | eval(['ProjData.' UName '=cos(PlaneAngle(3))*ProjData.' UName '+ sin(PlaneAngle(3))*ProjData.' VName ';'])
|
---|
| 1565 | eval(['ProjData.' VName '=cos(Theta)*(-sin(PlaneAngle(3))*ProjData.' UName '+ cos(PlaneAngle(3))*ProjData.' VName ');'])
|
---|
[204] | 1566 | if ~isempty(ivar_W)
|
---|
| 1567 | WName=FieldData.ListVarName{ivar_W};
|
---|
[227] | 1568 | eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
|
---|
[204] | 1569 | eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
|
---|
| 1570 | end
|
---|
| 1571 | if ~isequal(Psi,0)
|
---|
| 1572 | eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
|
---|
| 1573 | eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
|
---|
| 1574 | end
|
---|
| 1575 | end
|
---|
| 1576 | end
|
---|
| 1577 |
|
---|
| 1578 | %-----------------------------------------------------------------
|
---|
[206] | 1579 | %projection in a volume
|
---|
[204] | 1580 | function [ProjData,errormsg] = proj_volume(FieldData, ObjectData)
|
---|
| 1581 | %-----------------------------------------------------------------
|
---|
[206] | 1582 | ProjData=FieldData;%default output
|
---|
[204] | 1583 |
|
---|
[206] | 1584 | %% initialisation of the input parameters of the projection plane
|
---|
[204] | 1585 | ProjMode='projection';%direct projection by default
|
---|
| 1586 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
| 1587 |
|
---|
[206] | 1588 | %% axis origin
|
---|
[204] | 1589 | if isempty(ObjectData.Coord)
|
---|
[206] | 1590 | ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
|
---|
[204] | 1591 | ObjectData.Coord(1,2)=0;
|
---|
| 1592 | ObjectData.Coord(1,3)=0;
|
---|
| 1593 | end
|
---|
| 1594 |
|
---|
[206] | 1595 | %% rotation angles
|
---|
| 1596 | VolumeAngle=[0 0 0];
|
---|
| 1597 | norm_plane=[0 0 1];
|
---|
| 1598 | if isfield(ObjectData,'Angle')&& isequal(size(ObjectData.Angle),[1 3])&& ~isequal(ObjectData.Angle,[0 0 0])
|
---|
| 1599 | PlaneAngle=ObjectData.Angle;
|
---|
| 1600 | VolumeAngle=ObjectData.Angle;
|
---|
| 1601 | om=norm(VolumeAngle);%norm of rotation angle in radians
|
---|
| 1602 | OmAxis=VolumeAngle/om; %unit vector marking the rotation axis
|
---|
| 1603 | cos_om=cos(pi*om/180);
|
---|
| 1604 | sin_om=sin(pi*om/180);
|
---|
| 1605 | coeff=OmAxis(3)*(1-cos_om);
|
---|
| 1606 | %components of the unity vector norm_plane normal to the projection plane
|
---|
| 1607 | norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
|
---|
| 1608 | norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
|
---|
| 1609 | norm_plane(3)=OmAxis(3)*coeff+cos_om;
|
---|
[204] | 1610 | end
|
---|
[206] | 1611 | testangle=~isequal(VolumeAngle,[0 0 0]);
|
---|
[204] | 1612 |
|
---|
[206] | 1613 | %% mesh sizes DX, DY, DZ
|
---|
[204] | 1614 | DX=0;
|
---|
| 1615 | DY=0; %default
|
---|
[206] | 1616 | DZ=0;
|
---|
[204] | 1617 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
| 1618 | DX=abs(ObjectData.DX);%mesh of interpolation points
|
---|
| 1619 | end
|
---|
| 1620 | if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
|
---|
| 1621 | DY=abs(ObjectData.DY);%mesh of interpolation points
|
---|
| 1622 | end
|
---|
| 1623 | if isfield(ObjectData,'DZ')&~isempty(ObjectData.DZ)
|
---|
| 1624 | DZ=abs(ObjectData.DZ);%mesh of interpolation points
|
---|
| 1625 | end
|
---|
[206] | 1626 | if ~strcmp(ProjMode,'projection') && (DX==0||DY==0||DZ==0)
|
---|
| 1627 | errormsg='grid mesh DX , DY or DZ is missing';
|
---|
| 1628 | return
|
---|
| 1629 | end
|
---|
[204] | 1630 |
|
---|
[206] | 1631 | %% extrema along each axis
|
---|
[204] | 1632 | testXMin=0;
|
---|
| 1633 | testXMax=0;
|
---|
| 1634 | testYMin=0;
|
---|
| 1635 | testYMax=0;
|
---|
| 1636 | if isfield(ObjectData,'RangeX')
|
---|
| 1637 | XMin=min(ObjectData.RangeX);
|
---|
| 1638 | XMax=max(ObjectData.RangeX);
|
---|
| 1639 | testXMin=XMax>XMin;
|
---|
| 1640 | testXMax=1;
|
---|
| 1641 | end
|
---|
| 1642 | if isfield(ObjectData,'RangeY')
|
---|
| 1643 | YMin=min(ObjectData.RangeY);
|
---|
| 1644 | YMax=max(ObjectData.RangeY);
|
---|
| 1645 | testYMin=YMax>YMin;
|
---|
| 1646 | testYMax=1;
|
---|
| 1647 | end
|
---|
| 1648 | width=0;%default width of the projection band
|
---|
| 1649 | if isfield(ObjectData,'RangeZ')
|
---|
[206] | 1650 | ZMin=min(ObjectData.RangeZ);
|
---|
[204] | 1651 | ZMax=max(ObjectData.RangeZ);
|
---|
[206] | 1652 | testZMin=ZMax>ZMin;
|
---|
[204] | 1653 | testZMax=1;
|
---|
| 1654 | end
|
---|
| 1655 |
|
---|
[206] | 1656 | %% initiate Matlab structure for physical field
|
---|
[204] | 1657 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
| 1658 | ProjData.NbDim=3;
|
---|
| 1659 | ProjData.ListVarName={};
|
---|
| 1660 | ProjData.VarDimName={};
|
---|
[206] | 1661 | if ~isequal(DX,0)&& ~isequal(DY,0)
|
---|
| 1662 | ProjData.Mesh=sqrt(DX*DY);%define typical data mesh, useful for mouse selection in plots
|
---|
| 1663 | elseif isfield(FieldData,'Mesh')
|
---|
| 1664 | ProjData.Mesh=FieldData.Mesh;
|
---|
| 1665 | end
|
---|
[204] | 1666 |
|
---|
| 1667 | error=0;%default
|
---|
| 1668 | flux=0;
|
---|
| 1669 | testfalse=0;
|
---|
| 1670 | ListIndex={};
|
---|
| 1671 |
|
---|
| 1672 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[206] | 1673 | %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
[204] | 1674 | %-----------------------------------------------------------------
|
---|
| 1675 | idimvar=0;
|
---|
[206] | 1676 | [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
[204] | 1677 | if ~isempty(errormsg)
|
---|
| 1678 | errormsg=['error in proj_field/proj_plane:' errormsg];
|
---|
| 1679 | return
|
---|
| 1680 | end
|
---|
[206] | 1681 |
|
---|
| 1682 | % LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
[204] | 1683 | % CellVarIndex=cells of variable index arrays
|
---|
| 1684 | ivar_new=0; % index of the current variable in the projected field
|
---|
| 1685 | icoord=0;
|
---|
| 1686 | nbcoord=0;%number of added coordinate variables brought by projection
|
---|
[206] | 1687 | nbvar=0;
|
---|
[204] | 1688 | for icell=1:length(CellVarIndex)
|
---|
[206] | 1689 | NbDim=NbDimVec(icell);
|
---|
| 1690 | if NbDim<3
|
---|
[204] | 1691 | continue
|
---|
| 1692 | end
|
---|
| 1693 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 1694 | VarType=VarTypeCell{icell};
|
---|
| 1695 | ivar_X=VarType.coord_x;
|
---|
| 1696 | ivar_Y=VarType.coord_y;
|
---|
| 1697 | ivar_Z=VarType.coord_z;
|
---|
| 1698 | ivar_U=VarType.vector_x;
|
---|
| 1699 | ivar_V=VarType.vector_y;
|
---|
| 1700 | ivar_W=VarType.vector_z;
|
---|
| 1701 | ivar_C=VarType.scalar ;
|
---|
| 1702 | ivar_Anc=VarType.ancillary;
|
---|
| 1703 | test_anc=zeros(size(VarIndex));
|
---|
| 1704 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
| 1705 | ivar_F=VarType.warnflag;
|
---|
| 1706 | ivar_FF=VarType.errorflag;
|
---|
| 1707 | testX=~isempty(ivar_X) && ~isempty(ivar_Y);
|
---|
| 1708 | DimCell=FieldData.VarDimName{VarIndex(1)};
|
---|
| 1709 | if ischar(DimCell)
|
---|
| 1710 | DimCell={DimCell};%name of dimensions
|
---|
| 1711 | end
|
---|
[206] | 1712 |
|
---|
| 1713 | %% case of input fields with unstructured coordinates
|
---|
[204] | 1714 | if testX
|
---|
| 1715 | XName=FieldData.ListVarName{ivar_X};
|
---|
| 1716 | YName=FieldData.ListVarName{ivar_Y};
|
---|
| 1717 | eval(['coord_x=FieldData.' XName ';'])
|
---|
| 1718 | eval(['coord_y=FieldData.' YName ';'])
|
---|
| 1719 | if length(ivar_Z)==1
|
---|
| 1720 | ZName=FieldData.ListVarName{ivar_Z};
|
---|
| 1721 | eval(['coord_z=FieldData.' ZName ';'])
|
---|
| 1722 | end
|
---|
| 1723 |
|
---|
| 1724 | % translate initial coordinates
|
---|
| 1725 | coord_x=coord_x-ObjectData.Coord(1,1);
|
---|
| 1726 | coord_y=coord_y-ObjectData.Coord(1,2);
|
---|
| 1727 | if ~isempty(ivar_Z)
|
---|
| 1728 | coord_z=coord_z-ObjectData.Coord(1,3);
|
---|
| 1729 | end
|
---|
| 1730 |
|
---|
[206] | 1731 | % selection of the vectors in the projection range
|
---|
| 1732 | % if length(ivar_Z)==1 && width > 0
|
---|
| 1733 | % %components of the unitiy vector normal to the projection plane
|
---|
| 1734 | % fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane
|
---|
| 1735 | % indcut=find(abs(fieldZ) <= width);
|
---|
| 1736 | % for ivar=VarIndex
|
---|
| 1737 | % VarName=FieldData.ListVarName{ivar};
|
---|
| 1738 | % eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
| 1739 | % % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
|
---|
| 1740 | % end
|
---|
| 1741 | % coord_x=coord_x(indcut);
|
---|
| 1742 | % coord_y=coord_y(indcut);
|
---|
| 1743 | % coord_z=coord_z(indcut);
|
---|
| 1744 | % end
|
---|
[204] | 1745 |
|
---|
[206] | 1746 | %rotate coordinates if needed: TODO modify
|
---|
| 1747 | if testangle
|
---|
| 1748 | coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
|
---|
| 1749 | coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
|
---|
| 1750 | if ~isempty(ivar_Z)
|
---|
| 1751 | coord_Y=coord_Y+coord_z *sin(Theta);
|
---|
| 1752 | end
|
---|
| 1753 |
|
---|
| 1754 | coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
|
---|
| 1755 | coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
|
---|
| 1756 |
|
---|
| 1757 | else
|
---|
| 1758 | coord_X=coord_x;
|
---|
| 1759 | coord_Y=coord_y;
|
---|
| 1760 | coord_Z=coord_z;
|
---|
| 1761 | end
|
---|
[204] | 1762 | %restriction to the range of x and y if imposed
|
---|
| 1763 | testin=ones(size(coord_X)); %default
|
---|
| 1764 | testbound=0;
|
---|
| 1765 | if testXMin
|
---|
| 1766 | testin=testin & (coord_X >= XMin);
|
---|
| 1767 | testbound=1;
|
---|
| 1768 | end
|
---|
| 1769 | if testXMax
|
---|
| 1770 | testin=testin & (coord_X <= XMax);
|
---|
| 1771 | testbound=1;
|
---|
| 1772 | end
|
---|
| 1773 | if testYMin
|
---|
| 1774 | testin=testin & (coord_Y >= YMin);
|
---|
| 1775 | testbound=1;
|
---|
| 1776 | end
|
---|
| 1777 | if testYMin
|
---|
| 1778 | testin=testin & (coord_Y <= YMax);
|
---|
| 1779 | testbound=1;
|
---|
| 1780 | end
|
---|
| 1781 | if testbound
|
---|
| 1782 | indcut=find(testin);
|
---|
| 1783 | for ivar=VarIndex
|
---|
| 1784 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1785 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
| 1786 | end
|
---|
| 1787 | coord_X=coord_X(indcut);
|
---|
| 1788 | coord_Y=coord_Y(indcut);
|
---|
| 1789 | if length(ivar_Z)==1
|
---|
| 1790 | coord_Z=coord_Z(indcut);
|
---|
| 1791 | end
|
---|
| 1792 | end
|
---|
| 1793 | % different cases of projection
|
---|
[206] | 1794 | if isequal(ObjectData.ProjMode,'projection')%%%%%%% NOT USED %%%%%%%%%%
|
---|
[204] | 1795 | for ivar=VarIndex %transfer variables to the projection plane
|
---|
| 1796 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1797 | if ivar==ivar_X %x coordinate
|
---|
| 1798 | eval(['ProjData.' VarName '=coord_X;'])
|
---|
| 1799 | elseif ivar==ivar_Y % y coordinate
|
---|
| 1800 | eval(['ProjData.' VarName '=coord_Y;'])
|
---|
| 1801 | elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
|
---|
| 1802 | eval(['ProjData.' VarName '=FieldData.' VarName ';'])
|
---|
| 1803 | end
|
---|
| 1804 | if isempty(ivar_Z) || ivar~=ivar_Z
|
---|
| 1805 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1806 | ProjData.VarDimName=[ProjData.VarDimName DimCell];
|
---|
| 1807 | nbvar=nbvar+1;
|
---|
[206] | 1808 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
[204] | 1809 | ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
|
---|
| 1810 | end
|
---|
| 1811 | end
|
---|
| 1812 | end
|
---|
| 1813 | elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
|
---|
[206] | 1814 | coord_x_proj=XMin:DX:XMax;
|
---|
| 1815 | coord_y_proj=YMin:DY:YMax;
|
---|
| 1816 | coord_z_proj=ZMin:DZ:ZMax;
|
---|
| 1817 | DimCell={'coord_z','coord_y','coord_x'};
|
---|
[204] | 1818 | ProjData.ListVarName={'coord_z','coord_y','coord_x'};
|
---|
| 1819 | ProjData.VarDimName={'coord_z','coord_y','coord_x'};
|
---|
[206] | 1820 | nbcoord=2;
|
---|
[204] | 1821 | ProjData.coord_z=[ZMin ZMax];
|
---|
| 1822 | ProjData.coord_y=[YMin YMax];
|
---|
| 1823 | ProjData.coord_x=[XMin XMax];
|
---|
| 1824 | if isempty(ivar_X), ivar_X=0; end;
|
---|
| 1825 | if isempty(ivar_Y), ivar_Y=0; end;
|
---|
| 1826 | if isempty(ivar_Z), ivar_Z=0; end;
|
---|
| 1827 | if isempty(ivar_U), ivar_U=0; end;
|
---|
| 1828 | if isempty(ivar_V), ivar_V=0; end;
|
---|
| 1829 | if isempty(ivar_W), ivar_W=0; end;
|
---|
| 1830 | if isempty(ivar_F), ivar_F=0; end;
|
---|
| 1831 | if isempty(ivar_FF), ivar_FF=0; end;
|
---|
| 1832 | if ~isequal(ivar_FF,0)
|
---|
| 1833 | VarName_FF=FieldData.ListVarName{ivar_FF};
|
---|
| 1834 | eval(['indsel=find(FieldData.' VarName_FF '==0);'])
|
---|
| 1835 | coord_X=coord_X(indsel);
|
---|
| 1836 | coord_Y=coord_Y(indsel);
|
---|
| 1837 | end
|
---|
| 1838 | FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
|
---|
| 1839 | testFF=0;
|
---|
[206] | 1840 | [X,Y,Z]=meshgrid(coord_y_proj,coord_z_proj,coord_x_proj);%grid in the new coordinates
|
---|
[204] | 1841 | for ivar=VarIndex
|
---|
[206] | 1842 | VarName=FieldData.ListVarName{ivar};
|
---|
[204] | 1843 | if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)
|
---|
| 1844 | ivar_new=ivar_new+1;
|
---|
| 1845 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
| 1846 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1847 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
| 1848 | ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
| 1849 | end
|
---|
| 1850 | if ~isequal(ivar_FF,0)
|
---|
| 1851 | eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
|
---|
| 1852 | end
|
---|
[206] | 1853 | eval(['InterpFct=TriScatteredInterp(double(coord_X),double(coord_Y),double(coord_Z),double(FieldData.' VarName '))'])
|
---|
| 1854 | eval(['ProjData.' VarName '=InterpFct(X,Y,Z);'])
|
---|
[204] | 1855 | % eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
|
---|
| 1856 | % FFlag= isnan(varline); %detect undefined values NaN
|
---|
| 1857 | % indnan=find(FFlag);
|
---|
| 1858 | % if~isempty(indnan)
|
---|
| 1859 | % varline(indnan)=zeros(size(indnan));
|
---|
| 1860 | % eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
|
---|
| 1861 | % FF(indnan)=ones(size(indnan));
|
---|
| 1862 | % testFF=1;
|
---|
| 1863 | % end
|
---|
[206] | 1864 | if ivar==ivar_U
|
---|
| 1865 | ivar_U=ivar_new;
|
---|
| 1866 | end
|
---|
| 1867 | if ivar==ivar_V
|
---|
| 1868 | ivar_V=ivar_new;
|
---|
| 1869 | end
|
---|
| 1870 | if ivar==ivar_W
|
---|
| 1871 | ivar_W=ivar_new;
|
---|
| 1872 | end
|
---|
[204] | 1873 | end
|
---|
| 1874 | end
|
---|
| 1875 | if testFF
|
---|
| 1876 | ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
|
---|
| 1877 | ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
|
---|
| 1878 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1879 | ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
|
---|
| 1880 | end
|
---|
| 1881 | end
|
---|
[206] | 1882 |
|
---|
| 1883 | %% case of input fields defined on a structured grid
|
---|
| 1884 | else
|
---|
| 1885 | VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
|
---|
| 1886 | eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
|
---|
[227] | 1887 | DimValue(DimValue==1)=[];%remove singleton dimensions
|
---|
[206] | 1888 | NbDim=numel(DimValue);%update number of space dimensions
|
---|
| 1889 | nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
|
---|
| 1890 | if NbDim>=3
|
---|
| 1891 | if NbDim>3
|
---|
| 1892 | errormsg='matrices with more than 3 dimensions not handled';
|
---|
| 1893 | return
|
---|
| 1894 | else
|
---|
| 1895 | if numel(find(VarType.coord))==2% the third matrix dimension does not correspond to a space coordinate
|
---|
| 1896 | nbcolor=DimValue(3);
|
---|
| 1897 | DimValue(3)=[]; %number of 'color' components updated
|
---|
| 1898 | NbDim=2;% space dimension set to 2
|
---|
| 1899 | end
|
---|
| 1900 | end
|
---|
| 1901 | end
|
---|
| 1902 | AYName=FieldData.ListVarName{VarType.coord(NbDim-1)};%name of input x coordinate (name preserved on projection)
|
---|
| 1903 | AXName=FieldData.ListVarName{VarType.coord(NbDim)};%name of input y coordinate (name preserved on projection)
|
---|
[204] | 1904 | eval(['AX=FieldData.' AXName ';'])
|
---|
| 1905 | eval(['AY=FieldData.' AYName ';'])
|
---|
| 1906 | ListDimName=FieldData.VarDimName{VarIndex(1)};
|
---|
[206] | 1907 | ProjData.ListVarName=[ProjData.ListVarName {AYName} {AXName}]; %TODO: check if it already exists in Projdata (several cells)
|
---|
| 1908 | ProjData.VarDimName=[ProjData.VarDimName {AYName} {AXName}];
|
---|
| 1909 |
|
---|
| 1910 | % for idim=1:length(ListDimName)
|
---|
| 1911 | % DimName=ListDimName{idim};
|
---|
| 1912 | % if strcmp(DimName,'rgb')||strcmp(DimName,'nb_coord')||strcmp(DimName,'nb_coord_i')
|
---|
| 1913 | % nbcolor=DimValue(idim);
|
---|
| 1914 | % DimValue(idim)=[];
|
---|
| 1915 | % end
|
---|
| 1916 | % if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
|
---|
| 1917 | % DimValue(idim)=[];
|
---|
| 1918 | % end
|
---|
| 1919 | % end
|
---|
[204] | 1920 | Coord_z=[];
|
---|
| 1921 | Coord_y=[];
|
---|
| 1922 | Coord_x=[];
|
---|
[206] | 1923 |
|
---|
[204] | 1924 | for idim=1:NbDim %loop on space dimensions
|
---|
| 1925 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
[206] | 1926 | ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension
|
---|
| 1927 | if ~isequal(ivar,0)% a variable corresponds to the dimension #idim
|
---|
| 1928 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
|
---|
| 1929 | if numel(Coord{idim})==2 %input array defined on a regular grid
|
---|
| 1930 | DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
|
---|
| 1931 | else
|
---|
| 1932 | DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
|
---|
| 1933 | DCoord_min(idim)=min(DCoord);
|
---|
| 1934 | DCoord_max=max(DCoord);
|
---|
| 1935 | % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
| 1936 | if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000)
|
---|
| 1937 | msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'])
|
---|
[204] | 1938 | return
|
---|
[206] | 1939 | end
|
---|
| 1940 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
| 1941 | end
|
---|
| 1942 | test_direct(idim)=(DCoord_min(idim)>0);
|
---|
| 1943 | else % no variable associated with the dimension #idim, the coordinate value is set equal to the matrix index by default
|
---|
[204] | 1944 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
| 1945 | DCoord_min(idim)=1;%default
|
---|
| 1946 | Coord{idim}=[0.5 DimValue(idim)-0.5];
|
---|
| 1947 | test_direct(idim)=1;
|
---|
| 1948 | end
|
---|
| 1949 | end
|
---|
[206] | 1950 | if DY==0
|
---|
| 1951 | DY=abs(DCoord_min(NbDim-1));
|
---|
| 1952 | end
|
---|
| 1953 | npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol
|
---|
| 1954 | if DX==0
|
---|
| 1955 | DX=abs(DCoord_min(NbDim));
|
---|
| 1956 | end
|
---|
| 1957 | npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol
|
---|
| 1958 | for idim=1:NbDim
|
---|
| 1959 | if test_interp(idim)
|
---|
| 1960 | DimValue(idim)=1+round(abs(Coord{idim}(end)-Coord{idim}(1))/abs(DCoord_min(idim)));%nbre of points after possible interpolation on a regular gri
|
---|
[204] | 1961 | end
|
---|
[206] | 1962 | end
|
---|
| 1963 | Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY);
|
---|
| 1964 | test_direct_y=test_direct(NbDim-1);
|
---|
| 1965 | Coord_x=linspace(Coord{NbDim}(1),Coord{NbDim}(end),npX);
|
---|
| 1966 | test_direct_x=test_direct(NbDim);
|
---|
| 1967 | DAX=DCoord_min(NbDim);
|
---|
| 1968 | DAY=DCoord_min(NbDim-1);
|
---|
[204] | 1969 | minAX=min(Coord_x);
|
---|
| 1970 | maxAX=max(Coord_x);
|
---|
| 1971 | minAY=min(Coord_y);
|
---|
| 1972 | maxAY=max(Coord_y);
|
---|
| 1973 | xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
|
---|
| 1974 | ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
|
---|
| 1975 | xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
|
---|
| 1976 | ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
|
---|
| 1977 | if ~testXMax
|
---|
| 1978 | XMax=max(xcor_new);
|
---|
| 1979 | end
|
---|
| 1980 | if ~testXMin
|
---|
| 1981 | XMin=min(xcor_new);
|
---|
| 1982 | end
|
---|
| 1983 | if ~testYMax
|
---|
| 1984 | YMax=max(ycor_new);
|
---|
| 1985 | end
|
---|
| 1986 | if ~testYMin
|
---|
| 1987 | YMin=min(ycor_new);
|
---|
| 1988 | end
|
---|
[206] | 1989 | DXinit=(maxAX-minAX)/(DimValue(NbDim)-1);
|
---|
| 1990 | DYinit=(maxAY-minAY)/(DimValue(NbDim-1)-1);
|
---|
[204] | 1991 | if DX==0
|
---|
| 1992 | DX=DXinit;
|
---|
| 1993 | end
|
---|
| 1994 | if DY==0
|
---|
| 1995 | DY=DYinit;
|
---|
| 1996 | end
|
---|
[206] | 1997 | if NbDim==3
|
---|
| 1998 | DZ=(Coord{1}(end)-Coord{1}(1))/(DimValue(1)-1);
|
---|
| 1999 | if ~test_direct(1)
|
---|
| 2000 | DZ=-DZ;
|
---|
| 2001 | end
|
---|
| 2002 | Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
|
---|
| 2003 | test_direct_z=test_direct(1);
|
---|
| 2004 | end
|
---|
[204] | 2005 | npX=floor((XMax-XMin)/DX+1);
|
---|
[206] | 2006 | npY=floor((YMax-YMin)/DY+1);
|
---|
[204] | 2007 | if test_direct_y
|
---|
| 2008 | coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
|
---|
| 2009 | else
|
---|
| 2010 | coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
|
---|
| 2011 | end
|
---|
| 2012 | if test_direct_x
|
---|
| 2013 | coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
|
---|
| 2014 | else
|
---|
| 2015 | coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
|
---|
| 2016 | end
|
---|
| 2017 |
|
---|
| 2018 | % case with no rotation and interpolation
|
---|
| 2019 | if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
|
---|
[206] | 2020 | if ~testXMin && ~testXMax && ~testYMin && ~testYMax && NbDim==2
|
---|
| 2021 | ProjData=FieldData;
|
---|
[204] | 2022 | else
|
---|
[206] | 2023 | indY=NbDim-1;
|
---|
| 2024 | if test_direct(indY)
|
---|
| 2025 | min_indy=ceil((YMin-Coord{indY}(1))/DYinit)+1;
|
---|
| 2026 | max_indy=floor((YMax-Coord{indY}(1))/DYinit)+1;
|
---|
| 2027 | Ybound(1)=Coord{indY}(1)+DYinit*(min_indy-1);
|
---|
| 2028 | Ybound(2)=Coord{indY}(1)+DYinit*(max_indy-1);
|
---|
| 2029 | else
|
---|
| 2030 | min_indy=ceil((Coord{indY}(1)-YMax)/DYinit)+1;
|
---|
| 2031 | max_indy=floor((Coord{indY}(1)-YMin)/DYinit)+1;
|
---|
| 2032 | Ybound(2)=Coord{indY}(1)-DYinit*(max_indy-1);
|
---|
| 2033 | Ybound(1)=Coord{indY}(1)-DYinit*(min_indy-1);
|
---|
| 2034 | end
|
---|
| 2035 | if test_direct(NbDim)==1
|
---|
| 2036 | min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1;
|
---|
| 2037 | max_indx=floor((XMax-Coord{NbDim}(1))/DXinit)+1;
|
---|
| 2038 | Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
|
---|
| 2039 | Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
|
---|
| 2040 | else
|
---|
| 2041 | min_indx=ceil((Coord{NbDim}(1)-XMax)/DXinit)+1;
|
---|
| 2042 | max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1;
|
---|
| 2043 | Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
|
---|
| 2044 | Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
|
---|
| 2045 | end
|
---|
| 2046 | if NbDim==3
|
---|
| 2047 | DimCell(1)=[]; %suppress z variable
|
---|
| 2048 | DimValue(1)=[];
|
---|
| 2049 | %structured coordinates
|
---|
| 2050 | if test_direct(1)
|
---|
| 2051 | iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
|
---|
| 2052 | else
|
---|
| 2053 | iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;
|
---|
| 2054 | end
|
---|
[204] | 2055 | end
|
---|
[206] | 2056 | min_indy=max(min_indy,1);% deals with margin (bound lower than the first index)
|
---|
| 2057 | min_indx=max(min_indx,1);
|
---|
| 2058 | max_indy=min(max_indy,DimValue(1));
|
---|
| 2059 | max_indx=min(max_indx,DimValue(2));
|
---|
| 2060 | for ivar=VarIndex% loop on non coordinate variables
|
---|
| 2061 | VarName=FieldData.ListVarName{ivar};
|
---|
| 2062 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 2063 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 2064 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
|
---|
| 2065 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
|
---|
| 2066 | end
|
---|
| 2067 | if NbDim==3
|
---|
| 2068 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']);
|
---|
| 2069 | else
|
---|
| 2070 | eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']);
|
---|
| 2071 | end
|
---|
| 2072 | end
|
---|
| 2073 | eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
|
---|
| 2074 | eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates
|
---|
| 2075 | end
|
---|
| 2076 | else % case with rotation and/or interpolation
|
---|
| 2077 | if NbDim==2 %2D case
|
---|
[204] | 2078 | [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
|
---|
| 2079 | XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
|
---|
| 2080 | YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
|
---|
| 2081 | XIMA=(XIMA-minAX)/DXinit+1;% image index along x
|
---|
| 2082 | YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
|
---|
| 2083 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
| 2084 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
| 2085 | flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
|
---|
| 2086 | if isequal(ObjectData.ProjMode,'filter')
|
---|
| 2087 | npx_filter=ceil(abs(DX/DAX));
|
---|
| 2088 | npy_filter=ceil(abs(DY/DAY));
|
---|
| 2089 | Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
|
---|
| 2090 | test_filter=1;
|
---|
| 2091 | else
|
---|
| 2092 | test_filter=0;
|
---|
| 2093 | end
|
---|
[206] | 2094 | eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
|
---|
| 2095 | eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates
|
---|
[204] | 2096 | for ivar=VarIndex
|
---|
[206] | 2097 | VarName=FieldData.ListVarName{ivar};
|
---|
| 2098 | if test_interp(1) || test_interp(2)%interpolate on a regular grid
|
---|
| 2099 | eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
|
---|
[204] | 2100 | end
|
---|
| 2101 | %filter the field (image) if option 'filter' is used
|
---|
| 2102 | if test_filter
|
---|
| 2103 | Aclass=class(FieldData.A);
|
---|
[206] | 2104 | eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
|
---|
[204] | 2105 | if ~isequal(Aclass,'double')
|
---|
[206] | 2106 | eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
|
---|
[204] | 2107 | end
|
---|
| 2108 | end
|
---|
| 2109 | eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
|
---|
[206] | 2110 | %ind_in=find(flagin);
|
---|
[204] | 2111 | ind_out=find(~flagin);
|
---|
| 2112 | ICOMB=(XIMA-1)*DimValue(1)+YIMA;
|
---|
| 2113 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
[206] | 2114 | vec_B(flagin,1:nbcolor)=vec_A(ICOMB,:);
|
---|
[204] | 2115 | for icolor=1:nbcolor
|
---|
| 2116 | vec_B(ind_out,icolor)=zeros(size(ind_out));
|
---|
| 2117 | end
|
---|
[206] | 2118 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 2119 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 2120 | if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
|
---|
[204] | 2121 | ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
| 2122 | end
|
---|
| 2123 | eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
|
---|
| 2124 | end
|
---|
| 2125 | ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
|
---|
| 2126 | ProjData.ListVarName=[ProjData.ListVarName 'FF'];
|
---|
[206] | 2127 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
[204] | 2128 | ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
|
---|
| 2129 | else %3D case
|
---|
[206] | 2130 | if ~testangle
|
---|
| 2131 | % unstructured z coordinate
|
---|
[204] | 2132 | test_sup=(Coord{1}>=ObjectData.Coord(1,3));
|
---|
| 2133 | iz_sup=find(test_sup);
|
---|
| 2134 | iz=iz_sup(1);
|
---|
| 2135 | if iz>=1 & iz<=npz
|
---|
| 2136 | %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
|
---|
| 2137 | %ProjData.DimValue=[ProjData.DimValue npY npX];
|
---|
| 2138 | for ivar=VarIndex
|
---|
| 2139 | VarName=FieldData.ListVarName{ivar};
|
---|
| 2140 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 2141 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
| 2142 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
| 2143 | %TODO : do a vertical average for a thick plane
|
---|
| 2144 | if test_interp(2) || test_interp(3)
|
---|
| 2145 | eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
|
---|
| 2146 | end
|
---|
| 2147 | end
|
---|
| 2148 | end
|
---|
| 2149 | else
|
---|
| 2150 | errormsg='projection of structured coordinates on oblique plane not yet implemented';
|
---|
| 2151 | %TODO: use interp3
|
---|
| 2152 | return
|
---|
| 2153 | end
|
---|
| 2154 | end
|
---|
| 2155 | end
|
---|
| 2156 | end
|
---|
[206] | 2157 |
|
---|
| 2158 | %% projection of velocity components in the rotated coordinates
|
---|
| 2159 | if testangle
|
---|
[204] | 2160 | if isempty(ivar_V)
|
---|
| 2161 | msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
|
---|
| 2162 | return
|
---|
| 2163 | end
|
---|
| 2164 | UName=FieldData.ListVarName{ivar_U};
|
---|
| 2165 | VName=FieldData.ListVarName{ivar_V};
|
---|
| 2166 | eval(['ProjData.' UName '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
|
---|
| 2167 | eval(['ProjData.' VName '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
|
---|
| 2168 | if ~isempty(ivar_W)
|
---|
| 2169 | WName=FieldData.ListVarName{ivar_W};
|
---|
| 2170 | eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
|
---|
| 2171 | eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
|
---|
| 2172 | end
|
---|
| 2173 | if ~isequal(Psi,0)
|
---|
| 2174 | eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
|
---|
| 2175 | eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
|
---|
| 2176 | end
|
---|
| 2177 | end
|
---|
| 2178 | end
|
---|
| 2179 |
|
---|
[206] | 2180 | %------------------------------------------------------------------------
|
---|
| 2181 | %--- transfer the global attributes
|
---|
[204] | 2182 | function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)
|
---|
[206] | 2183 | %------------------------------------------------------------------------
|
---|
[204] | 2184 | ProjData=[];%default
|
---|
[206] | 2185 | errormsg='';%default
|
---|
| 2186 |
|
---|
| 2187 | %% transfer error
|
---|
| 2188 | if isfield(FieldData,'Txt')
|
---|
| 2189 | errormsg=FieldData.Txt; %transmit erreur message
|
---|
| 2190 | return;
|
---|
| 2191 | end
|
---|
| 2192 |
|
---|
| 2193 | %% transfer global attributes
|
---|
[204] | 2194 | if ~isfield(FieldData,'ListGlobalAttribute')
|
---|
| 2195 | ProjData.ListGlobalAttribute={};
|
---|
| 2196 | else
|
---|
| 2197 | ProjData.ListGlobalAttribute=FieldData.ListGlobalAttribute;
|
---|
| 2198 | end
|
---|
| 2199 | for iattr=1:length(ProjData.ListGlobalAttribute)
|
---|
| 2200 | AttrName=ProjData.ListGlobalAttribute{iattr};
|
---|
| 2201 | if isfield(FieldData,AttrName)
|
---|
| 2202 | eval(['ProjData.' AttrName '=FieldData.' AttrName ';']);
|
---|
| 2203 | end
|
---|
| 2204 | end
|
---|
[206] | 2205 |
|
---|
| 2206 | %% transfer coordinate unit
|
---|
[204] | 2207 | if isfield(FieldData,'CoordUnit')
|
---|
| 2208 | if isfield(ObjectData,'CoordUnit')&~isequal(FieldData.CoordUnit,ObjectData.CoordUnit)
|
---|
| 2209 | errormsg=[ObjectData.Style ' in ' ObjectData.CoordUnit ' coordinates, while field in ' FieldData.CoordUnit ];
|
---|
| 2210 | return
|
---|
| 2211 | else
|
---|
| 2212 | ProjData.CoordUnit=FieldData.CoordUnit;
|
---|
| 2213 | end
|
---|
| 2214 | end
|
---|
| 2215 |
|
---|
[206] | 2216 | %% store the properties of the projection object
|
---|
[204] | 2217 | ListObject={'Style','ProjMode','RangeX','RangeY','RangeZ','Phi','Theta','Psi','Coord'};
|
---|
| 2218 | for ilist=1:length(ListObject)
|
---|
| 2219 | if isfield(ObjectData,ListObject{ilist})
|
---|
| 2220 | eval(['val=ObjectData.' ListObject{ilist} ';'])
|
---|
| 2221 | if ~isempty(val)
|
---|
| 2222 | eval(['ProjData.Object' ListObject{ilist} '=val;']);
|
---|
| 2223 | ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['Object' ListObject{ilist}]}];
|
---|
| 2224 | end
|
---|
| 2225 | end
|
---|
| 2226 | end
|
---|