Skip to content

Commit

Permalink
Update fire start position and wind parameters in HistoricalLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
doyled-it authored and afennelly-mitre committed May 24, 2024
1 parent 62faf2d commit 8c2a8b8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
10 changes: 5 additions & 5 deletions configs/historical_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ historical:
year: 2020
state: "California"
fire: "mineral"
height: 12_000 # in meters
width: 12_000 # in meters
height: 20_000 # in meters
width: 20_000 # in meters

terrain:
topography:
Expand Down Expand Up @@ -86,7 +86,7 @@ terrain:

fire:
fire_initial_position:
type: static
type: historical
static:
position: (25, 25)
random:
Expand All @@ -110,8 +110,8 @@ wind:
speed: 19.0
direction: north
simple:
speed: 15
direction: 135
speed: 5
direction: 320
perlin:
speed:
seed: 2345
Expand Down
17 changes: 11 additions & 6 deletions simfire/utils/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,13 @@ def __init__(
self.topography = OperationalTopographyLayer(self.lat_lon_box)
self.fuel = OperationalFuelLayer(self.lat_lon_box)
self.lat_lon_array = self.lat_lon_box.create_lat_lon_array()
self.fire_start_y, self.fire_start_x = get_closest_indice(
self.lat_lon_array, (self.latitude, self.longitude)
)
self.screen_size = self.lat_lon_array.shape[:2]
self.start_time = self.polygons_df.iloc[0]["DateStart"]
self.end_time = self.polygons_df.iloc[0]["DateContai"]
self.perimeter_deltas = self._get_perimeter_time_deltas()
# get the duraton of fire specified
self.duration = self._calc_time_elapsed(self.start_time, self.end_time)

Expand Down Expand Up @@ -911,10 +915,10 @@ def _get_fire_init_pos(self):
(latitude, longitude)
"""
fire_init_pos = self.polygons_df.iloc[0]["FireInitPo"]
latitutde = float(fire_init_pos.split(", ")[0])
longitude = float(fire_init_pos.split(", ")[1])
longitude = float(fire_init_pos.split(", ")[0])
latitude = float(fire_init_pos.split(", ")[1])

return latitutde, longitude
return latitude, longitude

def make_mitigations(
self, start_time: datetime.datetime, end_time: datetime.datetime
Expand Down Expand Up @@ -1101,6 +1105,7 @@ def _get_perimeter_time_deltas(self):
)

perimeter_time_deltas.append(delta)
return perimeter_time_deltas


def get_closest_indice(
Expand All @@ -1112,7 +1117,7 @@ def get_closest_indice(
Arguments:
lat_lon_data: array of the (h, w, (lat, lon)) data of the screen_size of the
simulation
point: a tuple pair of lat/lon point. [longitude, latitude]
point: a tuple pair of lat/lon point. [latitude, longitude]
Returns:
y, x: tuple pair of index in lat/lon array that corresponds to
Expand All @@ -1121,8 +1126,8 @@ def get_closest_indice(

idx = np.argmin(
np.sqrt(
np.square(lat_lon_data[..., 0] - point[1])
+ np.square(lat_lon_data[..., 1] - point[0])
np.square(lat_lon_data[..., 0] - point[0])
+ np.square(lat_lon_data[..., 1] - point[1])
)
)
x, y = np.unravel_index(idx, lat_lon_data.shape[:2])
Expand Down
31 changes: 23 additions & 8 deletions tests/historical_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import timedelta
import datetime
import re

import numpy as np

Expand All @@ -13,23 +14,37 @@

hist_layer = config.historical_layer

update_minutes = 1 * 60
update_interval = f"{update_minutes}m"
update_interval_datetime = timedelta(minutes=update_minutes)
current_time = hist_layer.convert_to_datetime(hist_layer.start_time)
end_time = hist_layer.convert_to_datetime(hist_layer.end_time)
while current_time < end_time:
hist_layer.perimeter_deltas
i = 0


def parse_duration(duration_str):
"""Converts a string like '2d 1h 06m 21s' to a timedelta object."""
pattern = r"(?:(\d+)d)?\s*(?:(\d+)h)?\s*(?:(\d+)m)?\s*(?:(\d+)s)?"
match = re.match(pattern, duration_str)
if not match:
raise ValueError("Invalid duration format")

days, hours, minutes, seconds = (int(x) if x else 0 for x in match.groups())
return datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)


for time in hist_layer.perimeter_deltas:
mitigation_iterable = []
duration = parse_duration(time)
mitigations = hist_layer.make_mitigations(
current_time, current_time + update_interval_datetime
current_time,
current_time + duration,
)
locations = np.argwhere(mitigations != 0)
try:
mitigation_iterable = np.insert(locations, 2, BurnStatus.FIRELINE.value, axis=1)
except IndexError:
mitigation_iterable = []
sim.update_mitigation(mitigation_iterable)
sim.run(update_interval)
current_time += update_interval_datetime
sim.run(time)
current_time += duration

sim.save_gif()

0 comments on commit 8c2a8b8

Please sign in to comment.