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

Tipping points #446

Open
wants to merge 62 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5ceb865
Update function to handle edge case
dumontgoulart Apr 12, 2024
b014275
added config for benefits visualization threshold (#387)
dumontgoulart Apr 30, 2024
da9249d
Update tipping point#
dumontgoulart May 15, 2024
6dfae92
update tipping_points from main (#439)
dumontgoulart May 15, 2024
45ab27a
Merge remote-tracking branch 'origin/main' into tipping_points
dumontgoulart May 15, 2024
4d307a4
Update TippingPointMetrics enum with additional options
dumontgoulart May 16, 2024
cf8d0c8
Edits on tp
dumontgoulart May 16, 2024
1e91d40
more edits
dumontgoulart May 16, 2024
fd50713
updating deprecated terms
dumontgoulart May 16, 2024
34f4034
Update TippingPointMetrics enum with additional options
dumontgoulart May 16, 2024
c2f1bfa
Update TippingPointMetrics enum with additional options
dumontgoulart May 17, 2024
26ffea2
Update TippingPointMetrics enum with additional options
dumontgoulart May 17, 2024
8a1a748
Update TippingPointMetrics enum with additional options
dumontgoulart Jun 11, 2024
3ab3964
Merge branch 'main' into tipping_points
dumontgoulart Jun 18, 2024
b44fba8
chore: Refactor object_model/tipping_point.py and interface/tipping_p…
dumontgoulart Jun 19, 2024
2ff6088
Update paths in dbs_controller.py for database_name
dumontgoulart Jun 19, 2024
1f8f97c
refactor functions
dumontgoulart Jun 20, 2024
9ce90fb
add tests
dumontgoulart Jun 21, 2024
f028b87
add tests for tipping points
dumontgoulart Jun 21, 2024
e2f102c
updating tipping points wrt main (#479)
dumontgoulart Jul 9, 2024
15f63a7
update tipping_points wrt main (#480)
dumontgoulart Jul 9, 2024
fa09dbf
refactor functions
dumontgoulart Jul 9, 2024
f108e9a
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Jul 10, 2024
a4f8860
chore: Refactor object_model/tipping_point.py and interface/tipping_p…
dumontgoulart Jul 10, 2024
8bc416c
update tp from main (#482)
dumontgoulart Jul 11, 2024
c1524ed
comments
dumontgoulart Jul 11, 2024
8f57e19
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Jul 11, 2024
2a620bd
update tp (#486)
dumontgoulart Jul 11, 2024
7f2b41d
Merge remote-tracking branch 'origin/main' into tipping_points
dumontgoulart Jul 11, 2024
0a398de
chore: Refactor object_model/tipping_point.py and interface/tipping_p…
dumontgoulart Jul 11, 2024
0522ab2
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Jul 11, 2024
28df051
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Jul 18, 2024
c7e59bc
update tp (#496)
dumontgoulart Jul 18, 2024
4cec8c8
Merge branch 'main' into tipping_points
dumontgoulart Jul 18, 2024
49477fb
chore: Refactor object_model/tipping_point.py and interface/tipping_p…
dumontgoulart Jul 18, 2024
bb29294
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Jul 19, 2024
914708f
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Jul 19, 2024
509f586
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Aug 26, 2024
0d87a9b
update tp from main (#518)
dumontgoulart Aug 26, 2024
beeb7d3
update tipping points to db and api
dumontgoulart Aug 26, 2024
29a0eec
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Aug 27, 2024
a65eccd
Merge branch 'main' into tipping_points
dumontgoulart Aug 27, 2024
5394985
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Aug 27, 2024
4767068
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Aug 28, 2024
ad8cd88
Refactor object_model/tipping_point.py to ensure availability of Data…
dumontgoulart Aug 28, 2024
971d7f6
Merge branch 'main' into tipping_points
dumontgoulart Aug 28, 2024
a1d6f57
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Aug 28, 2024
dacdb31
Merge branch 'tipping_points' of https://github.com/Deltares-research…
dumontgoulart Aug 28, 2024
3360678
Refactor object_model/tipping_point.py and interface/tipping_points.py
dumontgoulart Aug 28, 2024
8170ddd
Refactor TippingPoint class to update projection name and save it if …
dumontgoulart Sep 18, 2024
c6c53f6
Merge branch 'main' of https://github.com/Deltares-research/FloodAdap…
Santonia27 Oct 2, 2024
a7b16b0
adding "_tp_" to paths for easy locating
dumontgoulart Oct 3, 2024
279ee5f
invert order database
dumontgoulart Oct 8, 2024
f638cde
Merge branch 'main' of https://github.com/Deltares-research/FloodAdap…
Santonia27 Oct 29, 2024
231f84a
instead of plot outside gui plot inside (still needs fixing)
Santonia27 Oct 29, 2024
69a7ae0
add annotation to plot
Santonia27 Oct 30, 2024
4e35370
add y axis label
Santonia27 Oct 30, 2024
bc414fc
add view plot button
Santonia27 Nov 4, 2024
d9506c6
fix plot
Santonia27 Nov 4, 2024
86821f4
Merge branch 'main' of https://github.com/Deltares-research/FloodAdap…
Santonia27 Nov 4, 2024
81ecfcd
remove comments
Santonia27 Nov 5, 2024
76b59f8
update plot labels
Santonia27 Nov 6, 2024
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
6 changes: 3 additions & 3 deletions flood_adapt/dbs_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def __init__(
The name of the database.
Notes
"""
self.input_path = Path(database_path / database_name / "input")
self.static_path = Path(database_path / database_name / "static")
self.output_path = Path(database_path / database_name / "output")
self.input_path = Path(database_path) / database_name / "input"
self.static_path = Path(database_path) / database_name / "static"
self.output_path = Path(database_path) / database_name / "output"

self.site = Site.load_file(self.static_path / "site" / "site.toml")
self.aggr_areas = self.get_aggregation_areas()
Expand Down
6 changes: 3 additions & 3 deletions flood_adapt/object_model/benefit.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ def load_file(filepath: Union[str, os.PathLike]):
obj = Benefit()
with open(filepath, mode="rb") as fp:
toml = tomli.load(fp)
obj.attrs = BenefitModel.parse_obj(toml)
obj.attrs = BenefitModel.model_validate(toml) # Replace parse_obj with model_validate
# if benefits is created by path use that to get to the database path
obj.database_input_path = Path(filepath).parents[2]
obj.init()
Expand All @@ -515,12 +515,12 @@ def load_dict(data: dict[str, Any], database_input_path: Union[str, os.PathLike]
"""create Benefit object from dictionary, e.g. when initialized from GUI"""

obj = Benefit()
obj.attrs = BenefitModel.parse_obj(data)
obj.attrs = BenefitModel.model_validate(data)
obj.database_input_path = Path(database_input_path)
obj.init()
return obj

def save(self, filepath: Union[str, os.PathLike]):
"""save Benefit object to a toml file"""
with open(filepath, "wb") as f:
tomli_w.dump(self.attrs.dict(exclude_none=True), f)
tomli_w.model_dump(self.attrs, f, exclude_none=True)
101 changes: 101 additions & 0 deletions flood_adapt/object_model/interface/tipping_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import os
from abc import ABC, abstractmethod
from typing import Any, Optional, Union
from enum import Enum

import pandas as pd
from pydantic import BaseModel


class TippingPointMetrics(str, Enum):
"""class describing the accepted input for the variable metric_type in TippingPoint"""

# based on what I have found in floodadapt - but can be changed
FloodedAll = "FloodedAll"
FloodedLowVulnerability = "FloodedLowVulnerability"
FloodedHighVulnerability = "FloodedHighVulnerability"
TotalDamageEvent = "TotalDamageEvent"
TotalResDamageEvent = "TotalResDamageEvent"
ResidentialMinorCount = "ResidentialMinorCount"
ResidentialMajorCount = "ResidentialMajorCount"
ResidentialDestroyedCount = "ResidentialDestroyedCount"
CommercialCount = "CommercialCount"
CommercialMinorCount = "CommercialMinorCount"
CommercialMajorCount = "CommercialMajorCount"
CommercialDestroyedCount = "CommercialDestroyedCount"
HealthCount = "HealthCount"
HealthMinorCount = "HealthMinorCount"
HealthMajorCount = "HealthMajorCount"
HealthDestroyedCount = "HealthDestroyedCount"
SchoolsCount = "SchoolsCount"
SchoolsMinorCount = "SchoolsMinorCount"
SchoolsMajorCount = "SchoolsMajorCount"
SchoolsDestroyedCount = "SchoolsDestroyedCount"
EmergencyCount = "EmergencyCount"
EmergencyMinorCount = "EmergencyMinorCount"
EmergencyMajorCount = "EmergencyMajorCount"
EmergencyDestroyedCount = "EmergencyDestroyedCount"
DisplacedLowVulnerability = "DisplacedLowVulnerability"
DisplacedHighVulnerability = "DisplacedHighVulnerability"
SlightlyFloodedRoads = "SlightlyFloodedRoads"
MinorFloodedRoads = "MinorFloodedRoads"
MajorFloodedRoads = "MajorFloodedRoads"
FullyFloodedRoads = "FullyFloodedRoads"


class TippingPointStatus(str, Enum):
"""class describing the accepted input for the variable metric_type in TippingPoint"""

reached = "reached"
not_reached = "not_reached"
completed = "completed"


class TippingPointOperator(str, Enum):
"""class describing the accepted input for the variable operator in TippingPoint"""

greater = "greater"
less = "less"


class TipPointModel(BaseModel):
dumontgoulart marked this conversation as resolved.
Show resolved Hide resolved
"""BaseModel describing the expected variables and data types of a Tipping Point analysis object"""

name: str
description: Optional[str] = ""
strategy: str
event_set: str
projection: str
sealevelrise: list[float] # could be a numpy array too
tipping_point_metric: list[tuple[TippingPointMetrics, float, TippingPointOperator]]
status: Optional[TippingPointStatus] = TippingPointStatus.not_reached
dumontgoulart marked this conversation as resolved.
Show resolved Hide resolved


class ITipPoint(ABC):
attrs: TipPointModel
database_input_path: Union[str, os.PathLike]
results_path: Union[str, os.PathLike]
scenarios: pd.DataFrame
has_run: bool = False

@staticmethod
@abstractmethod
def load_file(filepath: Union[str, os.PathLike]):
"""get Tipping Point attributes from toml file"""
...

@staticmethod # copping from benefits.py
@abstractmethod
def load_dict(data: dict[str, Any]):
"""get Tipping Point attributes from an object, e.g. when initialized from GUI"""
...

@abstractmethod
def save(self, filepath: Union[str, os.PathLike]):
"""save Tipping Point attributes to a toml file"""
...

@abstractmethod
def check_scenarios(self) -> pd.DataFrame:
"""Check which scenarios are needed for this tipping point calculation and if they have already been created"""
...
Loading
Loading