convert data into x, y location format centered at 0,0
This commit is contained in:
parent
e4a919d022
commit
463d0290c2
|
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
import pickle
|
||||
import numpy as np
|
||||
|
||||
|
||||
def convert_gps_into_xy(latlon1, latlon2, convert2radian=False):
|
||||
radius = 6371e3
|
||||
lat1, lon1 = latlon1
|
||||
lat2, lon2 = latlon2
|
||||
if convert2radian:
|
||||
lat1 = lat1 * np.pi / 180
|
||||
lat2 = lat2 * np.pi / 180
|
||||
lon1 = lon1 * np.pi / 180
|
||||
lon2 = lon2 * np.pi / 180
|
||||
delta_lat = lat2 - lat1
|
||||
delta_lon = lon2 - lon1
|
||||
# a = np.sin(delta_lat / 2) ** 2 + np.cos(lat1) * np.cos(lat2) * np.sin(delta_lon / 2) ** 2
|
||||
# c = 2 * np.arctan2(np.sqrt(a), np.sqrt(1 - a))
|
||||
# d1meters = radius * c # Haversine distance
|
||||
x = delta_lon * np.cos((lat1 + lat2) / 2)
|
||||
y = delta_lat
|
||||
# d2meters = radius * np.sqrt(x*x + y*y) # Pythagorean distance
|
||||
return x, y
|
||||
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print('Usage: {} folderpath code_to_country_fp'.format(sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
folderpath = sys.argv[1]
|
||||
code_to_country_fp = sys.argv[2]
|
||||
|
||||
############################
|
||||
# load
|
||||
############################
|
||||
code_to_country = pickle.load(open(code_to_country_fp, 'rb'))
|
||||
|
||||
############################
|
||||
# convert
|
||||
############################
|
||||
|
||||
pickle_fp_with_groundtruth = '{}/with_groundtruth_converted.pickle'.format(folderpath)
|
||||
|
||||
all_data = []
|
||||
for filepath in glob.glob("{}/with_groundtruth/*/*/*/*/*.csv".format(folderpath)):
|
||||
__, __, radio, mcc, mnc, area, cell_and_loc = list(filter(None, filepath.rstrip('.csv').split('/')))
|
||||
cell, cell_lon, cell_lat = cell_and_loc.split('_')
|
||||
cell_lon = float(cell_lon)
|
||||
cell_lon_rad = cell_lon * np.pi / 180
|
||||
cell_lat = float(cell_lat)
|
||||
cell_lat_rad = cell_lat * np.pi / 180
|
||||
data = []
|
||||
with open(filepath, 'r') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
if '#' in line:
|
||||
continue
|
||||
tmp = line.rstrip().split(',')
|
||||
lon = float(tmp[0])
|
||||
lat = float(tmp[1])
|
||||
sig = float(tmp[2])
|
||||
x, y = convert_gps_into_xy((lat, lon), (cell_lat_rad, cell_lon_rad))
|
||||
data.append([lon, lat, sig, x, y])
|
||||
all_data.append({
|
||||
'radio': radio,
|
||||
'mcc': mcc,
|
||||
'mnc': mnc,
|
||||
'country_code': code_to_country.get('{}_{}'.format(mcc, mnc), 'unknown')[0],
|
||||
'area': area,
|
||||
'cell': cell,
|
||||
'longitude': cell_lon,
|
||||
'latitude': cell_lat,
|
||||
'x': 0.0,
|
||||
'y': 0.0,
|
||||
'measurements': np.array(data) # lon, lat, sig, x, y
|
||||
})
|
||||
|
||||
pickle.dump(all_data, open(pickle_fp_with_groundtruth, 'wb'))
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 20 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Loading…
Reference in New Issue