[958] | 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 | %=======================================================================
|
---|
[1126] | 47 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[958] | 48 | % http://www.legi.grenoble-inp.fr
|
---|
[1127] | 49 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
|
---|
[958] | 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 | Field=[];
|
---|
| 80 | VelTypeOut=VelType;
|
---|
| 81 | errormsg='';
|
---|
| 82 | if ~exist(FileName,'file')
|
---|
| 83 | errormsg=['input file ' FileName ' does not exist'];
|
---|
| 84 | return
|
---|
| 85 | end
|
---|
| 86 | if ischar(FieldNames), FieldNames={FieldNames}; end;
|
---|
| 87 | ProjModeRequest='';
|
---|
| 88 | for ilist=1:length(FieldNames)
|
---|
| 89 | if ~isempty(FieldNames{ilist})
|
---|
| 90 | switch FieldNames{ilist}
|
---|
[987] | 91 | case {'U','V','norm(U,V)'}
|
---|
[958] | 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
|
---|
| 99 | end
|
---|
| 100 |
|
---|
[1131] | 101 | %% read the hdf file
|
---|
| 102 | Datasets=hdf5load(FileName);%read the hdf file
|
---|
[958] | 103 |
|
---|
[1131] | 104 | %% Global attributes
|
---|
| 105 | Field.ListGlobalAttribute={'Dt','Time','CivStage','NbCoord','NbDim','TimeUnit','CoordUnit'};
|
---|
[958] | 106 | Field.Dt=1;
|
---|
| 107 | Field.Time=0;
|
---|
| 108 | if isfield(Datasets, 'piv1')
|
---|
| 109 | Field.CivStage=6;
|
---|
| 110 | else
|
---|
| 111 | Field.CivStage=3;
|
---|
| 112 | end
|
---|
[1131] | 113 | Field.NbCoord=2;
|
---|
| 114 | Field.NbDim=2;
|
---|
| 115 | Field.TimeUnit='s';
|
---|
| 116 | Field.CoordUnit='pixel';
|
---|
| 117 |
|
---|
| 118 | %% reading data
|
---|
| 119 | Field.ListVarName={'X' 'Y' 'U' 'V' 'C' 'F' 'FF'};
|
---|
| 120 | Field.VarDimName={'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec'};
|
---|
[958] | 121 | VelTypeOut=VelType;
|
---|
| 122 | switch VelType
|
---|
| 123 | case {'civ1','filter1'}
|
---|
| 124 | Data=Datasets.piv0;
|
---|
[1131] | 125 | %VelTypeOut='filter1';
|
---|
[958] | 126 | case {'civ2','filter2'}
|
---|
| 127 | Data=Datasets.piv1;
|
---|
[1131] | 128 | %VelTypeOut='filter2';
|
---|
| 129 | case ''% no field specified as input, choose the most appropriate
|
---|
[958] | 130 | if isfield(Datasets, 'piv1')
|
---|
| 131 | Data=Datasets.piv1;
|
---|
| 132 | VelTypeOut='filter2';
|
---|
| 133 | else
|
---|
| 134 | Data=Datasets.piv0;
|
---|
| 135 | VelTypeOut='filter1';
|
---|
| 136 | end
|
---|
| 137 | end
|
---|
[1131] | 138 | npy=double(Datasets.couple.shape_images(1)); %number of pixels along y for the image sources
|
---|
[958] | 139 | switch VelType
|
---|
| 140 | case {'civ1','civ2'}
|
---|
| 141 | Field.X= double(Data.xs);
|
---|
[1131] | 142 | Field.Y= npy-double(Data.ys);
|
---|
[958] | 143 | Field.U= double(Data.deltaxs);
|
---|
[1131] | 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',''}
|
---|
[1003] | 153 | Field.X= double(Data.ixvecs_final);
|
---|
[1131] | 154 | Field.Y= npy-double(Data.iyvecs_final);
|
---|
[1003] | 155 | Field.U= double(Data.deltaxs_final);
|
---|
[1131] | 156 | Field.V= -double(Data.deltays_final);
|
---|
| 157 | checkcolor=1;%color representation of the correlation and errors
|
---|
[958] | 158 | end
|
---|
[1131] | 159 | Field.U(isnan(Field.U)) = 0;
|
---|
| 160 | Field.V(isnan(Field.V)) = 0;
|
---|
| 161 | Field.C=ones(size(Field.U));%default
|
---|
| 162 | Field.F=zeros(size(Field.U));
|
---|
| 163 | Field.FF=zeros(size(Field.U));
|
---|
| 164 | if 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;
|
---|
[958] | 168 | end
|
---|
[1131] | 169 |
|
---|
| 170 | %% set variable attributes
|
---|
[958] | 171 | ivar_U_tps=[];
|
---|
| 172 | ivar_V_tps=[];
|
---|
[1131] | 173 | role={'coord_x','coord_y','vector_x','vector_y','ancillary','warnflag','errorflag'};
|
---|
| 174 | vardetect=ones(size(role));
|
---|
[958] | 175 | var_ind=find(vardetect);
|
---|
| 176 | for ivar=1:numel(var_ind)
|
---|
| 177 | Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
|
---|
[1131] | 178 | Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
|
---|
[958] | 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
|
---|
| 196 | end
|
---|
| 197 | if ~isempty(ivar_U_tps)
|
---|
| 198 | Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
|
---|
| 199 | end
|
---|
| 200 | if ~isempty(ivar_V_tps)
|
---|
| 201 | Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
|
---|
| 202 | end
|
---|
| 203 |
|
---|
[1131] | 204 |
|
---|