Skip to content

Commit

Permalink
go through PR and fix obvious stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
LuukBlom committed Oct 22, 2024
1 parent 5264ab6 commit 0741ece
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 93 deletions.
13 changes: 6 additions & 7 deletions flood_adapt/dbs_classes/dbs_measure.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from pathlib import Path
from typing import Any

import geopandas as gpd

from flood_adapt.dbs_classes.dbs_template import DbsTemplate
from flood_adapt.object_model.interface.measures import IMeasure

# from flood_adapt.object_model.measure import Measure
from flood_adapt.object_model.measure_factory import MeasureFactory
from flood_adapt.object_model.utils import resolve_filepath


class DbsMeasure(DbsTemplate):
Expand Down Expand Up @@ -47,10 +45,11 @@ def list_objects(self) -> dict[str, list[Any]]:
for path, obj in zip(measures["path"], objects):
# If polygon is used read the polygon file
if obj.attrs.polygon_file:
if Path(obj.attrs.polygon_file).exists():
_path = Path(obj.attrs.polygon_file)
else:
_path = self.input_path / obj.attrs.name / obj.attrs.polygon_file
_path = resolve_filepath(
object_dir=self._object_class.dir_name,
obj_name=obj.attrs.name,
file_name=obj.attrs.polygon_file,
)
geometries.append(gpd.read_file(_path))
# If aggregation area is used read the polygon from the aggregation area name
elif obj.attrs.aggregation_area_name:
Expand Down
36 changes: 0 additions & 36 deletions flood_adapt/object_model/interface/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,39 +246,3 @@ class ImpactMeasure(IMeasure[ImpactMeasureModel], Generic[ImpactMeasureModelType
"""All the information for a specific measure type that affects the impact model."""

attrs: ImpactMeasureModel


# class IElevate(IMeasure[ElevateModel]):
# """A class for a FloodAdapt "elevate" measure."""

# attrs: ElevateModel


# class IBuyout(IMeasure[BuyoutModel]):
# """A class for a FloodAdapt "buyout" measure."""

# attrs: BuyoutModel


# class IFloodProof(IMeasure[FloodProofModel]):
# """A class for a FloodAdapt "floodproof" measure."""

# attrs: FloodProofModel


# class IFloodWall(IMeasure[FloodWallModel]):
# """A class for a FloodAdapt "floodwall" measure."""

# attrs: FloodWallModel


# class IPump(IMeasure[PumpModel]):
# """A class for a FloodAdapt "pump" measure."""

# attrs: PumpModel


# class IGreenInfrastructure(IMeasure[GreenInfrastructureModel]):
# """A class for a FloodAdapt "green infrastrcutre" measure."""

# attrs: GreenInfrastructureModel
12 changes: 6 additions & 6 deletions flood_adapt/object_model/interface/path_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class ObjectDir(str, Enum):
projection = "projections"
scenario = "scenarios"

buyout = "measures"
elevate = "measures"
floodproof = "measures"
greening = "measures"
floodwall = "measures"
pump = "measures"
# buyout = "measures"
# elevate = "measures"
# floodproof = "measures"
# greening = "measures"
# floodwall = "measures"
# pump = "measures"


def db_path(
Expand Down
2 changes: 1 addition & 1 deletion flood_adapt/object_model/interface/projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ class ProjectionModel(IObjectModel):


class IProjection(IObject[ProjectionModel]):
attrs = ProjectionModel
attrs: ProjectionModel
dir_name = ObjectDir.projection
1 change: 0 additions & 1 deletion flood_adapt/object_model/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def __init__(self, data: dict[str, Any]) -> None:

def run(self):
"""Run direct impact models for the scenario."""
# self.init_object_model()
os.makedirs(self.results_path, exist_ok=True)

# Initiate the logger for all the integrator scripts.
Expand Down
11 changes: 0 additions & 11 deletions flood_adapt/object_model/site.py

This file was deleted.

28 changes: 8 additions & 20 deletions tests/test_integrator/test_hazard_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_scenarios(test_db):
# @pytest.mark.skip(reason="running the model takes long")
def test_hazard_preprocess_synthetic_wl(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]
# # test_scenario.init_object_model()

test_scenario.direct_impacts.hazard.preprocess_models()

fn_bc = (
Expand Down Expand Up @@ -75,7 +75,6 @@ def test_hazard_preprocess_synthetic_wl(test_db, test_scenarios):
def test_hazard_preprocess_synthetic_discharge(test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

# test_scenario.init_object_model()
test_scenario.direct_impacts.hazard.preprocess_models()

test_scenario.attrs.name = f"{test_scenario.attrs.name}_2"
Expand All @@ -99,8 +98,6 @@ def test_preprocess_rainfall_timeseriesfile(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]
event_path = test_db.input_path / "events" / "extreme12ft"

# test_scenario.init_object_model()

hazard = test_scenario.direct_impacts.hazard
hazard.event.attrs.rainfall.source = "timeseries"
hazard.event.attrs.rainfall.timeseries_file = "rainfall.csv"
Expand Down Expand Up @@ -129,7 +126,6 @@ def test_preprocess_pump(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]
test_scenario.attrs.strategy = "pump"
test_scenario.attrs.name = test_scenario.attrs.name.replace("no_measures", "pump")
# test_scenario.init_object_model()

hazard = test_scenario.direct_impacts.hazard

Expand All @@ -148,7 +144,7 @@ def test_preprocess_greenInfra(test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

test_scenario.attrs.strategy = "greeninfra"
# test_scenario.init_object_model()

assert isinstance(
test_scenario.direct_impacts.hazard.hazard_strategy.measures[0],
GreenInfrastructure,
Expand All @@ -169,7 +165,7 @@ def test_preprocess_greenInfra_aggr_area(test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

test_scenario.attrs.strategy = "total_storage_aggregation_area"
# test_scenario.init_object_model()

assert isinstance(
test_scenario.direct_impacts.hazard.hazard_strategy.measures[0],
GreenInfrastructure,
Expand All @@ -181,7 +177,6 @@ def test_preprocess_greenInfra_aggr_area(test_scenarios):
def test_write_floodmap_geotiff(test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

# test_scenario.init_object_model()
test_scenario.direct_impacts.hazard.preprocess_models()
test_scenario.direct_impacts.hazard.run_models()
test_scenario.direct_impacts.hazard.postprocess_models()
Expand All @@ -195,7 +190,7 @@ def test_write_floodmap_geotiff(test_scenarios):
@pytest.mark.skip(reason="Fails in CICD. REFACTOR HAZARD!")
def test_preprocess_prob_eventset(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]
# test_scenario.init_object_model()

test_scenario.direct_impacts.hazard.preprocess_models()

bzs_file1 = (
Expand Down Expand Up @@ -230,7 +225,7 @@ def test_preprocess_rainfall_increase(test_db, test_scenarios):
test_scenario: Scenario = test_scenarios["current_extreme12ft_no_measures.toml"]
test_scenario.attrs.projection = "SLR_2ft"
test_scenario.attrs.name = "SLR_2ft_test_set_no_measures"
# test_scenario.init_object_model()

slr = test_scenario.direct_impacts.hazard.physical_projection.attrs.sea_level_rise
test_scenario.direct_impacts.hazard.preprocess_models()

Expand Down Expand Up @@ -264,7 +259,7 @@ def test_preprocess_rainfall_increase(test_db, test_scenarios):
def test_preprocess_rainfall_increase_alternate(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]
test_scenario.attrs.name = "current_extreme12ft_precip_no_measures"
# test_scenario.init_object_model()

test_scenario.direct_impacts.hazard.event.attrs.rainfall.source = "shape"
test_scenario.direct_impacts.hazard.event.attrs.rainfall.shape_type = "block"
test_scenario.direct_impacts.hazard.event.attrs.rainfall.cumulative = (
Expand All @@ -288,7 +283,7 @@ def test_preprocess_rainfall_increase_alternate(test_db, test_scenarios):
cum_precip1 = df1.sum()[1]

test_scenario.attrs.name = "current_extreme12ft_precip_rainfall_incr_no_measures"
# test_scenario.init_object_model()

test_scenario.direct_impacts.hazard.event.attrs.rainfall.source = "shape"
test_scenario.direct_impacts.hazard.event.attrs.rainfall.shape_type = "block"
test_scenario.direct_impacts.hazard.event.attrs.rainfall.cumulative = (
Expand Down Expand Up @@ -320,7 +315,7 @@ def test_preprocess_rainfall_increase_alternate(test_db, test_scenarios):
@pytest.mark.skip(reason="Running models takes a couple of minutes")
def test_run_prob_eventset(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]
# test_scenario.init_object_model()

test_scenario.direct_impacts.hazard.preprocess_models()
test_scenario.direct_impacts.hazard.run_models()
zs_file1 = (
Expand Down Expand Up @@ -353,7 +348,6 @@ def test_run_prob_eventset(test_db, test_scenarios):
def test_rp_floodmap_calculation(test_db, test_scenarios):
test_scenario = test_scenarios["current_test_set_no_measures.toml"]

# test_scenario.init_object_model()
test_scenario.direct_impacts.hazard.calculate_rp_floodmaps()
nc_file = (
test_db.output_path
Expand Down Expand Up @@ -418,8 +412,6 @@ def test_rp_floodmap_calculation(test_db, test_scenarios):
def test_multiple_rivers(test_db, test_scenarios):
test_scenario: Scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

# test_scenario.init_object_model()

# Add an extra river
test_scenario.direct_impacts.hazard.event.attrs.river.append(
test_scenario.direct_impacts.hazard.event.attrs.river[0].copy()
Expand Down Expand Up @@ -505,8 +497,6 @@ def test_multiple_rivers(test_db, test_scenarios):
def test_no_rivers(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

# test_scenario.init_object_model()

# Overwrite river data of Event
test_scenario.direct_impacts.hazard.event.attrs.river = []

Expand Down Expand Up @@ -543,8 +533,6 @@ def test_no_rivers(test_db, test_scenarios):
def test_plot_wl_obs(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

# test_scenario.init_object_model()

# Preprocess the models
test_scenario.direct_impacts.hazard.preprocess_models()
test_scenario.direct_impacts.hazard.run_models()
Expand Down
1 change: 0 additions & 1 deletion tests/test_integrator/test_sfincs_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def test_scenarios(test_db):
def test_add_obs_points(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

# test_scenario.init_object_model()
path_in = (
test_db.static_path
/ "templates"
Expand Down
7 changes: 1 addition & 6 deletions tests/test_object_model/test_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def test_scenarios(test_db, test_tomls) -> dict[str, Scenario]:
def test_initObjectModel_validInput(test_db, test_scenarios):
test_scenario = test_scenarios["all_projections_extreme12ft_strategy_comb.toml"]

# test_scenario.init_object_model()

assert isinstance(test_scenario.site_info, Site)
assert isinstance(test_scenario.direct_impacts, DirectImpacts)
assert isinstance(
Expand All @@ -67,7 +65,6 @@ def test_initObjectModel_validInput(test_db, test_scenarios):
def test_hazard_load(test_db, test_scenarios):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

# test_scenario.init_object_model()
event = test_db.events.get(test_scenario.direct_impacts.hazard.event_name)

assert event.attrs.timing == "idealized"
Expand All @@ -78,8 +75,6 @@ def test_hazard_load(test_db, test_scenarios):
def test_scs_rainfall(test_db: Database, test_scenarios: dict[str, Scenario]):
test_scenario = test_scenarios["current_extreme12ft_no_measures.toml"]

# test_scenario.init_object_model()

event = test_db.events.get(test_scenario.direct_impacts.hazard.event_name)

event.attrs.rainfall = RainfallModel(
Expand Down Expand Up @@ -153,5 +148,5 @@ def test_infographic(self, test_db):

# use event template to get the associated Event child class
test_scenario = Scenario.load_file(test_toml)
# test_scenario.init_object_model()

test_scenario.infographic()
4 changes: 0 additions & 4 deletions tests/test_object_model/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ def test_green_infra(test_db):

strategy = Strategy.load_file(test_toml)

print(strategy)
print(strategy.attrs)
print(strategy.get_hazard_strategy())
print(strategy.get_hazard_strategy().measures)
assert strategy.attrs.name == "greeninfra"
assert isinstance(strategy.attrs.measures, list)
assert isinstance(strategy.get_hazard_strategy().measures[0], GreenInfrastructure)
Expand Down

0 comments on commit 0741ece

Please sign in to comment.