-
Notifications
You must be signed in to change notification settings - Fork 0
/
ensembleAverage.m
196 lines (176 loc) · 5.33 KB
/
ensembleAverage.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
function [AxisCell,Ucell,Lciavg,Omega_avg,CHCavg] = ensembleAverage(CompVecList,cores,crop,pathDir)
% Read all the velocity data of a Stereo experiment inside the current folder
% and calculate the emsemble averages of the velocities.
%
% Output variables:
%
% AxisCell is a cell vector that contains the Axis variables. If it's a 2D
% PIV AxisCell has X and Y. If it's a Stereo, AxisCell has X,Y and Z
%
% Ucell is a cell vector that contains the Velocities variables
%
%
% Author: Julio Barros
% University of Illinois at Urbana-Champaign
% Date: 05/10/2011
% Version: 2.1
%
% Major modification that uses a single function for all the PIV cases
% Handles Insight 9
if ispc == 1
slash = '\';
else
slash ='/';
end
spmd
% Initilization of te Variables
% Find how many columns the file has
vecfile = CompVecList(1).name;
vecfile = strcat(pathDir,slash,vecfile);
[nc,Iori,Jori] = matrix(vecfile);
if nc == 5 || nc == 9 || nc == 11 || nc == 12 || nc == 15% Insight 11
[~,~,~,Dx,Dy,X,Y,U,V,CHC] = matrix(vecfile);
elseif nc == 8 || nc == 7
[~,~,~,Dx,Dy,X,Y,Z,U,V,W,CHC] = matrix(vecfile);
end
% Crop the matrices based on the ROI
[~,~,X,Y,U,V,CHC] = WindowFile(crop,Iori,Jori,X,Y,U,V,CHC);
% X = X(crop(4):end-crop(3),crop(1):end-crop(2));
% Y = Y(crop(4):end-crop(3),crop(1):end-crop(2));
% U = U(crop(4):end-crop(3),crop(1):end-crop(2));
% V = V(crop(4):end-crop(3),crop(1):end-crop(2));
% CHC = CHC(crop(4):end-crop(3),crop(1):end-crop(2));
if nc == 8 || nc == 7
[~,~,Z,W] = WindowFile(crop,Iori,Jori,Z,W);
% Z = Z(crop(4):end-crop(3),crop(1):end-crop(2));
% W = W(crop(4):end-crop(3),crop(1):end-crop(2));
end
% Make the CHC 0's and 1's
%CHC = CHC./abs(CHC);
%CHC = (CHC+abs(CHC))/2;
CHC = double(CHC > 0);
%test = CHC; %DEBUG PURPOSE
% Multiply the remaining outliers by CHC normalized
U = U.*CHC;
V = V.*CHC;
if nc == 8 || nc == 7
W = W.*CHC;
end
% Calculate the Swirling Strength
dx = Dx/1000;
dy = Dy/1000;
[Lci,Omega] = swirlingStrength(dx,dy,U,V);
% Start the Ensemble average matrices
Uavg_p = U;
Vavg_p = V;
if nc == 8 || nc == 7
Wavg_p = W;
end
Lciavg_p = Lci;
Omega_p = Omega;
CHC_p = CHC;
for i=2:length(CompVecList)
vecfile = CompVecList(i).name;
vecfile = strcat(pathDir,slash,vecfile);
if nc == 5 || nc == 9 || nc == 11 || nc == 12 || nc == 15
[~,~,~,Dx,Dy,~,~,U,V,CHC] = matrix(vecfile);
elseif nc == 8 || nc == 7
[~,~,~,Dx,Dy,~,~,~,U,V,W,CHC] = matrix(vecfile);
end
% Crop the matrices based on the ROI
[~,~,U,V,CHC] = WindowFile(crop,Iori,Jori,U,V,CHC);
% U = U(crop(4):end-crop(3),crop(1):end-crop(2));
% V = V(crop(4):end-crop(3),crop(1):end-crop(2));
% CHC = CHC(crop(4):end-crop(3),crop(1):end-crop(2));
if nc == 8 || nc == 7
[~,~,W] = WindowFile(crop,Iori,Jori,W);
% W = W(crop(4):end-crop(3),crop(1):end-crop(2));
end
% Make the CHC 0's and 1's
%CHC = CHC./abs(CHC);
%CHC = (CHC+abs(CHC))/2;
CHC = double(CHC > 0);
% Multiply the remaining outliers by CHC normalized
U = U.*CHC;
V = V.*CHC;
if nc == 8 || nc == 7
W = W.*CHC;
end
% Calculate the Swirling Strength
dx = Dx/1000;
dy = Dy/1000;
[Lci,Omega] = swirlingStrength(dx,dy,U,V);
Uavg_p = Uavg_p + U;
Vavg_p = Vavg_p + V;
if nc == 8 || nc == 7
Wavg_p = Wavg_p + W;
end
Lciavg_p = Lciavg_p + Lci;
Omega_p = Omega_p + Omega;
CHC_p = CHC_p + CHC;
end
end
% Gathers some variables from the first core just for exporting purposes
nc = nc{1};
X = X{1};
Y = Y{1};
if nc == 8 || nc == 7
Z = Z{1};
end
%I = I{1};
%J = J{1};
% Initializing the final average matrices
%Xavg = zeros(size(Xavg_p{1})); %DEGUB PURPOSE
Uavg = zeros(size(Uavg_p{1}));
Vavg = Uavg;
if nc == 8 || nc == 7
Wavg = Uavg;
end
Lciavg = Uavg;
Omega_avg = Uavg;
CHCavg = Uavg;
%debug1 = Uavg;
%debug2 = Uavg;
% Adding all the cores matrices
for i=1:cores
Uavg = Uavg_p{i} + Uavg;
Vavg = Vavg_p{i} + Vavg;
if nc == 8 || nc == 7
Wavg = Wavg_p{i} + Wavg;
end
Lciavg = Lciavg_p{i} + Lciavg;
Omega_avg = Omega_p{i} + Omega_avg;
CHCavg = CHC_p{i} + CHCavg;
%debug1 = debug_p1{i} + debug1;
%debug2 = debug_p2{i} + debug2;
end
% Calculatibg the final Ensemble Averages
Uavg = Uavg./CHCavg;
Vavg = Vavg./CHCavg;
if nc == 8 || nc == 7
Wavg = Wavg./CHCavg;
end
Lciavg = Lciavg./CHCavg;
Omega_avg = Omega_avg./CHCavg;
% Outputing the variables in cell format
if nc == 5 || nc == 9 || nc == 11 || nc == 12 || nc == 15
AxisCell = cell(1,2);
Ucell = cell(1,2);
% Not an elegant way
AxisCell{1} = X;
AxisCell{2} = Y;
% Not an elegant way
Ucell{1} = Uavg;
Ucell{2} = Vavg;
elseif nc == 8 || nc == 7
AxisCell = cell(1,3);
Ucell = cell(1,3);
% Not an elegant way
AxisCell{1} = X;
AxisCell{2} = Y;
AxisCell{3} = Z;
% Not an elegant way
Ucell{1} = Uavg;
Ucell{2} = Vavg;
Ucell{3} = Wavg;
end