def burn(area_bounds, ignition_point, wind):
     """Burn some area from an ignition point with given wind conditions"""
     env = propagation.Environment(area_bounds,
                                   wind_speed=wind[0],
                                   wind_dir=wind[1])
     f_propagation = propagation.propagate_from_points(
         env, (ignition_point[0], ignition_point[1], 0), until=120 * 60)
     return f_propagation.ignitions()
    def test_vns(self):
        def pr(cpp_raster, blocking=False):  # plots a cpp raster
            return GeoData.from_cpp_raster(cpp_raster,
                                           "xx").plot(blocking=blocking)

        from fire_rs.firemodel import propagation
        env = propagation.Environment(
            [[480060.0, 485060.0], [6210074.0, 6214074.0]],
            wind_speed=4.11,
            wind_dir=0)
        prop = propagation.propagate_from_points(env,
                                                 TimedPoint(
                                                     482060, 6211074, 0),
                                                 until=14000)

        ignitions = prop.ignitions()
        # ax = ignitions.plot(blocking=False)
        elev = env.raster.slice('elevation')

        conf = {
            'min_time': 9500,
            'max_time': 12000,
            'save_every': 0,
            'save_improvements': False,
            'discrete_elevation_interval': 1,
            'vns': fire_rs.planning.benchmark.vns_configurations['base']
        }
        conf['vns']['configuration_name'] = 'base'

        wp = up.Waypoint(480060.0 + 100, 6210074.0 + 100, 0, 0)
        flight = up.TrajectoryConfig(uav, wp, wp, conf['min_time'], 1500)

        res = up.plan_vns([
            flight,
        ], ignitions.as_cpp_raster(), elev.as_cpp_raster(), json.dumps(conf))

        plan = res.final_plan()

        geodatadisplay = GeoDataDisplay.pyplot_figure(
            env.raster.combine(ignitions))
        geodatadisplay.add_extension(TrajectoryDisplayExtension, (None, ), {})

        plot_plan(plan, geodatadisplay, show=True)

        for intermediate_plan in res.intermediate_plans:
            geodatadisplay = GeoDataDisplay.pyplot_figure(
                env.raster.combine(ignitions))
            geodatadisplay.add_extension(TrajectoryDisplayExtension, (None, ),
                                         {})
            plot_plan(intermediate_plan, geodatadisplay, show=True)

        print("durations: ")
        for traj in plan.trajectories():
            print(traj.duration())
 def test_propagate_full(self):
     env = propagation.Environment(self.test_area,
                                   wind_speed=4.11,
                                   wind_dir=0)
     prop = propagation.propagate_from_points(env, [self.ignition_point])
Example #4
0
from fire_rs.firemodel import propagation
from fire_rs.geodata.display import GeoDataDisplay
from fire_rs.geodata.geo_data import TimedPoint


if __name__ == "__main__":
    output_format = "svg"

    # Uncomment below to use latex for typesetting
    # matplotlib.rcParams['font.family'] = 'sans-serif'
    # matplotlib.rcParams['text.usetex'] = True
    # output_format="pdf"

    area = ((480000.0, 485000.0), (6210000.0, 6215000.0))
    env = propagation.Environment(area, wind_speed=5., wind_dir=0.)
    ignition_point = TimedPoint(area[0][0] + 1000.0, area[1][0] + 2000.0, 0)
    fire = propagation.propagate_from_points(env, ignition_point, 90000)

    # Figure terrain + ignition contour + ignition point
    gdd = GeoDataDisplay.pyplot_figure(env.raster.combine(fire.ignitions().slice(["ignition"])),
                                       frame=(0., 0.))
    # gdd.draw_elevation_shade(with_colorbar=False, cmap=matplotlib.cm.terrain)
    # gdd.draw_wind_quiver()
    gdd.draw_ignition_shade(cmap=matplotlib.cm.Reds)
    gdd.draw_ignition_contour(with_labels=True,cmap=matplotlib.cm.plasma)
    gdd.draw_ignition_points(ignition_point)

    gdd.figure.show()

    gdd.figure.savefig(".".join(("demo_propagation", output_format)), dpi=150, bbox_inches='tight')
from fire_rs.firemodel import propagation
from fire_rs.geodata.display import GeoDataDisplay
from fire_rs.geodata.geo_data import TimedPoint, GeoData

if __name__ == "__main__":
    output_format = "svg"

    # Uncomment below to use latex for typesetting
    # matplotlib.rcParams['font.family'] = 'sans-serif'
    # matplotlib.rcParams['text.usetex'] = True
    # output_format="pdf"

    area = ((481000.0, 484000.0), (6211000.0, 6213500.0))

    expected_env = propagation.Environment(area, wind_speed=5., wind_dir=0.)
    now = datetime.datetime.now().timestamp()
    ignition_point = TimedPoint(area[0][0] + 1000.0, area[1][0] + 1000.0, now)
    expected_fire = propagation.propagate_from_points(
        expected_env, ignition_point, now + datetime.timedelta(hours=2).total_seconds())

    env = propagation.Environment(area, wind_speed=6., wind_dir=0.)
    fire = propagation.propagate_from_points(
        env, ignition_point, now + datetime.timedelta(hours=2).total_seconds())

    # Create fire perimeter geodata
    fire_perimeter = GeoData.full_like(fire.prop_data.slice("ignition"), np.nan)
    # Create contour with scikit-image
    contours = skimage.measure.find_contours(fire.prop_data.data["ignition"],
                                             now + datetime.timedelta(hours=1).total_seconds())
    # Draw contour in the geodata
Example #6
0
    def draw_scenario(i, scen, a):
        # Fetch scenario environment data with additional elevation mode for planning
        env = propagation.Environment(
            scen.area,
            wind_speed=scen.wind_speed,
            wind_dir=scen.wind_direction,
            world=fire_rs.geodata.environment.World(
                landcover_to_fuel_remap=fire_rs.geodata.environment.
                EVERYTHING_FUELMODEL_REMAP))

        # Propagate fires in the environment
        propagation_end_time = scen.time_window_end + 60 * 10
        _logger.debug("Propagating fire ignitions %s until %s",
                      str(scen.ignitions), str(propagation_end_time))
        prop = propagation.propagate_from_points(env,
                                                 scen.ignitions,
                                                 until=propagation_end_time)
        ignitions = prop.ignitions()

        # Transform altitude of UAV bases from agl (above ground level) to absolute
        for f in scen.flights:
            base_h = 0.  # If flat, start at the default segment insertion h
            f.base_waypoint = Waypoint(f.base_waypoint.x, f.base_waypoint.y,
                                       base_h, f.base_waypoint.dir)

        # Define the flight window
        flight_window = TimeWindow(scen.time_window_start,
                                   scen.time_window_end)

        # Create utility map
        utility = make_utility_map(ignitions,
                                   flight_window,
                                   layer='ignition',
                                   output_layer='utility')
        utility_cpp = utility.as_cpp_raster('utility')

        # Make a FireData object
        fire_data = make_fire_data(ignitions,
                                   env.raster,
                                   elevation_map_layer='elevation')

        # Create an initial plan
        initial_plan = Plan(str(i), [f.as_cpp() for f in scen.flights],
                            fire_data, flight_window, utility_cpp)

        final_plan = initial_plan

        # Propagation was running more time than desired in order to reduce edge effect.
        # Now we need to filter out-of-range ignition times. Crop range is rounded up to the next
        # 10-minute mark (minus 1). This makes color bar ranges and fire front contour plots nicer
        ignitions['ignition'][ignitions['ignition'] > \
                              int(scen.time_window_end / 60. + 5) * 60. - 60] = _DBL_MAX
        # Representation of unburned cells using max double is not suitable for display,
        # so those values must be converted to NaN
        ignitions_nan = ignitions['ignition'].copy()
        ignitions_nan[ignitions_nan == _DBL_MAX] = np.nan
        first_ignition = np.nanmin(ignitions_nan)
        last_ignition = np.nanmax(ignitions_nan)

        # Create the geodatadisplay object & extensions that are going to be used
        geodatadisplay = GeoDataDisplay.pyplot_figure(
            env.raster.combine(ignitions), frame=(0, 0))
        geodatadisplay.add_extension(TrajectoryDisplayExtension, (None, ), {})

        plot_plan_with_background(final_plan, geodatadisplay,
                                  (first_ignition, last_ignition), {
                                      'colorbar': a.colorbar,
                                      'background': a.background,
                                      'foreground': []
                                  })

        # Save the picture
        filepath = os.path.join(a.output, str(i) + "." + a.format)
        _logger.info("Saving as figure as: %s", str(filepath))
        geodatadisplay.axes.get_figure().set_size_inches(a.size)
        geodatadisplay.axes.get_figure().savefig(filepath,
                                                 dpi=a.dpi,
                                                 bbox_inches='tight')
        geodatadisplay.close()