def bound_dataframe(geodataframe, ax): dy = geodataframe.bounds.maxy[0] - geodataframe.bounds.miny[0] dx = geodataframe.bounds.maxx[0] - geodataframe.bounds.minx[0] if dy > dx: minx = geodataframe.bounds.minx[0] - (dy - dx) / 2 maxx = geodataframe.bounds.maxx[0] + (dy - dx) / 2 miny = geodataframe.bounds.miny[0] maxy = geodataframe.bounds.maxy[0] else: minx = geodataframe.bounds.minx[0] maxx = geodataframe.bounds.maxx[0] miny = geodataframe.bounds.miny[0] - (dx - dy) / 2 maxy = geodataframe.bounds.maxy[0] + (dx - dy) / 2 pol = Polygon([(minx, miny), (minx, maxy), (maxx, maxy), (maxx, miny), (minx, miny)]) crs = {'init': 'epsg:3857'} pol = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[pol]) pol.plot(ax=ax, alpha=0.)
def update(frame): global step, ax, episode, pre_agent_positions, pre_agent_targets, ax1, local_view, tt t1 = time.time() print(len(agent_pos), step, frame) # sea base_x = [x_lim[0], x_lim[1], x_lim[1], x_lim[0]] base_y = [y_lim[1], y_lim[1], y_lim[0], y_lim[0]] base_pol = Polygon(zip(base_x, base_y)) base_pol = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[base_pol]) ax = base_pol.plot(ax=ax, color=Color.sea.value[0]) # ground ax = gpd_map.plot(ax=ax, color=Color.ground.value[0]) # target p = Point(target[episode][0], target[episode][1]).buffer(target_r) target_point = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[p]) if step == 0: pre_agent_targets.append(p) if episode > 1: previous_points_gdf = gpd.GeoDataFrame(index=[i for i in range(len(pre_agent_targets) - 1)], crs={'init': 'epsg:4326'}, geometry=pre_agent_targets[:-1]) ax = previous_points_gdf.plot(ax=ax, color=Color.sea.value[0], edgecolor=[211 / 255, 211 / 255, 211 / 255], markersize=1) ax = target_point.plot(ax=ax, color=Color.target.value[0]) p = Point(last_target[0], last_target[1]).buffer(target_r) target_point = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[p]) ax = target_point.plot(ax=ax, color=Color.last_target.value[0]) # static objects static_points = [] for o in static_object: r = o[0] pos = o[1] p = Point(pos[0], pos[1]).buffer(r * 3.0) static_points.append(p) static_points_gdf = gpd.GeoDataFrame(index=[i for i in range(len(static_points))], crs={'init': 'epsg:4326'}, geometry=static_points) ax = static_points_gdf.plot(ax=ax, color="orange") # dynamic objects for o in dynamic_object: if step > 0: previous_points = [Point(pos[0], pos[1]).buffer(way_size) for pos in o[1][:step]] previous_points_gdf = gpd.GeoDataFrame(index=[i for i in range(len(previous_points))], crs={'init': 'epsg:4326'}, geometry=previous_points) ax = previous_points_gdf.plot(ax=ax, color=Color.dynamic_object.value[0]) r = o[0] pos = o[1][step] last_point = Point(pos[0], pos[1]).buffer(r * 3.0) last_point = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[last_point]) ax = last_point.plot(ax=ax, color=Color.dynamic_object.value[0]) # ais objects for o in ais_object: if step > 0: previous_points = [Point(pos[0], pos[1]).buffer(way_size) for pos in o[1][:step]] previous_points_gdf = gpd.GeoDataFrame(index=[i for i in range(len(previous_points))], crs={'init': 'epsg:4326'}, geometry=previous_points) ax = previous_points_gdf.plot(ax=ax, color=Color.ais_object.value[0]) r = o[0] pos = o[1][step] last_point = Point(pos[0], pos[1]).buffer(r * 3.0) last_point = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[last_point]) ax = last_point.plot(ax=ax, color=Color.ais_object.value[0]) # agent if step > 0 or episode > 0: previous_points = [Point(pos[0], pos[1]).buffer(way_size) for pos in pre_agent_positions] previous_points_gdf = gpd.GeoDataFrame(index=[i for i in range(len(pre_agent_positions))], crs={'init': 'epsg:4326'}, geometry=previous_points) ax = previous_points_gdf.plot(ax=ax, color=[1, 99 / 255, 71 / 255]) pos = agent_pos[step] pre_agent_positions.append(pos) last_point = Point(pos[0], pos[1]).buffer(agent_r*3) last_point = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[last_point]) ax = last_point.plot(ax=ax, color=[1, 99 / 255, 71 / 255]) # local view if show_local_view: ax1.cla() ax1.set_xlim([0, 50]) ax1.set_ylim([0, 50]) local_view_all_x = [[i for _ in range(51)] for i in range(51)] local_view_all_y = [[j for j in range(51)] for _ in range(51)] local_view_ground_x = [] local_view_ground_y = [] local_view_obs_x = [] local_view_obs_y = [] local_view_target_x = [] local_view_target_y = [] for x in range(len(local_view[step])): for y in range(len(local_view[step][0])): if 0.49 < local_view[step][x][y] < 0.51: local_view_ground_x.append(x) local_view_ground_y.append(y) if local_view[step][x][y] > 0.8: local_view_target_x.append(x) local_view_target_y.append(y) if 0.29 < local_view[step][x][y] < 0.31: local_view_obs_x.append(x) local_view_obs_y.append(y) ax1.plot(local_view_all_x, local_view_all_y, 'o', color='white', markersize=12) ax1.plot(local_view_target_x, local_view_target_y, 'o', color='green', markersize=7) ax1.plot(local_view_ground_x, local_view_ground_y, 'o', color='saddlebrown', markersize=7) ax1.plot(local_view_obs_x, local_view_obs_y, 'o', color='orange', markersize=7) ax1.plot([25], [25], 'o', color=Color.agent.value, markersize=8) step += 1 tt.append(time.time() - t1) return ln,