[237] | 1 | %'read_civdata': reads new civ data from netcdf files
|
---|
| 2 | %------------------------------------------------------------------
|
---|
| 3 | %
|
---|
[613] | 4 | % function [Field,VelTypeOut]=read_civdata(FileName,FieldNames,VelType)
|
---|
[237] | 5 | %
|
---|
| 6 | % OUTPUT:
|
---|
| 7 | % Field: structure representing the selected field, containing
|
---|
| 8 | % .Txt: (char string) error message if any
|
---|
| 9 | % .ListGlobalAttribute: list of global attributes containing:
|
---|
| 10 | % .NbCoord: number of vector components
|
---|
| 11 | % .NbDim: number of dimensions (=2 or 3)
|
---|
[515] | 12 | % .Dt: time interval for the corresponding image pair
|
---|
[237] | 13 | % .Time: absolute time (average of the initial image pair)
|
---|
| 14 | % .CivStage: =0,
|
---|
| 15 | % =1, civ1 has been performed only
|
---|
| 16 | % =2, fix1 has been performed
|
---|
| 17 | % =3, pacth1 has been performed
|
---|
| 18 | % =4, civ2 has been performed
|
---|
| 19 | % =5, fix2 has been performed
|
---|
| 20 | % =6, pacth2 has been performed
|
---|
| 21 | % .CoordUnit: 'pixel'
|
---|
| 22 | % .ListVarName: {'X' 'Y' 'U' 'V' 'F' 'FF'}
|
---|
| 23 | % .X, .Y, .Z: set of vector coordinates
|
---|
| 24 | % .U,.V,.W: corresponding set of vector components
|
---|
| 25 | % .F: warning flags
|
---|
| 26 | % .FF: error flag, =0 for good vectors
|
---|
| 27 | % .C: scalar associated with velocity (used for vector colors)
|
---|
| 28 | %
|
---|
| 29 | % VelTypeOut: velocity type corresponding to the selected field: ='civ1','interp1','interp2','civ2'....
|
---|
| 30 | %
|
---|
| 31 | % INPUT:
|
---|
[613] | 32 | % FileName: file name (string).
|
---|
[237] | 33 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
[1135] | 34 | % 'U','V','norm(U,V)','curl(U,V)','div(U,V)','strain(U,V)'
|
---|
[237] | 35 | % VelType : character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
| 36 | % if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
|
---|
| 37 | % if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
|
---|
[809] | 38 | %
|
---|
[237] | 39 | % FUNCTIONS called:
|
---|
| 40 | % 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
|
---|
| 41 | % 'nc2struct': reads a netcdf file
|
---|
| 42 |
|
---|
[809] | 43 | %=======================================================================
|
---|
[1126] | 44 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[809] | 45 | % http://www.legi.grenoble-inp.fr
|
---|
[1127] | 46 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
|
---|
[809] | 47 | %
|
---|
| 48 | % This file is part of the toolbox UVMAT.
|
---|
| 49 | %
|
---|
| 50 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 51 | % it under the terms of the GNU General Public License as published
|
---|
| 52 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 53 | % or (at your option) any later version.
|
---|
| 54 | %
|
---|
| 55 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 56 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 57 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 58 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 59 | %=======================================================================
|
---|
| 60 |
|
---|
[613] | 61 | function [Field,VelTypeOut,errormsg]=read_civdata(FileName,FieldNames,VelType)
|
---|
[406] | 62 |
|
---|
[237] | 63 | %% default input
|
---|
| 64 | if ~exist('VelType','var')
|
---|
[246] | 65 | VelType='';
|
---|
[237] | 66 | end
|
---|
[1135] | 67 | if isempty(VelType)||strcmp(VelType,'*')
|
---|
[246] | 68 | VelType='';
|
---|
[237] | 69 | end
|
---|
| 70 | if ~exist('FieldNames','var')
|
---|
[1135] | 71 | FieldNames={}; %default
|
---|
[237] | 72 | end
|
---|
[613] | 73 | Field=[];
|
---|
| 74 | VelTypeOut=VelType;
|
---|
[406] | 75 | errormsg='';
|
---|
[515] | 76 | if ischar(FieldNames), FieldNames={FieldNames}; end;
|
---|
[581] | 77 | ProjModeRequest='';
|
---|
[515] | 78 | for ilist=1:length(FieldNames)
|
---|
| 79 | if ~isempty(FieldNames{ilist})
|
---|
| 80 | switch FieldNames{ilist}
|
---|
[987] | 81 | case {'U','V','norm(U,V)'}
|
---|
[654] | 82 | if ~strcmp(FieldNames{1},'vec(U,V)')% if the scalar is not used as color of vectors
|
---|
[581] | 83 | ProjModeRequest='interp_lin';
|
---|
[654] | 84 | end
|
---|
[515] | 85 | case {'curl(U,V)','div(U,V)','strain(U,V)'}
|
---|
[581] | 86 | ProjModeRequest='interp_tps';
|
---|
[515] | 87 | end
|
---|
| 88 | end
|
---|
| 89 | end
|
---|
[237] | 90 |
|
---|
| 91 | %% reading data
|
---|
[1050] | 92 | [Data,tild,tild,errormsg]=nc2struct(FileName,'ListGlobalAttribute','CivStage');
|
---|
| 93 | if ~isempty(errormsg)
|
---|
| 94 | errormsg=['read_civdata: ' errormsg];
|
---|
[612] | 95 | return
|
---|
| 96 | end
|
---|
[822] | 97 | % set the list of variables to read and their role
|
---|
[581] | 98 | [varlist,role,VelTypeOut]=varcivx_generator(ProjModeRequest,VelType,Data.CivStage);
|
---|
[406] | 99 | if isempty(varlist)
|
---|
[1050] | 100 | errormsg=['read_civdata: unknow velocity type ' VelType];
|
---|
[406] | 101 | return
|
---|
| 102 | else
|
---|
[613] | 103 | [Field,vardetect]=nc2struct(FileName,varlist);%read the variables in the netcdf file
|
---|
[406] | 104 | end
|
---|
[237] | 105 | if isfield(Field,'Txt')
|
---|
| 106 | errormsg=Field.Txt;
|
---|
| 107 | return
|
---|
| 108 | end
|
---|
| 109 | if vardetect(1)==0
|
---|
[613] | 110 | errormsg=[ 'requested field not available in ' FileName '/' VelType ': need to run patch'];
|
---|
[237] | 111 | return
|
---|
| 112 | end
|
---|
[380] | 113 | switch VelTypeOut
|
---|
[987] | 114 | case {'civ1','filter1'}
|
---|
[494] | 115 | if isfield(Field,'Patch1_SubDomain')
|
---|
| 116 | Field.SubDomain=Field.Patch1_SubDomain;
|
---|
| 117 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
|
---|
[822] | 118 | end
|
---|
[594] | 119 | if isfield(Field,'Civ1_Dt')
|
---|
[822] | 120 | Field.Dt=Field.Civ1_Dt;
|
---|
[594] | 121 | end
|
---|
| 122 | if isfield(Field,'Civ1_Time')
|
---|
[822] | 123 | Field.Time=Field.Civ1_Time;
|
---|
[594] | 124 | end
|
---|
[987] | 125 | case {'civ2','filter2'}
|
---|
[494] | 126 | if isfield(Field,'Patch2_SubDomain')
|
---|
| 127 | Field.SubDomain=Field.Patch2_SubDomain;
|
---|
| 128 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
|
---|
| 129 | end
|
---|
[594] | 130 | if isfield(Field,'Civ2_Dt')
|
---|
[380] | 131 | Field.Dt=Field.Civ2_Dt;
|
---|
[594] | 132 | end
|
---|
| 133 | if isfield(Field,'Civ2_Time')
|
---|
[494] | 134 | Field.Time=Field.Civ2_Time;
|
---|
[594] | 135 | end
|
---|
[372] | 136 | end
|
---|
[494] | 137 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt','Time'}];
|
---|
[515] | 138 | ivar_U_tps=[];
|
---|
[581] | 139 | ivar_V_tps=[];
|
---|
[237] | 140 | var_ind=find(vardetect);
|
---|
[389] | 141 | for ivar=1:numel(var_ind)
|
---|
[237] | 142 | Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
|
---|
[871] | 143 | %Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
|
---|
[674] | 144 | Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
|
---|
[515] | 145 | if strcmp(role{var_ind(ivar)},'vector_x')
|
---|
[576] | 146 | Field.VarAttribute{ivar}.FieldName=FieldNames;
|
---|
[515] | 147 | ivar_U=ivar;
|
---|
| 148 | end
|
---|
| 149 | if strcmp(role{var_ind(ivar)},'vector_x_tps')
|
---|
[576] | 150 | Field.VarAttribute{ivar}.FieldName=FieldNames;
|
---|
[515] | 151 | ivar_U_tps=ivar;
|
---|
| 152 | end
|
---|
[581] | 153 | if strcmp(role{var_ind(ivar)},'vector_y')
|
---|
| 154 | Field.VarAttribute{ivar}.FieldName=FieldNames;
|
---|
| 155 | ivar_V=ivar;
|
---|
| 156 | end
|
---|
| 157 | if strcmp(role{var_ind(ivar)},'vector_y_tps')
|
---|
| 158 | Field.VarAttribute{ivar}.FieldName=FieldNames;
|
---|
| 159 | ivar_V_tps=ivar;
|
---|
| 160 | end
|
---|
[237] | 161 | end
|
---|
[515] | 162 | if ~isempty(ivar_U_tps)
|
---|
| 163 | Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
|
---|
| 164 | end
|
---|
[581] | 165 | if ~isempty(ivar_V_tps)
|
---|
| 166 | Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
|
---|
| 167 | end
|
---|
[515] | 168 |
|
---|
[581] | 169 | %% update list of global attributes
|
---|
[237] | 170 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
|
---|
| 171 | Field.NbCoord=2;
|
---|
| 172 | Field.NbDim=2;
|
---|
| 173 | Field.TimeUnit='s';
|
---|
| 174 | Field.CoordUnit='pixel';
|
---|
| 175 |
|
---|
| 176 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 177 | % [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
|
---|
| 178 | %INPUT:
|
---|
| 179 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
| 180 | % 'ima_cor': image correlation, vec_c or vec2_C
|
---|
| 181 | % 'vort','div','strain': requires velocity derivatives DUDX...
|
---|
| 182 | % 'error': error estimate (vec_E or vec2_E)
|
---|
| 183 | %
|
---|
| 184 | % vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
[380] | 185 | % if vel_type=[] or'*', a priority choice is done, civ2 considered better than civ1 )
|
---|
[237] | 186 |
|
---|
[581] | 187 | function [var,role,vel_type_out,errormsg]=varcivx_generator(ProjModeRequest,vel_type,CivStage)
|
---|
[237] | 188 |
|
---|
| 189 | %% default input values
|
---|
[1135] | 190 | if ~exist('vel_type','var'),vel_type='';end
|
---|
| 191 | if iscell(vel_type),vel_type=vel_type{1}; end%transform cell to string if needed
|
---|
[406] | 192 | errormsg='';
|
---|
[1153] | 193 | if CivStage>=6
|
---|
| 194 | CivStage=6;
|
---|
| 195 | end
|
---|
[237] | 196 |
|
---|
| 197 | %% select the priority order for automatic vel_type selection
|
---|
[1153] | 198 | if strcmp(ProjModeRequest,'derivatives')&& numel(vel_type)>=3 && strcmp(vel_type(1:3),'civ')
|
---|
| 199 | vel_type=['filter' vel_type(4:end)];
|
---|
[492] | 200 | end
|
---|
[406] | 201 | if isempty(vel_type)||strcmp(vel_type,'*')
|
---|
[851] | 202 | vel_type='filter2';% case CivStage >=6
|
---|
[380] | 203 | switch CivStage
|
---|
[1153] | 204 | case {1,2}% civ1 available but not filter1
|
---|
| 205 | vel_type='civ1';
|
---|
| 206 | case 3
|
---|
| 207 | vel_type='filter1';
|
---|
| 208 |
|
---|
[380] | 209 | case {4,5}% civ2 available but not filter2
|
---|
[581] | 210 | if strcmp(ProjModeRequest,'derivatives')% derivatives needed
|
---|
[492] | 211 | vel_type='filter1';
|
---|
[380] | 212 | else
|
---|
| 213 | vel_type='civ2';
|
---|
| 214 | end
|
---|
| 215 | end
|
---|
| 216 | end
|
---|
[492] | 217 |
|
---|
[406] | 218 | var={};
|
---|
[246] | 219 | switch vel_type
|
---|
[1117] | 220 | case{'civ1','civ2','civ3'}
|
---|
| 221 | varout={'X','Y','Z','U','V','W','C','F','FF'};
|
---|
| 222 | varin= {'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
|
---|
| 223 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
|
---|
| 224 | case{'filter1','filter2','filter3'}
|
---|
| 225 | varout={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre'};
|
---|
| 226 | varin={'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U_smooth','Civ1_V_smooth','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
|
---|
[651] | 227 | 'Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps','Civ1_W_tps','Civ1_SubRange','Civ1_NbCentre','Civ1_NbCentres','Civ1_NbSites'};
|
---|
[497] | 228 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
|
---|
[651] | 229 | 'vector_y_tps','vector_z_tps','ancillary','ancillary','ancillary','ancillary'};
|
---|
[1117] | 230 | % rmq: NbCentres and NbSites obsolete replaced by NbCentre, kept for consistency with previous data
|
---|
[246] | 231 | end
|
---|
[1117] | 232 | switch vel_type
|
---|
| 233 | case {'civ2','filter2'}
|
---|
| 234 | varin=regexprep(varin,'1','2');
|
---|
| 235 | case {'civ3','filter3'}
|
---|
| 236 | varin=regexprep(varin,'1','3');
|
---|
| 237 | end
|
---|
| 238 | var=[varout;varin];
|
---|
[581] | 239 | if ~strcmp(ProjModeRequest,'interp_tps')
|
---|
[515] | 240 | var=var(:,1:9);%suppress tps if not needed
|
---|
| 241 | end
|
---|
[380] | 242 | vel_type_out=vel_type;
|
---|
[237] | 243 |
|
---|
| 244 |
|
---|
| 245 |
|
---|
[246] | 246 |
|
---|
| 247 |
|
---|