source: trunk/src/read_civdata.m @ 1040

Last change on this file since 1040 was 1033, checked in by sommeria, 6 years ago

miscellaneous updates

File size: 10.6 KB
RevLine 
[237]1%'read_civdata': reads new civ data from netcdf files
2%------------------------------------------------------------------
3%
[613]4% function [Field,VelTypeOut]=read_civdata(FileName,FieldNames,VelType)
[237]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)
[515]12%                    .Dt: time interval for the corresponding image pair
[237]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:
[613]32% FileName: file name (string).
[237]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)
[809]41%
[237]42% FUNCTIONS called:
43% 'varcivx_generator':, sets the names of vaiables to read in the netcdf file
44% 'nc2struct': reads a netcdf file
45
[809]46%=======================================================================
[1027]47% Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[809]48%   http://www.legi.grenoble-inp.fr
49%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.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
[613]64function [Field,VelTypeOut,errormsg]=read_civdata(FileName,FieldNames,VelType)
[406]65
[237]66%% default input
67if ~exist('VelType','var')
[246]68    VelType='';
[237]69end
70if isequal(VelType,'*')
[246]71    VelType='';
[237]72end
[246]73if isempty(VelType)
74    VelType='';
75end
[237]76if ~exist('FieldNames','var')
77    FieldNames=[]; %default
78end
[613]79Field=[];
80VelTypeOut=VelType;
[406]81errormsg='';
[515]82if ischar(FieldNames), FieldNames={FieldNames}; end;
[581]83ProjModeRequest='';
[515]84for ilist=1:length(FieldNames)
85    if ~isempty(FieldNames{ilist})
86        switch FieldNames{ilist}
[987]87            case {'U','V','norm(U,V)'}
[654]88                if ~strcmp(FieldNames{1},'vec(U,V)')% if the scalar is not used as color of vectors
[581]89                ProjModeRequest='interp_lin';
[654]90                end
[515]91            case {'curl(U,V)','div(U,V)','strain(U,V)'}
[581]92                ProjModeRequest='interp_tps';
[515]93        end
94    end
95end
[237]96
97%% reading data
[613]98Data=nc2struct(FileName,'ListGlobalAttribute','CivStage');
[612]99if isfield(Data,'Txt')
[1033]100     errormsg=['error in read_civdata: ' Data.Txt];
[612]101    return
102end
[822]103% set the list of variables to read and their role
[581]104[varlist,role,VelTypeOut]=varcivx_generator(ProjModeRequest,VelType,Data.CivStage);
[406]105if isempty(varlist)
[1033]106    errormsg=['error in read_civdata: unknow velocity type ' VelType];
[406]107    return
108else
[613]109    [Field,vardetect]=nc2struct(FileName,varlist);%read the variables in the netcdf file
[406]110end
[237]111if isfield(Field,'Txt')
112    errormsg=Field.Txt;
113    return
114end
115if vardetect(1)==0
[613]116     errormsg=[ 'requested field not available in ' FileName '/' VelType ': need to run patch'];
[237]117     return
118end
[380]119switch VelTypeOut
[987]120    case {'civ1','filter1'}
[494]121        if isfield(Field,'Patch1_SubDomain')
122            Field.SubDomain=Field.Patch1_SubDomain;
123            Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
[822]124        end
[594]125        if isfield(Field,'Civ1_Dt')
[822]126            Field.Dt=Field.Civ1_Dt;
[594]127        end
128        if isfield(Field,'Civ1_Time')
[822]129            Field.Time=Field.Civ1_Time;
[594]130        end
[987]131    case {'civ2','filter2'}
[494]132        if isfield(Field,'Patch2_SubDomain')
133            Field.SubDomain=Field.Patch2_SubDomain;
134            Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
135        end
[594]136        if isfield(Field,'Civ2_Dt')
[380]137        Field.Dt=Field.Civ2_Dt;
[594]138        end
139        if isfield(Field,'Civ2_Time')
[494]140        Field.Time=Field.Civ2_Time;
[594]141        end
[372]142end
[494]143Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt','Time'}];
[515]144ivar_U_tps=[];
[581]145ivar_V_tps=[];
[237]146var_ind=find(vardetect);
[389]147for ivar=1:numel(var_ind)
[237]148    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
[871]149    %Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
[674]150    Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
[515]151    if strcmp(role{var_ind(ivar)},'vector_x')
[576]152        Field.VarAttribute{ivar}.FieldName=FieldNames;
[515]153        ivar_U=ivar;
154    end
155    if strcmp(role{var_ind(ivar)},'vector_x_tps')
[576]156        Field.VarAttribute{ivar}.FieldName=FieldNames;
[515]157        ivar_U_tps=ivar;
158    end
[581]159    if strcmp(role{var_ind(ivar)},'vector_y')
160        Field.VarAttribute{ivar}.FieldName=FieldNames;
161        ivar_V=ivar;
162    end
163    if strcmp(role{var_ind(ivar)},'vector_y_tps')
164        Field.VarAttribute{ivar}.FieldName=FieldNames;
165        ivar_V_tps=ivar;
166    end
[237]167end
[515]168if ~isempty(ivar_U_tps)
169    Field.VarAttribute{ivar_U}.VarIndex_tps=ivar_U_tps;
170end
[581]171if ~isempty(ivar_V_tps)
172    Field.VarAttribute{ivar_V}.VarIndex_tps=ivar_V_tps;
173end
[515]174
[581]175%% update list of global attributes
[237]176Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
177Field.NbCoord=2;
178Field.NbDim=2;
179Field.TimeUnit='s';
180Field.CoordUnit='pixel';
181
182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183% [var,role,units,vel_type_out]=varcivx_generator(FieldNames,vel_type)
184%INPUT:
185% FieldNames =cell of field names to get, which can contain the strings:
186%             'ima_cor': image correlation, vec_c or vec2_C
187%             'vort','div','strain': requires velocity derivatives DUDX...
188%             'error': error estimate (vec_E or vec2_E)
189%             
190% vel_type: character string indicating the types of velocity fields to read ('civ1','civ2'...)
[380]191%            if vel_type=[] or'*', a  priority choice is done, civ2 considered better than civ1 )
[237]192
[581]193function [var,role,vel_type_out,errormsg]=varcivx_generator(ProjModeRequest,vel_type,CivStage)
[237]194
195%% default input values
[246]196if ~exist('vel_type','var'),vel_type='';end;
[237]197if iscell(vel_type),vel_type=vel_type{1}; end;%transform cell to string if needed
[406]198errormsg='';
[237]199
200%% select the priority order for automatic vel_type selection
[581]201if strcmp(vel_type,'civ2') && strcmp(ProjModeRequest,'derivatives')
[492]202    vel_type='filter2';
[581]203elseif strcmp(vel_type,'civ1') && strcmp(ProjModeRequest,'derivatives')
[492]204    vel_type='filter1';
205end
[406]206if isempty(vel_type)||strcmp(vel_type,'*')
[851]207    vel_type='filter2';% case CivStage >=6
[380]208    switch CivStage
209        case {4,5}% civ2 available but not filter2
[581]210            if strcmp(ProjModeRequest,'derivatives')% derivatives needed
[492]211                vel_type='filter1';
[380]212            else
213                vel_type='civ2';
214            end
[492]215        case 3
216            vel_type='filter1';
217        case {1,2}% civ1 available but not filter1
[380]218            vel_type='civ1';
219    end
220end
[492]221
[406]222var={};
[246]223switch vel_type
[389]224    case 'civ1'
[492]225        var={'X','Y','Z','U','V','W','C','F','FF';...
226            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U','Civ1_V','Civ1_W','Civ1_C','Civ1_F','Civ1_FF'};
227        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
[515]228    %    units={'pixel','pixel','pixel','pixel','pixel','pixel','','',''};
[389]229    case 'filter1'
[651]230        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre';...
[389]231            'Civ1_X','Civ1_Y','Civ1_Z','Civ1_U_smooth','Civ1_V_smooth','Civ1_W','Civ1_C','Civ1_F','Civ1_FF',...
[651]232            'Civ1_Coord_tps','Civ1_U_tps','Civ1_V_tps','Civ1_W_tps','Civ1_SubRange','Civ1_NbCentre','Civ1_NbCentres','Civ1_NbSites'};
[497]233        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
[651]234            'vector_y_tps','vector_z_tps','ancillary','ancillary','ancillary','ancillary'};
235     %  rmq: NbCentres and NbSites obsolete replaced by NbCentre, kept for consistency with previous data
[389]236    case 'civ2'
[492]237        var={'X','Y','Z','U','V','W','C','F','FF';...
238            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U','Civ2_V','Civ2_W','Civ2_C','Civ2_F','Civ2_FF'};
239        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag'};
[389]240    case 'filter2'
[651]241        var={'X','Y','Z','U','V','W','C','F','FF','Coord_tps','U_tps','V_tps','W_tps','SubRange','NbCentre','NbCentre','NbCentre';...
[389]242            'Civ2_X','Civ2_Y','Civ2_Z','Civ2_U_smooth','Civ2_V_smooth','Civ2_W','Civ2_C','Civ2_F','Civ2_FF',...
[651]243            'Civ2_Coord_tps','Civ2_U_tps','Civ2_V_tps','','Civ2_SubRange','Civ2_NbCentre','Civ2_NbCentres','Civ2_NbSites'};
[497]244        role={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','ancillary','warnflag','errorflag','coord_tps','vector_x_tps',...
[651]245            'vector_y_tps','vector_z_tps','ancillary','ancillary','ancillary','ancillary'};
[246]246end
[581]247if ~strcmp(ProjModeRequest,'interp_tps')
[515]248    var=var(:,1:9);%suppress tps if not needed
249end
[380]250vel_type_out=vel_type;
[237]251
252
253
[246]254
255
Note: See TracBrowser for help on using the repository browser.