[884] | 1 | %'aver_stat': calculate field average over a time series
|
---|
| 2 | %------------------------------------------------------------------------
|
---|
| 3 | % function ParamOut=aver_stat(Param)
|
---|
| 4 | %
|
---|
| 5 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 6 | %
|
---|
| 7 | %OUTPUT
|
---|
| 8 | % ParamOut: sets options in the GUI series.fig needed for the function
|
---|
| 9 | %
|
---|
| 10 | %INPUT:
|
---|
| 11 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
|
---|
| 12 | % In batch mode, Param is the name of the corresponding xml file containing the same information
|
---|
| 13 | % when Param.Action.RUN=0 (as activated when the current Action is selected
|
---|
| 14 | % in series), the function ouput paramOut set the activation of the needed GUI elements
|
---|
| 15 | %
|
---|
[960] | 16 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to
|
---|
[884] | 17 | % see the current structure Param)
|
---|
| 18 | % .InputTable: cell of input file names, (several lines for multiple input)
|
---|
| 19 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
|
---|
| 20 | % .OutputSubDir: name of the subdirectory for data outputs
|
---|
| 21 | % .OutputDirExt: directory extension for data outputs
|
---|
| 22 | % .Action: .ActionName: name of the current activated function
|
---|
| 23 | % .ActionPath: path of the current activated function
|
---|
| 24 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct
|
---|
| 25 | % .RUN =0 for GUI input, =1 for function activation
|
---|
| 26 | % .RunMode='local','background', 'cluster': type of function use
|
---|
[960] | 27 | %
|
---|
[884] | 28 | % .IndexRange: set the file or frame indices on which the action must be performed
|
---|
| 29 | % .FieldTransform: .TransformName: name of the selected transform function
|
---|
| 30 | % .TransformPath: path of the selected transform function
|
---|
| 31 | % .InputFields: sub structure describing the input fields withfields
|
---|
| 32 | % .FieldName: name(s) of the field
|
---|
| 33 | % .VelType: velocity type
|
---|
| 34 | % .FieldName_1: name of the second field in case of two input series
|
---|
| 35 | % .VelType_1: velocity type of the second field in case of two input series
|
---|
| 36 | % .Coord_y: name of y coordinate variable
|
---|
| 37 | % .Coord_x: name of x coordinate variable
|
---|
| 38 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
|
---|
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 40 |
|
---|
| 41 | %=======================================================================
|
---|
[1126] | 42 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[884] | 43 | % http://www.legi.grenoble-inp.fr
|
---|
[1127] | 44 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
|
---|
[884] | 45 | %
|
---|
| 46 | % This file is part of the toolbox UVMAT.
|
---|
| 47 | %
|
---|
| 48 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 49 | % it under the terms of the GNU General Public License as published
|
---|
| 50 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 51 | % or (at your option) any later version.
|
---|
| 52 | %
|
---|
| 53 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 54 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 55 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 56 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 57 | %=======================================================================
|
---|
| 58 |
|
---|
| 59 | function ParamOut=aver_stat(Param)
|
---|
| 60 |
|
---|
| 61 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName
|
---|
| 62 | if isstruct(Param) && isequal(Param.Action.RUN,0)% function activated from the GUI series but not RUN
|
---|
| 63 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
|
---|
| 64 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
|
---|
| 65 | ParamOut.NbSlice='on'; %nbre of slices ('off' by default)
|
---|
| 66 | ParamOut.VelType='two';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default)
|
---|
| 67 | ParamOut.FieldName='two';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
|
---|
| 68 | ParamOut.FieldTransform = 'on';%can use a transform function
|
---|
| 69 | ParamOut.ProjObject='on';%can use projection object(option 'off'/'on',
|
---|
| 70 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default)
|
---|
| 71 | ParamOut.OutputDirExt='.stat';%set the output dir extension
|
---|
[960] | 72 | ParamOut.OutputFileMode='NbSlice';% '=NbInput': one output file per input file index, '=NbInput_i': one file per input file index i, '=NbSlice': one file per slice
|
---|
| 73 | % check for selection of a projection object
|
---|
[884] | 74 | hseries=findobj(allchild(0),'Tag','series');% handles of the GUI series
|
---|
| 75 | if ~isfield(Param,'ProjObject')
|
---|
| 76 | answer=msgbox_uvmat('INPUT_Y-N','use a projection object?');
|
---|
| 77 | if strcmp(answer,'Yes')
|
---|
| 78 | hhseries=guidata(hseries);
|
---|
| 79 | set(hhseries.CheckObject,'Visible','on')
|
---|
| 80 | set(hhseries.CheckObject,'Value',1)
|
---|
| 81 | Param.CheckObject=1;
|
---|
| 82 | series('CheckObject_Callback',hseries,[],hhseries); %file input with xml reading in uvmat, show the image in phys coordinates
|
---|
| 83 | end
|
---|
| 84 | end
|
---|
| 85 | % introduce bin size for histograms
|
---|
| 86 | if isfield(Param,'CheckObject') && Param.CheckObject
|
---|
| 87 | SeriesData=get(hseries,'UserData');
|
---|
| 88 | if ismember(SeriesData.ProjObject.ProjMode,{'inside','outside'})
|
---|
| 89 | answer=msgbox_uvmat('INPUT_TXT','set bin size for histograms (or keep ''auto'' by default)?','auto');
|
---|
| 90 | ParamOut.ActionInput.VarMesh=str2num(answer);
|
---|
| 91 | end
|
---|
| 92 | end
|
---|
| 93 | % check the existence of the first and last file in the series
|
---|
| 94 | first_j=[];
|
---|
| 95 | if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end
|
---|
| 96 | last_j=[];
|
---|
| 97 | if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end
|
---|
| 98 | PairString='';
|
---|
| 99 | if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end
|
---|
| 100 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString);
|
---|
| 101 | FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
|
---|
| 102 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
|
---|
| 103 | if ~exist(FirstFileName,'file')
|
---|
| 104 | msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist'])
|
---|
| 105 | else
|
---|
| 106 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,PairString);
|
---|
| 107 | LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},...
|
---|
[960] | 108 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2);
|
---|
[884] | 109 | if ~exist(LastFileName,'file')
|
---|
[960] | 110 | msgbox_uvmat('WARNING',['the last input file ' LastFileName ' does not exist'])
|
---|
[884] | 111 | end
|
---|
| 112 | end
|
---|
[959] | 113 | % determine volume scan mode
|
---|
[960] | 114 | prompt = {'volume scan mode (Yes/No)'};
|
---|
[959] | 115 | dlg_title = 'determine volume scan';
|
---|
| 116 | num_lines= 1;
|
---|
| 117 | def = { 'No'};
|
---|
[960] | 118 | answer=msgbox_uvmat('INPUT_Y-N','volume scan mode (OK/No)?');
|
---|
| 119 | % answer = inputdlg(prompt,dlg_title,num_lines,def);
|
---|
[959] | 120 | if isempty(answer)
|
---|
| 121 | return
|
---|
| 122 | end
|
---|
| 123 | %check input consistency
|
---|
[960] | 124 | if strcmp(answer,'Yes')
|
---|
| 125 | ParamOut.NbSlice=1;% set NbSlice to 1 ( for i index)
|
---|
| 126 | ParamOut.ActionInput.CheckVolume=1;
|
---|
[959] | 127 | end
|
---|
[884] | 128 | return
|
---|
| 129 | end
|
---|
| 130 |
|
---|
| 131 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%%
|
---|
| 132 | ParamOut=[];%default output
|
---|
| 133 | %% read input parameters from an xml file if input is a file name (batch mode)
|
---|
| 134 | checkrun=1;
|
---|
| 135 | if ischar(Param)
|
---|
| 136 | Param=xml2struct(Param);% read Param as input file (batch case)
|
---|
| 137 | checkrun=0;
|
---|
[1148] | 138 | WaitbarHandle=[];
|
---|
| 139 | else
|
---|
[884] | 140 | hseries=findobj(allchild(0),'Tag','series');
|
---|
| 141 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
|
---|
| 142 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
|
---|
[1148] | 143 | end
|
---|
[884] | 144 |
|
---|
| 145 | %% define the directory for result file (with path=RootPath{1})
|
---|
| 146 | OutputDir=[Param.OutputSubDir Param.OutputDirExt];
|
---|
[960] | 147 |
|
---|
[884] | 148 | %% root input file(s) name, type and index series
|
---|
| 149 | RootPath=Param.InputTable(:,1);
|
---|
| 150 | RootFile=Param.InputTable(:,3);
|
---|
| 151 | SubDir=Param.InputTable(:,2);
|
---|
| 152 | NomType=Param.InputTable(:,4);
|
---|
| 153 | FileExt=Param.InputTable(:,5);
|
---|
[960] | 154 |
|
---|
[884] | 155 | hdisp=disp_uvmat('WAITING...','checking the file series',checkrun);
|
---|
[960] | 156 | % gives the series of input file names and indices set by the input parameters:
|
---|
[884] | 157 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
|
---|
| 158 | % filecell{iview,fileindex}:
|
---|
| 159 | % iview: line in the table corresponding to a given file series
|
---|
[960] | 160 | % fileindex: file index with i and j reshaped as a 1D array
|
---|
| 161 | % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
|
---|
[884] | 162 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
|
---|
[960] | 163 | if ~isempty(hdisp),delete(hdisp),end;%end the waiting display
|
---|
| 164 |
|
---|
[884] | 165 | NbView=numel(i1_series);%number of input file series (lines in InputTable)
|
---|
| 166 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
|
---|
| 167 | NbField_i=size(i1_series{1},2); %nb of fields for the i index
|
---|
| 168 | NbField=NbField_j*NbField_i; %total number of fields
|
---|
| 169 |
|
---|
[960] | 170 | %% determine the file type on each line from the first input file
|
---|
[884] | 171 | NcTypeOptions={'netcdf','civx','civdata'};
|
---|
| 172 | for iview=1:NbView
|
---|
| 173 | if ~exist(filecell{iview,1}','file')
|
---|
| 174 | disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun)
|
---|
| 175 | return
|
---|
| 176 | end
|
---|
| 177 | [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1});
|
---|
| 178 | FileType{iview}=FileInfo{iview}.FileType;
|
---|
[1033] | 179 | CheckImage{iview}=strcmp(FileInfo{iview}.FieldType,'image');% =1 for images
|
---|
[884] | 180 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
|
---|
| 181 | if ~isempty(j1_series{iview})
|
---|
| 182 | frame_index{iview}=j1_series{iview};
|
---|
| 183 | else
|
---|
| 184 | frame_index{iview}=i1_series{iview};
|
---|
| 185 | end
|
---|
| 186 | end
|
---|
| 187 |
|
---|
| 188 | %% calibration data and timing: read the ImaDoc files
|
---|
| 189 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series);
|
---|
| 190 | if size(time,1)>1
|
---|
| 191 | diff_time=max(max(diff(time)));
|
---|
| 192 | if diff_time>0
|
---|
| 193 | disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
|
---|
[960] | 194 | end
|
---|
[884] | 195 | end
|
---|
| 196 |
|
---|
| 197 | %% coordinate transform or other user defined transform
|
---|
| 198 | transform_fct='';%default
|
---|
| 199 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName)
|
---|
| 200 | addpath(Param.FieldTransform.TransformPath)
|
---|
| 201 | transform_fct=str2func(Param.FieldTransform.TransformName);
|
---|
| 202 | rmpath(Param.FieldTransform.TransformPath)
|
---|
| 203 | if isfield(Param,'TransformInput')
|
---|
[960] | 204 | XmlData{1}.TransformInput=Param.TransformInput;
|
---|
| 205 | end
|
---|
[884] | 206 | end
|
---|
| 207 |
|
---|
| 208 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%%
|
---|
[960] | 209 | % EDIT FROM HERE
|
---|
[884] | 210 |
|
---|
| 211 | %% check the validity of input file types and set the output file type
|
---|
| 212 | if CheckImage{1}
|
---|
| 213 | FileExtOut='.png'; % write result as .png images for image inputs
|
---|
| 214 | elseif CheckNc{1}
|
---|
| 215 | FileExtOut='.nc';% write result as .nc files for netcdf inputs
|
---|
| 216 | else
|
---|
| 217 | disp_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
|
---|
| 218 | return
|
---|
| 219 | end
|
---|
| 220 | if NbView==2 && ~isequal(CheckImage{1},CheckImage{2})
|
---|
| 221 | disp_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun)
|
---|
| 222 | return
|
---|
| 223 | end
|
---|
| 224 | if isfield(Param,'ProjObject') && ~strcmp(Param.ProjObject.Type,'plane')
|
---|
[960] | 225 | FileExtOut='.nc';% write result as .nc files (even for image input)
|
---|
[884] | 226 | end
|
---|
| 227 |
|
---|
| 228 | %% settings for the output file
|
---|
[1097] | 229 | OutputDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
|
---|
| 230 | OutputPath=fullfile(Param.OutputPath,num2str(Param.Experiment),num2str(Param.Device));
|
---|
[884] | 231 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file
|
---|
| 232 | first_i=i1_series{1}(1);
|
---|
| 233 | last_i=i1_series{1}(end);
|
---|
| 234 | if isempty(j1_series{1})% if there is no second index j
|
---|
| 235 | first_j=1;last_j=1;
|
---|
| 236 | else
|
---|
| 237 | first_j=j1_series{1}(1);
|
---|
| 238 | last_j=j1_series{1}(end);
|
---|
| 239 | end
|
---|
| 240 |
|
---|
| 241 | %% Set field names and velocity types
|
---|
| 242 | InputFields{1}=[];%default (case of images)
|
---|
| 243 | if NbView==2
|
---|
| 244 | InputFields{2}=[];%default (case of images)
|
---|
| 245 | end
|
---|
| 246 | if isfield(Param,'InputFields')
|
---|
| 247 | InputFields{1}=Param.InputFields;
|
---|
| 248 | if NbView==2
|
---|
| 249 | InputFields{2}=Param.InputFields;%default
|
---|
| 250 | if isfield(Param.InputFields,'FieldName_1')
|
---|
| 251 | InputFields{2}.FieldName=Param.InputFields.FieldName_1;
|
---|
| 252 | if isfield(Param.InputFields,'VelType_1')
|
---|
| 253 | InputFields{2}.VelType=Param.InputFields.VelType_1;
|
---|
| 254 | end
|
---|
| 255 | end
|
---|
| 256 | end
|
---|
| 257 | end
|
---|
[960] | 258 |
|
---|
[884] | 259 | VarMesh=[];
|
---|
| 260 | if isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'})
|
---|
[960] | 261 | if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'VarMesh')%case of histograms
|
---|
| 262 | VarMesh=Param.ActionInput.VarMesh;
|
---|
[884] | 263 | else
|
---|
[960] | 264 | VarMesh=[];
|
---|
| 265 | disp_uvmat('WARNING','automatic bin size for histograms, select aver_stat again to set the value',checkrun)
|
---|
[884] | 266 | end
|
---|
| 267 | end
|
---|
[959] | 268 |
|
---|
[960] | 269 | NbSlice_j=1;% number of j slices =1 except fo volume scan
|
---|
[959] | 270 | index_series=1:size(filecell,2);
|
---|
[960] | 271 | index_j=1;
|
---|
| 272 |
|
---|
| 273 | %% set volume scan if requested
|
---|
| 274 | first_j_out=first_j;%first j index to use for the output file name
|
---|
| 275 | last_j_out=last_j;%last j index to use for the output file name
|
---|
[959] | 276 | if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'CheckVolume') ...
|
---|
| 277 | && Param.ActionInput.CheckVolume
|
---|
[960] | 278 | index_j=Param.IndexRange.first_j:Param.IndexRange.incr_j:Param.IndexRange.last_j;
|
---|
| 279 | NbSlice_j=numel(index_j);
|
---|
| 280 | index_series=1:NbSlice_j:size(filecell,2);
|
---|
[959] | 281 | end
|
---|
| 282 |
|
---|
[960] | 283 | %% loop on j slices (volume scan)
|
---|
[959] | 284 | for islice=index_j
|
---|
[960] | 285 | nbfiles=0;%counter of the successfully read files (bad files are skipped)
|
---|
[959] | 286 | if NbSlice_j>1
|
---|
[960] | 287 | first_j_out=islice;%first and last j index to use for the output file name are the current j index
|
---|
| 288 | last_j_out=islice;
|
---|
[884] | 289 | end
|
---|
[959] | 290 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 291 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
|
---|
[960] | 292 | for index=index_series+index_j(islice)-index_j(1)
|
---|
[959] | 293 | update_waitbar(WaitbarHandle,index/NbField)
|
---|
| 294 | if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue')
|
---|
| 295 | disp('program stopped by user')
|
---|
[884] | 296 | break
|
---|
| 297 | end
|
---|
| 298 |
|
---|
[959] | 299 | %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
|
---|
| 300 | for iview=1:NbView
|
---|
| 301 | % reading input file(s)
|
---|
[1129] | 302 | filecell{iview,index}
|
---|
[959] | 303 | [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
|
---|
[884] | 304 | if ~isempty(errormsg)
|
---|
[959] | 305 | errormsg=['error of input reading: ' errormsg];
|
---|
[960] | 306 | break% leave the loop on views in case of error
|
---|
[884] | 307 | end
|
---|
[959] | 308 | if ~isempty(NbSlice_calib)
|
---|
| 309 | Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
|
---|
| 310 | end
|
---|
[884] | 311 | end
|
---|
[959] | 312 | %%%%%%%%%%%%%%%% end loop on views (input lines) %%%%%%%%%%%%%%%%
|
---|
| 313 |
|
---|
[960] | 314 | if ~isempty(errormsg)
|
---|
| 315 | disp(errormsg)
|
---|
| 316 | continue % go to next input field in case of error (file skipped in the average)
|
---|
| 317 | end
|
---|
| 318 | Field=Data{1}; % default input field structure
|
---|
| 319 | nbfiles=nbfiles+1; %increment the file counter
|
---|
| 320 |
|
---|
| 321 | %% coordinate transform (or other user defined transform)
|
---|
| 322 | if ~isempty(transform_fct)
|
---|
| 323 | switch nargin(transform_fct)
|
---|
| 324 | case 4
|
---|
| 325 | if length(Data)==2
|
---|
| 326 | Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
|
---|
| 327 | else
|
---|
[959] | 328 | Field=transform_fct(Data{1},XmlData{1});
|
---|
[960] | 329 | end
|
---|
| 330 | case 3
|
---|
| 331 | if length(Data)==2
|
---|
| 332 | Field=transform_fct(Data{1},XmlData{1},Data{2});
|
---|
| 333 | else
|
---|
| 334 | Field=transform_fct(Data{1},XmlData{1});
|
---|
| 335 | end
|
---|
| 336 | case 2
|
---|
| 337 | Field=transform_fct(Data{1},XmlData{1});
|
---|
| 338 | case 1
|
---|
| 339 | Field=transform_fct(Data{1});
|
---|
[884] | 340 | end
|
---|
[960] | 341 | end
|
---|
| 342 |
|
---|
| 343 | %% field projection on an object
|
---|
| 344 | if Param.CheckObject
|
---|
| 345 | if strcmp(Param.ProjObject.ProjMode,'interp_tps')
|
---|
| 346 | Field=tps_coeff_field(Field,check_proj_tps);% calculate tps coefficients if needed
|
---|
[959] | 347 | end
|
---|
[960] | 348 | [Field,errormsg]=proj_field(Field,Param.ProjObject,VarMesh);
|
---|
| 349 | if ~isempty(errormsg)
|
---|
| 350 | disp_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg],checkrun)
|
---|
| 351 | return
|
---|
| 352 | end
|
---|
| 353 | end
|
---|
| 354 |
|
---|
| 355 | %%%%%%%%%%%% MAIN RUNNING OPERATIONS %%%%%%%%%%%%
|
---|
| 356 | if nbfiles==1 %first field
|
---|
| 357 | time_1=[];
|
---|
| 358 | if isfield(Field,'Time')
|
---|
| 359 | time_1=Field.Time(1);
|
---|
| 360 | end
|
---|
| 361 | DataOut=Field;%outcome reproduces the first (projected) field by default
|
---|
| 362 | DataOut.Conventions='uvmat'; %suppress Conventions='uvmat/civdata' for civ input files
|
---|
| 363 | if isfield(Param,'ProjObject')&& ismember(Param.ProjObject.ProjMode,{'inside','outside'})%case of histograms
|
---|
| 364 | for ivar=1:numel(Field.ListVarName)% list of variable names before projection (histogram)
|
---|
| 365 | VarName=Field.ListVarName{ivar};
|
---|
| 366 | if isfield(Data{1},VarName)
|
---|
| 367 | DataOut.(VarName)=Field.(VarName);
|
---|
| 368 | DataOut.([VarName 'Histo'])=zeros(size(DataOut.(VarName)));
|
---|
| 369 | VarMesh=DataOut.(VarName)(2)-DataOut.(VarName)(1);
|
---|
| 370 | end
|
---|
[959] | 371 | end
|
---|
[960] | 372 | disp(['mesh for histogram = ' num2str(VarMesh)])
|
---|
| 373 | else
|
---|
| 374 | errorvar=zeros(numel(Field.ListVarName));%index of errorflag associated to each variable
|
---|
| 375 | if isfield(Field,'VarAttribute')
|
---|
| 376 | for ivar=1:numel(Field.ListVarName)
|
---|
[884] | 377 | VarName=Field.ListVarName{ivar};
|
---|
[960] | 378 | DataOut.(VarName)=zeros(size(DataOut.(VarName)));% initiate each field to zero
|
---|
| 379 | NbData.(VarName)=zeros(size(DataOut.(VarName)));% initiate the nbre of good data to zero
|
---|
| 380 |
|
---|
| 381 | for iivar=1:length(Field.VarAttribute)
|
---|
| 382 | if isequal(Field.VarDimName{iivar},Field.VarDimName{ivar})&& isfield(Field.VarAttribute{iivar},'Role')...
|
---|
| 383 | && strcmp(Field.VarAttribute{iivar}.Role,'errorflag')
|
---|
| 384 | errorvar(ivar)=iivar; % index of the errorflag variable corresponding to ivar
|
---|
| 385 | end
|
---|
[959] | 386 | end
|
---|
| 387 | end
|
---|
[960] | 388 | DataOut.ListVarName(errorvar(errorvar~=0))=[]; %remove errorflag from result
|
---|
| 389 | DataOut.VarDimName(errorvar(errorvar~=0))=[]; %remove errorflag from result
|
---|
| 390 | DataOut.VarAttribute(errorvar(errorvar~=0))=[]; %remove errorflag from result
|
---|
[959] | 391 | else
|
---|
[960] | 392 | for ivar=1:numel(Field.ListVarName)
|
---|
| 393 | VarName=Field.ListVarName{ivar};
|
---|
| 394 | DataOut.(VarName)=zeros(size(DataOut.(VarName)));% initiate each field to zero
|
---|
| 395 | NbData.(VarName)=zeros(size(DataOut.(VarName)));% initiate the nbre of good data to zero
|
---|
[884] | 396 | end
|
---|
| 397 | end
|
---|
[960] | 398 |
|
---|
| 399 | end
|
---|
| 400 | end %current field
|
---|
| 401 | for ivar=1:length(DataOut.ListVarName)
|
---|
| 402 | VarName=DataOut.ListVarName{ivar};
|
---|
| 403 | sizmean=size(DataOut.(VarName));
|
---|
| 404 | siz=size(Field.(VarName));
|
---|
| 405 | if isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'})
|
---|
| 406 | if isfield(Data{1},VarName)
|
---|
| 407 | MaxValue=max(DataOut.(VarName));% current max of histogram absissa
|
---|
| 408 | MinValue=min(DataOut.(VarName));% current min of histogram absissa
|
---|
| 409 | % VarMesh=Field.VarAttribute{ivar}.Mesh;
|
---|
| 410 | MaxIndex=round(MaxValue/VarMesh);
|
---|
| 411 | MinIndex=round(MinValue/VarMesh);
|
---|
| 412 | MaxIndex_new=round(max(Field.(VarName)/VarMesh));% max of the current field
|
---|
| 413 | MinIndex_new=round(min(Field.(VarName)/VarMesh));
|
---|
| 414 | if MaxIndex_new>MaxIndex% the variable max for the current field exceeds the previous one
|
---|
| 415 | DataOut.(VarName)=[DataOut.(VarName) VarMesh*(MaxIndex+1:MaxIndex_new)];% append the new variable values
|
---|
| 416 | DataOut.([VarName 'Histo'])=[DataOut.([VarName 'Histo']) zeros(1,MaxIndex_new-MaxIndex)]; % append the new histo values
|
---|
[884] | 417 | end
|
---|
[960] | 418 | if MinIndex_new <= MinIndex-1
|
---|
| 419 | DataOut.(VarName)=[VarMesh*(MinIndex_new:MinIndex-1) DataOut.(VarName)];% insert the new variable values
|
---|
| 420 | DataOut.([VarName 'Histo'])=[zeros(1,MinIndex-MinIndex_new) DataOut.([VarName 'Histo'])];% insert the new histo values
|
---|
| 421 | ind_start=1;
|
---|
[884] | 422 | else
|
---|
[960] | 423 | ind_start=MinIndex_new-MinIndex+1;
|
---|
[884] | 424 | end
|
---|
[960] | 425 | DataOut.([VarName 'Histo'])(ind_start:ind_start+MaxIndex_new-MinIndex_new)=...
|
---|
| 426 | DataOut.([VarName 'Histo'])(ind_start:ind_start+MaxIndex_new-MinIndex_new)+Field.([VarName 'Histo']);
|
---|
[884] | 427 | end
|
---|
[960] | 428 | elseif ~isequal(DataOut.(VarName),0)&& ~isequal(siz,sizmean)
|
---|
| 429 | disp_uvmat('ERROR',['unequal size of input field ' VarName ', need to project on a grid'],checkrun)
|
---|
| 430 | return
|
---|
| 431 | else
|
---|
| 432 | if errorvar(ivar)==0
|
---|
| 433 | check_bad=isnan(Field.(VarName));%=0 for NaN data values, 1 else
|
---|
| 434 | else
|
---|
| 435 | check_bad=isnan(Field.(VarName)) | Field.(Field.ListVarName{errorvar(ivar)})~=0;%=0 for NaN or error flagged data values, 1 else
|
---|
| 436 | end
|
---|
| 437 | Field.(VarName)(check_bad)=0; %set to zero NaN or data marked by error flag
|
---|
| 438 | DataOut.(VarName)=DataOut.(VarName)+ double(Field.(VarName)); % update the sum
|
---|
| 439 | NbData.(VarName)=NbData.(VarName)+ ~check_bad;% records the number of data for each point
|
---|
[884] | 440 | end
|
---|
| 441 | end
|
---|
[960] | 442 | %%%%%%%%%%%% END MAIN RUNNING OPERATIONS %%%%%%%%%%%%
|
---|
[884] | 443 | end
|
---|
[959] | 444 | %%%%%%%%%%%%%%%% end loop on field indices %%%%%%%%%%%%%%%%
|
---|
[960] | 445 |
|
---|
| 446 | if ~(isfield(Param,'ProjObject') && ismember(Param.ProjObject.ProjMode,{'inside','outside'}))
|
---|
| 447 | for ivar=1:length(Field.ListVarName)
|
---|
| 448 | VarName=Field.ListVarName{ivar};
|
---|
| 449 | DataOut.(VarName)=DataOut.(VarName)./NbData.(VarName); % normalize the mean
|
---|
| 450 | end
|
---|
[884] | 451 | end
|
---|
[960] | 452 | nbmissing=numel(index_series+index_j(islice)-index_j(1))-nbfiles;
|
---|
| 453 | if nbmissing~=0
|
---|
| 454 | if NbSlice_j==1
|
---|
| 455 | disp_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipped'],checkrun)
|
---|
| 456 | else
|
---|
| 457 | disp(['WARNING: ' num2str(nbmissing) ' input files are missing or skipped in slice ' num2str(islice)])
|
---|
[884] | 458 | end
|
---|
| 459 | end
|
---|
[960] | 460 | if isempty(time) % time is read from files
|
---|
| 461 | if isfield(Field,'Time')
|
---|
| 462 | time_end=Field.Time(1);%last time read
|
---|
| 463 | if ~isempty(time_1)
|
---|
| 464 | DataOut.Time=time_1;
|
---|
| 465 | DataOut.Time_end=time_end;
|
---|
| 466 | end
|
---|
| 467 | end
|
---|
| 468 | else % time from ImaDoc prevails if it exists
|
---|
| 469 | DataOut.Time=time(1);
|
---|
| 470 | DataOut.Time_end=time(end);
|
---|
[884] | 471 | end
|
---|
[960] | 472 |
|
---|
| 473 | %% writing the result file
|
---|
[1129] | 474 | RootPathOut=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
|
---|
| 475 | OutputDir=[Param.OutputSubDir Param.OutputDirExt];
|
---|
| 476 | OutputFile=fullfile_uvmat(RootPathOut,OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j_out,last_j_out);
|
---|
[960] | 477 | if strcmp(FileExtOut,'.png') %case of images
|
---|
| 478 | if isequal(FileInfo{1}.BitDepth,16)||(numel(FileInfo)==2 &&isequal(FileInfo{2}.BitDepth,16))
|
---|
| 479 | DataOut.A=uint16(DataOut.A);
|
---|
| 480 | imwrite(DataOut.A,OutputFile,'BitDepth',16); % case of 16 bit images
|
---|
| 481 | else
|
---|
| 482 | DataOut.A=uint8(DataOut.A);
|
---|
| 483 | imwrite(DataOut.A,OutputFile,'BitDepth',8); % case of 16 bit images
|
---|
| 484 | end
|
---|
[884] | 485 | disp([OutputFile ' written']);
|
---|
[960] | 486 | else %case of netcdf file , determine global attributes
|
---|
| 487 | errormsg=struct2nc(OutputFile,DataOut); %save result file
|
---|
| 488 | if isempty(errormsg)
|
---|
| 489 | disp([OutputFile ' written']);
|
---|
| 490 | else
|
---|
| 491 | disp(['error in writting result file: ' errormsg])
|
---|
| 492 | end
|
---|
| 493 | end % end averaging loop
|
---|
[959] | 494 | end
|
---|
[884] | 495 |
|
---|
| 496 | %% open the result file with uvmat (in RUN mode)
|
---|
| 497 | if checkrun
|
---|
| 498 | uvmat(OutputFile)% open the last result file with uvmat
|
---|
| 499 | end
|
---|