Skip to content

Commit

Permalink
Fix logic when loading landfire tifs (resolves #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
afennelly-mitre committed May 15, 2024
1 parent 6dad562 commit 14a044b
Showing 1 changed file with 32 additions and 26 deletions.
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

0 comments on commit 14a044b

Please sign in to comment.