1 | %'read_civdata': reads new civ data from netcdf files
|
---|
2 | %------------------------------------------------------------------
|
---|
3 | %
|
---|
4 | % function [Field,VelTypeOut]=read_civdata(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 | %
|
---|
29 | % VelTypeOut: velocity type corresponding to the selected field: ='civ1','interp1','interp2','civ2'....
|
---|
30 | %
|
---|
31 | % INPUT:
|
---|
32 | % FileName: file name (string).
|
---|
33 | % FieldNames =cell of field names to get, which can contain the strings:
|
---|
34 | % 'ima_cor': image correlation, vec_c or vec2_C
|
---|
35 | % 'vort','div','strain': requires velocity derivatives DUDX...
|
---|
36 | % 'error': error estimate (vec_E or vec2_E)
|
---|
37 | %
|
---|
38 | % VelType : character string indicating the types of velocity fields to read ('civ1','civ2'...)
|
---|
39 | % if vel_type=[] or'*', a priority choice, given by vel_type_out{1,2}, is done depending
|
---|
40 | % if vel_type='filter'; a structured field is sought (filter2 in priority, then filter1)
|
---|
41 | %
|
---|
42 | % FUNCTIONS called:
|
---|
43 | % 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
|
---|
44 | % 'nc2struct': reads a netcdf file
|
---|
45 |
|
---|
46 | %=======================================================================
|
---|
47 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
48 | % http://www.legi.grenoble-inp.fr
|
---|
49 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
|
---|
50 | %
|
---|
51 | % This file is part of the toolbox UVMAT.
|
---|
52 | %
|
---|
53 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
54 | % it under the terms of the GNU General Public License as published
|
---|
55 | % by the Free Software Foundation; either version 2 of the license,
|
---|
56 | % or (at your option) any later version.
|
---|
57 | %
|
---|
58 | % UVMAT is distributed in the hope that it will be useful,
|
---|
59 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
60 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
61 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
62 | %=======================================================================
|
---|
63 |
|
---|
64 | function [Field,VelTypeOut,errormsg]=read_pivdata_fluidimage(FileName,FieldNames,VelType)
|
---|
65 |
|
---|
66 | %% default input
|
---|
67 | if ~exist('VelType','var')
|
---|
68 | VelType='';
|
---|
69 | end
|
---|
70 | if isequal(VelType,'*')
|
---|
71 | VelType='';
|
---|
72 | end
|
---|
73 | if isempty(VelType)
|
---|
74 | VelType='';
|
---|
75 | end
|
---|
76 | if ~exist('FieldNames','var')
|
---|
77 | FieldNames=[]; %default
|
---|
78 | end
|
---|
79 | if isempty(FieldNames)||isempty(FieldNames{1})
|
---|
80 | FieldNames={'vec(U,V)'};
|
---|
81 | end
|
---|
82 | Field=[];
|
---|
83 | VelTypeOut=VelType;
|
---|
84 | errormsg='';
|
---|
85 | if ~exist(FileName,'file')
|
---|
86 | errormsg=['input file ' FileName ' does not exist'];
|
---|
87 | return
|
---|
88 | end
|
---|
89 | if ischar(FieldNames), FieldNames={FieldNames}; end
|
---|
90 | ProjModeRequest='';
|
---|
91 | for ilist=1:length(FieldNames)
|
---|
92 | if ~isempty(FieldNames{ilist})
|
---|
93 | switch FieldNames{ilist}
|
---|
94 | case {'U','V','norm(U,V)'}
|
---|
95 | if ~strcmp(FieldNames{1},'vec(U,V)')% if the scalar is not used as color of vectors
|
---|
96 | ProjModeRequest='interp_lin';
|
---|
97 | end
|
---|
98 | case {'curl(U,V)','div(U,V)','strain(U,V)'}
|
---|
99 | ProjModeRequest='interp_tps';
|
---|
100 | end
|
---|
101 | end
|
---|
102 | end
|
---|
103 |
|
---|
104 | %% read the hdf file
|
---|
105 | Datasets=hdf5load(FileName);%read the hdf file
|
---|
106 |
|
---|
107 | %% Global attributes
|
---|
108 | Field.ListGlobalAttribute={'Dt','Time','CivStage','NbCoord','NbDim','TimeUnit','CoordUnit'};
|
---|
109 | Field.Dt=1;
|
---|
110 | Field.Time=0;
|
---|
111 | if isfield(Datasets, 'piv1')
|
---|
112 | Field.CivStage=6;
|
---|
113 | else
|
---|
114 | Field.CivStage=3;
|
---|
115 | end
|
---|
116 | Field.NbCoord=2;
|
---|
117 | Field.NbDim=2;
|
---|
118 | Field.TimeUnit='s';
|
---|
119 | Field.CoordUnit='pixel';
|
---|
120 |
|
---|
121 | %% reading data
|
---|
122 | Field.ListVarName={'X' 'Y' 'U' 'V' 'C' 'F' 'FF'};
|
---|
123 | Field.VarDimName={'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec'};
|
---|
124 | % Field.VarAttribute{1}.Role='coord_x';
|
---|
125 | % Field.VarAttribute{2}.Role='coord_y';
|
---|
126 | % Field.VarAttribute{3}.Role='vector_x';
|
---|
127 | % Field.VarAttribute{3}.FieldName={'vec(U,V)'};
|
---|
128 |
|
---|
129 | VelTypeOut=VelType;
|
---|
130 | switch VelType
|
---|
131 | case {'civ1','filter1'}
|
---|
132 | Data=Datasets.piv0;
|
---|
133 | %VelTypeOut='filter1';
|
---|
134 | case {'civ2','filter2'}
|
---|
135 | Data=Datasets.piv1;
|
---|
136 | %VelTypeOut='filter2';
|
---|
137 | case ''% no field specified as input, choose the most appropriate
|
---|
138 | if isfield(Datasets, 'piv1')
|
---|
139 | Data=Datasets.piv1;
|
---|
140 | VelTypeOut='filter2';
|
---|
141 | else
|
---|
142 | Data=Datasets.piv0;
|
---|
143 | VelTypeOut='filter1';
|
---|
144 | end
|
---|
145 | end
|
---|
146 | npy=double(Datasets.couple.shape_images(1)); %number of pixels along y for the image sources
|
---|
147 | switch VelType
|
---|
148 | case {'civ1','civ2'}
|
---|
149 | Field.X= double(Data.xs);
|
---|
150 | Field.Y= npy-double(Data.ys);
|
---|
151 | Field.U= double(Data.deltaxs);
|
---|
152 | Field.V= -double(Data.deltays);
|
---|
153 | checkcolor=1;%color representation of the correlation and errors
|
---|
154 | case 'filter1'
|
---|
155 | Field.X= double(Data.ixvecs_approx);
|
---|
156 | Field.Y= npy-double(Data.iyvecs_approx);
|
---|
157 | Field.U= double(Data.deltaxs_approx);
|
---|
158 | Field.V= -double(Data.deltays_approx);
|
---|
159 | checkcolor=0;%no color representation of the correlation and errors
|
---|
160 | case {'filter2',''}
|
---|
161 | Field.X= double(Data.ixvecs_final);
|
---|
162 | Field.Y= npy-double(Data.iyvecs_final);
|
---|
163 | Field.U= double(Data.deltaxs_final);
|
---|
164 | Field.V= -double(Data.deltays_final);
|
---|
165 | checkcolor=1;%color representation of the correlation and errors
|
---|
166 | end
|
---|
167 | Field.U(isnan(Field.U)) = 0;
|
---|
168 | Field.V(isnan(Field.V)) = 0;
|
---|
169 | Field.C=ones(size(Field.U));%default
|
---|
170 | Field.F=zeros(size(Field.U));
|
---|
171 | Field.FF=zeros(size(Field.U));
|
---|
172 | if checkcolor
|
---|
173 | Field.C = double(Data.correls_max);
|
---|
174 | Field.F(Data.errors.keys + 1)=1; % !!! convention matlab vs python
|
---|
175 | Field.FF(Data.errors.keys + 1)=1;
|
---|
176 | end
|
---|
177 |
|
---|
178 | %% set variable attributes
|
---|
179 | ivar_U_tps=[];
|
---|
180 | ivar_V_tps=[];
|
---|
181 | role={'coord_x','coord_y','vector_x','vector_y','ancillary','warnflag','errorflag'};
|
---|
182 | vardetect=ones(size(role));
|
---|
183 | var_ind=find(vardetect);
|
---|
184 | for ivar=1:numel(var_ind)
|
---|
185 | Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
|
---|
186 | Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
|
---|
187 | Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
|
---|
188 | if strcmp(role{var_ind(ivar)},'vector_x')
|
---|
189 | Field.VarAttribute{ivar}.FieldName=FieldNames;
|
---|
190 | ivar_U=ivar;
|
---|
191 | end
|
---|
192 | if strcmp(role{var_ind(ivar)},'vector_x_tps')
|
---|
193 | Field.VarAttribute{ivar}.FieldName=FieldNames;
|
---|
194 | ivar_U_tps=ivar;
|
---|
195 | end
|
---|
196 | if strcmp(role{var_ind(ivar)},'vector_y')
|
---|
197 | Field.VarAttribute{ivar}.FieldName=FieldNames;
|
---|
198 | ivar_V=ivar;
|
---|
199 | end
|
---|
200 | if strcmp(role{var_ind(ivar)},'vector_y_tps')
|
---|
201 | Field.VarAttribute{ivar}.FieldName=FieldNames;
|
---|
202 | ivar_V_tps=ivar;
|
---|
203 | end
|
---|
204 | end
|
---|
205 | if ~isempty(ivar_U_tps)
|
---|
206 | Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
|
---|
207 | end
|
---|
208 | if ~isempty(ivar_V_tps)
|
---|
209 | Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
|
---|
210 | end
|
---|
211 |
|
---|
212 |
|
---|