Skip to content

Commit 774f391

Browse files
committed
export cell coord in progress
1 parent c56467d commit 774f391

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

area-scanning/analyse_area_scanning

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import sys
1414
import pandas as pd
1515
import collections
1616
from fractions import Fraction
17+
import json
1718
# import yaml
1819
# from sailing_robot.navigation import Navigation
1920

@@ -29,10 +30,10 @@ def latlon_to_utm(lat, lon):
2930
"""Returns (x, y) coordinates in metres"""
3031
return projection(lon, lat)
3132

32-
# def utm_to_latlon(x, y):
33-
# """Returns a LatLon object"""
34-
# lon, lat = projection(x, y, inverse=True)
35-
# return LatLon(lat, lon)
33+
def utm_to_latlon(coord):
34+
"""Returns a LatLon object"""
35+
lon, lat = projection(coord[0], coord[1], inverse=True)
36+
return lat, lon
3637

3738

3839

@@ -41,7 +42,7 @@ def latlon_to_utm(lat, lon):
4142
# Lat *10^^7
4243
# Lon *10^^7
4344

44-
# C
45+
# C D
4546
# +-+-+-+-+-+
4647
# +-+-+-+-+-+
4748
# +-+-+-+-+-+
@@ -55,7 +56,7 @@ def latlon_to_utm(lat, lon):
5556
# Number of subdivision of the grid
5657
subY = 58
5758
subX = 45
58-
59+
cell_size = 4
5960

6061
# gps log file given as the 2nd argument
6162
# cvs_file = sys.argv[2]
@@ -88,8 +89,16 @@ vAB_orth = vAC
8889
# vAB_orth = np.array([-vAB[1], vAB[0]])
8990

9091

91-
92-
92+
def cell_ij_to_coord(i,j):
93+
A = wpA_utm + vAB*cell_size*i + vAB_orth*cell_size*j
94+
B = A+vAB_orth*cell_size
95+
C = B+vAB*cell_size
96+
D = A+vAB*cell_size
97+
A = utm_to_latlon(A)
98+
B = utm_to_latlon(B)
99+
C = utm_to_latlon(C)
100+
D = utm_to_latlon(D)
101+
return A,B,C,D
93102

94103

95104
def generate_visit_set(filename):
@@ -106,8 +115,8 @@ def generate_visit_set(filename):
106115
for point in position_utm:
107116
# projection of point in the (wpA_utm; vAB,vAB_orth) base
108117
point_base = [point[0] - wpA_utm[0], point[1] - wpA_utm[1]]
109-
point_i = np.dot(point_base, vAB)*subX/2/AB
110-
point_j = np.dot(point_base, vAB_orth)*subY/2/AC
118+
point_i = np.dot(point_base, vAB)*subX/AB
119+
point_j = np.dot(point_base, vAB_orth)*subY/AC
111120

112121
if point_i < 0 or point_j < 0 or point_i > subX or point_j > subY:
113122
continue
@@ -127,8 +136,17 @@ CellVisitors = collections.namedtuple('CellVisitors', 'in_window out_of_window')
127136
# in_window
128137
master_data = pd.read_csv(sys.argv[1])
129138
master_data['visit_set'] = master_data.filename.apply(generate_visit_set)
139+
attempt_per_cell = collections.defaultdict(int)
130140
for row in master_data.itertuples():
131141
print(row.filename, len(row.visit_set))
142+
for cell_pos in row.visit_set:
143+
attempt_per_cell[cell_pos] += 1
144+
145+
data = []
146+
for cell, count in attempt_per_cell.items():
147+
data.append([cell_ij_to_coord(cell[0],cell[1]), count])
148+
with open("heat_map_data"+sys.argv[1]+".json",'w') as f:
149+
json.dump(data,f)
132150

133151
# Build map of what teams visited which cells, in their in-window and out-of-window attempts
134152
cell_visits = collections.defaultdict(lambda: CellVisitors(set(), set()))

0 commit comments

Comments
 (0)