source: trunk/src/read_pivdata_fluidimage.m @ 1131

Last change on this file since 1131 was 1131, checked in by sommeria, 3 months ago

updated to read pivdata from fluidimage

File size: 7.6 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
79Field=[];
80VelTypeOut=VelType;
81errormsg='';
82if ~exist(FileName,'file')
83    errormsg=['input file ' FileName ' does not exist'];
84    return
85end
86if ischar(FieldNames), FieldNames={FieldNames}; end;
87ProjModeRequest='';
88for ilist=1:length(FieldNames)
89    if ~isempty(FieldNames{ilist})
90        switch FieldNames{ilist}
91            case {'U','V','norm(U,V)'}
92                if ~strcmp(FieldNames{1},'vec(U,V)')% if the scalar is not used as color of vectors
93                ProjModeRequest='interp_lin';
94                end
95            case {'curl(U,V)','div(U,V)','strain(U,V)'}
96                ProjModeRequest='interp_tps';
97        end
98    end
99end
100
101%% read the hdf file
102Datasets=hdf5load(FileName);%read the hdf file
103
104%% Global attributes
105Field.ListGlobalAttribute={'Dt','Time','CivStage','NbCoord','NbDim','TimeUnit','CoordUnit'};
106Field.Dt=1;
107Field.Time=0;
108if isfield(Datasets, 'piv1')
109    Field.CivStage=6;
110else
111    Field.CivStage=3;
112end
113Field.NbCoord=2;
114Field.NbDim=2;
115Field.TimeUnit='s';
116Field.CoordUnit='pixel';
117
118%% reading data
119Field.ListVarName={'X'  'Y'  'U'  'V'  'C'  'F'  'FF'};
120Field.VarDimName={'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec'};
121VelTypeOut=VelType;
122switch VelType
123    case {'civ1','filter1'}
124        Data=Datasets.piv0;
125        %VelTypeOut='filter1';
126    case {'civ2','filter2'}
127        Data=Datasets.piv1;
128        %VelTypeOut='filter2';
129    case ''% no field specified as input, choose the most appropriate
130        if isfield(Datasets, 'piv1')
131            Data=Datasets.piv1;
132            VelTypeOut='filter2';
133        else
134            Data=Datasets.piv0;
135            VelTypeOut='filter1';
136        end
137end
138npy=double(Datasets.couple.shape_images(1)); %number of pixels along y for the image sources
139switch VelType
140    case {'civ1','civ2'}
141        Field.X= double(Data.xs);
142        Field.Y= npy-double(Data.ys);
143        Field.U= double(Data.deltaxs);
144        Field.V= -double(Data.deltays);
145        checkcolor=1;%color representation of the correlation and errors
146    case 'filter1'
147        Field.X= double(Data.ixvecs_approx);
148        Field.Y= npy-double(Data.iyvecs_approx);
149        Field.U= double(Data.deltaxs_approx);
150        Field.V= -double(Data.deltays_approx);
151        checkcolor=0;%no color representation of the correlation and errors
152    case {'filter2',''}
153        Field.X= double(Data.ixvecs_final);
154        Field.Y= npy-double(Data.iyvecs_final);
155        Field.U= double(Data.deltaxs_final);
156        Field.V= -double(Data.deltays_final);
157        checkcolor=1;%color representation of the correlation and errors
158end
159Field.U(isnan(Field.U)) = 0;
160Field.V(isnan(Field.V)) = 0;
161Field.C=ones(size(Field.U));%default
162Field.F=zeros(size(Field.U));
163Field.FF=zeros(size(Field.U));
164if checkcolor
165    Field.C = double(Data.correls_max);
166    Field.F(Data.errors.keys + 1)=1; % !!! convention matlab vs python
167    Field.FF(Data.errors.keys + 1)=1;
168end
169
170%% set variable attributes
171ivar_U_tps=[];
172ivar_V_tps=[];
173role={'coord_x','coord_y','vector_x','vector_y','ancillary','warnflag','errorflag'};
174vardetect=ones(size(role));
175var_ind=find(vardetect);
176for ivar=1:numel(var_ind)
177    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
178    Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
179    Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
180    if strcmp(role{var_ind(ivar)},'vector_x')
181        Field.VarAttribute{ivar}.FieldName=FieldNames;
182        ivar_U=ivar;
183    end
184    if strcmp(role{var_ind(ivar)},'vector_x_tps')
185        Field.VarAttribute{ivar}.FieldName=FieldNames;
186        ivar_U_tps=ivar;
187    end
188    if strcmp(role{var_ind(ivar)},'vector_y')
189        Field.VarAttribute{ivar}.FieldName=FieldNames;
190        ivar_V=ivar;
191    end
192    if strcmp(role{var_ind(ivar)},'vector_y_tps')
193        Field.VarAttribute{ivar}.FieldName=FieldNames;
194        ivar_V_tps=ivar;
195    end
196end
197if ~isempty(ivar_U_tps)
198    Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
199end
200if ~isempty(ivar_V_tps)
201    Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
202end
203
204
Note: See TracBrowser for help on using the repository browser.