flood-adapt 0.3.8__py3-none-any.whl → 0.3.10__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 +26 -22
- flood_adapt/adapter/__init__.py +9 -9
- flood_adapt/adapter/fiat_adapter.py +1541 -1536
- flood_adapt/adapter/interface/hazard_adapter.py +70 -70
- flood_adapt/adapter/interface/impact_adapter.py +36 -36
- flood_adapt/adapter/interface/model_adapter.py +89 -89
- flood_adapt/adapter/interface/offshore.py +19 -19
- flood_adapt/adapter/sfincs_adapter.py +1848 -1846
- flood_adapt/adapter/sfincs_offshore.py +193 -193
- flood_adapt/config/config.py +248 -290
- flood_adapt/config/fiat.py +219 -219
- flood_adapt/config/gui.py +331 -331
- flood_adapt/config/sfincs.py +481 -336
- flood_adapt/config/site.py +129 -129
- flood_adapt/database_builder/database_builder.py +2210 -2210
- flood_adapt/database_builder/templates/default_units/imperial.toml +9 -9
- flood_adapt/database_builder/templates/default_units/metric.toml +9 -9
- flood_adapt/database_builder/templates/green_infra_table/green_infra_lookup_table.csv +10 -10
- flood_adapt/database_builder/templates/infographics/OSM/config_charts.toml +90 -90
- flood_adapt/database_builder/templates/infographics/OSM/config_people.toml +57 -57
- flood_adapt/database_builder/templates/infographics/OSM/config_risk_charts.toml +121 -121
- flood_adapt/database_builder/templates/infographics/OSM/config_roads.toml +65 -65
- flood_adapt/database_builder/templates/infographics/OSM/styles.css +45 -45
- flood_adapt/database_builder/templates/infographics/US_NSI/config_charts.toml +126 -126
- flood_adapt/database_builder/templates/infographics/US_NSI/config_people.toml +60 -60
- flood_adapt/database_builder/templates/infographics/US_NSI/config_risk_charts.toml +121 -121
- flood_adapt/database_builder/templates/infographics/US_NSI/config_roads.toml +65 -65
- flood_adapt/database_builder/templates/infographics/US_NSI/styles.css +45 -45
- flood_adapt/database_builder/templates/infometrics/OSM/metrics_additional_risk_configs.toml +4 -4
- flood_adapt/database_builder/templates/infometrics/OSM/with_SVI/infographic_metrics_config.toml +143 -143
- flood_adapt/database_builder/templates/infometrics/OSM/with_SVI/infographic_metrics_config_risk.toml +153 -153
- flood_adapt/database_builder/templates/infometrics/OSM/without_SVI/infographic_metrics_config.toml +127 -127
- flood_adapt/database_builder/templates/infometrics/OSM/without_SVI/infographic_metrics_config_risk.toml +57 -57
- flood_adapt/database_builder/templates/infometrics/US_NSI/metrics_additional_risk_configs.toml +4 -4
- flood_adapt/database_builder/templates/infometrics/US_NSI/with_SVI/infographic_metrics_config.toml +191 -191
- flood_adapt/database_builder/templates/infometrics/US_NSI/with_SVI/infographic_metrics_config_risk.toml +153 -153
- flood_adapt/database_builder/templates/infometrics/US_NSI/without_SVI/infographic_metrics_config.toml +178 -178
- flood_adapt/database_builder/templates/infometrics/US_NSI/without_SVI/infographic_metrics_config_risk.toml +57 -57
- flood_adapt/database_builder/templates/infometrics/mandatory_metrics_config.toml +9 -9
- flood_adapt/database_builder/templates/infometrics/mandatory_metrics_config_risk.toml +65 -65
- flood_adapt/database_builder/templates/output_layers/bin_colors.toml +5 -5
- flood_adapt/database_builder.py +16 -16
- flood_adapt/dbs_classes/__init__.py +21 -21
- flood_adapt/dbs_classes/database.py +495 -688
- flood_adapt/dbs_classes/dbs_benefit.py +77 -76
- flood_adapt/dbs_classes/dbs_event.py +61 -59
- flood_adapt/dbs_classes/dbs_measure.py +112 -111
- flood_adapt/dbs_classes/dbs_projection.py +34 -34
- flood_adapt/dbs_classes/dbs_scenario.py +137 -137
- flood_adapt/dbs_classes/dbs_static.py +274 -273
- flood_adapt/dbs_classes/dbs_strategy.py +130 -129
- flood_adapt/dbs_classes/dbs_template.py +279 -278
- flood_adapt/dbs_classes/interface/database.py +107 -139
- flood_adapt/dbs_classes/interface/element.py +121 -121
- flood_adapt/dbs_classes/interface/static.py +47 -47
- flood_adapt/flood_adapt.py +1207 -1178
- flood_adapt/misc/database_user.py +16 -16
- flood_adapt/misc/exceptions.py +22 -0
- flood_adapt/misc/log.py +183 -183
- flood_adapt/misc/path_builder.py +54 -54
- flood_adapt/misc/utils.py +185 -185
- flood_adapt/objects/__init__.py +82 -82
- flood_adapt/objects/benefits/benefits.py +61 -61
- flood_adapt/objects/events/event_factory.py +135 -135
- flood_adapt/objects/events/event_set.py +88 -84
- flood_adapt/objects/events/events.py +234 -234
- flood_adapt/objects/events/historical.py +58 -58
- flood_adapt/objects/events/hurricane.py +68 -67
- flood_adapt/objects/events/synthetic.py +46 -50
- flood_adapt/objects/forcing/__init__.py +92 -92
- flood_adapt/objects/forcing/csv.py +68 -68
- flood_adapt/objects/forcing/discharge.py +66 -66
- flood_adapt/objects/forcing/forcing.py +150 -150
- flood_adapt/objects/forcing/forcing_factory.py +182 -182
- flood_adapt/objects/forcing/meteo_handler.py +93 -93
- flood_adapt/objects/forcing/netcdf.py +40 -40
- flood_adapt/objects/forcing/plotting.py +453 -429
- flood_adapt/objects/forcing/rainfall.py +98 -98
- flood_adapt/objects/forcing/tide_gauge.py +191 -191
- flood_adapt/objects/forcing/time_frame.py +90 -90
- flood_adapt/objects/forcing/timeseries.py +564 -564
- flood_adapt/objects/forcing/unit_system.py +580 -580
- flood_adapt/objects/forcing/waterlevels.py +108 -108
- flood_adapt/objects/forcing/wind.py +124 -124
- flood_adapt/objects/measures/measure_factory.py +92 -92
- flood_adapt/objects/measures/measures.py +529 -529
- flood_adapt/objects/object_model.py +74 -68
- flood_adapt/objects/projections/projections.py +103 -89
- flood_adapt/objects/scenarios/scenarios.py +22 -22
- flood_adapt/objects/strategies/strategies.py +89 -89
- flood_adapt/workflows/benefit_runner.py +579 -544
- flood_adapt/workflows/floodmap.py +85 -85
- flood_adapt/workflows/impacts_integrator.py +85 -82
- flood_adapt/workflows/scenario_runner.py +70 -70
- {flood_adapt-0.3.8.dist-info → flood_adapt-0.3.10.dist-info}/LICENSE +674 -674
- {flood_adapt-0.3.8.dist-info → flood_adapt-0.3.10.dist-info}/METADATA +866 -860
- flood_adapt-0.3.10.dist-info/RECORD +140 -0
- flood_adapt-0.3.8.dist-info/RECORD +0 -139
- {flood_adapt-0.3.8.dist-info → flood_adapt-0.3.10.dist-info}/WHEEL +0 -0
- {flood_adapt-0.3.8.dist-info → flood_adapt-0.3.10.dist-info}/top_level.txt +0 -0
|
@@ -1,76 +1,77 @@
|
|
|
1
|
-
import shutil
|
|
2
|
-
|
|
3
|
-
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
4
|
-
from flood_adapt.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
import shutil
|
|
2
|
+
|
|
3
|
+
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
4
|
+
from flood_adapt.misc.exceptions import DatabaseError
|
|
5
|
+
from flood_adapt.workflows.benefit_runner import Benefit, BenefitRunner
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DbsBenefit(DbsTemplate[Benefit]):
|
|
9
|
+
display_name = "Benefit"
|
|
10
|
+
dir_name = "benefits"
|
|
11
|
+
_object_class = Benefit
|
|
12
|
+
|
|
13
|
+
def save(self, object_model: Benefit, overwrite: bool = False):
|
|
14
|
+
"""Save a benefit object in the database.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
object_model : Benefit
|
|
19
|
+
object of Benefit type
|
|
20
|
+
overwrite : bool, optional
|
|
21
|
+
whether to overwrite existing benefit with same name, by default False
|
|
22
|
+
|
|
23
|
+
Raises
|
|
24
|
+
------
|
|
25
|
+
DatabaseError
|
|
26
|
+
Raise error if name is already in use. Names of benefits assessments should be unique.
|
|
27
|
+
"""
|
|
28
|
+
runner = BenefitRunner(self._database, benefit=object_model)
|
|
29
|
+
|
|
30
|
+
# Check if all scenarios are created
|
|
31
|
+
if not all(runner.scenarios["scenario created"] != "No"):
|
|
32
|
+
raise DatabaseError(
|
|
33
|
+
f"'{object_model.name}' name cannot be created before all necessary scenarios are created."
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Save the benefit
|
|
37
|
+
super().save(object_model, overwrite=overwrite)
|
|
38
|
+
|
|
39
|
+
def delete(self, name: str, toml_only: bool = False):
|
|
40
|
+
"""Delete an already existing benefit in the database.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
name : str
|
|
45
|
+
name of the benefit
|
|
46
|
+
toml_only : bool, optional
|
|
47
|
+
whether to only delete the toml file or the entire folder. If the folder is empty after deleting the toml,
|
|
48
|
+
it will always be deleted. By default False
|
|
49
|
+
|
|
50
|
+
Raises
|
|
51
|
+
------
|
|
52
|
+
DatabaseError
|
|
53
|
+
Raise error if benefit has already model output
|
|
54
|
+
"""
|
|
55
|
+
# First delete the benefit
|
|
56
|
+
super().delete(name, toml_only=toml_only)
|
|
57
|
+
|
|
58
|
+
# Delete output if edited
|
|
59
|
+
output_path = self.output_path / name
|
|
60
|
+
if output_path.exists():
|
|
61
|
+
shutil.rmtree(output_path, ignore_errors=True)
|
|
62
|
+
|
|
63
|
+
def get_runner(self, name: str) -> BenefitRunner:
|
|
64
|
+
return BenefitRunner(self._database, self.get(name))
|
|
65
|
+
|
|
66
|
+
def has_run_check(self, name: str) -> bool:
|
|
67
|
+
return self.get_runner(name).has_run_check()
|
|
68
|
+
|
|
69
|
+
def ready_to_run(self, name: str) -> bool:
|
|
70
|
+
"""Check if all the required scenarios have already been run.
|
|
71
|
+
|
|
72
|
+
Returns
|
|
73
|
+
-------
|
|
74
|
+
bool
|
|
75
|
+
True if required scenarios have been already run
|
|
76
|
+
"""
|
|
77
|
+
return self.get_runner(name).ready_to_run()
|
|
@@ -1,59 +1,61 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
|
|
3
|
-
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
4
|
-
from flood_adapt.
|
|
5
|
-
from flood_adapt.objects.events.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
4
|
+
from flood_adapt.misc.exceptions import DatabaseError
|
|
5
|
+
from flood_adapt.objects.events.event_factory import EventFactory
|
|
6
|
+
from flood_adapt.objects.events.event_set import EventSet
|
|
7
|
+
from flood_adapt.objects.events.events import Event
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DbsEvent(DbsTemplate[Event]):
|
|
11
|
+
dir_name = "events"
|
|
12
|
+
display_name = "Event"
|
|
13
|
+
_object_class = Event
|
|
14
|
+
|
|
15
|
+
def get(self, name: str, load_all: bool = False) -> Event | EventSet:
|
|
16
|
+
"""Return an event object.
|
|
17
|
+
|
|
18
|
+
Parameters
|
|
19
|
+
----------
|
|
20
|
+
name : str
|
|
21
|
+
name of the event to be returned
|
|
22
|
+
|
|
23
|
+
Returns
|
|
24
|
+
-------
|
|
25
|
+
Event
|
|
26
|
+
event object
|
|
27
|
+
"""
|
|
28
|
+
# Get event path
|
|
29
|
+
event_path = self.input_path / f"{name}" / f"{name}.toml"
|
|
30
|
+
|
|
31
|
+
# Check if the object exists
|
|
32
|
+
if not Path(event_path).is_file():
|
|
33
|
+
raise DatabaseError(f"{self.display_name} '{name}' does not exist.")
|
|
34
|
+
|
|
35
|
+
# Load event
|
|
36
|
+
return EventFactory.load_file(event_path, load_all=load_all)
|
|
37
|
+
|
|
38
|
+
def check_higher_level_usage(self, name: str) -> list[str]:
|
|
39
|
+
"""Check if an event is used in a scenario.
|
|
40
|
+
|
|
41
|
+
Parameters
|
|
42
|
+
----------
|
|
43
|
+
name : str
|
|
44
|
+
name of the event to be checked
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
list[str]
|
|
49
|
+
list of scenarios that use the event
|
|
50
|
+
"""
|
|
51
|
+
# Get all the scenarios
|
|
52
|
+
scenarios = [
|
|
53
|
+
self._database.scenarios.get(scn)
|
|
54
|
+
for scn in self._database.scenarios.summarize_objects()["name"]
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
# Check if event is used in a scenario
|
|
58
|
+
used_in_scenario = [
|
|
59
|
+
scenario.name for scenario in scenarios if name == scenario.event
|
|
60
|
+
]
|
|
61
|
+
return used_in_scenario
|
|
@@ -1,111 +1,112 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
from typing import Any
|
|
3
|
-
|
|
4
|
-
import geopandas as gpd
|
|
5
|
-
|
|
6
|
-
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
7
|
-
from flood_adapt.misc.
|
|
8
|
-
from flood_adapt.
|
|
9
|
-
from flood_adapt.objects.measures.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
for
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
import geopandas as gpd
|
|
5
|
+
|
|
6
|
+
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
7
|
+
from flood_adapt.misc.exceptions import DatabaseError
|
|
8
|
+
from flood_adapt.misc.utils import resolve_filepath
|
|
9
|
+
from flood_adapt.objects.measures.measure_factory import MeasureFactory
|
|
10
|
+
from flood_adapt.objects.measures.measures import Measure
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DbsMeasure(DbsTemplate[Measure]):
|
|
14
|
+
dir_name = "measures"
|
|
15
|
+
display_name = "Measure"
|
|
16
|
+
_object_class = Measure
|
|
17
|
+
|
|
18
|
+
def get(self, name: str) -> Measure:
|
|
19
|
+
"""Return a measure object.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
name : str
|
|
24
|
+
name of the measure to be returned
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
Measure
|
|
29
|
+
measure object
|
|
30
|
+
"""
|
|
31
|
+
# Make the full path to the object
|
|
32
|
+
full_path = self.input_path / name / f"{name}.toml"
|
|
33
|
+
|
|
34
|
+
# Check if the object exists
|
|
35
|
+
if not Path(full_path).is_file():
|
|
36
|
+
raise DatabaseError(f"{self.display_name}: '{name}' does not exist.")
|
|
37
|
+
|
|
38
|
+
# Load and return the object
|
|
39
|
+
return MeasureFactory.get_measure_object(full_path)
|
|
40
|
+
|
|
41
|
+
def summarize_objects(self) -> dict[str, list[Any]]:
|
|
42
|
+
"""Return a dictionary with info on the measures that currently exist in the database.
|
|
43
|
+
|
|
44
|
+
Returns
|
|
45
|
+
-------
|
|
46
|
+
dict[str, Any]
|
|
47
|
+
Includes 'name', 'description', 'path' and 'last_modification_date' and 'geometry' info
|
|
48
|
+
"""
|
|
49
|
+
measures = self._get_object_summary()
|
|
50
|
+
objects = [self.get(name) for name in measures["name"]]
|
|
51
|
+
|
|
52
|
+
geometries = []
|
|
53
|
+
for obj in objects:
|
|
54
|
+
# If polygon is used read the polygon file
|
|
55
|
+
if hasattr(obj, "polygon_file") and obj.polygon_file:
|
|
56
|
+
src_path = resolve_filepath(
|
|
57
|
+
object_dir=self.dir_name,
|
|
58
|
+
obj_name=obj.name,
|
|
59
|
+
path=obj.polygon_file,
|
|
60
|
+
)
|
|
61
|
+
geometries.append(gpd.read_file(src_path))
|
|
62
|
+
# If aggregation area is used read the polygon from the aggregation area name
|
|
63
|
+
elif hasattr(obj, "aggregation_area_name") and obj.aggregation_area_name:
|
|
64
|
+
if (
|
|
65
|
+
obj.aggregation_area_type
|
|
66
|
+
not in self._database.static.get_aggregation_areas()
|
|
67
|
+
):
|
|
68
|
+
raise DatabaseError(
|
|
69
|
+
f"Aggregation area type {obj.aggregation_area_type} for measure {obj.name} does not exist."
|
|
70
|
+
)
|
|
71
|
+
gdf = self._database.static.get_aggregation_areas()[
|
|
72
|
+
obj.aggregation_area_type
|
|
73
|
+
]
|
|
74
|
+
if obj.aggregation_area_name not in gdf["name"].to_numpy():
|
|
75
|
+
raise DatabaseError(
|
|
76
|
+
f"Aggregation area name {obj.aggregation_area_name} for measure {obj.name} does not exist."
|
|
77
|
+
)
|
|
78
|
+
geometries.append(gdf.loc[gdf["name"] == obj.aggregation_area_name, :])
|
|
79
|
+
# Else assign a None value
|
|
80
|
+
else:
|
|
81
|
+
geometries.append(None)
|
|
82
|
+
|
|
83
|
+
measures["geometry"] = geometries
|
|
84
|
+
return measures
|
|
85
|
+
|
|
86
|
+
def check_higher_level_usage(self, name: str) -> list[str]:
|
|
87
|
+
"""Check if a measure is used in a strategy.
|
|
88
|
+
|
|
89
|
+
Parameters
|
|
90
|
+
----------
|
|
91
|
+
name : str
|
|
92
|
+
name of the measure to be checked
|
|
93
|
+
|
|
94
|
+
Returns
|
|
95
|
+
-------
|
|
96
|
+
list[str]
|
|
97
|
+
list of strategies that use the measure
|
|
98
|
+
"""
|
|
99
|
+
# Get all the strategies
|
|
100
|
+
strategies = [
|
|
101
|
+
self._database.strategies.get(strategy)
|
|
102
|
+
for strategy in self._database.strategies.summarize_objects()["name"]
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
# Check if measure is used in a strategy
|
|
106
|
+
used_in_strategy = [
|
|
107
|
+
strategy.name
|
|
108
|
+
for strategy in strategies
|
|
109
|
+
for measure in strategy.measures
|
|
110
|
+
if name == measure
|
|
111
|
+
]
|
|
112
|
+
return used_in_strategy
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
2
|
-
from flood_adapt.objects.projections.projections import Projection
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class DbsProjection(DbsTemplate[Projection]):
|
|
6
|
-
dir_name = "projections"
|
|
7
|
-
display_name = "Projection"
|
|
8
|
-
_object_class = Projection
|
|
9
|
-
|
|
10
|
-
def check_higher_level_usage(self, name: str) -> list[str]:
|
|
11
|
-
"""Check if a projection is used in a scenario.
|
|
12
|
-
|
|
13
|
-
Parameters
|
|
14
|
-
----------
|
|
15
|
-
name : str
|
|
16
|
-
name of the projection to be checked
|
|
17
|
-
|
|
18
|
-
Returns
|
|
19
|
-
-------
|
|
20
|
-
list[str]
|
|
21
|
-
list of scenarios that use the projection
|
|
22
|
-
"""
|
|
23
|
-
# Get all the scenarios
|
|
24
|
-
scenarios = [
|
|
25
|
-
self._database.scenarios.get(scn)
|
|
26
|
-
for scn in self._database.scenarios.summarize_objects()["name"]
|
|
27
|
-
]
|
|
28
|
-
|
|
29
|
-
# Check if projection is used in a scenario
|
|
30
|
-
used_in_scenario = [
|
|
31
|
-
scenario.name for scenario in scenarios if name == scenario.projection
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
return used_in_scenario
|
|
1
|
+
from flood_adapt.dbs_classes.dbs_template import DbsTemplate
|
|
2
|
+
from flood_adapt.objects.projections.projections import Projection
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DbsProjection(DbsTemplate[Projection]):
|
|
6
|
+
dir_name = "projections"
|
|
7
|
+
display_name = "Projection"
|
|
8
|
+
_object_class = Projection
|
|
9
|
+
|
|
10
|
+
def check_higher_level_usage(self, name: str) -> list[str]:
|
|
11
|
+
"""Check if a projection is used in a scenario.
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
name : str
|
|
16
|
+
name of the projection to be checked
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
list[str]
|
|
21
|
+
list of scenarios that use the projection
|
|
22
|
+
"""
|
|
23
|
+
# Get all the scenarios
|
|
24
|
+
scenarios = [
|
|
25
|
+
self._database.scenarios.get(scn)
|
|
26
|
+
for scn in self._database.scenarios.summarize_objects()["name"]
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
# Check if projection is used in a scenario
|
|
30
|
+
used_in_scenario = [
|
|
31
|
+
scenario.name for scenario in scenarios if name == scenario.projection
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
return used_in_scenario
|