flood-adapt 0.3.2__py3-none-any.whl → 0.3.4__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.
@@ -38,6 +38,7 @@ from flood_adapt.objects.projections.projections import Projection
38
38
  from flood_adapt.objects.scenarios.scenarios import Scenario
39
39
  from flood_adapt.objects.strategies.strategies import Strategy
40
40
  from flood_adapt.workflows.impacts_integrator import Impacts
41
+ from flood_adapt.workflows.scenario_runner import ScenarioRunner
41
42
 
42
43
 
43
44
  class FloodAdapt:
@@ -68,7 +69,7 @@ class FloodAdapt:
68
69
  Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
69
70
  Each value is a list of the corresponding attribute for each measure.
70
71
  """
71
- return self.database.measures.list_objects()
72
+ return self.database.measures.summarize_objects()
72
73
 
73
74
  def get_measure(self, name: str) -> Measure:
74
75
  """
@@ -208,7 +209,7 @@ class FloodAdapt:
208
209
  Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
209
210
  Each value is a list of the corresponding attribute for each strategy.
210
211
  """
211
- return self.database.strategies.list_objects()
212
+ return self.database.strategies.summarize_objects()
212
213
 
213
214
  def get_strategy(self, name: str) -> Strategy:
214
215
  """
@@ -310,7 +311,7 @@ class FloodAdapt:
310
311
  Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
311
312
  Each value is a list of the corresponding attribute for each benefit.
312
313
  """
313
- return self.database.events.list_objects()
314
+ return self.database.events.summarize_objects()
314
315
 
315
316
  def get_event(self, name: str) -> Event | EventSet:
316
317
  """Get an event from the database by name.
@@ -476,7 +477,7 @@ class FloodAdapt:
476
477
  Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'
477
478
  Each value is a list of the corresponding attribute for each projection.
478
479
  """
479
- return self.database.projections.list_objects()
480
+ return self.database.projections.summarize_objects()
480
481
 
481
482
  def get_projection(self, name: str) -> Projection:
482
483
  """Get a projection from the database by name.
@@ -633,7 +634,7 @@ class FloodAdapt:
633
634
  Includes keys: 'name', 'description', 'path', 'last_modification_date', 'objects'.
634
635
  Each value is a list of the corresponding attribute for each scenario.
635
636
  """
636
- return self.database.scenarios.list_objects()
637
+ return self.database.scenarios.summarize_objects()
637
638
 
638
639
  def get_scenario(self, name: str) -> Scenario:
639
640
  """Get a scenario from the database by name.
@@ -726,20 +727,26 @@ class FloodAdapt:
726
727
  """
727
728
  self.database.scenarios.delete(name)
728
729
 
729
- def run_scenario(self, name: Union[str, list[str]]) -> None:
730
- """Run a scenario.
730
+ def run_scenario(self, scenario_name: Union[str, list[str]]) -> None:
731
+ """Run a scenario hazard and impacts.
731
732
 
732
733
  Parameters
733
734
  ----------
734
- name : Union[str, list[str]]
735
- The name(s) of the scenario to run.
735
+ scenario_name : Union[str, list[str]]
736
+ name(s) of the scenarios to run.
736
737
 
737
738
  Raises
738
739
  ------
739
- ValueError
740
- If the scenario does not exist.
740
+ RuntimeError
741
+ If an error occurs while running one of the scenarios
741
742
  """
742
- self.database.run_scenario(name)
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()
743
750
 
744
751
  # Outputs
745
752
  def get_completed_scenarios(
@@ -1088,7 +1095,7 @@ class FloodAdapt:
1088
1095
  Each value is a list of the corresponding attribute for each benefit.
1089
1096
  """
1090
1097
  # sorting and filtering either with PyQt table or in the API
1091
- return self.database.benefits.list_objects()
1098
+ return self.database.benefits.summarize_objects()
1092
1099
 
1093
1100
  def get_benefit(self, name: str) -> Benefit:
1094
1101
  """Get a benefit from the database by name.
@@ -0,0 +1,92 @@
1
+ from flood_adapt.objects.forcing.discharge import (
2
+ DischargeConstant,
3
+ DischargeCSV,
4
+ DischargeSynthetic,
5
+ )
6
+ from flood_adapt.objects.forcing.forcing import ForcingSource, ForcingType, IForcing
7
+ from flood_adapt.objects.forcing.meteo_handler import MeteoHandler
8
+ from flood_adapt.objects.forcing.rainfall import (
9
+ RainfallConstant,
10
+ RainfallCSV,
11
+ RainfallMeteo,
12
+ RainfallNetCDF,
13
+ RainfallSynthetic,
14
+ RainfallTrack,
15
+ )
16
+ from flood_adapt.objects.forcing.tide_gauge import TideGauge, TideGaugeSource
17
+ from flood_adapt.objects.forcing.time_frame import TimeFrame
18
+ from flood_adapt.objects.forcing.timeseries import (
19
+ BlockTimeseries,
20
+ CSVTimeseries,
21
+ GaussianTimeseries,
22
+ ScsTimeseries,
23
+ Scstype,
24
+ ShapeType,
25
+ SyntheticTimeseries,
26
+ TimeseriesFactory,
27
+ TriangleTimeseries,
28
+ )
29
+ from flood_adapt.objects.forcing.waterlevels import (
30
+ SurgeModel,
31
+ TideModel,
32
+ WaterlevelCSV,
33
+ WaterlevelGauged,
34
+ WaterlevelModel,
35
+ WaterlevelSynthetic,
36
+ )
37
+ from flood_adapt.objects.forcing.wind import (
38
+ WindConstant,
39
+ WindCSV,
40
+ WindMeteo,
41
+ WindNetCDF,
42
+ WindSynthetic,
43
+ WindTrack,
44
+ )
45
+
46
+ __all__ = [
47
+ # Forcing
48
+ "IForcing",
49
+ "ForcingSource",
50
+ "ForcingType",
51
+ # Timeseries
52
+ "ShapeType",
53
+ "Scstype",
54
+ "CSVTimeseries",
55
+ "TimeseriesFactory",
56
+ "SyntheticTimeseries",
57
+ "BlockTimeseries",
58
+ "ScsTimeseries",
59
+ "GaussianTimeseries",
60
+ "TriangleTimeseries",
61
+ # TimeFrame
62
+ "TimeFrame",
63
+ # Discharge
64
+ "DischargeConstant",
65
+ "DischargeCSV",
66
+ "DischargeSynthetic",
67
+ # Waterlevels
68
+ "WaterlevelCSV",
69
+ "WaterlevelGauged",
70
+ "WaterlevelModel",
71
+ "WaterlevelSynthetic",
72
+ "TideModel",
73
+ "SurgeModel",
74
+ "TideGauge",
75
+ "TideGaugeSource",
76
+ # Rainfall
77
+ "RainfallConstant",
78
+ "RainfallCSV",
79
+ "RainfallSynthetic",
80
+ "RainfallMeteo",
81
+ "RainfallNetCDF",
82
+ "RainfallTrack",
83
+ # Wind
84
+ "WindConstant",
85
+ "WindCSV",
86
+ "WindSynthetic",
87
+ "WindMeteo",
88
+ "WindNetCDF",
89
+ "WindTrack",
90
+ # Other
91
+ "MeteoHandler",
92
+ ]
@@ -117,7 +117,10 @@ class BenefitRunner:
117
117
  scenarios_calc[scenario]["strategy"] = self.benefit.strategy
118
118
 
119
119
  # Get the available scenarios
120
- scenarios_avail = self.database.scenarios.list_objects()["objects"]
120
+ scenarios_avail = [
121
+ self.database.scenarios.get(scn)
122
+ for scn in self.database.scenarios.summarize_objects()["name"]
123
+ ]
121
124
 
122
125
  # Check if any of the needed scenarios are already there
123
126
  for scenario in scenarios_calc.keys():
@@ -30,16 +30,17 @@ class ScenarioRunner:
30
30
  scenario=self._scenario,
31
31
  )
32
32
 
33
- def run(self, scenario: Scenario) -> None:
33
+ def run(self) -> None:
34
34
  """Run hazard and impact models for the scenario."""
35
- self._load_objects(scenario)
35
+ self._database.has_run_hazard(self._scenario.name)
36
+ self._load_objects(self._scenario)
36
37
  self.results_path.mkdir(parents=True, exist_ok=True)
37
38
 
38
39
  # Initiate the logger for all the integrator scripts.
39
- log_file = self.results_path.joinpath(f"logfile_{scenario.name}.log")
40
+ log_file = self.results_path.joinpath(f"logfile_{self._scenario.name}.log")
40
41
  with FloodAdaptLogging.to_file(file_path=log_file):
41
42
  self.logger.info(f"FloodAdapt version `{__version__}`")
42
- self.logger.info(f"Started evaluation of `{scenario.name}`")
43
+ self.logger.info(f"Started evaluation of `{self._scenario.name}`")
43
44
 
44
45
  hazard_models = [
45
46
  self._database.static.get_overland_sfincs_model(),
@@ -49,17 +50,17 @@ class ScenarioRunner:
49
50
  hazard.run(self._scenario)
50
51
  else:
51
52
  self.logger.info(
52
- f"Hazard for scenario '{scenario.name}' has already been run."
53
+ f"Hazard for scenario '{self._scenario.name}' has already been run."
53
54
  )
54
55
 
55
56
  if not self.impacts.has_run:
56
57
  self.impacts.run()
57
58
  else:
58
59
  self.logger.info(
59
- f"Impacts for scenario `{scenario.name}` has already been run."
60
+ f"Impacts for scenario `{self._scenario.name}` has already been run."
60
61
  )
61
62
 
62
- self.logger.info(f"Finished evaluation of `{scenario.name}`")
63
+ self.logger.info(f"Finished evaluation of `{self._scenario.name}`")
63
64
 
64
65
  # write finished file to indicate that the scenario has been run
65
66
  write_finished_file(self.results_path)