flood-adapt 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flood_adapt/__init__.py +1 -1
- flood_adapt/config/fiat.py +7 -7
- flood_adapt/config/site.py +2 -2
- flood_adapt/database_builder/database_builder.py +14 -6
- flood_adapt/dbs_classes/database.py +24 -17
- flood_adapt/dbs_classes/dbs_event.py +0 -15
- flood_adapt/dbs_classes/dbs_measure.py +15 -7
- flood_adapt/dbs_classes/dbs_static.py +3 -5
- flood_adapt/dbs_classes/dbs_template.py +3 -4
- flood_adapt/flood_adapt.py +115 -260
- flood_adapt/objects/__init__.py +40 -17
- flood_adapt/objects/benefits/benefits.py +6 -6
- flood_adapt/objects/events/event_set.py +4 -4
- flood_adapt/objects/events/events.py +18 -5
- flood_adapt/objects/events/historical.py +11 -8
- flood_adapt/objects/events/hurricane.py +11 -8
- flood_adapt/objects/events/synthetic.py +9 -7
- flood_adapt/objects/forcing/forcing.py +9 -1
- flood_adapt/objects/forcing/plotting.py +1 -0
- flood_adapt/objects/forcing/tide_gauge.py +14 -14
- flood_adapt/objects/forcing/time_frame.py +13 -0
- flood_adapt/objects/forcing/timeseries.py +27 -15
- flood_adapt/objects/measures/measures.py +38 -15
- flood_adapt/objects/object_model.py +2 -2
- flood_adapt/objects/projections/projections.py +18 -18
- flood_adapt/objects/strategies/strategies.py +22 -1
- flood_adapt/workflows/benefit_runner.py +1 -1
- {flood_adapt-0.3.0.dist-info → flood_adapt-0.3.2.dist-info}/METADATA +1 -2
- {flood_adapt-0.3.0.dist-info → flood_adapt-0.3.2.dist-info}/RECORD +32 -32
- {flood_adapt-0.3.0.dist-info → flood_adapt-0.3.2.dist-info}/LICENSE +0 -0
- {flood_adapt-0.3.0.dist-info → flood_adapt-0.3.2.dist-info}/WHEEL +0 -0
- {flood_adapt-0.3.0.dist-info → flood_adapt-0.3.2.dist-info}/top_level.txt +0 -0
flood_adapt/__init__.py
CHANGED
flood_adapt/config/fiat.py
CHANGED
|
@@ -198,18 +198,18 @@ class FiatModel(BaseModel):
|
|
|
198
198
|
|
|
199
199
|
Attributes
|
|
200
200
|
----------
|
|
201
|
-
risk : RiskModel
|
|
202
|
-
Configuration of probabilistic risk runs.
|
|
201
|
+
risk : Optional[RiskModel]
|
|
202
|
+
Configuration of probabilistic risk runs. default=None
|
|
203
203
|
config : FiatConfigModel
|
|
204
204
|
Configuration for the FIAT model.
|
|
205
|
-
benefits : BenefitsModel
|
|
206
|
-
Configuration for running benefit calculations.
|
|
205
|
+
benefits : Optional[BenefitsModel]
|
|
206
|
+
Configuration for running benefit calculations. default=None
|
|
207
207
|
"""
|
|
208
208
|
|
|
209
|
-
risk: RiskModel
|
|
210
|
-
|
|
211
209
|
config: FiatConfigModel
|
|
212
|
-
|
|
210
|
+
|
|
211
|
+
benefits: Optional[BenefitsModel] = None
|
|
212
|
+
risk: Optional[RiskModel] = None
|
|
213
213
|
|
|
214
214
|
@staticmethod
|
|
215
215
|
def read_toml(path: Path) -> "FiatModel":
|
flood_adapt/config/site.py
CHANGED
|
@@ -379,6 +379,7 @@ class DatabaseBuilder:
|
|
|
379
379
|
|
|
380
380
|
_has_roads: bool = False
|
|
381
381
|
_aggregation_areas: Optional[list] = None
|
|
382
|
+
_probabilistic_set_name: Optional[str] = None
|
|
382
383
|
|
|
383
384
|
def __init__(self, config: ConfigModel, overwrite: bool = True):
|
|
384
385
|
self.config = config
|
|
@@ -579,19 +580,26 @@ class DatabaseBuilder:
|
|
|
579
580
|
### FIAT ###
|
|
580
581
|
def create_fiat_model(self) -> FiatModel:
|
|
581
582
|
fiat = FiatModel(
|
|
582
|
-
risk=self.create_risk_model(),
|
|
583
583
|
config=self.create_fiat_config(),
|
|
584
584
|
benefits=self.create_benefit_config(),
|
|
585
|
+
risk=self.create_risk_model(),
|
|
585
586
|
)
|
|
586
587
|
return fiat
|
|
587
588
|
|
|
588
|
-
def create_risk_model(self) -> RiskModel:
|
|
589
|
+
def create_risk_model(self) -> Optional[RiskModel]:
|
|
589
590
|
# Check if return periods are provided
|
|
590
591
|
if not self.config.return_periods:
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
592
|
+
if self._probabilistic_set_name:
|
|
593
|
+
risk = RiskModel()
|
|
594
|
+
self.logger.warning(
|
|
595
|
+
f"No return periods provided, but a probabilistic set is available. Using default return periods {risk.return_periods}."
|
|
596
|
+
)
|
|
597
|
+
return risk
|
|
598
|
+
else:
|
|
599
|
+
self.logger.warning(
|
|
600
|
+
"No return periods provided and no probabilistic set available. Risk calculations will not be performed."
|
|
601
|
+
)
|
|
602
|
+
return None
|
|
595
603
|
else:
|
|
596
604
|
risk = RiskModel(return_periods=self.config.return_periods)
|
|
597
605
|
return risk
|
|
@@ -2,9 +2,8 @@ import gc
|
|
|
2
2
|
import os
|
|
3
3
|
import shutil
|
|
4
4
|
import time
|
|
5
|
-
from datetime import datetime
|
|
6
5
|
from pathlib import Path
|
|
7
|
-
from typing import Any, Optional, Union
|
|
6
|
+
from typing import Any, Literal, Optional, Union
|
|
8
7
|
|
|
9
8
|
import geopandas as gpd
|
|
10
9
|
import numpy as np
|
|
@@ -566,7 +565,12 @@ class Database(IDatabase):
|
|
|
566
565
|
gdfs[label] = gdfs[label].to_crs(4326)
|
|
567
566
|
return gdfs
|
|
568
567
|
|
|
569
|
-
def get_object_list(
|
|
568
|
+
def get_object_list(
|
|
569
|
+
self,
|
|
570
|
+
object_type: Literal[
|
|
571
|
+
"projections", "events", "measures", "strategies", "scenarios", "benefits"
|
|
572
|
+
],
|
|
573
|
+
) -> dict[str, Any]:
|
|
570
574
|
"""Get a dictionary with all the toml paths and last modification dates that exist in the database that correspond to object_type.
|
|
571
575
|
|
|
572
576
|
Parameters
|
|
@@ -579,20 +583,23 @@ class Database(IDatabase):
|
|
|
579
583
|
dict[str, Any]
|
|
580
584
|
Includes 'path' and 'last_modification_date' info
|
|
581
585
|
"""
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
"
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
586
|
+
match object_type:
|
|
587
|
+
case "projections":
|
|
588
|
+
return self.projections.list_objects()
|
|
589
|
+
case "events":
|
|
590
|
+
return self.events.list_objects()
|
|
591
|
+
case "measures":
|
|
592
|
+
return self.measures.list_objects()
|
|
593
|
+
case "strategies":
|
|
594
|
+
return self.strategies.list_objects()
|
|
595
|
+
case "scenarios":
|
|
596
|
+
return self.scenarios.list_objects()
|
|
597
|
+
case "benefits":
|
|
598
|
+
return self.benefits.list_objects()
|
|
599
|
+
case _:
|
|
600
|
+
raise ValueError(
|
|
601
|
+
f"Object type '{object_type}' is not valid. Must be one of 'projections', 'events', 'measures', 'strategies' or 'scenarios'."
|
|
602
|
+
)
|
|
596
603
|
|
|
597
604
|
def has_run_hazard(self, scenario_name: str) -> None:
|
|
598
605
|
"""Check if there is already a simulation that has the exact same hazard component.
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
|
-
from typing import Any
|
|
3
2
|
|
|
4
3
|
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
5
4
|
from flood_adapt.objects.events.event_factory import EventFactory
|
|
@@ -34,20 +33,6 @@ class DbsEvent(DbsTemplate[Event]):
|
|
|
34
33
|
# Load event
|
|
35
34
|
return EventFactory.load_file(event_path)
|
|
36
35
|
|
|
37
|
-
def list_objects(self) -> dict[str, list[Any]]:
|
|
38
|
-
"""Return a dictionary with info on the events that currently exist in the database.
|
|
39
|
-
|
|
40
|
-
Returns
|
|
41
|
-
-------
|
|
42
|
-
dict[str, Any]
|
|
43
|
-
Includes 'name', 'description', 'path' and 'last_modification_date' info
|
|
44
|
-
"""
|
|
45
|
-
events = self._get_object_list()
|
|
46
|
-
objects = [self.get(name) for name in events["name"]]
|
|
47
|
-
events["description"] = [obj.description for obj in objects]
|
|
48
|
-
events["objects"] = objects
|
|
49
|
-
return events
|
|
50
|
-
|
|
51
36
|
def _check_standard_objects(self, name: str) -> bool:
|
|
52
37
|
"""Check if an event is a standard event.
|
|
53
38
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from pathlib import Path
|
|
1
2
|
from typing import Any
|
|
2
3
|
|
|
3
4
|
import geopandas as gpd
|
|
@@ -26,9 +27,15 @@ class DbsMeasure(DbsTemplate[Measure]):
|
|
|
26
27
|
Measure
|
|
27
28
|
measure object
|
|
28
29
|
"""
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
# Make the full path to the object
|
|
31
|
+
full_path = self.input_path / name / f"{name}.toml"
|
|
32
|
+
|
|
33
|
+
# Check if the object exists
|
|
34
|
+
if not Path(full_path).is_file():
|
|
35
|
+
raise ValueError(f"{self.display_name}: '{name}' does not exist.")
|
|
36
|
+
|
|
37
|
+
# Load and return the object
|
|
38
|
+
return MeasureFactory.get_measure_object(full_path)
|
|
32
39
|
|
|
33
40
|
def list_objects(self) -> dict[str, list[Any]]:
|
|
34
41
|
"""Return a dictionary with info on the measures that currently exist in the database.
|
|
@@ -39,14 +46,15 @@ class DbsMeasure(DbsTemplate[Measure]):
|
|
|
39
46
|
Includes 'name', 'description', 'path' and 'last_modification_date' info
|
|
40
47
|
"""
|
|
41
48
|
measures = self._get_object_list()
|
|
42
|
-
objects = [
|
|
49
|
+
objects = [self.get(name) for name in measures["name"]]
|
|
50
|
+
|
|
43
51
|
measures["description"] = [obj.description for obj in objects]
|
|
44
52
|
measures["objects"] = objects
|
|
45
53
|
|
|
46
54
|
geometries = []
|
|
47
|
-
for
|
|
55
|
+
for obj in objects:
|
|
48
56
|
# If polygon is used read the polygon file
|
|
49
|
-
if obj.polygon_file:
|
|
57
|
+
if hasattr(obj, "polygon_file") and obj.polygon_file:
|
|
50
58
|
src_path = resolve_filepath(
|
|
51
59
|
object_dir=self.dir_name,
|
|
52
60
|
obj_name=obj.name,
|
|
@@ -54,7 +62,7 @@ class DbsMeasure(DbsTemplate[Measure]):
|
|
|
54
62
|
)
|
|
55
63
|
geometries.append(gpd.read_file(src_path))
|
|
56
64
|
# If aggregation area is used read the polygon from the aggregation area name
|
|
57
|
-
elif obj.aggregation_area_name:
|
|
65
|
+
elif hasattr(obj, "aggregation_area_name") and obj.aggregation_area_name:
|
|
58
66
|
if (
|
|
59
67
|
obj.aggregation_area_type
|
|
60
68
|
not in self._database.static.get_aggregation_areas()
|
|
@@ -128,11 +128,9 @@ class DbsStatic(IDbsStatic):
|
|
|
128
128
|
"""
|
|
129
129
|
# Read the map
|
|
130
130
|
full_path = self._database.static_path / path
|
|
131
|
-
if full_path.is_file():
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
# If the file is not found, throw an error
|
|
135
|
-
raise FileNotFoundError(f"File {full_path} not found")
|
|
131
|
+
if not full_path.is_file():
|
|
132
|
+
raise FileNotFoundError(f"File {full_path} not found")
|
|
133
|
+
return gpd.read_file(full_path, engine="pyogrio").to_crs(4326)
|
|
136
134
|
|
|
137
135
|
@cache_method_wrapper
|
|
138
136
|
def get_slr_scn_names(self) -> list:
|
|
@@ -60,10 +60,9 @@ class DbsTemplate(AbstractDatabaseElement[T_OBJECTMODEL]):
|
|
|
60
60
|
object_list = self._get_object_list()
|
|
61
61
|
|
|
62
62
|
# Load all objects
|
|
63
|
-
objects = [self.
|
|
63
|
+
objects = [self.get(name) for name in object_list["name"]]
|
|
64
64
|
|
|
65
|
-
# From the loaded objects, get the
|
|
66
|
-
object_list["name"] = [obj.name for obj in objects]
|
|
65
|
+
# From the loaded objects, get the description and add them to the object_list
|
|
67
66
|
object_list["description"] = [obj.description for obj in objects]
|
|
68
67
|
object_list["objects"] = objects
|
|
69
68
|
return object_list
|
|
@@ -248,7 +247,7 @@ class DbsTemplate(AbstractDatabaseElement[T_OBJECTMODEL]):
|
|
|
248
247
|
Returns
|
|
249
248
|
-------
|
|
250
249
|
dict[str, Any]
|
|
251
|
-
A dictionary that contains the keys: `name` to
|
|
250
|
+
A dictionary that contains the keys: `name` to `path` and `last_modification_date`
|
|
252
251
|
Each key has a list of the corresponding values, where the index of the values corresponds to the same object.
|
|
253
252
|
"""
|
|
254
253
|
# If the toml doesnt exist, we might be in the middle of saving a new object or could be a broken object.
|