-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessOutput.m
More file actions
280 lines (254 loc) · 10.4 KB
/
ProcessOutput.m
File metadata and controls
280 lines (254 loc) · 10.4 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
% ProcessOutput ----------------------------------------------------------
clear, clc, close all
% ----- TRAFFIC ANALYSES -----
% VBSim (VBSimInput) OR VBWIM (VBWIMInput)
% Goal is to get OverMax (Sim) MaxEvents (WIM)
% ----- TRAFFIC ANALYSES POST-PROCESSING -----
% Goals of PROCESSOUTPUT
% 0. Remove unnecessary things
% 1. Move from OverMaxT/MaxEvents to BlockMax (Max) GetBlockMax
% 2. Perform fits of Max & get design values (Eds) GetFit
% 3. Compare to code values to get partial factors/alphas VBGetECode
% 4. Organize in easily plottable structures GetPlotFormat
% Replaces Output2Struct
% ----- TRAFFIC ANALYSES PLOTTING -----
% AlphaSummaryPlot(_Q2)
% VBPlotProResults
% VBPlotFatigue
% Create a script that will go into an Output folder, load the contents,
% delete unnecessary things... and re-add stuff we care about.
% Minimum what we require:
% Name (datestring)
% BaseData (table)
% ILData (struct)
% MaxEvents (table) daily maxes
% {'DTS', 'SITE', 'MaxLE', 'InfCase', 'm', 'DayRank', 'BrStInd', 'PlatType'}
% OR
% OverMaxT (table) yearly maxes
% {'InfCase','SimNum','BatchNum','MaxLE','DLF','BrStInd','MaxDamage'}
% Things we will add:
% Max (struct)
% pd, Eds (structs)
% Ecodes (struct)
% Alphas (struct)
% This script will work with any output file that contains MaxEvents or
% OverMaxT... will hunt for unneeded things and delete them or archive them
% When MaxEvents doesn't exist, it will work with Max
Folder_Name = 'SimFev19JamTest'; %'WIMOct18';
NewFolder = 'SimFev19JamTestprBeta4_2'; %'WIMOct18prA42v2';
BETATarget = 4.2;
IncZ = 0; %Do we want to include zeros... Special case when we want to study
% only 2sd lane with sometimes no trafic. Normal case IncZ = 0; we dont
% include zeros. Tip : GetFit -> if zeros not possible to use Lognormal
% Ensure file list is succinct
File_List = GetFileList(Folder_Name);
% Load even if not WIM, just in case
load('Sites.mat'); LenPrint = []; RamUsed = [];
% Start Progress Bar
u = StartProgBar(length(File_List), 1, 1, 4); tic; st = now;
% Read in .mat results variables into a single OInfo variable
for v = 1:length(File_List)
load(['Output/' Folder_Name '/' File_List(v).name])
OInfo(v) = OutInfo;
OInfo(v).BaseData = BaseDataDefaults(OInfo(v).BaseData);
% Update progress bar
try
user = memory;
RamUsed = [RamUsed;user.MemUsedMATLAB/(user.MemAvailableAllArrays+user.MemUsedMATLAB)*100];
LenPrint = VBUpProgBar(st,RamUsed(end),v,LenPrint);
catch
LenPrint = VBUpProgBar(st,1,v,LenPrint);
end
end
clear OutInfo
% Hunt for the following to delete:
% .pd, .Max, .x_values, .y_valuespdf, .EdLN, ESIA, .AQ, .SimStop (use BaseData)
for v = 1:length(OInfo)
fields = fieldnames(OInfo(v));
if any(contains(fields,'SimStop'))
if OInfo(v).SimStop == 1
OInfo(v).BaseData.StopSim = 1;
else
OInfo(v).BaseData.StopSim = 0;
end
end
end
if any(contains(fields,'SimStop'))
OInfo = rmfield(OInfo,'SimStop');
end
if any(contains(fields,'y_valuespdf'))
OInfo = rmfield(OInfo,'y_valuespdf');
fields = fieldnames(OInfo(v));
end
if any(contains(fields,'pd'))
OInfo = rmfield(OInfo,'pd');
end
if any(contains(fields,'x_values'))
OInfo = rmfield(OInfo,'x_values');
end
if any(contains(fields,'EdLN'))
OInfo = rmfield(OInfo,'EdLN');
end
if any(contains(fields,'AQ'))
OInfo = rmfield(OInfo,'AQ');
end
if any(contains(fields,'ESIA'))
OInfo = rmfield(OInfo,'ESIA');
end
if any(contains(fields,'MaxEvents'))
if any(matches(fields,'max','IgnoreCase',true))
OInfo = rmfield(OInfo,'Max');
end
end
fields = fieldnames(OInfo(v));
% If we have MaxEvents then perform GetBlockMax
% Otherwise, 2 scenarios
% 1. We are doing WIM, but only have Max Available (skip to next step)
% This is not ideal, but OK (GetBlockMax is better than predecessors
% that were probably used to create Max... elimantes low values from
% partial blocks for example.
% 2. We are doing SIM, and therefore only have OverMax
% GetBlockMax and GetFit
BlockMax = {'Weekly'}; %{'Yearly'}; % j
ClassTypes = {'All', 'ClassOW', 'Class'}; %{'ClassOW'}; %{'All', 'ClassOW', 'Class'}; % i
DistTypes = {'All'}; % k
%DistTypes = {'NormalLM', 'LognormalLM', 'LognormalTF', 'gev', 'gevGumbel'}; % For the 60t analyses
if strcmp(OInfo(1).BaseData.AnalysisType,'WIM')
% Start Progress Bar
u = StartProgBar(length(File_List), 1, 2, 4); tic; st = now;
for v = 1:length(OInfo)
% GetBlockMax can handle however MaxEvents is structured...
% no need to loop ILs, BlockMaxs, or ClassTypes
if any(contains(fields,'MaxEvents'))
OInfo(v).Max = GetBlockMax(OInfo(v).MaxEvents,ClassTypes,BlockMax);
else
BlockMax = fieldnames(OInfo(v).Max(1).All); % j
end
% GetFit, only the other hand we need to give specific Data and BlockM
% for this we loop between ILs, BlockMax, and ClassTypes
for r = 1:length(OInfo(v).ILData)
for j = 1:length(BlockMax)
BM = BlockMax{j};
for i = 1:length(ClassTypes)
CT = ClassTypes{i};
OInfo(v).pd(r).(CT).(BM) = GetFit(OInfo(v).Max(r).(CT).(BM).Max,BM,DistTypes,0,[IncZ BETATarget]);
end
end
end
% Update progress bar
try
user = memory;
RamUsed = [RamUsed;user.MemUsedMATLAB/(user.MemAvailableAllArrays+user.MemUsedMATLAB)*100];
LenPrint = VBUpProgBar(st,RamUsed(end),v,LenPrint);
catch
LenPrint = VBUpProgBar(st,1,v,LenPrint);
end
end
end
% For Sim
if strcmp(OInfo(1).BaseData.AnalysisType,'Sim')
% Start Progress Bar
u = StartProgBar(length(File_List), 1, 2, 4); tic; st = now;
BlockMax = OInfo(v).BaseData.Period;
ClassTypes = {'Class'}; CT = ClassTypes{1};
for v = 1:length(OInfo)
for r = 1:length(OInfo(v).ILData)
for j = 1:length(BlockMax)
BM = BlockMax{j};
for i = 1:length(ClassTypes)
OInfo(v).pd(r).(CT).(BM) = GetFit(OInfo(v).OverMax(:,r),BM,DistTypes,0,[IncZ BETATarget]);
end
end
end
% Update progress bar
try
user = memory;
RamUsed = [RamUsed;user.MemUsedMATLAB/(user.MemAvailableAllArrays+user.MemUsedMATLAB)*100];
LenPrint = VBUpProgBar(st,RamUsed(end),v,LenPrint);
catch
LenPrint = VBUpProgBar(st,1,v,LenPrint);
end
end
end
% Potential problem here with BlockMax Sim when having 2 durations in one
% input file. Line 167 it adapts for each OInfo, but then the last loop
% defines the new BlockMax, which then assigns BM in line 201 irrespective
% of OInfo.
Gamma = 1.5;
AQ1 = 0.7; AQ2 = 0.5;
% VBGetECode and GetAlphas
% Start Progress Bar
u = StartProgBar(length(File_List), 1, 3, 4); tic; st = now;
for v = 1:length(OInfo)
OInfo(v).E = VBGetECode(OInfo(v).ILData,OInfo(v).BaseData.ILRes);
for r = 1:length(OInfo(v).ILData)
for j = 1:length(BlockMax)
BM = BlockMax{j};
for i = 1:length(ClassTypes)
CT = ClassTypes{i};
Ed = OInfo(v).pd(r).(CT).(BM).(OInfo(v).pd(r).(CT).(BM).Best).Ed;
OInfo(v).AQ.(CT).(BM)(r) = Ed./OInfo(v).E(r).SIA.Total;
OInfo(v).Aq.(CT).(BM)(r) = ((Ed/1.5)-AQ1*OInfo(v).E(r).SIA.EQ(1)-AQ2*OInfo(v).E(r).SIA.EQ(2))./(sum(OInfo(v).E(r).SIA.Eq));
end
end
end
% Update progress bar
try
user = memory;
RamUsed = [RamUsed;user.MemUsedMATLAB/(user.MemAvailableAllArrays+user.MemUsedMATLAB)*100];
LenPrint = VBUpProgBar(st,RamUsed(end),v,LenPrint);
catch
LenPrint = VBUpProgBar(st,1,v,LenPrint);
end
end
% Repeat some of the above for each site... save as OInfo(v).SNameSITE
if strcmp(OInfo(1).BaseData.AnalysisType,'WIM')
% Start Progress Bar
u = StartProgBar(length(File_List), 1, 4, 4); tic; st = now;
BlockMax = {'Weekly'}; % j
for v = 1:length(OInfo)
if isempty(strcat(Sites.SName(Sites.SITE == OInfo(v).BaseData.SITE),num2str(OInfo(v).BaseData.SITE)))
Sitex = VBGetSiteSet(OInfo(v).BaseData.SITE,OInfo(v).BaseData.LightVehs,0,OInfo(v).BaseData.Country);
for z = 1:length(Sitex)
Traffic = strcat(Sites.SName(Sites.SITE == Sitex(z)),num2str(Sitex(z)));
% GetFit for individual SITE
for r = 1:length(OInfo(v).ILData)
for j = 1:length(BlockMax)
BM = BlockMax{j};
for i = 1:length(ClassTypes)
CT = ClassTypes{i};
Maxi = OInfo(v).Max(r).(CT).(BM).Max(OInfo(v).Max(r).(CT).(BM).SITE == Sitex(z));
if ~isempty(Maxi)
OInfo(v).(Traffic).pd(r).(CT).(BM) = GetFit(Maxi,BM,DistTypes,0,[IncZ BETATarget]);
Ed = OInfo(v).(Traffic).pd(r).(CT).(BM).(OInfo(v).(Traffic).pd(r).(CT).(BM).Best).Ed;
OInfo(v).(Traffic).AQ.(CT).(BM)(r) = Ed./OInfo(v).E(r).SIA.Total;
OInfo(v).(Traffic).Aq.(CT).(BM)(r) = ((Ed/1.5)-AQ1*OInfo(v).E(r).SIA.EQ(1)-AQ2*OInfo(v).E(r).SIA.EQ(2))./(sum(OInfo(v).E(r).SIA.Eq));
end
end
end
end
end
end
% Update progress bar
try
user = memory;
RamUsed = [RamUsed;user.MemUsedMATLAB/(user.MemAvailableAllArrays+user.MemUsedMATLAB)*100];
LenPrint = VBUpProgBar(st,RamUsed(end),v,LenPrint);
catch
LenPrint = VBUpProgBar(st,1,v,LenPrint);
end
end
end
% check if NewFolder folder exist, if not create one
Dir_List = dir('Output/');
Folder_List = {Dir_List.name}';
if sum(strcmp(Folder_List,NewFolder))>=1
else
mkdir(append('Output/',NewFolder));
end
% Save
for v = 1:length(OInfo)
OutInfo = OInfo(v);
%save(['Output' char(OutInfo.BaseData.Folder) '/' OutInfo.Name], 'OutInfo')
save(['Output' '/' NewFolder '/' OutInfo.Name], 'OutInfo','-v7.3')
end