Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

27 current logic to quit game causes simharness vectorized environment setup to crash #28

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions simfire/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Game:
terrain, fire, and other sprites to be rendered and interact.
"""

num_active_games: int = 0

def __init__(
self,
screen_size: Tuple[int, int],
Expand Down Expand Up @@ -90,6 +92,9 @@ def __init__(
if self.record:
self.frames = []

# Increment number of active games to track across instances.
Game.num_active_games += 1

def _toggle_wind_magnitude_display(self):
"""
Toggle display of wind MAGNITUDE over the main screen.
Expand Down Expand Up @@ -281,8 +286,11 @@ def quit(self) -> None:
"""
Close the PyGame window and stop the `Game`
"""
pygame.display.quit()
pygame.quit()
Game.num_active_games -= 1

if Game.num_active_games == 0:
pygame.display.quit()
pygame.quit()

def save(self, path: pathlib.Path, duration: int = 100) -> None:
"""Save a GIF of the simulation to a specified path
Expand Down
58 changes: 32 additions & 26 deletions simfire/utils/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(
self.fuel = self.fuel[:pixel_height, :pixel_width]
self.topography = self.topography[:pixel_height, :pixel_width]

print(
log.info(
f"Output shape of Fire Map: {height}m x {width}m "
f"--> {self.fuel.shape} in pixel space"
)
Expand All @@ -129,11 +129,20 @@ def _check_paths(self):
This could greatly improve functionality and speed up training interations
"""
if self.output_path.exists():
log.debug(
"Data for this area already exists. Loading from file: "
f"{self.output_path}"
)
return True
tifs = [str(t) for t in self.output_path.glob("*.tif")]
if len(tifs) == 0:
log.info(
f"The output path, {self.output_path}, exists, but does not "
"contain any tif files. Returning false to ensure that data "
"for this area is pulled."
)
return False
else:
log.debug(
"Data for this area already exists. Loading from file: "
f"{self.output_path}"
)
return True
else:
return False

Expand Down Expand Up @@ -212,26 +221,23 @@ def query_lat_lon_layer_data(self):
band: the gdal raster band that contains the data

"""
if not self.output_path.exists():
self.output_path.mkdir(parents=True, exist_ok=True)

lf = landfire.Landfire(
bbox=f"{self.points[0][1]} {self.points[0][0]} \
{self.points[1][1]+self.pad_distance} \
{self.points[1][0]-self.pad_distance}",
output_crs="4326",
)
# assume the order of data retrieval stays the same
lf.request_data(
layers=self.layer_products.values(),
output_path=str(self.output_path / self.product_layers_path),
)

shutil.unpack_archive(
self.output_path / self.product_layers_path, self.output_path
)
else:
log.debug(f"Data already exists for {self.output_path}")
self.output_path.mkdir(parents=True, exist_ok=True)

lf = landfire.Landfire(
bbox=f"{self.points[0][1]} {self.points[0][0]} \
{self.points[1][1]+self.pad_distance} \
{self.points[1][0]-self.pad_distance}",
output_crs="4326",
)
# assume the order of data retrieval stays the same
lf.request_data(
layers=self.layer_products.values(),
output_path=str(self.output_path / self.product_layers_path),
)

shutil.unpack_archive(
self.output_path / self.product_layers_path, self.output_path
)

def _make_data(self):
"""
Expand Down