flood-adapt 0.3.1__py3-none-any.whl → 0.3.3__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/adapter/fiat_adapter.py +35 -1
- flood_adapt/config/config.py +58 -36
- flood_adapt/config/fiat.py +7 -7
- flood_adapt/config/gui.py +189 -82
- flood_adapt/config/site.py +2 -2
- flood_adapt/database_builder/database_builder.py +100 -65
- flood_adapt/dbs_classes/database.py +16 -53
- flood_adapt/dbs_classes/dbs_event.py +4 -1
- flood_adapt/dbs_classes/dbs_measure.py +7 -7
- flood_adapt/dbs_classes/dbs_projection.py +4 -1
- flood_adapt/dbs_classes/dbs_scenario.py +17 -8
- flood_adapt/dbs_classes/dbs_static.py +3 -5
- flood_adapt/dbs_classes/dbs_strategy.py +7 -5
- flood_adapt/dbs_classes/dbs_template.py +21 -22
- flood_adapt/dbs_classes/interface/database.py +0 -8
- flood_adapt/dbs_classes/interface/element.py +1 -1
- flood_adapt/flood_adapt.py +135 -273
- 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 +17 -4
- 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/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 +5 -2
- flood_adapt/workflows/scenario_runner.py +8 -7
- flood_adapt-0.3.3.dist-info/LICENSE +674 -0
- flood_adapt-0.3.3.dist-info/METADATA +859 -0
- {flood_adapt-0.3.1.dist-info → flood_adapt-0.3.3.dist-info}/RECORD +41 -41
- flood_adapt-0.3.1.dist-info/LICENSE +0 -21
- flood_adapt-0.3.1.dist-info/METADATA +0 -183
- /flood_adapt/database_builder/templates/{mapbox_layers → output_layers}/bin_colors.toml +0 -0
- {flood_adapt-0.3.1.dist-info → flood_adapt-0.3.3.dist-info}/WHEEL +0 -0
- {flood_adapt-0.3.1.dist-info → flood_adapt-0.3.3.dist-info}/top_level.txt +0 -0
flood_adapt/flood_adapt.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import os
|
|
2
1
|
from pathlib import Path
|
|
3
|
-
from typing import Any, List, Optional,
|
|
2
|
+
from typing import Any, List, Optional, Union
|
|
4
3
|
|
|
5
4
|
import geopandas as gpd
|
|
6
5
|
import numpy as np
|
|
@@ -10,7 +9,6 @@ from fiat_toolbox.infographics.infographics_factory import InforgraphicFactory
|
|
|
10
9
|
from fiat_toolbox.metrics_writer.fiat_read_metrics_file import MetricsFileReader
|
|
11
10
|
from hydromt_sfincs.quadtree import QuadtreeGrid
|
|
12
11
|
|
|
13
|
-
from flood_adapt.config.site import Site
|
|
14
12
|
from flood_adapt.dbs_classes.database import Database
|
|
15
13
|
from flood_adapt.misc.log import FloodAdaptLogging
|
|
16
14
|
from flood_adapt.objects.benefits.benefits import Benefit
|
|
@@ -20,21 +18,13 @@ from flood_adapt.objects.events.event_factory import (
|
|
|
20
18
|
from flood_adapt.objects.events.event_set import EventSet
|
|
21
19
|
from flood_adapt.objects.events.events import (
|
|
22
20
|
Event,
|
|
23
|
-
Mode,
|
|
24
|
-
Template,
|
|
25
21
|
)
|
|
26
|
-
from flood_adapt.objects.forcing import unit_system as us
|
|
27
|
-
from flood_adapt.objects.forcing.csv import read_csv as _read_csv
|
|
28
22
|
from flood_adapt.objects.forcing.forcing import (
|
|
29
23
|
ForcingType,
|
|
30
|
-
IForcing,
|
|
31
24
|
)
|
|
32
|
-
from flood_adapt.objects.forcing.forcing_factory import ForcingFactory
|
|
33
25
|
from flood_adapt.objects.forcing.plotting import (
|
|
34
26
|
plot_forcing as _plot_forcing,
|
|
35
27
|
)
|
|
36
|
-
from flood_adapt.objects.forcing.tide_gauge import TideGauge
|
|
37
|
-
from flood_adapt.objects.forcing.time_frame import TimeFrame
|
|
38
28
|
from flood_adapt.objects.measures.measures import (
|
|
39
29
|
Buyout,
|
|
40
30
|
Elevate,
|
|
@@ -48,6 +38,7 @@ from flood_adapt.objects.projections.projections import Projection
|
|
|
48
38
|
from flood_adapt.objects.scenarios.scenarios import Scenario
|
|
49
39
|
from flood_adapt.objects.strategies.strategies import Strategy
|
|
50
40
|
from flood_adapt.workflows.impacts_integrator import Impacts
|
|
41
|
+
from flood_adapt.workflows.scenario_runner import ScenarioRunner
|
|
51
42
|
|
|
52
43
|
|
|
53
44
|
class FloodAdapt:
|
|
@@ -73,12 +64,12 @@ class FloodAdapt:
|
|
|
73
64
|
|
|
74
65
|
Returns
|
|
75
66
|
-------
|
|
76
|
-
dict[str, Any]
|
|
67
|
+
measures : dict[str, Any]
|
|
77
68
|
A dictionary containing all measures.
|
|
78
69
|
Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
|
|
79
70
|
Each value is a list of the corresponding attribute for each measure.
|
|
80
71
|
"""
|
|
81
|
-
return self.database.measures.
|
|
72
|
+
return self.database.measures.summarize_objects()
|
|
82
73
|
|
|
83
74
|
def get_measure(self, name: str) -> Measure:
|
|
84
75
|
"""
|
|
@@ -91,7 +82,7 @@ class FloodAdapt:
|
|
|
91
82
|
|
|
92
83
|
Returns
|
|
93
84
|
-------
|
|
94
|
-
Measure
|
|
85
|
+
measure : Measure
|
|
95
86
|
The measure object with the given name.
|
|
96
87
|
|
|
97
88
|
Raises
|
|
@@ -113,7 +104,7 @@ class FloodAdapt:
|
|
|
113
104
|
|
|
114
105
|
Returns
|
|
115
106
|
-------
|
|
116
|
-
Measure
|
|
107
|
+
measure : Measure
|
|
117
108
|
Measure object.
|
|
118
109
|
"""
|
|
119
110
|
if type == "elevate_properties":
|
|
@@ -132,7 +123,7 @@ class FloodAdapt:
|
|
|
132
123
|
raise ValueError(f"Invalid measure type: {type}")
|
|
133
124
|
|
|
134
125
|
def save_measure(self, measure: Measure, overwrite: bool = False) -> None:
|
|
135
|
-
"""Save
|
|
126
|
+
"""Save a measure object to the database.
|
|
136
127
|
|
|
137
128
|
Parameters
|
|
138
129
|
----------
|
|
@@ -142,101 +133,54 @@ class FloodAdapt:
|
|
|
142
133
|
Raises
|
|
143
134
|
------
|
|
144
135
|
ValueError
|
|
145
|
-
If the
|
|
136
|
+
If the measure object is not valid.
|
|
146
137
|
"""
|
|
147
138
|
self.database.measures.save(measure, overwrite=overwrite)
|
|
148
139
|
|
|
149
140
|
def edit_measure(self, measure: Measure) -> None:
|
|
150
|
-
"""Edit
|
|
141
|
+
"""Edit a measure object in the database.
|
|
151
142
|
|
|
152
143
|
Parameters
|
|
153
144
|
----------
|
|
154
145
|
measure : Measure
|
|
155
146
|
The measure object to edit.
|
|
156
147
|
|
|
157
|
-
|
|
158
148
|
Raises
|
|
159
149
|
------
|
|
160
150
|
ValueError
|
|
161
|
-
If the
|
|
151
|
+
If the measure object does not exist.
|
|
162
152
|
"""
|
|
163
153
|
self.database.measures.edit(measure)
|
|
164
154
|
|
|
165
155
|
def delete_measure(self, name: str) -> None:
|
|
166
|
-
"""Delete an
|
|
156
|
+
"""Delete an measure from the database.
|
|
167
157
|
|
|
168
158
|
Parameters
|
|
169
159
|
----------
|
|
170
160
|
name : str
|
|
171
|
-
The name of the
|
|
161
|
+
The name of the measure to delete.
|
|
172
162
|
|
|
173
163
|
Raises
|
|
174
164
|
------
|
|
175
165
|
ValueError
|
|
176
|
-
If the
|
|
166
|
+
If the measure does not exist.
|
|
177
167
|
"""
|
|
178
168
|
self.database.measures.delete(name)
|
|
179
169
|
|
|
180
170
|
def copy_measure(self, old_name: str, new_name: str, new_description: str) -> None:
|
|
181
|
-
"""Copy
|
|
171
|
+
"""Copy a measure in the database.
|
|
182
172
|
|
|
183
173
|
Parameters
|
|
184
174
|
----------
|
|
185
175
|
old_name : str
|
|
186
|
-
The name of the
|
|
176
|
+
The name of the measure to copy.
|
|
187
177
|
new_name : str
|
|
188
|
-
The name of the new
|
|
178
|
+
The name of the new measure.
|
|
189
179
|
new_description : str
|
|
190
|
-
The description of the new
|
|
180
|
+
The description of the new measure
|
|
191
181
|
"""
|
|
192
182
|
self.database.measures.copy(old_name, new_name, new_description)
|
|
193
183
|
|
|
194
|
-
def calculate_polygon_area(self, gdf: gpd.GeoDataFrame, site: Site) -> float:
|
|
195
|
-
"""
|
|
196
|
-
Calculate the area of a polygon from a GeoDataFrame.
|
|
197
|
-
|
|
198
|
-
Parameters
|
|
199
|
-
----------
|
|
200
|
-
gdf : gpd.GeoDataFrame
|
|
201
|
-
A GeoDataFrame containing the polygon geometry.
|
|
202
|
-
site : Site
|
|
203
|
-
An instance of Site representing the site information.
|
|
204
|
-
|
|
205
|
-
Returns
|
|
206
|
-
-------
|
|
207
|
-
float: The area of the polygon in the specified units.
|
|
208
|
-
"""
|
|
209
|
-
return GreenInfrastructure.calculate_polygon_area(gdf=gdf, site=site)
|
|
210
|
-
|
|
211
|
-
def calculate_volume(
|
|
212
|
-
self,
|
|
213
|
-
area: us.UnitfulArea,
|
|
214
|
-
height: us.UnitfulHeight = us.UnitfulHeight(
|
|
215
|
-
value=0.0, units=us.UnitTypesLength.meters
|
|
216
|
-
),
|
|
217
|
-
percent_area: float = 100.0,
|
|
218
|
-
) -> float:
|
|
219
|
-
"""
|
|
220
|
-
Calculate the volume of green infrastructure based on the given area, height, and percent area.
|
|
221
|
-
|
|
222
|
-
Parameters
|
|
223
|
-
----------
|
|
224
|
-
area : float
|
|
225
|
-
The area of the green infrastructure in square units.
|
|
226
|
-
height : float
|
|
227
|
-
The height of the green infrastructure in units. Defaults to 0.0.
|
|
228
|
-
percent_area : float
|
|
229
|
-
The percentage of the area to be considered. Defaults to 100.0.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
Returns
|
|
233
|
-
-------
|
|
234
|
-
float: The calculated volume of the green infrastructure.
|
|
235
|
-
"""
|
|
236
|
-
return GreenInfrastructure.calculate_volume(
|
|
237
|
-
area=area, height=height, percent_area=percent_area
|
|
238
|
-
)
|
|
239
|
-
|
|
240
184
|
def get_green_infra_table(self, measure_type: str) -> pd.DataFrame:
|
|
241
185
|
"""Return a table with different types of green infrastructure measures and their infiltration depths.
|
|
242
186
|
|
|
@@ -247,7 +191,7 @@ class FloodAdapt:
|
|
|
247
191
|
|
|
248
192
|
Returns
|
|
249
193
|
-------
|
|
250
|
-
pd.DataFrame
|
|
194
|
+
table : pd.DataFrame
|
|
251
195
|
A table with different types of green infrastructure measures and their infiltration depths.
|
|
252
196
|
|
|
253
197
|
"""
|
|
@@ -260,12 +204,12 @@ class FloodAdapt:
|
|
|
260
204
|
|
|
261
205
|
Returns
|
|
262
206
|
-------
|
|
263
|
-
dict[str, Any]
|
|
207
|
+
strategies : dict[str, Any]
|
|
264
208
|
A dictionary containing all strategies.
|
|
265
209
|
Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
|
|
266
210
|
Each value is a list of the corresponding attribute for each strategy.
|
|
267
211
|
"""
|
|
268
|
-
return self.database.strategies.
|
|
212
|
+
return self.database.strategies.summarize_objects()
|
|
269
213
|
|
|
270
214
|
def get_strategy(self, name: str) -> Strategy:
|
|
271
215
|
"""
|
|
@@ -278,7 +222,7 @@ class FloodAdapt:
|
|
|
278
222
|
|
|
279
223
|
Returns
|
|
280
224
|
-------
|
|
281
|
-
Strategy
|
|
225
|
+
strategy : Strategy
|
|
282
226
|
The strategy object with the given name.
|
|
283
227
|
|
|
284
228
|
Raises
|
|
@@ -298,7 +242,7 @@ class FloodAdapt:
|
|
|
298
242
|
|
|
299
243
|
Returns
|
|
300
244
|
-------
|
|
301
|
-
Strategy
|
|
245
|
+
strategy : Strategy
|
|
302
246
|
The strategy object
|
|
303
247
|
|
|
304
248
|
Raises
|
|
@@ -342,18 +286,32 @@ class FloodAdapt:
|
|
|
342
286
|
"""
|
|
343
287
|
self.database.strategies.delete(name)
|
|
344
288
|
|
|
289
|
+
def copy_strategy(self, old_name: str, new_name: str, new_description: str) -> None:
|
|
290
|
+
"""Copy a strategy in the database.
|
|
291
|
+
|
|
292
|
+
Parameters
|
|
293
|
+
----------
|
|
294
|
+
old_name : str
|
|
295
|
+
The name of the strategy to copy.
|
|
296
|
+
new_name : str
|
|
297
|
+
The name of the new strategy.
|
|
298
|
+
new_description : str
|
|
299
|
+
The description of the new strategy
|
|
300
|
+
"""
|
|
301
|
+
self.database.strategies.copy(old_name, new_name, new_description)
|
|
302
|
+
|
|
345
303
|
# Events
|
|
346
304
|
def get_events(self) -> dict[str, Any]:
|
|
347
305
|
"""Get all events from the database.
|
|
348
306
|
|
|
349
307
|
Returns
|
|
350
308
|
-------
|
|
351
|
-
dict[str, Any]
|
|
309
|
+
events : dict[str, Any]
|
|
352
310
|
A dictionary containing all events.
|
|
353
311
|
Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
|
|
354
312
|
Each value is a list of the corresponding attribute for each benefit.
|
|
355
313
|
"""
|
|
356
|
-
return self.database.events.
|
|
314
|
+
return self.database.events.summarize_objects()
|
|
357
315
|
|
|
358
316
|
def get_event(self, name: str) -> Event | EventSet:
|
|
359
317
|
"""Get an event from the database by name.
|
|
@@ -365,7 +323,7 @@ class FloodAdapt:
|
|
|
365
323
|
|
|
366
324
|
Returns
|
|
367
325
|
-------
|
|
368
|
-
Event
|
|
326
|
+
event: Union[Event, EventSet]
|
|
369
327
|
The event with the given name.
|
|
370
328
|
|
|
371
329
|
Raises
|
|
@@ -375,20 +333,6 @@ class FloodAdapt:
|
|
|
375
333
|
"""
|
|
376
334
|
return self.database.events.get(name)
|
|
377
335
|
|
|
378
|
-
def get_event_mode(self, name: str) -> Mode:
|
|
379
|
-
"""Get the mode of an event from the database by name.
|
|
380
|
-
|
|
381
|
-
Parameters
|
|
382
|
-
----------
|
|
383
|
-
name : str
|
|
384
|
-
|
|
385
|
-
Returns
|
|
386
|
-
-------
|
|
387
|
-
Mode
|
|
388
|
-
The mode of the event with the given name, either `risk` or `single_event`.
|
|
389
|
-
"""
|
|
390
|
-
return self.database.events.get(name).mode
|
|
391
|
-
|
|
392
336
|
def create_event(self, attrs: dict[str, Any] | Event) -> Event:
|
|
393
337
|
"""Create a event object from a dictionary of attributes.
|
|
394
338
|
|
|
@@ -399,7 +343,7 @@ class FloodAdapt:
|
|
|
399
343
|
|
|
400
344
|
Returns
|
|
401
345
|
-------
|
|
402
|
-
Event
|
|
346
|
+
event : Event
|
|
403
347
|
Depending on attrs.template an event object.
|
|
404
348
|
Can be of type: Synthetic, Historical, Hurricane.
|
|
405
349
|
"""
|
|
@@ -419,19 +363,11 @@ class FloodAdapt:
|
|
|
419
363
|
|
|
420
364
|
Returns
|
|
421
365
|
-------
|
|
422
|
-
EventSet
|
|
366
|
+
event_set : EventSet
|
|
423
367
|
EventSet object
|
|
424
368
|
"""
|
|
425
369
|
return EventSet(**attrs, sub_events=sub_events)
|
|
426
370
|
|
|
427
|
-
@staticmethod
|
|
428
|
-
def list_forcings() -> list[Type[IForcing]]:
|
|
429
|
-
return ForcingFactory.list_forcings()
|
|
430
|
-
|
|
431
|
-
@staticmethod
|
|
432
|
-
def get_allowed_forcings(template: Template) -> dict[str, List[str]]:
|
|
433
|
-
return EventFactory.get_allowed_forcings(template)
|
|
434
|
-
|
|
435
371
|
def save_event(self, event: Event) -> None:
|
|
436
372
|
"""Save an event object to the database.
|
|
437
373
|
|
|
@@ -447,20 +383,6 @@ class FloodAdapt:
|
|
|
447
383
|
"""
|
|
448
384
|
self.database.events.save(event)
|
|
449
385
|
|
|
450
|
-
def save_timeseries_csv(self, name: str, event: Event, df: pd.DataFrame) -> None:
|
|
451
|
-
"""Save timeseries data to a csv file.
|
|
452
|
-
|
|
453
|
-
Parameters
|
|
454
|
-
----------
|
|
455
|
-
name : str
|
|
456
|
-
Name of the event
|
|
457
|
-
event : Event
|
|
458
|
-
Event object
|
|
459
|
-
df : pd.DataFrame
|
|
460
|
-
Dataframe of timeseries data
|
|
461
|
-
"""
|
|
462
|
-
self.database.write_to_csv(name, event, df)
|
|
463
|
-
|
|
464
386
|
def edit_event(self, event: Event) -> None:
|
|
465
387
|
"""Edit an event object in the database.
|
|
466
388
|
|
|
@@ -507,64 +429,7 @@ class FloodAdapt:
|
|
|
507
429
|
"""
|
|
508
430
|
self.database.events.copy(old_name, new_name, new_description)
|
|
509
431
|
|
|
510
|
-
def
|
|
511
|
-
"""Check if an event is used in a scenario.
|
|
512
|
-
|
|
513
|
-
Parameters
|
|
514
|
-
----------
|
|
515
|
-
name : str
|
|
516
|
-
name of the event to be checked
|
|
517
|
-
|
|
518
|
-
Returns
|
|
519
|
-
-------
|
|
520
|
-
list[str]
|
|
521
|
-
list of scenario names where the event is used
|
|
522
|
-
|
|
523
|
-
"""
|
|
524
|
-
return self.database.events.check_higher_level_usage(name)
|
|
525
|
-
|
|
526
|
-
def download_wl_data(
|
|
527
|
-
self,
|
|
528
|
-
tide_gauge: TideGauge,
|
|
529
|
-
time: TimeFrame,
|
|
530
|
-
units: us.UnitTypesLength,
|
|
531
|
-
out_path: str,
|
|
532
|
-
) -> pd.DataFrame:
|
|
533
|
-
"""Download water level data from a station or tide gauge.
|
|
534
|
-
|
|
535
|
-
Parameters
|
|
536
|
-
----------
|
|
537
|
-
tide_gauge : TideGauge
|
|
538
|
-
Tide gauge object to download data from
|
|
539
|
-
time: TimeFrame
|
|
540
|
-
Time model object containing start and end time
|
|
541
|
-
units : UnitTypesLength
|
|
542
|
-
Units that data the returned data will be converted to
|
|
543
|
-
out_path : str
|
|
544
|
-
Path to save the data to
|
|
545
|
-
"""
|
|
546
|
-
return tide_gauge.get_waterlevels_in_time_frame(
|
|
547
|
-
time=time,
|
|
548
|
-
units=units,
|
|
549
|
-
out_path=Path(out_path),
|
|
550
|
-
)
|
|
551
|
-
|
|
552
|
-
def read_csv(self, csvpath: Union[str, os.PathLike]) -> pd.DataFrame:
|
|
553
|
-
"""Read a csv file into a pandas DataFrame.
|
|
554
|
-
|
|
555
|
-
Parameters
|
|
556
|
-
----------
|
|
557
|
-
csvpath : Union[str, os.PathLike]
|
|
558
|
-
Path to the csv file
|
|
559
|
-
|
|
560
|
-
Returns
|
|
561
|
-
-------
|
|
562
|
-
pd.DataFrame
|
|
563
|
-
DataFrame containing the data from the csv file
|
|
564
|
-
"""
|
|
565
|
-
return _read_csv(csvpath)
|
|
566
|
-
|
|
567
|
-
def plot_forcing(
|
|
432
|
+
def plot_event_forcing(
|
|
568
433
|
self, event: Event, forcing_type: ForcingType
|
|
569
434
|
) -> tuple[str, Optional[List[Exception]]]:
|
|
570
435
|
"""Plot forcing data for an event.
|
|
@@ -578,19 +443,26 @@ class FloodAdapt:
|
|
|
578
443
|
"""
|
|
579
444
|
return _plot_forcing(event, self.database.site, forcing_type)
|
|
580
445
|
|
|
581
|
-
def
|
|
582
|
-
"""
|
|
446
|
+
def get_cyclone_track_by_index(self, index: int) -> TropicalCyclone:
|
|
447
|
+
"""
|
|
448
|
+
Get a cyclone track from the database by index.
|
|
583
449
|
|
|
584
450
|
Parameters
|
|
585
451
|
----------
|
|
586
|
-
|
|
587
|
-
The
|
|
588
|
-
track : TropicalCyclone
|
|
589
|
-
The cyclone track data
|
|
590
|
-
"""
|
|
591
|
-
self.database.write_cyc(event, track)
|
|
452
|
+
index : int
|
|
453
|
+
The index of the cyclone track to retrieve.
|
|
592
454
|
|
|
593
|
-
|
|
455
|
+
Returns
|
|
456
|
+
-------
|
|
457
|
+
cyclone : TropicalCyclone
|
|
458
|
+
The cyclone track object with the given index.
|
|
459
|
+
|
|
460
|
+
Raises
|
|
461
|
+
------
|
|
462
|
+
ValueError
|
|
463
|
+
If the cyclone track database is not defined in the site configuration.
|
|
464
|
+
If the cyclone track with the given index does not exist.
|
|
465
|
+
"""
|
|
594
466
|
return self.database.static.get_cyclone_track_database().get_track(index)
|
|
595
467
|
|
|
596
468
|
# Projections
|
|
@@ -600,12 +472,12 @@ class FloodAdapt:
|
|
|
600
472
|
|
|
601
473
|
Returns
|
|
602
474
|
-------
|
|
603
|
-
dict[str, Any]
|
|
475
|
+
projections: dict[str, Any]
|
|
604
476
|
A dictionary containing all projections.
|
|
605
477
|
Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
|
|
606
478
|
Each value is a list of the corresponding attribute for each projection.
|
|
607
479
|
"""
|
|
608
|
-
return self.database.projections.
|
|
480
|
+
return self.database.projections.summarize_objects()
|
|
609
481
|
|
|
610
482
|
def get_projection(self, name: str) -> Projection:
|
|
611
483
|
"""Get a projection from the database by name.
|
|
@@ -617,7 +489,7 @@ class FloodAdapt:
|
|
|
617
489
|
|
|
618
490
|
Returns
|
|
619
491
|
-------
|
|
620
|
-
Projection
|
|
492
|
+
projection : Projection
|
|
621
493
|
The projection object with the given name.
|
|
622
494
|
|
|
623
495
|
Raises
|
|
@@ -637,7 +509,7 @@ class FloodAdapt:
|
|
|
637
509
|
|
|
638
510
|
Returns
|
|
639
511
|
-------
|
|
640
|
-
Projection
|
|
512
|
+
projection : Projection
|
|
641
513
|
The projection object created from the attributes.
|
|
642
514
|
|
|
643
515
|
Raises
|
|
@@ -717,7 +589,7 @@ class FloodAdapt:
|
|
|
717
589
|
|
|
718
590
|
Returns
|
|
719
591
|
-------
|
|
720
|
-
|
|
592
|
+
names : List[str]
|
|
721
593
|
List of scenario names
|
|
722
594
|
"""
|
|
723
595
|
return self.database.static.get_slr_scn_names()
|
|
@@ -735,7 +607,7 @@ class FloodAdapt:
|
|
|
735
607
|
|
|
736
608
|
Returns
|
|
737
609
|
-------
|
|
738
|
-
float
|
|
610
|
+
interpolated : float
|
|
739
611
|
The interpolated sea level rise for the given scenario and year.
|
|
740
612
|
"""
|
|
741
613
|
return self.database.interp_slr(slr_scenario, year)
|
|
@@ -746,7 +618,7 @@ class FloodAdapt:
|
|
|
746
618
|
|
|
747
619
|
Returns
|
|
748
620
|
-------
|
|
749
|
-
str
|
|
621
|
+
html_path : str
|
|
750
622
|
The path to the html plot of the sea level rise scenarios.
|
|
751
623
|
"""
|
|
752
624
|
return self.database.plot_slr_scenarios()
|
|
@@ -757,12 +629,12 @@ class FloodAdapt:
|
|
|
757
629
|
|
|
758
630
|
Returns
|
|
759
631
|
-------
|
|
760
|
-
dict[str, Any]
|
|
632
|
+
scenarios : dict[str, Any]
|
|
761
633
|
A dictionary containing all scenarios.
|
|
762
634
|
Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'.
|
|
763
635
|
Each value is a list of the corresponding attribute for each scenario.
|
|
764
636
|
"""
|
|
765
|
-
return self.database.scenarios.
|
|
637
|
+
return self.database.scenarios.summarize_objects()
|
|
766
638
|
|
|
767
639
|
def get_scenario(self, name: str) -> Scenario:
|
|
768
640
|
"""Get a scenario from the database by name.
|
|
@@ -774,7 +646,7 @@ class FloodAdapt:
|
|
|
774
646
|
|
|
775
647
|
Returns
|
|
776
648
|
-------
|
|
777
|
-
Scenario
|
|
649
|
+
scenario : Scenario
|
|
778
650
|
The scenario object with the given name.
|
|
779
651
|
|
|
780
652
|
Raises
|
|
@@ -794,7 +666,7 @@ class FloodAdapt:
|
|
|
794
666
|
|
|
795
667
|
Returns
|
|
796
668
|
-------
|
|
797
|
-
Scenario
|
|
669
|
+
scenario : Scenario
|
|
798
670
|
The scenario object created from the attributes.
|
|
799
671
|
|
|
800
672
|
Raises
|
|
@@ -814,9 +686,9 @@ class FloodAdapt:
|
|
|
814
686
|
|
|
815
687
|
Returns
|
|
816
688
|
-------
|
|
817
|
-
bool
|
|
689
|
+
run_success : bool
|
|
818
690
|
Whether the scenario was saved successfully.
|
|
819
|
-
str
|
|
691
|
+
error_msg : str
|
|
820
692
|
The error message if the scenario was not saved successfully.
|
|
821
693
|
"""
|
|
822
694
|
try:
|
|
@@ -855,30 +727,36 @@ class FloodAdapt:
|
|
|
855
727
|
"""
|
|
856
728
|
self.database.scenarios.delete(name)
|
|
857
729
|
|
|
858
|
-
def run_scenario(self,
|
|
859
|
-
"""Run a scenario.
|
|
730
|
+
def run_scenario(self, scenario_name: Union[str, list[str]]) -> None:
|
|
731
|
+
"""Run a scenario hazard and impacts.
|
|
860
732
|
|
|
861
733
|
Parameters
|
|
862
734
|
----------
|
|
863
|
-
|
|
864
|
-
|
|
735
|
+
scenario_name : Union[str, list[str]]
|
|
736
|
+
name(s) of the scenarios to run.
|
|
865
737
|
|
|
866
738
|
Raises
|
|
867
739
|
------
|
|
868
|
-
|
|
869
|
-
If
|
|
740
|
+
RuntimeError
|
|
741
|
+
If an error occurs while running one of the scenarios
|
|
870
742
|
"""
|
|
871
|
-
|
|
743
|
+
if not isinstance(scenario_name, list):
|
|
744
|
+
scenario_name = [scenario_name]
|
|
745
|
+
|
|
746
|
+
for scn in scenario_name:
|
|
747
|
+
scenario = self.get_scenario(scn)
|
|
748
|
+
runner = ScenarioRunner(self.database, scenario=scenario)
|
|
749
|
+
runner.run()
|
|
872
750
|
|
|
873
751
|
# Outputs
|
|
874
|
-
def
|
|
752
|
+
def get_completed_scenarios(
|
|
875
753
|
self,
|
|
876
754
|
) -> dict[str, Any]:
|
|
877
755
|
"""Get all completed scenarios from the database.
|
|
878
756
|
|
|
879
757
|
Returns
|
|
880
758
|
-------
|
|
881
|
-
dict[str, Any]
|
|
759
|
+
scenarios : dict[str, Any]
|
|
882
760
|
A dictionary containing all scenarios.
|
|
883
761
|
Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
|
|
884
762
|
Each value is a list of the corresponding attribute for each output.
|
|
@@ -891,7 +769,7 @@ class FloodAdapt:
|
|
|
891
769
|
|
|
892
770
|
Returns
|
|
893
771
|
-------
|
|
894
|
-
str
|
|
772
|
+
topo_path : str
|
|
895
773
|
The path to the topobathy file.
|
|
896
774
|
|
|
897
775
|
"""
|
|
@@ -903,7 +781,7 @@ class FloodAdapt:
|
|
|
903
781
|
|
|
904
782
|
Returns
|
|
905
783
|
-------
|
|
906
|
-
str
|
|
784
|
+
index_path : str
|
|
907
785
|
The path to the index file.
|
|
908
786
|
"""
|
|
909
787
|
return self.database.get_index_path()
|
|
@@ -914,12 +792,12 @@ class FloodAdapt:
|
|
|
914
792
|
|
|
915
793
|
Returns
|
|
916
794
|
-------
|
|
917
|
-
float
|
|
795
|
+
fdc : float
|
|
918
796
|
The flood depth conversion.
|
|
919
797
|
"""
|
|
920
798
|
return self.database.get_depth_conversion()
|
|
921
799
|
|
|
922
|
-
def
|
|
800
|
+
def get_max_water_level_map(self, name: str, rp: int = None) -> np.ndarray:
|
|
923
801
|
"""
|
|
924
802
|
Return the maximum water level for the given scenario.
|
|
925
803
|
|
|
@@ -932,12 +810,12 @@ class FloodAdapt:
|
|
|
932
810
|
|
|
933
811
|
Returns
|
|
934
812
|
-------
|
|
935
|
-
np.ndarray
|
|
813
|
+
water_level_map : np.ndarray
|
|
936
814
|
2D gridded map with the maximum waterlevels for each cell.
|
|
937
815
|
"""
|
|
938
816
|
return self.database.get_max_water_level(name, rp)
|
|
939
817
|
|
|
940
|
-
def
|
|
818
|
+
def get_building_footprint_impacts(self, name: str) -> gpd.GeoDataFrame:
|
|
941
819
|
"""
|
|
942
820
|
Return a geodataframe of the impacts at the footprint level.
|
|
943
821
|
|
|
@@ -948,12 +826,12 @@ class FloodAdapt:
|
|
|
948
826
|
|
|
949
827
|
Returns
|
|
950
828
|
-------
|
|
951
|
-
gpd.GeoDataFrame
|
|
829
|
+
footprints : gpd.GeoDataFrame
|
|
952
830
|
The impact footprints for the scenario.
|
|
953
831
|
"""
|
|
954
832
|
return self.database.get_building_footprints(name)
|
|
955
833
|
|
|
956
|
-
def
|
|
834
|
+
def get_aggregated_impacts(self, name: str) -> dict[str, gpd.GeoDataFrame]:
|
|
957
835
|
"""
|
|
958
836
|
Return a dictionary with the aggregated impacts as geodataframes.
|
|
959
837
|
|
|
@@ -964,12 +842,12 @@ class FloodAdapt:
|
|
|
964
842
|
|
|
965
843
|
Returns
|
|
966
844
|
-------
|
|
967
|
-
dict[str, gpd.GeoDataFrame]
|
|
845
|
+
aggr_impacts : dict[str, gpd.GeoDataFrame]
|
|
968
846
|
The aggregated impacts for the scenario.
|
|
969
847
|
"""
|
|
970
848
|
return self.database.get_aggregation(name)
|
|
971
849
|
|
|
972
|
-
def
|
|
850
|
+
def get_road_impacts(self, name: str) -> gpd.GeoDataFrame:
|
|
973
851
|
"""
|
|
974
852
|
Return a geodataframe of the impacts at roads.
|
|
975
853
|
|
|
@@ -980,7 +858,7 @@ class FloodAdapt:
|
|
|
980
858
|
|
|
981
859
|
Returns
|
|
982
860
|
-------
|
|
983
|
-
gpd.GeoDataFrame
|
|
861
|
+
roads : gpd.GeoDataFrame
|
|
984
862
|
The impacted roads for the scenario.
|
|
985
863
|
"""
|
|
986
864
|
return self.database.get_roads(name)
|
|
@@ -995,7 +873,7 @@ class FloodAdapt:
|
|
|
995
873
|
|
|
996
874
|
Returns
|
|
997
875
|
-------
|
|
998
|
-
str
|
|
876
|
+
html_path : str
|
|
999
877
|
The HTML strings of the water level timeseries
|
|
1000
878
|
"""
|
|
1001
879
|
# Get the impacts objects from the scenario
|
|
@@ -1027,7 +905,7 @@ class FloodAdapt:
|
|
|
1027
905
|
|
|
1028
906
|
Returns
|
|
1029
907
|
-------
|
|
1030
|
-
str
|
|
908
|
+
html: str
|
|
1031
909
|
The HTML string of the infographic.
|
|
1032
910
|
"""
|
|
1033
911
|
# Get the impacts objects from the scenario
|
|
@@ -1066,7 +944,8 @@ class FloodAdapt:
|
|
|
1066
944
|
|
|
1067
945
|
Returns
|
|
1068
946
|
-------
|
|
1069
|
-
pd.DataFrame
|
|
947
|
+
metrics: pd.DataFrame
|
|
948
|
+
The metrics for the scenario.
|
|
1070
949
|
|
|
1071
950
|
Raises
|
|
1072
951
|
------
|
|
@@ -1093,25 +972,6 @@ class FloodAdapt:
|
|
|
1093
972
|
)
|
|
1094
973
|
|
|
1095
974
|
# Static
|
|
1096
|
-
@staticmethod
|
|
1097
|
-
def read_database(
|
|
1098
|
-
database_path: Union[str, os.PathLike], site_name: str
|
|
1099
|
-
) -> Database:
|
|
1100
|
-
"""Given a path and a site name returns a IDatabase object.
|
|
1101
|
-
|
|
1102
|
-
Parameters
|
|
1103
|
-
----------
|
|
1104
|
-
database_path : Union[str, os.PathLike]
|
|
1105
|
-
path to database
|
|
1106
|
-
site_name : str
|
|
1107
|
-
name of the site
|
|
1108
|
-
|
|
1109
|
-
Returns
|
|
1110
|
-
-------
|
|
1111
|
-
IDatabase
|
|
1112
|
-
"""
|
|
1113
|
-
return Database(database_path, site_name)
|
|
1114
|
-
|
|
1115
975
|
def get_aggregation_areas(
|
|
1116
976
|
self,
|
|
1117
977
|
) -> dict[str, gpd.GeoDataFrame]:
|
|
@@ -1121,7 +981,7 @@ class FloodAdapt:
|
|
|
1121
981
|
|
|
1122
982
|
Returns
|
|
1123
983
|
-------
|
|
1124
|
-
dict[str, GeoDataFrame]
|
|
984
|
+
aggregation_areas : dict[str, GeoDataFrame]
|
|
1125
985
|
list of geodataframes with the polygons defining the aggregation areas
|
|
1126
986
|
"""
|
|
1127
987
|
return self.database.static.get_aggregation_areas()
|
|
@@ -1135,7 +995,7 @@ class FloodAdapt:
|
|
|
1135
995
|
|
|
1136
996
|
Returns
|
|
1137
997
|
-------
|
|
1138
|
-
gpd.GeoDataFrame
|
|
998
|
+
observation_points : gpd.GeoDataFrame
|
|
1139
999
|
gpd.GeoDataFrame with observation points from the site.toml.
|
|
1140
1000
|
"""
|
|
1141
1001
|
return self.database.static.get_obs_points()
|
|
@@ -1147,7 +1007,7 @@ class FloodAdapt:
|
|
|
1147
1007
|
|
|
1148
1008
|
Returns
|
|
1149
1009
|
-------
|
|
1150
|
-
GeoDataFrame
|
|
1010
|
+
model_boundary : GeoDataFrame
|
|
1151
1011
|
GeoDataFrame with the model boundary
|
|
1152
1012
|
"""
|
|
1153
1013
|
return self.database.static.get_model_boundary()
|
|
@@ -1159,7 +1019,7 @@ class FloodAdapt:
|
|
|
1159
1019
|
|
|
1160
1020
|
Returns
|
|
1161
1021
|
-------
|
|
1162
|
-
QuadtreeGrid
|
|
1022
|
+
grid : QuadtreeGrid
|
|
1163
1023
|
QuadtreeGrid with the model grid
|
|
1164
1024
|
"""
|
|
1165
1025
|
return self.database.static.get_model_grid()
|
|
@@ -1171,7 +1031,7 @@ class FloodAdapt:
|
|
|
1171
1031
|
|
|
1172
1032
|
Returns
|
|
1173
1033
|
-------
|
|
1174
|
-
gpd.GeoDataFrame
|
|
1034
|
+
svi_map : gpd.GeoDataFrame
|
|
1175
1035
|
gpd.GeoDataFrames with the SVI map, None if not available
|
|
1176
1036
|
"""
|
|
1177
1037
|
if self.database.site.fiat.config.svi:
|
|
@@ -1191,59 +1051,51 @@ class FloodAdapt:
|
|
|
1191
1051
|
|
|
1192
1052
|
Returns
|
|
1193
1053
|
-------
|
|
1194
|
-
gpd.
|
|
1195
|
-
gpd.GeoDataFrame with the static map
|
|
1054
|
+
static_map : Union[gpd.GeoDataFrame, None]
|
|
1055
|
+
gpd.GeoDataFrame with the static map if available, None if not found
|
|
1196
1056
|
"""
|
|
1197
1057
|
try:
|
|
1198
1058
|
return self.database.static.get_static_map(path)
|
|
1199
|
-
except
|
|
1059
|
+
except FileNotFoundError:
|
|
1060
|
+
self.logger.warning(f"Static map {path} not found.")
|
|
1200
1061
|
return None
|
|
1201
1062
|
|
|
1202
|
-
def
|
|
1063
|
+
def get_building_geometries(self) -> gpd.GeoDataFrame:
|
|
1203
1064
|
"""Get the buildings exposure that are used in Fiat.
|
|
1204
1065
|
|
|
1205
1066
|
Returns
|
|
1206
1067
|
-------
|
|
1207
|
-
gpd.GeoDataFrame
|
|
1068
|
+
buildings : gpd.GeoDataFrame
|
|
1208
1069
|
gpd.GeoDataFrames with the buildings from FIAT exposure
|
|
1209
1070
|
"""
|
|
1210
1071
|
return self.database.static.get_buildings()
|
|
1211
1072
|
|
|
1212
|
-
def
|
|
1213
|
-
"""Get the
|
|
1073
|
+
def get_building_types(self) -> list:
|
|
1074
|
+
"""Get the building types/categories that are used in the exposure.
|
|
1075
|
+
|
|
1076
|
+
These are used to filter the buildings in the FIAT model, and can include types like:
|
|
1077
|
+
'Residential', 'Commercial', 'Industrial', etc.
|
|
1214
1078
|
|
|
1215
1079
|
Returns
|
|
1216
1080
|
-------
|
|
1217
|
-
list
|
|
1218
|
-
list of
|
|
1081
|
+
building_types: list[str]
|
|
1082
|
+
list of building types
|
|
1219
1083
|
"""
|
|
1220
1084
|
return self.database.static.get_property_types()
|
|
1221
1085
|
|
|
1222
|
-
def get_hazard_measure_types(self):
|
|
1223
|
-
"""Get list of all implemented hazard measure types."""
|
|
1224
|
-
raise NotImplementedError
|
|
1225
|
-
|
|
1226
|
-
def get_impact_measure_types(self):
|
|
1227
|
-
"""Get list of all implemented impact measure types."""
|
|
1228
|
-
raise NotImplementedError
|
|
1229
|
-
|
|
1230
|
-
def get_event_templates(self):
|
|
1231
|
-
"""Get list of all implemented event templates."""
|
|
1232
|
-
raise NotImplementedError
|
|
1233
|
-
|
|
1234
1086
|
# Benefits
|
|
1235
1087
|
def get_benefits(self) -> dict[str, Any]:
|
|
1236
1088
|
"""Get all benefits from the database.
|
|
1237
1089
|
|
|
1238
1090
|
Returns
|
|
1239
1091
|
-------
|
|
1240
|
-
dict[str, Any]
|
|
1092
|
+
benefits : dict[str, Any]
|
|
1241
1093
|
A dictionary containing all benefits.
|
|
1242
1094
|
Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
|
|
1243
1095
|
Each value is a list of the corresponding attribute for each benefit.
|
|
1244
1096
|
"""
|
|
1245
1097
|
# sorting and filtering either with PyQt table or in the API
|
|
1246
|
-
return self.database.benefits.
|
|
1098
|
+
return self.database.benefits.summarize_objects()
|
|
1247
1099
|
|
|
1248
1100
|
def get_benefit(self, name: str) -> Benefit:
|
|
1249
1101
|
"""Get a benefit from the database by name.
|
|
@@ -1255,7 +1107,7 @@ class FloodAdapt:
|
|
|
1255
1107
|
|
|
1256
1108
|
Returns
|
|
1257
1109
|
-------
|
|
1258
|
-
Benefit
|
|
1110
|
+
benefit: Benefit
|
|
1259
1111
|
The benefit object with the given name. See [Benefit](/api_ref/) for details.
|
|
1260
1112
|
|
|
1261
1113
|
Raises
|
|
@@ -1272,6 +1124,16 @@ class FloodAdapt:
|
|
|
1272
1124
|
----------
|
|
1273
1125
|
attrs : dict[str, Any]
|
|
1274
1126
|
The attributes of the benefit object to create. Should adhere to the Benefit schema.
|
|
1127
|
+
|
|
1128
|
+
Returns
|
|
1129
|
+
-------
|
|
1130
|
+
benefit : Benefit
|
|
1131
|
+
The benefit object created from the attributes.
|
|
1132
|
+
|
|
1133
|
+
Raises
|
|
1134
|
+
------
|
|
1135
|
+
ValueError
|
|
1136
|
+
If the attributes do not adhere to the Benefit schema.
|
|
1275
1137
|
"""
|
|
1276
1138
|
return Benefit(**attrs)
|
|
1277
1139
|
|
|
@@ -1330,7 +1192,7 @@ class FloodAdapt:
|
|
|
1330
1192
|
|
|
1331
1193
|
Returns
|
|
1332
1194
|
-------
|
|
1333
|
-
pd.DataFrame
|
|
1195
|
+
scenarios : pd.DataFrame
|
|
1334
1196
|
A dataframe with the scenarios needed for this benefit assessment run.
|
|
1335
1197
|
"""
|
|
1336
1198
|
return self.database.check_benefit_scenarios(benefit)
|
|
@@ -1355,7 +1217,7 @@ class FloodAdapt:
|
|
|
1355
1217
|
"""
|
|
1356
1218
|
self.database.run_benefit(name)
|
|
1357
1219
|
|
|
1358
|
-
def
|
|
1220
|
+
def get_aggregated_benefits(self, name: str) -> dict[str, gpd.GeoDataFrame]:
|
|
1359
1221
|
"""Get the aggregation benefits for a benefit assessment.
|
|
1360
1222
|
|
|
1361
1223
|
Parameters
|
|
@@ -1365,7 +1227,7 @@ class FloodAdapt:
|
|
|
1365
1227
|
|
|
1366
1228
|
Returns
|
|
1367
1229
|
-------
|
|
1368
|
-
gpd.GeoDataFrame
|
|
1230
|
+
aggregated_benefits : gpd.GeoDataFrame
|
|
1369
1231
|
The aggregation benefits for the benefit assessment.
|
|
1370
1232
|
"""
|
|
1371
1233
|
return self.database.get_aggregation_benefits(name)
|