-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpart2_bugsplat_maps_angles_rev5.m
444 lines (373 loc) · 22 KB
/
part2_bugsplat_maps_angles_rev5.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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
function part2_bugsplat_maps_angles_rev5(app,rev_folder,folder_names,sim_number,reliability,string_prop_model,grid_spacing,array_reliability_check,tf_calc_rx_angle,tf_recalculate,tf_tropo_cut,tf_server_status,array_bs_eirp_reductions,array_mitigation)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Function:
cell_status_filename=strcat('cell_',string_prop_model,'_',num2str(sim_number),'_contour_angles_status.mat')
label_single_filename=strcat(string_prop_model,'_',num2str(sim_number),'_contour_angles_status')
location_table=table([1:1:length(folder_names)]',folder_names)
%%%%%%%%%%Need a list because going through 470 folders takes 17 minutes
[cell_status]=initialize_or_load_generic_status_rev1(app,folder_names,cell_status_filename);
if tf_recalculate==1
cell_status(:,2)=num2cell(0);
end
zero_idx=find(cell2mat(cell_status(:,2))==0);
cell_status
if ~isempty(zero_idx)==1
temp_folder_names=folder_names(zero_idx)
num_folders=length(temp_folder_names);
%%%%%%%%Pick a random folder and go to the folder to do the sim
disp_progress(app,strcat('Mapping the Required Pathloss . . .'))
reset(RandStream.getGlobalStream,sum(100*clock)) %%%%%%Set the Random Seed to the clock because all compiled apps start with the same random seed.
[tf_ml_toolbox]=check_ml_toolbox(app);
if tf_ml_toolbox==1
array_rand_folder_idx=randsample(num_folders,num_folders,false);
else
array_rand_folder_idx=randperm(num_folders);
end
temp_folder_names(array_rand_folder_idx)
disp_randfolder(app,num2str(array_rand_folder_idx'))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[multi_hWaitbar,multi_hWaitbarMsgQueue]= ParForWaitbarCreateMH_time('Multi-Folder Mapping: ',num_folders); %%%%%%% Create ParFor Waitbar
for folder_idx=1:1:num_folders
%%%server_status_rev1(app)
server_status_rev2(app,tf_server_status)
%%%%%%%%Before going to the sim folder, check one last time if we
%%%%%%%%need to go to it, since another server may have already
%%%%%%%%checked.
%%%%%%%Load
[cell_status]=initialize_or_load_generic_status_rev1(app,folder_names,cell_status_filename);
if tf_recalculate==1
cell_status(:,2)=num2cell(0);
end
sim_folder=temp_folder_names{array_rand_folder_idx(folder_idx)};
temp_cell_idx=find(strcmp(cell_status(:,1),sim_folder)==1);
if cell_status{temp_cell_idx,2}==0
%%%%%%%%%%Calculate
retry_cd=1;
while(retry_cd==1)
try
cd(rev_folder)
pause(0.1);
retry_cd=0;
catch
retry_cd=1;
pause(0.1)
end
end
retry_cd=1;
while(retry_cd==1)
try
sim_folder=temp_folder_names{array_rand_folder_idx(folder_idx)};
cd(sim_folder)
pause(0.1);
retry_cd=0;
catch
retry_cd=1;
pause(0.1)
end
end
disp_multifolder(app,sim_folder)
data_label1=sim_folder;
%%%%%%Check for the tf_complete_ITM file
complete_filename=strcat(data_label1,'_',label_single_filename,'.mat'); %%%This is a marker for me
[var_exist]=persistent_var_exist_with_corruption(app,complete_filename);
if tf_recalculate==1
var_exist=0
end
if var_exist==2
retry_cd=1;
while(retry_cd==1)
try
cd(rev_folder)
pause(0.1);
retry_cd=0;
catch
retry_cd=1;
pause(0.1)
end
end
%%%%%%%%Update the Cell
[cell_status]=update_generic_status_cell_rev1(app,folder_names,sim_folder,cell_status_filename);
else
%%%%%Persistent Load the other variables
disp_progress(app,strcat('Mapping: Loading Sim Data . . .'))
retry_load=1;
while(retry_load==1)
try
load(strcat(data_label1,'_base_polygon.mat'),'base_polygon')
temp_data=base_polygon;
clear base_polygon;
base_polygon=temp_data;
clear temp_data;
load(strcat(data_label1,'_base_protection_pts.mat'),'base_protection_pts')
temp_data=base_protection_pts;
clear base_protection_pts;
base_protection_pts=temp_data;
clear temp_data;
load(strcat(data_label1,'_required_pathloss.mat'),'required_pathloss')
temp_data=required_pathloss;
clear required_pathloss;
required_pathloss=temp_data;
clear temp_data;
load(strcat(data_label1,'_sim_array_list_bs.mat'),'sim_array_list_bs')
temp_data=sim_array_list_bs;
clear sim_array_list_bs;
sim_array_list_bs=temp_data;
clear temp_data;
% % % %%%%array_list_bs %%%%%%%1) Lat, 2)Lon, 3)BS height, 4)BS EIRP 5) Nick Unique ID for each sector, 6)NLCD: R==1/S==2/U==3, 7) Azimuth 8)BS EIRP Mitigation
load(strcat(data_label1,'_radar_threshold.mat'),'radar_threshold')
temp_data=radar_threshold;
clear radar_threshold;
radar_threshold=temp_data;
clear temp_data;
if tf_calc_rx_angle==1 %%%%%%%Only need to load if we are doing the angles
%%%load(strcat(data_label1,'_array_ant_gain_vertical.mat'),'array_ant_gain_vertical')
load(strcat(data_label1,'_min_rx_ant_elevation.mat'),'min_rx_ant_elevation')
load(strcat(data_label1,'_pathloss_minus_rx_ant.mat'),'pathloss_minus_rx_ant')
load(strcat(data_label1,'_receiver_threshold.mat'),'receiver_threshold')
load(strcat(data_label1,'_multi_array_ant_gain_vertical.mat'),'multi_array_ant_gain_vertical')
end
%%%%%%%%%%%%%%%%%%%%%These are typically only used in Aggregate Calculations
%%%load(strcat(data_label1,'_min_ant_loss.mat'),'min_ant_loss')
%%%load(strcat(data_label1,'_radar_beamwidth.mat'),'radar_beamwidth')
%%%%%%%%1-5 is the antenna gain for each protection point, and #6 is the elevation degree
retry_load=0;
catch
retry_load=1;
pause(0.1)
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%Load all the ITM pathloss data and TIREM angles
%%%%%%Load all the pathloss data
tic;
[array_full_pl_data,full_prop_mode_data]=load_full_pathloss_info_multi_rel_rev3(app,data_label1,string_prop_model,grid_spacing,tf_recalculate,base_protection_pts,sim_array_list_bs,sim_number,tf_tropo_cut,reliability);
toc;
%%%%%%%%array_full_pl_data=NaN(num_grid_pts,num_pts,num_rels);
%%array_full_pl_data(:,point_idx,rel_idx)=pathloss(:,rel_idx);
%%%num_rels=length(reliability)
if tf_calc_rx_angle==1 %%%%%%Load the TIREM angles
%%%%%%%Load the Rx and Tx Angles
%%%%[array_full_pl_data,full_prop_mode_data,full_rx_angle_data]=load_full_pathloss_info_rev1(app,data_label1,'TIREM',grid_spacing,tf_recalculate,base_protection_pts,sim_array_list_bs,sim_number,tf_tropo_cut);
[~,~,full_rx_angle_data,full_tx_angle_data]=load_full_pathloss_info_angles_rev4(app,data_label1,'TIREM',grid_spacing,tf_recalculate,base_protection_pts,sim_array_list_bs,sim_number,tf_tropo_cut);
size(full_rx_angle_data)
size(full_tx_angle_data)
max(max(full_tx_angle_data))
max(max(full_rx_angle_data))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 'use multi_array_ant_gain_vertical instead'
double_ant_gain_degrees=vertcat(flipud(-1*multi_array_ant_gain_vertical(:,end)),multi_array_ant_gain_vertical(:,end));
double_multi_ant_gain_dB=vertcat(flipud(multi_array_ant_gain_vertical(:,[1:end-1])),multi_array_ant_gain_vertical(:,[1:end-1]));
shift_double_ant_gain_degrees=double_ant_gain_degrees+min_rx_ant_elevation;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Find the Off-Axis antenna gain based on the angle.
[num_tx_pts,num_rx_pts]=size(full_rx_angle_data)
full_rx_ant_gain=NaN(num_tx_pts,num_rx_pts);
for i=1:1:num_rx_pts
[idx_nn]=knnsearch(shift_double_ant_gain_degrees(:,1),full_rx_angle_data(:,i),'k',1); %%%Find Nearest Neighbor
full_rx_ant_gain(:,i)=double_multi_ant_gain_dB(idx_nn,i);
end
%%%%%%%%%%%%%%%%Calculate the Max Power Received
if length(array_bs_eirp_reductions)>1
'Need to check the size of array_bs_eirp_reductions and the dimensions of the output below'
pause;
end
full_pwr_rx_dBm=array_bs_eirp_reductions+full_rx_ant_gain-array_full_pl_data;
[max_pwr_rx_dBm,max_pwr_idx]=max(full_pwr_rx_dBm,[],2);
if length(reliability)>1
size(max_pwr_rx_dBm)
max_pwr_rx_dBm=squeeze(max_pwr_rx_dBm);
size(max_pwr_rx_dBm)
else
'Need to check sizes'
size(max_pwr_rx_dBm)
size(full_pwr_rx_dBm)
pause;
end
[num_grid_pts,~]=size(sim_array_list_bs);
%%%%%%%%%Convert to Margin Here: Number of Points x Number of Propagation Reliabilitities
array_margin_dB=max_pwr_rx_dBm-receiver_threshold;
size(array_margin_dB)
min(array_margin_dB)
max(array_margin_dB)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%This is the data to plot
num_rels=length(array_reliability_check);
min_rx_angle_data=NaN(num_tx_pts,1);
min_rx_ant_gain=NaN(num_tx_pts,1);
min_pl_data=NaN(num_tx_pts,num_rels);
min_prop_data=NaN(num_tx_pts,1);
for i=1:1:num_tx_pts
min_rx_angle_data(i)=full_rx_angle_data(i,max_pwr_idx(i));
min_rx_ant_gain(i)=full_rx_ant_gain(i,max_pwr_idx(i));
min_prop_data(i)=full_prop_mode_data(i,max_pwr_idx(i));
for rel_idx=1:1:num_rels
min_pl_data(i,rel_idx)=array_full_pl_data(i,max_pwr_idx(i),rel_idx);
end
end
%%%%%%%%%%%%%Can also plot the power received for each
%%%%%%%%%%%%%reliability will need to update the
%%%%%%%%%%%%%function
%plot_power_received_heatmap_rev1(app,sim_array_list_bs,max_pwr_rx_dBm,data_label1,string_prop_model,grid_spacing,base_protection_pts)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Rx Angle Heat Map
% %%%%%%%%%%%%%%%%Rx Launch Angle Heat Map
% mode_color_set_angles=plasma(100);
% f1=figure;
% AxesH = axes;
% hold on;
% scatter(sim_array_list_bs(1,2),sim_array_list_bs(1,1),10,max(edges),'filled');
% scatter(sim_array_list_bs(1,2),sim_array_list_bs(1,1),10,min(edges),'filled');
% scatter(sim_array_list_bs(:,2),sim_array_list_bs(:,1),10,min_rx_angle_data,'filled');
% plot(base_protection_pts(:,2),base_protection_pts(:,1),'xr','LineWidth',3,'DisplayName','Federal System')
% %plot(base_protection_pts(:,2),base_protection_pts(:,1),'ob','LineWidth',3,'DisplayName','Federal System')
% cbh = colorbar;
% ylabel(cbh, 'Elevation Angle [Degrees]')
% colormap(f1,mode_color_set_angles)
% grid on;
% xlabel('Longitude')
% ylabel('Latitude')
% title({strcat('Received Elevation Angle')})
% plot_google_map('maptype','terrain','APIKey','AIzaSyCgnWnM3NMYbWe7N4svoOXE7B2jwIv28F8') %%%Google's API key made by nick.matlab.error@gmail.com
% pause(0.1)
% filename1=strcat('Launch_Angles','_',data_label1,'_',string_prop_model,'_',num2str(grid_spacing),'km.png');
% saveas(gcf,char(filename1))
% pause(0.1);
% close(f1)
% %%%%%%%%%%%%%%%%Rx Antenna Gain Heat Map
% floor(min(min_rx_ant_gain))
% ceil(max(min_rx_ant_gain))
% f1=figure;
% AxesH = axes;
% hold on;
% scatter(sim_array_list_bs(1,2),sim_array_list_bs(1,1),10,floor(min(min_rx_ant_gain)),'filled');
% scatter(sim_array_list_bs(1,2),sim_array_list_bs(1,1),10,ceil(max(min_rx_ant_gain)),'filled');
% scatter(sim_array_list_bs(:,2),sim_array_list_bs(:,1),10,min_rx_ant_gain,'filled');
% plot(base_protection_pts(:,2),base_protection_pts(:,1),'xr','LineWidth',3,'DisplayName','Federal System')
% %plot(base_protection_pts(:,2),base_protection_pts(:,1),'ob','LineWidth',3,'DisplayName','Federal System')
% cbh = colorbar;
% ylabel(cbh, 'Antenna Gain [dBi]')
% colormap(f1,mode_color_set_angles)
% grid on;
% xlabel('Longitude')
% ylabel('Latitude')
% title({strcat('Receiver Antena Gain')})
% plot_google_map('maptype','terrain','APIKey','AIzaSyCgnWnM3NMYbWe7N4svoOXE7B2jwIv28F8') %%%Google's API key made by nick.matlab.error@gmail.com
% pause(0.1)
% filename1=strcat('Rx_Ant_Gain_Heatmap','_',data_label1,'_',string_prop_model,'_',num2str(grid_spacing),'km.png');
% saveas(gcf,char(filename1))
% pause(0.1);
% close(f1)
% %%%%%%%%%%%%%%%%%%%%%%%%%%%These are the angles that are used.
% edges=floor(min(min_rx_angle_data)):0.5:ceil(max(min_rx_angle_data))
% f1=figure;
% AxesH = axes;
% hold on;
% histogram(min_rx_angle_data,edges,'Normalization','probability')
% grid on;
% xlabel('Launch Angle [Degrees]')
% ylabel('Probability of Occurrence')
% title({strcat('Rx Launch Angle')})
% filename1=strcat('Launch_Angles_Histogram','_',data_label1,'_',string_prop_model,'.png');
% saveas(gcf,char(filename1))
% pause(0.1);
% close(f1)
% % %%%%%%%%%%%%%%%%%%%%%%%%%%%These are the angles that are used.
% % edges=floor(min(min_rx_angle_data)):0.5:ceil(max(min_rx_angle_data))
% % f1=figure;
% % AxesH = axes;
% % hold on;
% % histogram(min_rx_angle_data,edges,'Normalization','probability')
% % grid on;
% % xlabel('Vertical Receive Angle [Degrees]')
% % ylabel('Probability of Occurrence')
% % title({strcat('Histogram')})
% % filename1=strcat('Launch2_Angles_Histogram','_',data_label1,'_',string_prop_model,'.png');
% % saveas(gcf,char(filename1))
% % pause(0.1);
% % %close(f1)
else
'Need to put the data in a form so the plot functions can handle angles and non angles::: array_margin_dB'
'run a NSF RA example through'
pause;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Pathloss Heat Map for each Reliability
plot_pathloss_heatmat_reli_rev2(app,array_reliability_check,min_pl_data,data_label1,string_prop_model,grid_spacing,sim_array_list_bs,base_protection_pts)
plot_prop_mechanism_heatmap_rev1(app,data_label1,string_prop_model,grid_spacing,sim_array_list_bs,min_prop_data,base_protection_pts)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Find/Plot the Coordination Zones for each reliability
file_name_cell_bound_miti=strcat('cell_bound_',string_prop_model,'_',num2str(sim_number),'_',data_label1,'.mat');
num_miti=length(array_mitigation);
num_rels=length(array_reliability_check);
cell_bound_miti=cell(num_miti,5,num_rels);
%%%%1)Mitigation,
% %%2) Max knn dist,
% %%3)Convex Bound,
% %%4)Max Interference dB,
% %%%5)Prop Reliability
for rel_idx=1:1:num_rels
for miti_idx=1:1:num_miti
miti_dB=array_mitigation(miti_idx);
temp_rel=array_reliability_check(rel_idx);
temp_margin=array_margin_dB(:,rel_idx)-miti_dB;
idx_keep=find(temp_margin>=0);
if ~isempty(idx_keep)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Calculate the coordination zone
[max_knn_dist,convex_bound,max_int_dB]=plot_zone_miti_reli_rev2(app,temp_margin,sim_array_list_bs,base_protection_pts,data_label1,string_prop_model,temp_rel,grid_spacing,miti_dB);
cell_bound_miti{miti_idx,1,rel_idx}=miti_dB;
cell_bound_miti{miti_idx,2,rel_idx}=max_knn_dist;
cell_bound_miti{miti_idx,3,rel_idx}=convex_bound;
cell_bound_miti{miti_idx,4,rel_idx}=max_int_dB;
cell_bound_miti{miti_idx,5,rel_idx}=temp_rel;
end
end
%%%%%%%%%%%%%Plot the multi-zones, for each Reliability
temp_zones=cell_bound_miti(:,:,rel_idx);
plot_multi_zones_reli_rev3(app,temp_zones,base_protection_pts,data_label1,string_prop_model,temp_rel,grid_spacing)
end
cell_bound_miti
%%%%%%%%%%Save
retry_save=1;
while(retry_save==1)
try
save(file_name_cell_bound_miti,'cell_bound_miti')
pause(0.1);
retry_save=0;
catch
retry_save=1;
pause(0.1)
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%Save
retry_save=1;
while(retry_save==1)
try
comp_list=NaN(1);
save(complete_filename,'comp_list')
pause(0.1);
retry_save=0;
catch
retry_save=1;
pause(0.1)
end
end
retry_cd=1;
while(retry_cd==1)
try
cd(rev_folder)
pause(0.1);
retry_cd=0;
catch
retry_cd=1;
pause(0.1)
end
end
[cell_status]=update_generic_status_cell_rev1(app,folder_names,sim_folder,cell_status_filename)
%%%server_status_rev1(app)
server_status_rev2(app,tf_server_status)
end
end
multi_hWaitbarMsgQueue.send(0);
end
delete(multi_hWaitbarMsgQueue);
close(multi_hWaitbar);
end
%%%%server_status_rev1(app)
server_status_rev2(app,tf_server_status)
end