diff --git a/opencellid_parsing/003c.convert_data_into_xy_center_at_00.py b/opencellid_parsing/003c.convert_data_into_xy_center_at_00.py new file mode 100644 index 0000000..3d5faae --- /dev/null +++ b/opencellid_parsing/003c.convert_data_into_xy_center_at_00.py @@ -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')) diff --git a/opencellid_parsing/opencellid_with_groundtruth_num_distribution.png b/opencellid_parsing/opencellid_with_groundtruth_num_distribution.png index a2e8118..0488626 100644 Binary files a/opencellid_parsing/opencellid_with_groundtruth_num_distribution.png and b/opencellid_parsing/opencellid_with_groundtruth_num_distribution.png differ diff --git a/opencellid_parsing/opencellid_with_groundtruth_num_stat.png b/opencellid_parsing/opencellid_with_groundtruth_num_stat.png index 9fb6ac7..bad966d 100644 Binary files a/opencellid_parsing/opencellid_with_groundtruth_num_stat.png and b/opencellid_parsing/opencellid_with_groundtruth_num_stat.png differ