Ignore:
Timestamp:
Apr 11, 2024, 7:30:52 PM (3 weeks ago)
Author:
sommeria
Message:

updated to read pivdata from fluidimage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/read_pivdata_fluidimage.m

    r1127 r1131  
    9999end
    100100
    101 %% reading data
    102 
    103 
    104 % Data=nc2struct(FileName,'ListGlobalAttribute','CivStage');
    105 % if isfield(Data,'Txt')
    106 %      erromsg=['error in read_civdata: ' Data.Txt];
    107 %     return
    108 % end
    109 % % set the list of variables to read and their role
    110 %[varlist,role,VelTypeOut]=varcivx_generator(ProjModeRequest,VelType,Datasets.CivStage);
    111 % if isempty(varlist)
    112 %     erromsg=['error in read_civdata: unknow velocity type ' VelType];
    113 %     return
    114 % else
    115 Datasets=hdf5load(FileName);%read the variables in the netcdf file
    116 %[varlist,role,VelTypeOut]=varcivx_generator(ProjModeRequest,VelType,Datasets.CivStage);
    117 role={'coord_x','coord_y','vector_x','vector_y','ancillary','warnflag','errorflag'};
    118 vardetect=ones(size(role));
    119 Field.ListGlobalAttribute= {'Dt','Time','CivStage'};
     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'};
    120106Field.Dt=1;
    121107Field.Time=0;
     
    125111    Field.CivStage=3;
    126112end
     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'};
    127121VelTypeOut=VelType;
    128122switch VelType
    129123    case {'civ1','filter1'}
    130124        Data=Datasets.piv0;
    131         VelTypeOut='filter1';
     125        %VelTypeOut='filter1';
    132126    case {'civ2','filter2'}
    133127        Data=Datasets.piv1;
    134         VelTypeOut='filter2';
    135     case ''
     128        %VelTypeOut='filter2';
     129    case ''% no field specified as input, choose the most appropriate
    136130        if isfield(Datasets, 'piv1')
    137131            Data=Datasets.piv1;
     
    142136        end
    143137end
     138npy=double(Datasets.couple.shape_images(1)); %number of pixels along y for the image sources
    144139switch VelType
    145140    case {'civ1','civ2'}
    146141        Field.X= double(Data.xs);
    147         Field.Y= double(Data.ys);
     142        Field.Y= npy-double(Data.ys);
    148143        Field.U= double(Data.deltaxs);
    149         Field.U(isnan(Field.U)) = 0;
    150         Field.V= double(Data.deltays);
    151         Field.V(isnan(Field.V)) = 0;
    152     case {'filter1','filter2',''}
     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',''}
    153153        Field.X= double(Data.ixvecs_final);
    154         Field.Y= double(Data.iyvecs_final);
     154        Field.Y= npy-double(Data.iyvecs_final);
    155155        Field.U= double(Data.deltaxs_final);
    156         Field.U(isnan(Field.U)) = 0;
    157         Field.V= double(Data.deltays_final);
    158         Field.V(isnan(Field.V)) = 0;
    159 end
    160 Field.ListVarName={'X'  'Y'  'U'  'V'  'C'  'F'  'FF'};
    161 Field.VarDimName={'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec' 'nb_vec'};
    162 Field.C = double(Data.correls_max);
    163 Field.F=zeros(size(Field.U)); Field.F(Data.errors.keys + 1)=1; % !!! convention matlab vs python
    164 Field.FF=zeros(size(Field.U)); Field.FF(Data.errors.keys + 1)=1;
    165 % if vardetect(1)==0
    166 %      errormsg=[ 'requested field not available in ' FileName '/' VelType ': need to run patch'];
    167 %      return
    168 % end
    169 switch VelTypeOut
    170     case {'civ1','filter1'}
    171         if isfield(Field,'Patch1_SubDomain')
    172             Field.SubDomain=Field.Patch1_SubDomain;
    173             Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
    174         end
    175         if isfield(Field,'Civ1_Dt')
    176             Field.Dt=Field.Civ1_Dt;
    177         end
    178         if isfield(Field,'Civ1_Time')
    179             Field.Time=Field.Civ1_Time;
    180         end
    181     case {'civ2','filter2'}
    182         if isfield(Field,'Patch2_SubDomain')
    183             Field.SubDomain=Field.Patch2_SubDomain;
    184             Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'SubDomain'}];
    185         end
    186         if isfield(Field,'Civ2_Dt')
    187         Field.Dt=Field.Civ2_Dt;
    188         end
    189         if isfield(Field,'Civ2_Time')
    190         Field.Time=Field.Civ2_Time;
    191         end
    192 end
    193 %Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'Dt','Time'}];
     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
    194171ivar_U_tps=[];
    195172ivar_V_tps=[];
     173role={'coord_x','coord_y','vector_x','vector_y','ancillary','warnflag','errorflag'};
     174vardetect=ones(size(role));
    196175var_ind=find(vardetect);
    197176for ivar=1:numel(var_ind)
    198177    Field.VarAttribute{ivar}.Role=role{var_ind(ivar)};
    199     %Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
     178    Field.VarAttribute{ivar}.Mesh=0.025;%typical mesh for histograms O.025 pixel (used in series)
    200179    Field.VarAttribute{ivar}.ProjModeRequest=ProjModeRequest;
    201180    if strcmp(role{var_ind(ivar)},'vector_x')
     
    223202end
    224203
    225 %% update list of global attributes
    226 Field.ListGlobalAttribute=[Field.ListGlobalAttribute {'NbCoord','NbDim','TimeUnit','CoordUnit'}];
    227 Field.NbCoord=2;
    228 Field.NbDim=2;
    229 Field.TimeUnit='s';
    230 Field.CoordUnit='pixel';
     204
Note: See TracChangeset for help on using the changeset viewer.