-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDistanceMatrix2.py
53 lines (32 loc) · 3.07 KB
/
DistanceMatrix2.py
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
import xlrd
import numpy as np
import math
import pandas as pd
#Creating a Numpy Matrix of the lat and long of Current Telsa Locations & Mean Center Points of VA
book = xlrd.open_workbook('/Users/Ramzi/Dropbox/LatLongNOTesla.xlsx')
sheet = book.sheet_by_name('Sheet1')
data = [[sheet.cell_value(r, c) for c in range(sheet.ncols)] for r in range(sheet.nrows)]
# Profit !
#print (data)
# Check if Data prints correctly
#Straight Line distance matrix calculation
def spherical_dist(pos1, pos2, r=3958.75):
pos1 = pos1 * np.pi / 180
pos2 = pos2 * np.pi / 180
cos_lat1 = np.cos(pos1[..., 0])
cos_lat2 = np.cos(pos2[..., 0])
cos_lat_d = np.cos(pos1[..., 0] - pos2[..., 0])
cos_lon_d = np.cos(pos1[..., 1] - pos2[..., 1])
return r * np.arccos(cos_lat_d - cos_lat1 * cos_lat2 * (1 - cos_lon_d))
locations_1 = np.array(data)
soup = spherical_dist(locations_1[:, None], locations_1)
print(spherical_dist(locations_1[:, None], locations_1))
Locations = print(np.prod(soup.shape))
#MutiplyArray = np.array([2357,3860,4738,5085,5778,6030,6187,6544,6814,6842,7074,7215,7230,7284,7286,8556,9292,9555,9967,10750,11293,11472,11613,12083,12351,12356,12564,13259,13280,13364,13402,13591,13729,14084,14560,14695,14922,15339,15523,15711,16112,16139,16448,16492,16678,16793,17091,17619,17744,17803,18189,18652,18753,19004,19347,21537,21924,22096,22504,22915,23344,23772,23859,24297,24313,24641,24723,25371,25550,26243,26903,27249,28817,28864,29023,29262,29667,31595,32178,32540,32893,33430,33935,34758,34905,36023,36330,36476,37403,37791,38615,38805,41314,42062,42093,44399,44749,46493,48571,53266,53811,54757,54991,62390,64989,66174,68548,68698,72027,73430,76551,77720,85224,91780,92707,93391,97100,99998,101350,123398,128257,145210,146762,181614,201272,215842,223279,236947,300523,308819,314259,387988,436642,1041240])
#MutiplyArray = np.array([5.7,507.9,8.9,15.4,825.4,1057.9,896.7,962.4,20.9,834.4,19.7,2886,27.1,23.5,35.7,1030.8,86,44.2,33.3,638.5997701,659.7290026,680.8582351,701.9874676,723.1167,744.2459325,765.375165,786.5043975,807.63363,828.7628624,849.8920949,871.0213274,892.1505599,913.2797924,934.4090248,955.5382573,976.6674898,997.7967223,1018.925955,1040.055187,1061.18442,1082.313652,1103.442885,1124.572117,1145.70135,1166.830582,1187.959815,1209.089047,1230.21828,1251.347512,1272.476745,1293.605977,1314.735209,1335.864442,1356.993674,1378.122907,1399.252139,1420.381372,62.4,37.4,2161.8,2141.7,44.1,1211.1,48.2,129.6,78.4,3924.3,58,1738.1,2821.8,92.7,53.7,62,110.1,53.9,61.4,62.1,1361.9,71.1,47.9,68.7,61.2,66.4,101.2,105.9,43.4,100.1,3647.6,172.8,134.2,134.1,49.6,4011.1,82.1,104,85.4,1019.3,2641.6,127,74.9,106.1,96.8,143.1,63.8,478.9,369.1,89.1,105.5,74.2,1480.4,89.7,187,198.6,235.7,369.2,2176.9,133.7,2145.9,213.8,299.4,459.2,9429.2,1778.9,1526.2,3220.4,8269.8,636.5,2460.5,1228.1,592.5,718.8,1113.3,877.8,2560.8])
#arraynew = np.multiply(soup, MutiplyArray[:,np.newaxis])
#print(arraynew)
#df2 = pd.DataFrame(arraynew)
#Save as an OD-Matrix First 11 are Tesla The rest are mean center points of VA
df = pd.DataFrame(soup)
df.to_csv("/Users/Ramzi/Desktop/Distances_NoTesla1_NoWeight.csv")