"""High precision wildfire simulation"""

import os

import numpy as np
import matplotlib.cm

import fire_rs.geodata.environment as g_environment
import fire_rs.geodata.display as display


from fire_rs.geodata.geo_data import GeoData
from fire_rs.firemodel.propagation import Environment, FirePropagation, TimedPoint

FIRERS_DATA_FOLDER = '/home/rbailonr/firers_data_5m'
FIRERS_DEM_DATA = os.path.join(FIRERS_DATA_FOLDER,
                               'dem/RGEALTI_MNT_5M_ASC_LAMB93_IGN69')
FIRERS_WIND_DATA = os.path.join(FIRERS_DATA_FOLDER,
                                'wind/RGEALTI_MNT_5M_ASC_LAMB93_IGN69')
FIRERS_LANDCOVER_DATA = os.path.join(FIRERS_DATA_FOLDER,
                                     'landcover/RGEALTI_MNT_5M_ASC_LAMB93_IGN69')

the_world = g_environment.World(elevation_path=FIRERS_DEM_DATA,
                                wind_path=FIRERS_WIND_DATA,
                                landcover_path=FIRERS_LANDCOVER_DATA)
the_world.dem_wind_tile_split = 4
print(the_world.get_wind((574374, 6274377), domain_average=(10, np.pi)))

fire_env = Environment(((480010.0, 485010.0), (6210010.0, 6215010.0)), 5, 0, the_world)
fire_prop = FirePropagation(fire_env)
fire_prop.set_ignition_point(TimedPoint(482010, 6212010.0, 0))

fire_prop.propagate(9000)

fire_prop.ignitions().write_to_file("demo_propagation_highres_firemap.tif")
fire_env.raster.write_to_file("demo_propagation_highres_dem.tif", "elevation")

# Figure terrain + ignition contour + ignition point
gdd = display.GeoDataDisplay.pyplot_figure(
    fire_env.raster.combine(fire_prop.ignitions().slice(["ignition"])),
    frame=(0., 0.))
gdd.draw_elevation_shade(with_colorbar=False, cmap=matplotlib.cm.terrain)
gdd.draw_wind_quiver()
gdd.draw_ignition_contour(with_labels=True, cmap=matplotlib.cm.plasma)
gdd.draw_ignition_points(TimedPoint(482010, 6212010.0, 0))

gdd.figure.show()

gdd.figure.savefig(".".join(("demo_propagation_highres", "svg")), dpi=150, bbox_inches='tight')

@@ -182,17 +182,16 @@
 isplay%0A%0A
-%0A
 from fir
@@ -941,16 +941,45 @@
 VER_DATA
+, wind_mesh_resolution='fine'
 )%0Athe_wo
@@ -1008,84 +1008,153 @@
 t = 
-4%0Aprint(the_world.get_wind((574374, 6274377), domain_average=(10, np.pi))
+1%0A%0Afire_env = Environment(((479998.0 - 2000, 484997.0 + 2000), (6210003.0 - 2000, 6215002.0 + 2000)),%0A                       5, 0, the_world
 )%0A%0A
+# 
 fire
@@ -1175,17 +1175,17 @@
 ment(((4
-8
+7
 0010.0, 
@@ -1213,13 +1213,103 @@
 , 62
-15010
+25010.0)), 5, 0, the_world)%0A# fire_env = Environment(((574995.0, 575005.0), (6199995.0, 6200005
 .0))
@@ -1428,17 +1428,18 @@
 .0, 0))%0A
-%0A
+# 
 fire_pro
@@ -1444,100 +1444,752 @@
 rop.
-propagate(9000)%0A%0Afire_prop.ignitions().write_to_file(%22demo_propagation_highres_firemap.tif%22)
+set_ignition_point(TimedPoint(575000.0, 6200000.0, 0))%0A%0Apropagation_end_time = 10000%0Aexport_front = (7000, 7100)%0A%0Afire_prop.propagate(propagation_end_time)%0A%0Afire_prop.ignitions().write_to_file(%22demo_propagation_highres_firemap.tif%22)%0A%0Afilt_fire = fire_prop.ignitions().clone()%0Afilt_fire.data%5B%22ignition%22%5D%5Bfilt_fire.data%5B%22ignition%22%5D %3C export_front%5B0%5D%5D = 0%0Afilt_fire.data%5B%22ignition%22%5D%5Bfilt_fire.data%5B%22ignition%22%5D %3E export_front%5B1%5D%5D = 0%0Afilt_fire.data%5B%22ignition%22%5D%5Bfilt_fire.data%5B%22ignition%22%5D.nonzero()%5D = 65535%0Afilt_fire.write_to_image_file(%22demo_propagation_highres_firemap_%22 +%0A                              str(export_front%5B0%5D) + %22-%22 +%0A                              str(export_front%5B1%5D) + %22.png%22,%0A                              layer_name=%22ignition%22)%0A
 %0Afir

Update demo_propagation_highres