[8] | 1 | %'read_civxdata': reads civx data from netcdf files
|
---|
| 2 | %------------------------------------------------------------------
|
---|
| 3 | % COMBINE ET REMPLACE read_ncfield, read_vel et read_scalar_new
|
---|
| 4 | %------------------------------------------------------------------
|
---|
| 5 | % OUTPUT:
|
---|
| 6 | % nb_coord,nb_dim,
|
---|
| 7 | % Civ: =0 or 1, indicates whether the data is civ (A SUPPRIMER ?)
|
---|
| 8 | % CivStage: =0, ??? A UTILISER POUR REMPLACER civ
|
---|
| 9 | % =1, civ1 has been performed only
|
---|
| 10 | % =2, fix1 has been performed
|
---|
| 11 | % =3, pacth1 has been performed
|
---|
| 12 | % =4, civ2 has been performed
|
---|
| 13 | % =5, fix2 has been performed
|
---|
| 14 | % =6, pacth2 has been performed
|
---|
| 15 | % time: absolute time
|
---|
| 16 | % Field
|
---|
| 17 | % .Txt: (char string) error message if any
|
---|
| 18 | % .NbDim: number of dimensions (=0 by default)
|
---|
| 19 | % .NbCoord: number of vector components
|
---|
| 20 | % .CoordType: expresses the type of coordinate ('px' for image, 'sig' for instruments, or 'phys')
|
---|
| 21 | % .dt: time interval for the corresponding image pair
|
---|
| 22 | % .CivStage: =0, ??? A UTILISER POUR REMPLACER civ
|
---|
| 23 | % =1, civ1 has been performed only
|
---|
| 24 | % =2, fix1 has been performed
|
---|
| 25 | % =3, pacth1 has been performed
|
---|
| 26 | % =4, civ2 has been performed
|
---|
| 27 | % =5, fix2 has been performed
|
---|
| 28 | % =6, pacth2 has been performed
|
---|
| 29 | % .X, .Y, .Z: set of vector coordinates
|
---|
| 30 | % .U,.V,.W: corresponding set of vector components
|
---|
| 31 | % .F: warning flags
|
---|
| 32 | % .FF: error flag, =0 for good vectors
|
---|
| 33 | % .C: scalar associated with velocity (used for vector colors)
|
---|
| 34 | % .CoordType
|
---|
| 35 | % .DijU; matrix of spatial derivatives (DijU(1,1,:)=DUDX,
|
---|
| 36 | % DijU(1,2,:)=DUDY, Dij(2,1,:)=DVDX, DijU(2,2,:)=DVDY
|
---|
| 37 | % .A, .AX, .AY: additional scalar
|
---|
| 38 | % dt:time interval of the image pair red from a single file, or vector with
|
---|
| 39 |
|
---|
| 40 | % pixcmx,pixcmy: scaling factors (from the first file)
|
---|
| 41 | % vel_type_out: string representing the selected velocity type (civ1,civ2,filter1...)
|
---|
| 42 | %
|
---|
| 43 | % INPUT:
|
---|
| 44 | % filename: file name (string).
|
---|
| 45 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
| 46 | % 'ima_cor': image correlation, vec_c or vec2_C
|
---|
| 47 | % 'vort','div','strain': requires velocity derivatives DUDX...
|
---|
| 48 | % 'error': error estimate (vec_E or vec2_E)
|
---|
| 49 | %
|
---|
| 50 | % VelType : character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
| 51 | % if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
|
---|
| 52 | % if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | % FUNCTIONS called:
|
---|
| 56 | % 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
|
---|
| 57 | % 'nc2struct': reads a netcdf file
|
---|
| 58 |
|
---|
| 59 | function [Field,VelTypeOut]=read_civxdata(filename,FieldNames,VelType)
|
---|
| 60 |
|
---|
| 61 | if ~exist('VelType','var')
|
---|
| 62 | VelType=[];
|
---|
| 63 | end
|
---|
| 64 | if isequal(VelType,'*')
|
---|
| 65 | VelType=[];
|
---|
| 66 | end
|
---|
| 67 | if ~exist('FieldNames','var')
|
---|
| 68 | FieldNames=[]; %default
|
---|
| 69 | end
|
---|
| 70 |
|
---|
| 71 | VelTypeOut=VelType;%default
|
---|
| 72 | [var,role,units,vel_type_out_cell]=varcivx_generator(FieldNames,VelType);%determine the names of constants and variables to read
|
---|
| 73 | [Field,vardetect,ichoice]=nc2struct(filename,var);
|
---|
| 74 | if isfield(Field,'Txt')
|
---|
| 75 | return % error in file reading
|
---|
| 76 | end
|
---|
| 77 | if isequal(vardetect,0)
|
---|
| 78 | Field.Txt=[FieldNames ' not accessible in ' filename '/' VelType];
|
---|
| 79 | return
|
---|
| 80 | end
|
---|
| 81 | var_ind=find(vardetect);
|
---|
| 82 | for ivar=1:length(var_ind)
|
---|
| 83 | Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
|
---|
| 84 | % Field.VarAttribute{ivar}.units=units{var_ind(ivar)};% not necessary: set with calc_field
|
---|
| 85 | end
|
---|
| 86 | VelTypeOut=VelType;
|
---|
| 87 | if ~isempty(ichoice)
|
---|
| 88 | VelTypeOut=vel_type_out_cell{ichoice};
|
---|
| 89 | end
|
---|
| 90 |
|
---|
| 91 | %adjust for Djui:
|
---|
| 92 | if isfield(Field,'DjUi')
|
---|
| 93 | Field.ListVarName(end-2:end)=[];
|
---|
| 94 | Field.ListVarName{end}='DjUi';
|
---|
| 95 | Field.VarDimIndex(end-2:end)=[];
|
---|
| 96 | Field.VarAttribute(end-2:end)=[];
|
---|
| 97 | end
|
---|
| 98 |
|
---|
| 99 | %determine the appropriate constant for time and dt for the PIV pair
|
---|
| 100 | test_civ1=isequal(VelTypeOut,'civ1')||isequal(VelTypeOut,'interp1')||isequal(VelTypeOut,'filter1');
|
---|
| 101 | test_civ2=isequal(VelTypeOut,'civ2')||isequal(VelTypeOut,'interp2')||isequal(VelTypeOut,'filter2');
|
---|
| 102 | if test_civ1
|
---|
| 103 | Field.Time=Field.absolut_time_T0;
|
---|
| 104 | elseif test_civ2
|
---|
| 105 | Field.Time=Field.absolut_time_T0_2;
|
---|
| 106 | Field.dt=Field.dt2;
|
---|
| 107 | else
|
---|
| 108 | Field.Txt='the input file is not civx';
|
---|
| 109 | display(Field.Txt)
|
---|
| 110 | end
|
---|
| 111 |
|
---|
| 112 | % CivStage
|
---|
| 113 | if isfield(Field,'patch2')&& isequal(Field.patch2,1)
|
---|
| 114 | Field.CivStage=6;
|
---|
| 115 | elseif isfield(Field,'fix2')&& isequal(Field.fix2,1)
|
---|
| 116 | Field.CivStage=5;
|
---|
| 117 | elseif isfield(Field,'civ2')&& isequal(Field.civ2,1)
|
---|
| 118 | Field.CivStage=4;
|
---|
| 119 | elseif isfield(Field,'patch')&& isequal(Field.patch,1)
|
---|
| 120 | Field.CivStage=3;
|
---|
| 121 | elseif isfield(Field,'fix')&& isequal(Field.fix,1)
|
---|
| 122 | Field.CivStage=2;
|
---|
| 123 | else
|
---|
| 124 | Field.CivStage=1;
|
---|
| 125 | end
|
---|
| 126 |
|
---|
| 127 | %update list of global attributes
|
---|
| 128 | List=Field.ListGlobalAttribute;
|
---|
| 129 | ind_remove=[];
|
---|
| 130 | for ilist=1:length(List)
|
---|
| 131 | switch(List{ilist})
|
---|
| 132 | case {'patch2','fix2','civ2','patch','fix','dt2','absolut_time_T0','absolut_time_T0_2'}
|
---|
| 133 | ind_remove=[ind_remove ilist];
|
---|
| 134 | Field=rmfield(Field,List{ilist});
|
---|
| 135 | end
|
---|
| 136 | end
|
---|
| 137 | List(ind_remove)=[];
|
---|
| 138 | Field.ListGlobalAttribute=[List {'Time','CivStage','CoordUnit'}];
|
---|
| 139 |
|
---|
| 140 | % rescale to pixel coordiantes
|
---|
| 141 | if isfield(Field,'pixcmx')
|
---|
| 142 | Field.U=Field.U*Field.pixcmx;
|
---|
| 143 | Field.V=Field.V*Field.pixcmy;
|
---|
| 144 | Field.X=Field.X*Field.pixcmx;
|
---|
| 145 | Field.Y=Field.Y*Field.pixcmy;
|
---|
| 146 | end
|
---|
| 147 | if ~isequal(Field.dt,0)
|
---|
| 148 | Field.U=Field.U*Field.dt;%translate in px displacement
|
---|
| 149 | Field.V=Field.V*Field.dt;
|
---|
| 150 | if isfield(Field,'DjUi')
|
---|
| 151 | Field.DjUi(:,1,1)=Field.dt*Field.DjUi(:,1,1);
|
---|
| 152 | Field.DjUi(:,2,2)=Field.dt*Field.DjUi(:,2,2);
|
---|
| 153 | Field.DjUi(:,1,2)=(Field.pixcmy/Field.pixcmx)*Field.dt*Field.DjUi(:,1,2);
|
---|
| 154 | Field.DjUi(:,2,1)=(Field.pixcmx/Field.pixcmy)*Field.dt*Field.DjUi(:,2,1);
|
---|
| 155 | end
|
---|
| 156 | end
|
---|
| 157 | Field.CoordType='px';% TODO: abandon, use COORdUnit instead ? (to adapt 'px' and 'phys')
|
---|
| 158 | Field.CoordUnit='pixel';
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 162 | % [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
|
---|
| 163 | %INPUT:
|
---|
| 164 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
| 165 | % 'ima_cor': image correlation, vec_c or vec2_C
|
---|
| 166 | % 'vort','div','strain': requires velocity derivatives DUDX...
|
---|
| 167 | % 'error': error estimate (vec_E or vec2_E)
|
---|
| 168 | %
|
---|
| 169 | % vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
| 170 | % if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
|
---|
| 171 | % if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
|
---|
| 172 |
|
---|
| 173 | function [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
|
---|
| 174 |
|
---|
| 175 | %default input values
|
---|
| 176 | if ~exist('vel_type','var'),vel_type=[];end;
|
---|
| 177 | if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
|
---|
| 178 | % if ~exist('display','var'),display=[];end;
|
---|
| 179 | if ~exist('FieldNames','var'),FieldNames={'ima_cor'};end;%default scalar
|
---|
| 180 | if ischar(FieldNames), FieldNames={FieldNames}; end;
|
---|
| 181 |
|
---|
| 182 | %select the priority order for automatic vel_type selection
|
---|
| 183 | testder=0;
|
---|
| 184 | for ilist=1:length(FieldNames)
|
---|
| 185 | if ~isempty(FieldNames{ilist})
|
---|
| 186 | switch FieldNames{ilist}
|
---|
| 187 | case {'vort','div','strain'}
|
---|
| 188 | testder=1;
|
---|
| 189 | end
|
---|
| 190 | end
|
---|
| 191 | end
|
---|
| 192 | if isempty(vel_type) || isequal(vel_type,'*') %undefined velocity type (civ1,civ2...)
|
---|
| 193 | if testder
|
---|
| 194 | vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
|
---|
| 195 | vel_type_out{2}='filter1';
|
---|
| 196 | else
|
---|
| 197 | vel_type_out{1}='civ2'; %priority to civ2 for vector reading, civ1 as second priority
|
---|
| 198 | vel_type_out{2}='civ1';
|
---|
| 199 | end
|
---|
| 200 | elseif isequal(vel_type,'filter')
|
---|
| 201 | vel_type_out{1}='filter2'; %priority to filter2 for scalar reading, filter1 as second
|
---|
| 202 | vel_type_out{2}='filter1';
|
---|
| 203 | if ~testder
|
---|
| 204 | vel_type_out{3}='civ1';%civ1 as third priority if derivatives are not needed
|
---|
| 205 | end
|
---|
| 206 | elseif testder
|
---|
| 207 | test_civ1=isequal(vel_type,'civ1')||isequal(vel_type,'interp1')||isequal(vel_type,'filter1');
|
---|
| 208 | if test_civ1
|
---|
| 209 | vel_type_out{1}='filter1'; %switch to filter for reading spatial derivatives
|
---|
| 210 | else
|
---|
| 211 | vel_type_out{1}='filter2';
|
---|
| 212 | end
|
---|
| 213 | else
|
---|
| 214 | vel_type_out{1}=vel_type;%imposed velocity field
|
---|
| 215 | end
|
---|
| 216 | vel_type_out=vel_type_out';
|
---|
| 217 |
|
---|
| 218 | %determine names of netcdf variables to read
|
---|
| 219 | var={'X','Y','Z','U','V','W','C','F','FF'};
|
---|
| 220 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
|
---|
| 221 | units={'pixel','pixel','pixel','pixel','pixel','pixel',[],[],[]};
|
---|
| 222 | if testder
|
---|
| 223 | var=[var {'DjUi(:,1,1)','DjUi(:,1,2)','DjUi(:,2,1)','DjUi(:,2,2)'}];
|
---|
| 224 | role=[role {'tensor','tensor','tensor','tensor'}];
|
---|
| 225 | units=[units {'pixel','pixel','pixel','pixel'}];
|
---|
| 226 | end
|
---|
| 227 | for ilist=1:length(vel_type_out)
|
---|
| 228 | var=[var;varname1(vel_type_out{ilist},FieldNames)];
|
---|
| 229 | end
|
---|
| 230 |
|
---|
| 231 |
|
---|
| 232 | %-------------------------
|
---|
| 233 | %determine var names to read
|
---|
| 234 | %--------------------------------------
|
---|
| 235 | function varin=varname1(vel_type,FieldNames)
|
---|
| 236 |
|
---|
| 237 | testder=0;
|
---|
| 238 | C1='';
|
---|
| 239 | C2='';
|
---|
| 240 | for ilist=1:length(FieldNames)
|
---|
| 241 | if ~isempty(FieldNames{ilist})
|
---|
| 242 | switch FieldNames{ilist}
|
---|
| 243 | case 'ima_cor' %image correlation corresponding to a vel vector
|
---|
| 244 | C1='vec_C';
|
---|
| 245 | C2='vec2_C';
|
---|
| 246 | case 'error'
|
---|
| 247 | C1='vec_E';
|
---|
| 248 | C2='vec2_E';
|
---|
| 249 | case {'vort','div','strain'}
|
---|
| 250 | testder=1;
|
---|
| 251 | end
|
---|
| 252 | end
|
---|
| 253 | end
|
---|
| 254 | switch vel_type
|
---|
| 255 | case 'civ1'
|
---|
| 256 | varin={'vec_X','vec_Y','vec_Z','vec_U','vec_V','vec_W',C1,'vec_F','vec_FixFlag'};
|
---|
| 257 | case 'interp1'
|
---|
| 258 | varin={'vec_patch_X','vec_patch_Y','','vec_patch0_U','vec_patch0_V','','','',''};
|
---|
| 259 | case 'filter1'
|
---|
| 260 | varin={'vec_patch_X','vec_patch_Y','','vec_patch_U','vec_patch_V','','','',''};
|
---|
| 261 | case 'civ2'
|
---|
| 262 | varin={'vec2_X','vec2_Y','vec2_Z','vec2_U','vec2_V','vec2_W',C2,'vec2_F','vec2_FixFlag'};
|
---|
| 263 | case 'interp2'
|
---|
| 264 | varin={'vec2_patch_X','vec2_patch_Y','vec2_patch_Z','vec2_patch0_U','vec2_patch0_V','vec2_patch0_W','','',''};
|
---|
| 265 | case 'filter2'
|
---|
| 266 | varin={'vec2_patch_X','vec2_patch_Y','vec2_patch_Z','vec2_patch_U','vec2_patch_V','vec2_patch0_W','','',''};
|
---|
| 267 | end
|
---|
| 268 | if testder
|
---|
| 269 | switch vel_type
|
---|
| 270 | case 'filter1'
|
---|
| 271 | varin=[varin {'vec_patch_DUDX','vec_patch_DVDX','vec_patch_DUDY','vec_patch_DVDY'}];
|
---|
| 272 | case 'filter2'
|
---|
| 273 | varin=[varin {'vec2_patch_DUDX','vec2_patch_DVDX','vec2_patch_DUDY','vec2_patch_DVDY'}];
|
---|
| 274 | end
|
---|
| 275 | end |
---|