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

Standardize how we check for a run being completed #519

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
2 changes: 1 addition & 1 deletion flood_adapt/dbs_classes/dbs_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def list_objects(self) -> dict[str, Any]:
scenarios["Event"] = [obj.attrs.event for obj in objects]
scenarios["Strategy"] = [obj.attrs.strategy for obj in objects]
scenarios["finished"] = [
obj.init_object_model().direct_impacts.has_run for obj in objects
obj.init_object_model().has_run_check() for obj in objects
]

return scenarios
Expand Down
2 changes: 1 addition & 1 deletion flood_adapt/integrator/fiat_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __del__(self) -> None:
gc.collect()

def set_hazard(self, hazard: Hazard) -> None:
map_fn = hazard.flood_map_path
map_fn = hazard._get_flood_map_path()
map_type = hazard.site.attrs.fiat.floodmap_type
var = "zsmax" if hazard.event_mode == Mode.risk else "risk_maps"
is_risk = hazard.event_mode == Mode.risk
Expand Down
1 change: 1 addition & 0 deletions flood_adapt/object_model/hazard/hazard.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ def _get_flood_map_path(self):
map_fn.append(results_path.joinpath(f"RP_{rp:04d}_maps.nc"))

self.flood_map_path = map_fn
return map_fn

def write_water_level_map(self):
"""Read simulation results from SFINCS and saves a netcdf with the maximum water levels."""
Expand Down
8 changes: 8 additions & 0 deletions flood_adapt/object_model/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from flood_adapt.object_model.direct_impacts import DirectImpacts
from flood_adapt.object_model.hazard.hazard import ScenarioModel
from flood_adapt.object_model.interface.scenarios import IScenario
from flood_adapt.object_model.utils import finished_file_exists, write_finished_file


class Scenario(IScenario):
Expand Down Expand Up @@ -94,6 +95,13 @@ def run(self):
f"Finished evaluation of {self.attrs.name} for {self.site_info.attrs.name}"
)

# write finished file to indicate that the scenario has been run
write_finished_file(self.results_path)

def has_run_check(self):
"""Check if the scenario has been run."""
return finished_file_exists(self.results_path)

def __eq__(self, other):
if not isinstance(other, Scenario):
# don't attempt to compare against unrelated types
Expand Down
11 changes: 11 additions & 0 deletions flood_adapt/object_model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ def cd(newdir: Path):
yield
finally:
os.chdir(prevdir)


def write_finished_file(path: Path):
if not path.exists():
path.mkdir(parents=True)
with open(Path(path) / "finished.txt", "w") as f:
f.write("run finished")


def finished_file_exists(path: Path):
return (Path(path) / "finished.txt").exists()
Loading