source: trunk/src/read_pivdata_fluidimage.m @ 1157

Last change on this file since 1157 was 1141, checked in by sommeria, 7 months ago

smoothig parameter renormalised in filter_tps

File size: 7.8 KB
Line 
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
64function [Field,VelTypeOut,errormsg]=read_pivdata_fluidimage(FileName,FieldNames,VelType)
65
66%% default input
67if ~exist('VelType','var')
68    VelType='';
69end
70if isequal(VelType,'*')
71    VelType='';
72end
73if isempty(VelType)
74    VelType='';
75end
76if ~exist('FieldNames','var')
77    FieldNames=[]; %default
78end
79if isempty(FieldNames)||isempty(FieldNames{1})
80    FieldNames={'vec(U,V)'};
81end
82Field=[];
83VelTypeOut=VelType;
84errormsg='';
85if ~exist(FileName,'file')
86    errormsg=['input file ' FileName ' does not exist'];
87    return
88end
89if ischar(FieldNames), FieldNames={FieldNames}; end
90ProjModeRequest='';
91for 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
102end
103
104%% read the hdf file
105Datasets=hdf5load(FileName);%read the hdf file
106
107%% Global attributes
108Field.ListGlobalAttribute={'Dt','Time','CivStage','NbCoord','NbDim','TimeUnit','CoordUnit'};
109Field.Dt=1;
110Field.Time=0;
111if isfield(Datasets, 'piv1')
112    Field.CivStage=6;
113else
114    Field.CivStage=3;
115end
116Field.NbCoord=2;
117Field.NbDim=2;
118Field.TimeUnit='s';
119Field.CoordUnit='pixel';
120
121%% reading data
122Field.ListVarName={'X'  'Y'  'U'  'V'  'C'  'F'  'FF'};
123Field.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
129VelTypeOut=VelType;
130switch 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
145end
146npy=double(Datasets.couple.shape_images(1)); %number of pixels along y for the image sources
147switch 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.xs_smooth);
162        Field.Y= npy-double(Data.ys_smooth);
163        Field.U= double(Data.deltaxs_smooth);
164        Field.V= -double(Data.deltays_smooth);
165        checkcolor=1;%color representation of the correlation and errors
166end
167Field.U(isnan(Field.U)) = 0;
168Field.V(isnan(Field.V)) = 0;
169Field.C=ones(size(Field.U));%default
170Field.F=zeros(size(Field.U));
171Field.FF=zeros(size(Field.U));
172if 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;
176end
177
178%% set variable attributes
179ivar_U_tps=[];
180ivar_V_tps=[];
181role={'coord_x','coord_y','vector_x','vector_y','ancillary','warnflag','errorflag'};
182vardetect=ones(size(role));
183var_ind=find(vardetect);
184for 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
204end
205if ~isempty(ivar_U_tps)
206    Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
207end
208if ~isempty(ivar_V_tps)
209    Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
210end
211
212
Note: See TracBrowser for help on using the repository browser.