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