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