flood-adapt 0.3.9__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.
Files changed (100) hide show
  1. flood_adapt/__init__.py +26 -22
  2. flood_adapt/adapter/__init__.py +9 -9
  3. flood_adapt/adapter/fiat_adapter.py +1541 -1541
  4. flood_adapt/adapter/interface/hazard_adapter.py +70 -70
  5. flood_adapt/adapter/interface/impact_adapter.py +36 -36
  6. flood_adapt/adapter/interface/model_adapter.py +89 -89
  7. flood_adapt/adapter/interface/offshore.py +19 -19
  8. flood_adapt/adapter/sfincs_adapter.py +1848 -1848
  9. flood_adapt/adapter/sfincs_offshore.py +193 -193
  10. flood_adapt/config/config.py +248 -248
  11. flood_adapt/config/fiat.py +219 -219
  12. flood_adapt/config/gui.py +331 -331
  13. flood_adapt/config/sfincs.py +481 -336
  14. flood_adapt/config/site.py +129 -129
  15. flood_adapt/database_builder/database_builder.py +2210 -2210
  16. flood_adapt/database_builder/templates/default_units/imperial.toml +9 -9
  17. flood_adapt/database_builder/templates/default_units/metric.toml +9 -9
  18. flood_adapt/database_builder/templates/green_infra_table/green_infra_lookup_table.csv +10 -10
  19. flood_adapt/database_builder/templates/infographics/OSM/config_charts.toml +90 -90
  20. flood_adapt/database_builder/templates/infographics/OSM/config_people.toml +57 -57
  21. flood_adapt/database_builder/templates/infographics/OSM/config_risk_charts.toml +121 -121
  22. flood_adapt/database_builder/templates/infographics/OSM/config_roads.toml +65 -65
  23. flood_adapt/database_builder/templates/infographics/OSM/styles.css +45 -45
  24. flood_adapt/database_builder/templates/infographics/US_NSI/config_charts.toml +126 -126
  25. flood_adapt/database_builder/templates/infographics/US_NSI/config_people.toml +60 -60
  26. flood_adapt/database_builder/templates/infographics/US_NSI/config_risk_charts.toml +121 -121
  27. flood_adapt/database_builder/templates/infographics/US_NSI/config_roads.toml +65 -65
  28. flood_adapt/database_builder/templates/infographics/US_NSI/styles.css +45 -45
  29. flood_adapt/database_builder/templates/infometrics/OSM/metrics_additional_risk_configs.toml +4 -4
  30. flood_adapt/database_builder/templates/infometrics/OSM/with_SVI/infographic_metrics_config.toml +143 -143
  31. flood_adapt/database_builder/templates/infometrics/OSM/with_SVI/infographic_metrics_config_risk.toml +153 -153
  32. flood_adapt/database_builder/templates/infometrics/OSM/without_SVI/infographic_metrics_config.toml +127 -127
  33. flood_adapt/database_builder/templates/infometrics/OSM/without_SVI/infographic_metrics_config_risk.toml +57 -57
  34. flood_adapt/database_builder/templates/infometrics/US_NSI/metrics_additional_risk_configs.toml +4 -4
  35. flood_adapt/database_builder/templates/infometrics/US_NSI/with_SVI/infographic_metrics_config.toml +191 -191
  36. flood_adapt/database_builder/templates/infometrics/US_NSI/with_SVI/infographic_metrics_config_risk.toml +153 -153
  37. flood_adapt/database_builder/templates/infometrics/US_NSI/without_SVI/infographic_metrics_config.toml +178 -178
  38. flood_adapt/database_builder/templates/infometrics/US_NSI/without_SVI/infographic_metrics_config_risk.toml +57 -57
  39. flood_adapt/database_builder/templates/infometrics/mandatory_metrics_config.toml +9 -9
  40. flood_adapt/database_builder/templates/infometrics/mandatory_metrics_config_risk.toml +65 -65
  41. flood_adapt/database_builder/templates/output_layers/bin_colors.toml +5 -5
  42. flood_adapt/database_builder.py +16 -16
  43. flood_adapt/dbs_classes/__init__.py +21 -21
  44. flood_adapt/dbs_classes/database.py +495 -684
  45. flood_adapt/dbs_classes/dbs_benefit.py +77 -76
  46. flood_adapt/dbs_classes/dbs_event.py +61 -59
  47. flood_adapt/dbs_classes/dbs_measure.py +112 -111
  48. flood_adapt/dbs_classes/dbs_projection.py +34 -34
  49. flood_adapt/dbs_classes/dbs_scenario.py +137 -137
  50. flood_adapt/dbs_classes/dbs_static.py +274 -273
  51. flood_adapt/dbs_classes/dbs_strategy.py +130 -129
  52. flood_adapt/dbs_classes/dbs_template.py +279 -278
  53. flood_adapt/dbs_classes/interface/database.py +107 -139
  54. flood_adapt/dbs_classes/interface/element.py +121 -121
  55. flood_adapt/dbs_classes/interface/static.py +47 -47
  56. flood_adapt/flood_adapt.py +1207 -1178
  57. flood_adapt/misc/database_user.py +16 -16
  58. flood_adapt/misc/exceptions.py +22 -0
  59. flood_adapt/misc/log.py +183 -183
  60. flood_adapt/misc/path_builder.py +54 -54
  61. flood_adapt/misc/utils.py +185 -185
  62. flood_adapt/objects/__init__.py +82 -82
  63. flood_adapt/objects/benefits/benefits.py +61 -61
  64. flood_adapt/objects/events/event_factory.py +135 -135
  65. flood_adapt/objects/events/event_set.py +88 -84
  66. flood_adapt/objects/events/events.py +234 -234
  67. flood_adapt/objects/events/historical.py +58 -58
  68. flood_adapt/objects/events/hurricane.py +68 -67
  69. flood_adapt/objects/events/synthetic.py +46 -50
  70. flood_adapt/objects/forcing/__init__.py +92 -92
  71. flood_adapt/objects/forcing/csv.py +68 -68
  72. flood_adapt/objects/forcing/discharge.py +66 -66
  73. flood_adapt/objects/forcing/forcing.py +150 -150
  74. flood_adapt/objects/forcing/forcing_factory.py +182 -182
  75. flood_adapt/objects/forcing/meteo_handler.py +93 -93
  76. flood_adapt/objects/forcing/netcdf.py +40 -40
  77. flood_adapt/objects/forcing/plotting.py +453 -429
  78. flood_adapt/objects/forcing/rainfall.py +98 -98
  79. flood_adapt/objects/forcing/tide_gauge.py +191 -191
  80. flood_adapt/objects/forcing/time_frame.py +90 -90
  81. flood_adapt/objects/forcing/timeseries.py +564 -564
  82. flood_adapt/objects/forcing/unit_system.py +580 -580
  83. flood_adapt/objects/forcing/waterlevels.py +108 -108
  84. flood_adapt/objects/forcing/wind.py +124 -124
  85. flood_adapt/objects/measures/measure_factory.py +92 -92
  86. flood_adapt/objects/measures/measures.py +529 -529
  87. flood_adapt/objects/object_model.py +74 -68
  88. flood_adapt/objects/projections/projections.py +103 -103
  89. flood_adapt/objects/scenarios/scenarios.py +22 -22
  90. flood_adapt/objects/strategies/strategies.py +89 -89
  91. flood_adapt/workflows/benefit_runner.py +579 -554
  92. flood_adapt/workflows/floodmap.py +85 -85
  93. flood_adapt/workflows/impacts_integrator.py +85 -85
  94. flood_adapt/workflows/scenario_runner.py +70 -70
  95. {flood_adapt-0.3.9.dist-info → flood_adapt-0.3.10.dist-info}/LICENSE +674 -674
  96. {flood_adapt-0.3.9.dist-info → flood_adapt-0.3.10.dist-info}/METADATA +866 -865
  97. flood_adapt-0.3.10.dist-info/RECORD +140 -0
  98. flood_adapt-0.3.9.dist-info/RECORD +0 -139
  99. {flood_adapt-0.3.9.dist-info → flood_adapt-0.3.10.dist-info}/WHEEL +0 -0
  100. {flood_adapt-0.3.9.dist-info → flood_adapt-0.3.10.dist-info}/top_level.txt +0 -0
@@ -1,129 +1,130 @@
1
- from itertools import combinations
2
-
3
- from flood_adapt.dbs_classes.dbs_template import DbsTemplate
4
- from flood_adapt.objects.measures.measures import MeasureType
5
- from flood_adapt.objects.strategies.strategies import Strategy
6
-
7
-
8
- class DbsStrategy(DbsTemplate[Strategy]):
9
- dir_name = "strategies"
10
- display_name = "Strategy"
11
- _object_class = Strategy
12
-
13
- def get(self, name: str) -> Strategy:
14
- strategy = super().get(name)
15
- measures = [
16
- self._database.measures.get(measure) for measure in strategy.measures
17
- ]
18
- strategy.initialize_measure_objects(measures)
19
- return strategy
20
-
21
- def save(
22
- self,
23
- object_model: Strategy,
24
- overwrite: bool = False,
25
- ):
26
- """Save an object in the database and all associated files.
27
-
28
- This saves the toml file and any additional files attached to the object.
29
-
30
- Parameters
31
- ----------
32
- object_model : Object
33
- object to be saved in the database
34
- overwrite : bool, optional
35
- whether to overwrite the object if it already exists in the
36
- database, by default False
37
-
38
- Raises
39
- ------
40
- ValueError
41
- Raise error if name is already in use.
42
- """
43
- object_exists = object_model.name in self.summarize_objects()["name"]
44
-
45
- # If you want to overwrite the object, and the object already exists, first delete it. If it exists and you
46
- # don't want to overwrite, raise an error.
47
- if overwrite and object_exists:
48
- self.delete(object_model.name, toml_only=True)
49
- elif not overwrite and object_exists:
50
- raise ValueError(
51
- f"'{object_model.name}' name is already used by another {self.display_name}. Choose a different name"
52
- )
53
-
54
- # Check if any measures overlap
55
- self._check_overlapping_measures(object_model.measures)
56
-
57
- # If the folder doesnt exist yet, make the folder and save the object
58
- if not (self.input_path / object_model.name).exists():
59
- (self.input_path / object_model.name).mkdir()
60
-
61
- # Save the object and any additional files
62
- object_model.save(
63
- self.input_path / object_model.name / f"{object_model.name}.toml",
64
- )
65
-
66
- def _check_overlapping_measures(self, measures: list[str]):
67
- """Validate if the combination of impact measures can happen, since impact measures cannot affect the same properties.
68
-
69
- Raises
70
- ------
71
- ValueError
72
- information on which combinations of measures have overlapping properties
73
- """
74
- measure_objects = [self._database.measures.get(measure) for measure in measures]
75
- impact_measures = [
76
- measure
77
- for measure in measure_objects
78
- if MeasureType.is_impact(measure.type)
79
- ]
80
-
81
- adapter = self._database.static.get_fiat_model()
82
-
83
- ids = [adapter.get_object_ids(measure) for measure in impact_measures]
84
-
85
- # Get all possible pairs of measures and check overlapping buildings for each measure
86
- combs = list(combinations(enumerate(ids), 2))
87
- common_elements = []
88
- for comb in combs:
89
- common_elements.append(list(set(comb[0][1]).intersection(comb[1][1])))
90
- # If there is any combination with overlapping buildings raise Error and do not allow for Strategy object creation
91
- overlapping = [len(k) > 0 for k in common_elements]
92
-
93
- if any(overlapping):
94
- msg = "Cannot create strategy! There are overlapping buildings for which measures are proposed"
95
- counter = 0
96
- for i, comb in enumerate(combs):
97
- if overlapping[i]:
98
- if counter > 0:
99
- msg += " and"
100
- msg += " between '{}' and '{}'".format(
101
- impact_measures[comb[0][0]].name,
102
- impact_measures[comb[1][0]].name,
103
- )
104
- counter += 1
105
- raise ValueError(msg)
106
-
107
- def check_higher_level_usage(self, name: str) -> list[str]:
108
- """Check if a strategy is used in a scenario.
109
-
110
- Parameters
111
- ----------
112
- name : str
113
- name of the strategy to be checked
114
-
115
- Returns
116
- -------
117
- list[str]
118
- list of scenarios that use the strategy
119
- """
120
- scenarios = [
121
- self._database.scenarios.get(scn)
122
- for scn in self._database.scenarios.summarize_objects()["name"]
123
- ]
124
-
125
- used_in_scenario = [
126
- scenario.name for scenario in scenarios if name == scenario.strategy
127
- ]
128
-
129
- return used_in_scenario
1
+ from itertools import combinations
2
+
3
+ from flood_adapt.dbs_classes.dbs_template import DbsTemplate
4
+ from flood_adapt.misc.exceptions import DatabaseError
5
+ from flood_adapt.objects.measures.measures import MeasureType
6
+ from flood_adapt.objects.strategies.strategies import Strategy
7
+
8
+
9
+ class DbsStrategy(DbsTemplate[Strategy]):
10
+ dir_name = "strategies"
11
+ display_name = "Strategy"
12
+ _object_class = Strategy
13
+
14
+ def get(self, name: str) -> Strategy:
15
+ strategy = super().get(name)
16
+ measures = [
17
+ self._database.measures.get(measure) for measure in strategy.measures
18
+ ]
19
+ strategy.initialize_measure_objects(measures)
20
+ return strategy
21
+
22
+ def save(
23
+ self,
24
+ object_model: Strategy,
25
+ overwrite: bool = False,
26
+ ):
27
+ """Save an object in the database and all associated files.
28
+
29
+ This saves the toml file and any additional files attached to the object.
30
+
31
+ Parameters
32
+ ----------
33
+ object_model : Object
34
+ object to be saved in the database
35
+ overwrite : bool, optional
36
+ whether to overwrite the object if it already exists in the
37
+ database, by default False
38
+
39
+ Raises
40
+ ------
41
+ DatabaseError
42
+ Raise error if name is already in use.
43
+ """
44
+ object_exists = object_model.name in self.summarize_objects()["name"]
45
+
46
+ # If you want to overwrite the object, and the object already exists, first delete it. If it exists and you
47
+ # don't want to overwrite, raise an error.
48
+ if overwrite and object_exists:
49
+ self.delete(object_model.name, toml_only=True)
50
+ elif not overwrite and object_exists:
51
+ raise DatabaseError(
52
+ f"'{object_model.name}' name is already used by another {self.display_name}. Choose a different name"
53
+ )
54
+
55
+ # Check if any measures overlap
56
+ self._check_overlapping_measures(object_model.measures)
57
+
58
+ # If the folder doesnt exist yet, make the folder and save the object
59
+ if not (self.input_path / object_model.name).exists():
60
+ (self.input_path / object_model.name).mkdir()
61
+
62
+ # Save the object and any additional files
63
+ object_model.save(
64
+ self.input_path / object_model.name / f"{object_model.name}.toml",
65
+ )
66
+
67
+ def _check_overlapping_measures(self, measures: list[str]):
68
+ """Validate if the combination of impact measures can happen, since impact measures cannot affect the same properties.
69
+
70
+ Raises
71
+ ------
72
+ DatabaseError
73
+ information on which combinations of measures have overlapping properties
74
+ """
75
+ measure_objects = [self._database.measures.get(measure) for measure in measures]
76
+ impact_measures = [
77
+ measure
78
+ for measure in measure_objects
79
+ if MeasureType.is_impact(measure.type)
80
+ ]
81
+
82
+ adapter = self._database.static.get_fiat_model()
83
+
84
+ ids = [adapter.get_object_ids(measure) for measure in impact_measures]
85
+
86
+ # Get all possible pairs of measures and check overlapping buildings for each measure
87
+ combs = list(combinations(enumerate(ids), 2))
88
+ common_elements = []
89
+ for comb in combs:
90
+ common_elements.append(list(set(comb[0][1]).intersection(comb[1][1])))
91
+ # If there is any combination with overlapping buildings raise Error and do not allow for Strategy object creation
92
+ overlapping = [len(k) > 0 for k in common_elements]
93
+
94
+ if any(overlapping):
95
+ msg = "Cannot create strategy! There are overlapping buildings for which measures are proposed"
96
+ counter = 0
97
+ for i, comb in enumerate(combs):
98
+ if overlapping[i]:
99
+ if counter > 0:
100
+ msg += " and"
101
+ msg += " between '{}' and '{}'".format(
102
+ impact_measures[comb[0][0]].name,
103
+ impact_measures[comb[1][0]].name,
104
+ )
105
+ counter += 1
106
+ raise DatabaseError(msg)
107
+
108
+ def check_higher_level_usage(self, name: str) -> list[str]:
109
+ """Check if a strategy is used in a scenario.
110
+
111
+ Parameters
112
+ ----------
113
+ name : str
114
+ name of the strategy to be checked
115
+
116
+ Returns
117
+ -------
118
+ list[str]
119
+ list of scenarios that use the strategy
120
+ """
121
+ scenarios = [
122
+ self._database.scenarios.get(scn)
123
+ for scn in self._database.scenarios.summarize_objects()["name"]
124
+ ]
125
+
126
+ used_in_scenario = [
127
+ scenario.name for scenario in scenarios if name == scenario.strategy
128
+ ]
129
+
130
+ return used_in_scenario