from fire_rs.planning.display import TrajectoryDisplayExtension, plot_plan_trajectories # Geographic environment (elevation, landcover, wind...) wind = (10., 0.) area = ((480000.0, 485000.0), (6210000.0, 6215000.0)) env = PlanningEnvironment(area, wind_speed=wind[0], wind_dir=wind[1], planning_elevation_mode='flat', flat_altitude=0) # Fire applied to the previous environment ignition_point = TimedPoint(area[0][0] + 1000.0, area[1][0] + 2000.0, 0) logging.info("Start of propagation") fire = propagation.propagate_from_points(env, ignition_point, 240 * 60) logging.info("End of propagation") # Configure some flight base_wp = Waypoint(area[0][0] + 100., area[1][0] + 100., 0., 0.) start_t = 120 * 60 # 30 minutes after the ignition uavconf = UAVConf.slow_x8() fgconf = FlightConf(uavconf, start_t, base_wp) # Write down the desired VNS configuration conf_vns = { "full": { "max_restarts": 5, "max_time": 15.0, "neighborhoods": [ {"name": "dubins-opt", "max_trials": 100, "generators": [ {"name": "MeanOrientationChangeGenerator"}, {"name": "RandomOrientationChangeGenerator"},
# Geographic environment (elevation, landcover, wind...) wind = (10., 0.) area = ((480060.0, 485060.0), (6210074.0, 6215074.0)) flat_altitude = 700. env = PlanningEnvironment(area, wind_speed=wind[0], wind_dir=wind[1], planning_elevation_mode='flat', flat_altitude=flat_altitude) # Fire applied to the previous environment ignition_point = TimedPoint(area[0][0] + 1000.0, area[1][0] + 2000.0, 0) fire = propagation.propagate_from_points(env, ignition_point, 180 * 60) # Configure some flight base_wp = Waypoint(area[0][0] + 100., area[1][0] + 100., flat_altitude + 100., 0.) start_t = 120 * 60 # 30 minutes after the ignition fgconf = FlightConf(UAVConf.x8(), start_t, base_wp) # Write down the desired VNS configuration conf_vns = { "demo": { "max_time": 15., "neighborhoods": [{ "name": "dubins-opt", "max_trials": 200, "generators": [{ "name": "RandomOrientationChangeGenerator"
def threefire_twouav_figure( wind_speed=5., wind_dir=np.pi / 2) -> "fire_rs.geodata.display.GeoDataDisplay": """Plot a generic case with wind, multiple UAV from multiple bases, and multiple fire.""" # Geographic environment (elevation, landcover, wind...) wind = (wind_speed, wind_dir) area = ((480000.0, 485000.0), (6210000.0, 6215000.0)) env = PlanningEnvironment(area, wind_speed=wind[0], wind_dir=wind[1], planning_elevation_mode='flat', flat_altitude=0) # Fire applied to the previous environment ignition_points = [ TimedPoint(area[0][0] + 1000.0, area[1][0] + 1000.0, 0.), TimedPoint(area[0][0] + 4000.0, area[1][0] + 2000.0, 0.), TimedPoint(area[0][0] + 2000.0, area[1][0] + 3500.0, 0.) ] logging.info("Start of propagation") fire = propagation.propagate_from_points(env, ignition_points, 120 * 60) logging.info("End of propagation") # Configure some flight start_t = 90 * 60 uav = UAVConf.x8() uav.max_flight_time /= 3 f_confs = [ FlightConf(uav, start_t, Waypoint(area[0][0] + 100., area[1][0] + 100., 0., 0.), None, wind), FlightConf(uav, start_t, Waypoint(area[0][0] + 100., area[1][0] + 100., 0., 0.), None, wind), ] conf = SAOP_conf(start_t, start_t + uav.max_flight_time) fire1 = fire.ignitions() pl = Planner(env, fire1, f_confs, conf) pl.compute_plan() sr_1 = pl.search_result fmapper = FireMapper(env, fire1) gdd = fire_rs.geodata.display.GeoDataDisplay.pyplot_figure( env.raster.combine(fire1), frame=(0, 0)) gdd.add_extension(TrajectoryDisplayExtension, (None, ), {}) # Draw expected fire contour t_range = (sr_1.final_plan().trajectories()[0].start_time(0), sr_1.final_plan().trajectories()[0].end_time( len(sr_1.final_plan().trajectories()[0]) - 1)) t_range_fire = (0, np.inf) gdd.draw_ignition_contour(geodata=fire1, time_range=t_range_fire, cmap=matplotlib.cm.Reds, alpha=1) # Draw observed fire for i in range(len(f_confs)): executed_path = sr_1.final_plan().trajectories()[i].sampled_with_time( step_size=10) fmapper.observe(executed_path, pl.flights[i].uav) gdd.draw_ignition_shade(geodata=fmapper.firemap, cmap=matplotlib.cm.summer, vmin=t_range[0], vmax=t_range[1], with_colorbar=False) # Draw trajectory colors = ['blue', 'darkgreen', 'magenta'] labels = ["UAV " + str(i) for i in range(len(f_confs))] for i in range(len(f_confs)): plot_plan_trajectories(sr_1.final_plan(), gdd, trajectories=i, draw_path=True, draw_flighttime_path=False, colors=[colors[i]], labels=[labels[i]], linestyles=['-']) gdd.legend() return gdd
def detail_case_figure( wind_speed=5., wind_dir=0.) -> "fire_rs.geodata.display.GeoDataDisplay": """Plot a case with an small fire we can make a zoom and observe a dubinswind path and observed cells.""" # Geographic environment (elevation, landcover, wind...) wind = (wind_speed, wind_dir) wind_xy = (wind[0] * np.cos(wind[1]), wind[0] * np.sin(wind[1])) area = ((480000.0, 485000.0), (6210000.0, 6215000.0)) env = PlanningEnvironment(area, wind_speed=10, wind_dir=wind[1], planning_elevation_mode='flat', flat_altitude=0) # Fire applied to the previous environment ignition_points = [ TimedPoint(area[0][0] + 2000.0, area[1][0] + 2000.0, 0), ] logging.info("Start of propagation") fire = propagation.propagate_from_points(env, ignition_points, 180 * 60) logging.info("End of propagation") # Configure some flight base_wp = Waypoint(area[0][0] + 100., area[1][0] + 100., 0., 0.) start_t = 120 * 60 uav = UAVConf.x8() f_confs = [ FlightConf(uav, start_t, Waypoint(area[0][0] + 100., area[1][0] + 100., 0., 0.), None, wind_xy), ] conf = SAOP_conf(start_t, start_t + uav.max_flight_time) fire1 = fire.ignitions() pl = Planner(env, fire1, f_confs, conf) pl.compute_plan() sr_1 = pl.search_result fmapper = FireMapper(env, fire1) gdd = fire_rs.geodata.display.GeoDataDisplay.pyplot_figure( env.raster.combine(fire1), frame=(0, 0)) gdd.add_extension(TrajectoryDisplayExtension, (None, ), {}) gdd.axes.grid(True) # Draw expected fire contour t_range = (sr_1.final_plan().trajectories()[0].start_time(0) - 120, sr_1.final_plan().trajectories()[0].end_time( len(sr_1.final_plan().trajectories()[0]) - 1) + 120) t_range_fire = (0, np.inf) gdd.draw_ignition_contour(geodata=fire1, time_range=t_range_fire, cmap=matplotlib.cm.Reds) # Draw observed fire executed_path_1 = sr_1.final_plan().trajectories()[0].sampled_with_time( step_size=10) fmapper.observe(executed_path_1, pl.flights[0].uav) gdd.TrajectoryDisplayExtension.draw_observation_map( obs_map=fmapper.observed, layer='ignition', color='gray') gdd.TrajectoryDisplayExtension.draw_observation_map( obs_map=fmapper.firemap, layer='ignition', color='green') # Draw trajectory colors = ['blue', 'green', 'magenta'] labels = ["UAV " + str(i) for i in range(len(f_confs))] for i in range(len(f_confs)): plot_plan_trajectories(sr_1.final_plan(), gdd, trajectories=i, draw_path=True, draw_segments=False, draw_flighttime_path=False, colors=[colors[i]], labels=None) gdd.legend() return gdd
return anim_fire_figure.axes.contourf(anim_fire_figure._x_ticks, anim_fire_figure._y_ticks, igni, [0, i + 0.1, i + 1], cmap=matplotlib.cm.YlOrRd) anim = animation.FuncAnimation(anim_fire_figure.figure, animate, frames=120) anim.save('fire_animation.mp4', fps=12, dpi=200) anim_fire_figure.figure.show() print() # CREATE VNS PLAN # Configure some flight base_wp_1 = Waypoint(area[0][1] - 150., area[1][1] - 100., 0., 0.) # base_wp_2 = Waypoint(area[0][1] - 150., area[1][1] - 100., 0., 0.) start_t = 60 * 60 # 30 minutes after the ignition uavconf = UAVConf.x8() uavconf.max_flight_time = 30 * 60 fgconf_1 = FlightConf(uavconf, start_t, base_wp_1) # fgconf_2 = FlightConf(uavconf, start_t, base_wp_2) # Write down the desired VNS configuration conf_vns = { "full": { "max_restarts": 5, "max_time": 20.0, "neighborhoods": [
def give_me_a_plan(): import numpy as np import fire_rs.uav_planning as op from fire_rs.firemodel import propagation from fire_rs.geodata.geo_data import TimedPoint, GeoData from fire_rs.planning.planning import FireMapper, FlightConf, Planner, PlanningEnvironment, \ UAVConf, Waypoint from fire_rs.planning.display import TrajectoryDisplayExtension, plot_plan_trajectories # Geographic environment (elevation, landcover, wind...) wind = (10., np.pi / 4) # 10m/s = 36km/h area = ((478500.0, 483500.0), (6210000.0, 6215000.0)) env = PlanningEnvironment(area, wind_speed=wind[0], wind_dir=wind[1], planning_elevation_mode='flat', flat_altitude=0) # Fire applied to the previous environment ignition_point = TimedPoint(area[0][0] + 2500.0, area[1][0] + 2100.0, 0) fire = propagation.propagate_from_points(env, ignition_point, 120 * 60) # 60 minutes # Configure some flight base_wp_1 = Waypoint(area[0][1] - 150., area[1][1] - 100., 0., 0.) start_t = 60 * 60 # 30 minutes after the ignition uavconf = UAVConf.x8() uavconf.max_flight_time = 30 * 60 fgconf_1 = FlightConf(uavconf, start_t, base_wp_1) # Write down the desired VNS configuration conf_vns = { "full": { "max_restarts": 5, "max_time": 10.0, "neighborhoods": [ { "name": "dubins-opt", "max_trials": 100, "generators": [{ "name": "MeanOrientationChangeGenerator" }, { "name": "RandomOrientationChangeGenerator" }, { "name": "FlipOrientationChangeGenerator" }] }, { "name": "one-insert", "max_trials": 100, "select_arbitrary_trajectory": True, "select_arbitrary_position": False }, ] } } conf = { 'min_time': fgconf_1.start_time, 'max_time': fgconf_1.start_time + fgconf_1.uav.max_flight_time, 'save_every': 1, 'save_improvements': True, 'discrete_elevation_interval': 0, 'vns': conf_vns['full'] } conf['vns']['configuration_name'] = 'full' #################################### # 1st PLAN fire1 = fire.ignitions() pl = Planner(env, fire1, [fgconf_1], conf) pl.compute_plan() return pl.search_result.final_plan()