1 | %'read_civdata': reads new civ data from netcdf files
|
---|
2 | %------------------------------------------------------------------
|
---|
3 | %
|
---|
4 | % function [Field,VelTypeOut]=read_civxdata(filename,FieldNames,VelType)
|
---|
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)
|
---|
12 | % .Dt: time interval for the corresponding image pair
|
---|
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 | % .DijU; matrix of spatial derivatives (DijU(1,1,:)=DUDX,
|
---|
29 | % DijU(1,2,:)=DUDY, Dij(2,1,:)=DVDX, DijU(2,2,:)=DVDY
|
---|
30 | %
|
---|
31 | % VelTypeOut: velocity type corresponding to the selected field: ='civ1','interp1','interp2','civ2'....
|
---|
32 | %
|
---|
33 | % INPUT:
|
---|
34 | % filename: file name (string).
|
---|
35 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
36 | % 'ima_cor': image correlation, vec_c or vec2_C
|
---|
37 | % 'vort','div','strain': requires velocity derivatives DUDX...
|
---|
38 | % 'error': error estimate (vec_E or vec2_E)
|
---|
39 | %
|
---|
40 | % VelType : character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
41 | % if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
|
---|
42 | % if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
|
---|
43 |
|
---|
44 |
|
---|
45 | % FUNCTIONS called:
|
---|
46 | % 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
|
---|
47 | % 'nc2struct': reads a netcdf file
|
---|
48 |
|
---|
49 | function [Field,VelTypeOut,errormsg]=read_civdata(filename,FieldNames,VelType)
|
---|
50 |
|
---|
51 | %% default input
|
---|
52 | if ~exist('VelType','var')
|
---|
53 | VelType='';
|
---|
54 | end
|
---|
55 | if isequal(VelType,'*')
|
---|
56 | VelType='';
|
---|
57 | end
|
---|
58 | if isempty(VelType)
|
---|
59 | VelType='';
|
---|
60 | end
|
---|
61 | if ~exist('FieldNames','var')
|
---|
62 | FieldNames=[]; %default
|
---|
63 | end
|
---|
64 | errormsg='';
|
---|
65 | if ischar(FieldNames), FieldNames={FieldNames}; end;
|
---|
66 | FieldRequest='';
|
---|
67 | for ilist=1:length(FieldNames)
|
---|
68 | if ~isempty(FieldNames{ilist})
|
---|
69 | switch FieldNames{ilist}
|
---|
70 | case{'U','V','norm(U,V)'}
|
---|
71 | FieldRequest='interp_lin';
|
---|
72 | case {'curl(U,V)','div(U,V)','strain(U,V)'}
|
---|
73 | FieldRequest='interp_tps';
|
---|
74 | end
|
---|
75 | end
|
---|
76 | end
|
---|
77 |
|
---|
78 | %% reading data
|
---|
79 | Data=nc2struct(filename,'ListGlobalAttribute','CivStage');
|
---|
80 | [varlist,role,VelTypeOut]=varcivx_generator(FieldRequest,VelType,Data.CivStage);
|
---|
81 | if isempty(varlist)
|
---|
82 | erromsg=['error in read_civdata: unknow velocity type ' VelType];
|
---|
83 | return
|
---|
84 | else
|
---|
85 | [Field,vardetect]=nc2struct(filename,varlist);%read the variables in the netcdf file
|
---|
86 | end
|
---|
87 | if isfield(Field,'Txt')
|
---|
88 | errormsg=Field.Txt;
|
---|
89 | return
|
---|
90 | end
|
---|
91 | if vardetect(1)==0
|
---|
92 | errormsg=[ 'requested field not available in ' filename '/' VelType ': need to run patch'];
|
---|
93 | return
|
---|
94 | end
|
---|
95 | switch VelTypeOut
|
---|
96 | case{'civ1','filter1'}
|
---|
97 | if isfield(Field,'Patch1_SubDomain')
|
---|
98 | Field.SubDomain=Field.Patch1_SubDomain;
|
---|
99 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
|
---|
100 | end
|
---|
101 | Field.Dt=Field.Civ1_Dt;
|
---|
102 | Field.Time=Field.Civ1_Time;
|
---|
103 | case{'civ2','filter2'}
|
---|
104 | if isfield(Field,'Patch2_SubDomain')
|
---|
105 | Field.SubDomain=Field.Patch2_SubDomain;
|
---|
106 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
|
---|
107 | end
|
---|
108 | Field.Dt=Field.Civ2_Dt;
|
---|
109 | Field.Time=Field.Civ2_Time;
|
---|
110 | end
|
---|
111 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt','Time'}];
|
---|
112 | ivar_U_tps=[];
|
---|
113 | var_ind=find(vardetect);
|
---|
114 | for ivar=1:numel(var_ind)
|
---|
115 | Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
|
---|
116 | Field.VarAttribute{ivar}.FieldRequest=FieldRequest;
|
---|
117 | if strcmp(role{var_ind(ivar)},'vector_x')
|
---|
118 | Field.VarAttribute{ivar}.Operation=FieldNames;
|
---|
119 | ivar_U=ivar;
|
---|
120 | end
|
---|
121 | if strcmp(role{var_ind(ivar)},'vector_x_tps')
|
---|
122 | Field.VarAttribute{ivar}.Operation=FieldNames;
|
---|
123 | ivar_U_tps=ivar;
|
---|
124 | end
|
---|
125 | % Field.VarAttribute{ivar}.Unit=units{var_ind(ivar)};
|
---|
126 | Field.VarAttribute{ivar}.Mesh=0.1;%typical mesh for histograms O.1 pixel
|
---|
127 | end
|
---|
128 | if ~isempty(ivar_U_tps)
|
---|
129 | Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
|
---|
130 | end
|
---|
131 |
|
---|
132 | Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
|
---|
133 | % %% update list of global attributes
|
---|
134 | Field.NbCoord=2;
|
---|
135 | Field.NbDim=2;
|
---|
136 | Field.TimeUnit='s';
|
---|
137 | Field.CoordUnit='pixel';
|
---|
138 |
|
---|
139 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
140 | % [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
|
---|
141 | %INPUT:
|
---|
142 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
143 | % 'ima_cor': image correlation, vec_c or vec2_C
|
---|
144 | % 'vort','div','strain': requires velocity derivatives DUDX...
|
---|
145 | % 'error': error estimate (vec_E or vec2_E)
|
---|
146 | %
|
---|
147 | % vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
148 | % if vel_type=[] or'*', a priority choice is done, civ2 considered better than civ1 )
|
---|
149 |
|
---|
150 | function [var,role,vel_type_out,errormsg]=varcivx_generator(FieldRequest,vel_type,CivStage)
|
---|
151 |
|
---|
152 | %% default input values
|
---|
153 | if ~exist('vel_type','var'),vel_type='';end;
|
---|
154 | if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
|
---|
155 | errormsg='';
|
---|
156 |
|
---|
157 | %% select the priority order for automatic vel_type selection
|
---|
158 | if strcmp(vel_type,'civ2') && strcmp(FieldRequest,'derivatives')
|
---|
159 | vel_type='filter2';
|
---|
160 | elseif strcmp(vel_type,'civ1') && strcmp(FieldRequest,'derivatives')
|
---|
161 | vel_type='filter1';
|
---|
162 | end
|
---|
163 | if isempty(vel_type)||strcmp(vel_type,'*')
|
---|
164 | switch CivStage
|
---|
165 | case {6} %filter2 available
|
---|
166 | vel_type='filter2';
|
---|
167 | case {4,5}% civ2 available but not filter2
|
---|
168 | if strcmp(FieldRequest,'derivatives')% derivatives needed
|
---|
169 | vel_type='filter1';
|
---|
170 | else
|
---|
171 | vel_type='civ2';
|
---|
172 | end
|
---|
173 | case 3
|
---|
174 | vel_type='filter1';
|
---|
175 | case {1,2}% civ1 available but not filter1
|
---|
176 | vel_type='civ1';
|
---|
177 | end
|
---|
178 | end
|
---|
179 |
|
---|
180 | var={};
|
---|
181 | switch vel_type
|
---|
182 | case 'civ1'
|
---|
183 | var={'X','Y','Z','U','V','W','C','F','FF';...
|
---|
184 | 'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
|
---|
185 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
|
---|
186 | % units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
|
---|
187 | case 'filter1'
|
---|
188 | var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbSites';...
|
---|
189 | 'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U_smooth','Civ1_V_smooth','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
|
---|
190 | 'Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps','Civ1_W_tps','Civ1_SubRange','Civ1_NbSites'};
|
---|
191 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
|
---|
192 | 'vector_y_tps','vector_z_tps','ancillary','ancillary'};
|
---|
193 | % units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
|
---|
194 | case 'civ2'
|
---|
195 | var={'X','Y','Z','U','V','W','C','F','FF';...
|
---|
196 | 'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'};
|
---|
197 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
|
---|
198 | % units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
|
---|
199 | case 'filter2'
|
---|
200 | var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbSites';...
|
---|
201 | 'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U_smooth','Civ2_V_smooth','Civ2_W','Civ2_C','Civ2_F','Civ2_FF',...
|
---|
202 | 'Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps','','Civ2_SubRange','Civ2_NbSites'};
|
---|
203 | role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
|
---|
204 | 'vector_y_tps','vector_z_tps','ancillary','ancillary'};
|
---|
205 | % units={'pixel','pixel','pixel','pixel','pixel','pixel','','','','pixel','pixel','pixel','pixel','pixel',''};
|
---|
206 | end
|
---|
207 | if ~strcmp(FieldRequest,'interp_tps')
|
---|
208 | var=var(:,1:9);%suppress tps if not needed
|
---|
209 | end
|
---|
210 | vel_type_out=vel_type;
|
---|
211 |
|
---|
212 |
|
---|
213 |
|
---|
214 |
|
---|
215 |
|
---|