generate image per measurement

This commit is contained in:
HappyZ 2019-06-10 15:55:05 -05:00
parent 463d0290c2
commit e84b3fb142
2 changed files with 68 additions and 0 deletions

View File

@ -44,8 +44,10 @@ code_to_country = pickle.load(open(code_to_country_fp, 'rb'))
############################ ############################
pickle_fp_with_groundtruth = '{}/with_groundtruth_converted.pickle'.format(folderpath) pickle_fp_with_groundtruth = '{}/with_groundtruth_converted.pickle'.format(folderpath)
tmp_fp_with_groundtruth = '{}/with_groundtruth_converted.boundary'.format(folderpath)
all_data = [] all_data = []
boundaries = []
for filepath in glob.glob("{}/with_groundtruth/*/*/*/*/*.csv".format(folderpath)): for filepath in glob.glob("{}/with_groundtruth/*/*/*/*/*.csv".format(folderpath)):
__, __, radio, mcc, mnc, area, cell_and_loc = list(filter(None, filepath.rstrip('.csv').split('/'))) __, __, radio, mcc, mnc, area, cell_and_loc = list(filter(None, filepath.rstrip('.csv').split('/')))
cell, cell_lon, cell_lat = cell_and_loc.split('_') cell, cell_lon, cell_lat = cell_and_loc.split('_')
@ -54,6 +56,12 @@ for filepath in glob.glob("{}/with_groundtruth/*/*/*/*/*.csv".format(folderpath)
cell_lat = float(cell_lat) cell_lat = float(cell_lat)
cell_lat_rad = cell_lat * np.pi / 180 cell_lat_rad = cell_lat * np.pi / 180
data = [] data = []
min_x = float('inf')
min_y = float('inf')
min_sig = float('inf')
max_x = float('-inf')
max_y = float('-inf')
max_sig = float('-inf')
with open(filepath, 'r') as f: with open(filepath, 'r') as f:
lines = f.readlines() lines = f.readlines()
for line in lines: for line in lines:
@ -64,6 +72,12 @@ for filepath in glob.glob("{}/with_groundtruth/*/*/*/*/*.csv".format(folderpath)
lat = float(tmp[1]) lat = float(tmp[1])
sig = float(tmp[2]) sig = float(tmp[2])
x, y = convert_gps_into_xy((lat, lon), (cell_lat_rad, cell_lon_rad)) x, y = convert_gps_into_xy((lat, lon), (cell_lat_rad, cell_lon_rad))
min_x = min(min_x, x)
min_y = min(min_y, y)
min_sig = min(min_sig, sig)
max_x = max(max_x, x)
max_y = max(max_y, y)
max_sig = max(max_sig, sig)
data.append([lon, lat, sig, x, y]) data.append([lon, lat, sig, x, y])
all_data.append({ all_data.append({
'radio': radio, 'radio': radio,
@ -76,7 +90,13 @@ for filepath in glob.glob("{}/with_groundtruth/*/*/*/*/*.csv".format(folderpath)
'latitude': cell_lat, 'latitude': cell_lat,
'x': 0.0, 'x': 0.0,
'y': 0.0, 'y': 0.0,
'boundary': (min_x, min_y, max_x, max_y),
'measurements': np.array(data) # lon, lat, sig, x, y 'measurements': np.array(data) # lon, lat, sig, x, y
}) })
boundaries.append((min_x, max_x, min_y, max_y, min_sig, max_sig))
pickle.dump(all_data, open(pickle_fp_with_groundtruth, 'wb')) pickle.dump(all_data, open(pickle_fp_with_groundtruth, 'wb'))
with open(tmp_fp_with_groundtruth, 'w') as f:
f.write("#min_x,max_x,min_y,max_y,min_sig,max_sig\n")
for boundary in boundaries:
f.write("{:.4f},{:.4f},{:.4f},{:.4f},{:.0f},{:.0f}\n".format(boundary[0], boundary[1], boundary[2], boundary[3], boundary[4], boundary[5]))

View File

@ -0,0 +1,48 @@
#!/usr/bin/python
import os
import sys
import glob
import pickle
import numpy as np
import matplotlib.pyplot as plt
def blocking_display_signal_map(
data_vector: np.ndarray,
fp: str,
vmin: float = -80.0,
vmax: float = -40.0
):
'''
'''
plt.scatter(data_vector[:, 3], data_vector[:, 4], s=50, c=data_vector[:, 2])
plt.colorbar()
# plt.show()
plt.draw()
plt.savefig("{}.png".format(fp), dpi=50)
plt.pause(0.1)
q = input("press Enter to continue... type q to quit: ")
if q == 'q':
sys.exit()
plt.close()
if len(sys.argv) < 3:
print('Usage: {} pickle_fp'.format(sys.argv[0]))
sys.exit(0)
pickle_fp = sys.argv[1]
############################
# load
############################
all_data = pickle.load(open(pickle_fp, 'rb'))
for data in all_data:
filename = (
"{}_{}_{}_{}_{}_{}.png"
.format(data['country_code'], data['radio'], data['mcc'], data['mnc'], data['area'], data['cell'])
)
blocking_display_signal_map(data['measurements'], filename)