def compute_coverage_map(grid_size = 100): swlat=34.018212 swlng=-118.291716 nelat=34.025296 nelng=-118.279826 videos = get_videos(swlat, swlng, nelat, nelng) map = np.ndarray(shape=(grid_size, grid_size), dtype=int) for video in videos: if IS_FROM_MEDIAQ: if video.properties['vid']: vid = str(video.properties['vid']) fovs = getFOVs(vid) if fovs and len(fovs) > 0: for fov in fovs.features: f = FOV(fov) param = Params(200, swlat, swlng, nelat, nelng) param.GRID_SIZE = grid_size for cid in f.cellids(param): cell_lat, cell_lng = cell_coord(cid, param) if f.cover(cell_lat, cell_lng): y_idx = cid/param.GRID_SIZE x_idx = cid - y_idx*param.GRID_SIZE # print x_idx, y_idx, map[x_idx][y_idx] map[x_idx][y_idx] = map[x_idx][y_idx] + 1 else: for f in video.fovs: param = Params(200, swlat, swlng, nelat, nelng) param.GRID_SIZE = grid_size for cid in f.cellids(param): cell_lat, cell_lng = cell_coord(cid, param) if f.cover(cell_lat, cell_lng): y_idx = cid/param.GRID_SIZE x_idx = cid - y_idx*param.GRID_SIZE # print x_idx, y_idx, map[x_idx][y_idx] map[x_idx][y_idx] = map[x_idx][y_idx] + 1 fig, ax = plt.subplots() heatmap = ax.pcolor(map, cmap=plt.cm.Reds) plt.show() plt.close() np.savetxt("mediaq_coverage_heatmap.txt" , map, fmt='%i\t')
def compute_coverage_map(grid_size=100): swlat = 34.018212 swlng = -118.291716 nelat = 34.025296 nelng = -118.279826 videos = get_videos(swlat, swlng, nelat, nelng) map = np.ndarray(shape=(grid_size, grid_size), dtype=int) for video in videos: if IS_FROM_MEDIAQ: if video.properties['vid']: vid = str(video.properties['vid']) fovs = getFOVs(vid) if fovs and len(fovs) > 0: for fov in fovs.features: f = FOV(fov) param = Params(200, swlat, swlng, nelat, nelng) param.GRID_SIZE = grid_size for cid in f.cellids(param): cell_lat, cell_lng = cell_coord(cid, param) if f.cover(cell_lat, cell_lng): y_idx = cid / param.GRID_SIZE x_idx = cid - y_idx * param.GRID_SIZE # print x_idx, y_idx, map[x_idx][y_idx] map[x_idx][y_idx] = map[x_idx][y_idx] + 1 else: for f in video.fovs: param = Params(200, swlat, swlng, nelat, nelng) param.GRID_SIZE = grid_size for cid in f.cellids(param): cell_lat, cell_lng = cell_coord(cid, param) if f.cover(cell_lat, cell_lng): y_idx = cid / param.GRID_SIZE x_idx = cid - y_idx * param.GRID_SIZE # print x_idx, y_idx, map[x_idx][y_idx] map[x_idx][y_idx] = map[x_idx][y_idx] + 1 fig, ax = plt.subplots() heatmap = ax.pcolor(map, cmap=plt.cm.Reds) plt.show() plt.close() np.savetxt("mediaq_coverage_heatmap.txt", map, fmt='%i\t')
rads += pi / 2.0 return degrees(rads) # print angle_bwn_two_points(0,0,1,-1) def distance_km(lat1, lon1, lat2, lon2): """ Distance between two geographical locations """ R = 6371 # km dLat = math.radians(abs(lat2 - lat1)) dLon = math.radians(abs(lon2 - lon1)) lat1 = math.radians(lat1) lat2 = math.radians(lat2) a = math.sin(dLat / 2) * math.sin(dLat / 2) + math.sin( dLon / 2) * math.sin(dLon / 2) * math.cos(lat1) * math.cos(lat2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) d = R * c return d if False: # test box = np.array([[1.5, 1.5], [2.5, 3.5]]) param = Params(1000) param.GRID_SIZE = 5 param.x_min, param.y_min, param.x_max, param.y_max = 0, 0, 5, 5 print mbr_to_cellids(box, param)
rads = atan2(-dy,dx) # rads %= 2*pi rads += pi/2.0; return degrees(rads) # print angle_bwn_two_points(0,0,1,-1) def distance_km(lat1, lon1, lat2, lon2): """ Distance between two geographical locations """ R = 6371 # km dLat = math.radians(abs(lat2 - lat1)) dLon = math.radians(abs(lon2 - lon1)) lat1 = math.radians(lat1) lat2 = math.radians(lat2) a = math.sin(dLat / 2) * math.sin(dLat / 2) + math.sin(dLon / 2) * math.sin(dLon / 2) * math.cos(lat1) * math.cos( lat2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) d = R * c return d if False: # test box = np.array([[1.5,1.5],[2.5,3.5]]) param = Params(1000) param.GRID_SIZE = 5 param.x_min,param.y_min,param.x_max,param.y_max = 0,0,5,5 print mbr_to_cellids(box,param)