Skip to content

Commit

Permalink
Add historical layer
Browse files Browse the repository at this point in the history
Needs refactoring so that the layer isn't created and referenced in the config
  • Loading branch information
doyled-it committed May 17, 2024
1 parent 783a346 commit fc25787
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 90 deletions.
20 changes: 11 additions & 9 deletions configs/historical_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ simulation:
headless: false
draw_spread_graph: false
record: true
save_data: true
save_data: false
data_type: "npy"
sf_home: "~/.simfire"

Expand All @@ -27,8 +27,8 @@ operational:
seed:
latitude: 38.422 # top left corner
longitude: -118.266 # top left corner
height: 2000 # in meters
width: 2000 # in meters
height: 12_000 # in meters
width: 12_000 # in meters
resolution: 30 # in meters
year: 2020

Expand All @@ -38,10 +38,12 @@ historical:
year: 2020
state: "California"
fire: "mineral"
height: 12_000 # in meters
width: 12_000 # in meters

terrain:
topography:
type: operational
type: historical
functional:
function: perlin
perlin:
Expand All @@ -58,13 +60,13 @@ terrain:
sigma_x: 50
sigma_y: 50
fuel:
type: operational
type: historical
functional:
function: chaparral
chaparral:
seed: 1113
burn_probability:
type: operational
type: historical
functional:
function: perlin
perlin:
Expand Down Expand Up @@ -96,7 +98,7 @@ environment:
moisture: 0.001

wind:
function: perlin
function: simple
cfd:
time_to_train: 1000
result_accuracy: 1
Expand All @@ -108,8 +110,8 @@ wind:
speed: 19.0
direction: north
simple:
speed: 7
direction: 90.0
speed: 15
direction: 135
perlin:
speed:
seed: 2345
Expand Down
42 changes: 33 additions & 9 deletions simfire/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class HistoricalConfig:
year: int
state: str
fire: str
height: int
width: int


@dataclasses.dataclass
Expand Down Expand Up @@ -225,6 +227,12 @@ def __init__(
# operational to functional
self.original_screen_size = self.yaml_data["area"]["screen_size"]

if (
self.yaml_data["terrain"]["topography"]["type"] == "historical"
or self.yaml_data["terrain"]["fuel"]["type"] == "historical"
):
self.historical = self._load_historical()
self.historical_layer = self._create_historical_layer()
# This can take up to 30 seconds to pull LandFire data directly from source
self.landfire_lat_long_box = self._make_lat_long_box()

Expand All @@ -233,7 +241,6 @@ def __init__(
self.simulation = self._load_simulation()
self.mitigation = self._load_mitigation()
self.operational = self._load_operational()
self.historical = self._load_historical()
self.terrain = self._load_terrain()
self.fire = self._load_fire()
self.environment = self._load_environment()
Expand Down Expand Up @@ -333,6 +340,11 @@ def _make_lat_long_box(self) -> Optional[LandFireLatLongBox]:
width=width,
)
return landfire_lat_long_box
elif (
self.yaml_data["terrain"]["topography"]["type"] == "historical"
or self.yaml_data["terrain"]["fuel"]["type"] == "historical"
):
return self.historical_layer.lat_lon_box
else:
return None

Expand Down Expand Up @@ -580,6 +592,10 @@ def _create_topography_layer(
fn,
fn_name,
)
elif topo_type == "historical":
topo_layer = self.historical_layer.topography
fn_name = None
kwargs = None
else:
raise ConfigError(
f"The specified topography type ({topo_type}) " "is not supported"
Expand Down Expand Up @@ -650,6 +666,10 @@ def _create_burn_probability_layer(
fn,
fn_name,
)
elif bp_type == "historical":
burn_prob_layer = None
fn_name = None
kwargs = None
else:
raise ConfigError(
f"The specified topography type ({bp_type}) " "is not supported"
Expand Down Expand Up @@ -702,6 +722,10 @@ def _create_fuel_layer(
fn,
fn_name,
)
elif fuel_type == "historical":
fuel_layer = self.historical_layer.fuel
fn_name = None
kwargs = None
else:
raise ConfigError(
f"The specified fuel type ({fuel_type}) " "is not supported"
Expand All @@ -714,15 +738,15 @@ def _create_historical_layer(self):
This is an optional dataclass.
Returns:
A HIstoricalLayer that sets the screen size, area, and fire start location.
A HistoricalLayer that utilizes the data specified in the config.
"""
historical_config = self._load_historical()
historical_layer = HistoricalLayer(
historical_config.year,
historical_config.state,
historical_config.fire,
historical_config.path,
self.yaml_data["area"]["screen_size"],
self.historical.year,
self.historical.state,
self.historical.fire,
self.historical.path,
self.historical.height,
self.historical.width,
)
return historical_layer

Expand Down Expand Up @@ -804,7 +828,7 @@ def _load_wind(self) -> WindConfig:
self.yaml_data["area"]["screen_size"][0],
self.yaml_data["area"]["screen_size"][1],
)
speed = self.yaml_data["wind"]["simple"]["speed"]
speed = mph_to_ftpm(self.yaml_data["wind"]["simple"]["speed"])
direction = self.yaml_data["wind"]["simple"]["direction"]
speed_arr = np.full(arr_shape, speed)
direction_arr = np.full(arr_shape, direction)
Expand Down
Loading

0 comments on commit fc25787

Please sign in to comment.