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,76 +1,77 @@
1
- import shutil
2
-
3
- from flood_adapt.dbs_classes.dbs_template import DbsTemplate
4
- from flood_adapt.workflows.benefit_runner import Benefit, BenefitRunner
5
-
6
-
7
- class DbsBenefit(DbsTemplate[Benefit]):
8
- display_name = "Benefit"
9
- dir_name = "benefits"
10
- _object_class = Benefit
11
-
12
- def save(self, object_model: Benefit, overwrite: bool = False):
13
- """Save a benefit object in the database.
14
-
15
- Parameters
16
- ----------
17
- object_model : Benefit
18
- object of Benefit type
19
- overwrite : bool, optional
20
- whether to overwrite existing benefit with same name, by default False
21
-
22
- Raises
23
- ------
24
- ValueError
25
- Raise error if name is already in use. Names of benefits assessments should be unique.
26
- """
27
- runner = BenefitRunner(self._database, benefit=object_model)
28
-
29
- # Check if all scenarios are created
30
- if not all(runner.scenarios["scenario created"] != "No"):
31
- raise ValueError(
32
- f"'{object_model.name}' name cannot be created before all necessary scenarios are created."
33
- )
34
-
35
- # Save the benefit
36
- super().save(object_model, overwrite=overwrite)
37
-
38
- def delete(self, name: str, toml_only: bool = False):
39
- """Delete an already existing benefit in the database.
40
-
41
- Parameters
42
- ----------
43
- name : str
44
- name of the benefit
45
- toml_only : bool, optional
46
- whether to only delete the toml file or the entire folder. If the folder is empty after deleting the toml,
47
- it will always be deleted. By default False
48
-
49
- Raises
50
- ------
51
- ValueError
52
- Raise error if benefit has already model output
53
- """
54
- # First delete the benefit
55
- super().delete(name, toml_only=toml_only)
56
-
57
- # Delete output if edited
58
- output_path = self.output_path / name
59
- if output_path.exists():
60
- shutil.rmtree(output_path, ignore_errors=True)
61
-
62
- def get_runner(self, name: str) -> BenefitRunner:
63
- return BenefitRunner(self._database, self.get(name))
64
-
65
- def has_run_check(self, name: str) -> bool:
66
- return self.get_runner(name).has_run_check()
67
-
68
- def ready_to_run(self, name: str) -> bool:
69
- """Check if all the required scenarios have already been run.
70
-
71
- Returns
72
- -------
73
- bool
74
- True if required scenarios have been already run
75
- """
76
- return self.get_runner(name).ready_to_run()
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.objects.events.event_factory import EventFactory
5
- from flood_adapt.objects.events.events import Event
6
-
7
-
8
- class DbsEvent(DbsTemplate[Event]):
9
- dir_name = "events"
10
- display_name = "Event"
11
- _object_class = Event
12
-
13
- def get(self, name: str) -> Event:
14
- """Return an event object.
15
-
16
- Parameters
17
- ----------
18
- name : str
19
- name of the event to be returned
20
-
21
- Returns
22
- -------
23
- Event
24
- event object
25
- """
26
- # Get event path
27
- event_path = self.input_path / f"{name}" / f"{name}.toml"
28
-
29
- # Check if the object exists
30
- if not Path(event_path).is_file():
31
- raise ValueError(f"{self.display_name} '{name}' does not exist.")
32
-
33
- # Load event
34
- return EventFactory.load_file(event_path)
35
-
36
- def check_higher_level_usage(self, name: str) -> list[str]:
37
- """Check if an event is used in a scenario.
38
-
39
- Parameters
40
- ----------
41
- name : str
42
- name of the event to be checked
43
-
44
- Returns
45
- -------
46
- list[str]
47
- list of scenarios that use the event
48
- """
49
- # Get all the scenarios
50
- scenarios = [
51
- self._database.scenarios.get(scn)
52
- for scn in self._database.scenarios.summarize_objects()["name"]
53
- ]
54
-
55
- # Check if event is used in a scenario
56
- used_in_scenario = [
57
- scenario.name for scenario in scenarios if name == scenario.event
58
- ]
59
- return used_in_scenario
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.utils import resolve_filepath
8
- from flood_adapt.objects.measures.measure_factory import MeasureFactory
9
- from flood_adapt.objects.measures.measures import Measure
10
-
11
-
12
- class DbsMeasure(DbsTemplate[Measure]):
13
- dir_name = "measures"
14
- display_name = "Measure"
15
- _object_class = Measure
16
-
17
- def get(self, name: str) -> Measure:
18
- """Return a measure object.
19
-
20
- Parameters
21
- ----------
22
- name : str
23
- name of the measure to be returned
24
-
25
- Returns
26
- -------
27
- Measure
28
- measure object
29
- """
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)
39
-
40
- def summarize_objects(self) -> dict[str, list[Any]]:
41
- """Return a dictionary with info on the measures that currently exist in the database.
42
-
43
- Returns
44
- -------
45
- dict[str, Any]
46
- Includes 'name', 'description', 'path' and 'last_modification_date' and 'geometry' info
47
- """
48
- measures = self._get_object_summary()
49
- objects = [self.get(name) for name in measures["name"]]
50
-
51
- geometries = []
52
- for obj in objects:
53
- # If polygon is used read the polygon file
54
- if hasattr(obj, "polygon_file") and obj.polygon_file:
55
- src_path = resolve_filepath(
56
- object_dir=self.dir_name,
57
- obj_name=obj.name,
58
- path=obj.polygon_file,
59
- )
60
- geometries.append(gpd.read_file(src_path))
61
- # If aggregation area is used read the polygon from the aggregation area name
62
- elif hasattr(obj, "aggregation_area_name") and obj.aggregation_area_name:
63
- if (
64
- obj.aggregation_area_type
65
- not in self._database.static.get_aggregation_areas()
66
- ):
67
- raise ValueError(
68
- f"Aggregation area type {obj.aggregation_area_type} for measure {obj.name} does not exist."
69
- )
70
- gdf = self._database.static.get_aggregation_areas()[
71
- obj.aggregation_area_type
72
- ]
73
- if obj.aggregation_area_name not in gdf["name"].to_numpy():
74
- raise ValueError(
75
- f"Aggregation area name {obj.aggregation_area_name} for measure {obj.name} does not exist."
76
- )
77
- geometries.append(gdf.loc[gdf["name"] == obj.aggregation_area_name, :])
78
- # Else assign a None value
79
- else:
80
- geometries.append(None)
81
-
82
- measures["geometry"] = geometries
83
- return measures
84
-
85
- def check_higher_level_usage(self, name: str) -> list[str]:
86
- """Check if a measure is used in a strategy.
87
-
88
- Parameters
89
- ----------
90
- name : str
91
- name of the measure to be checked
92
-
93
- Returns
94
- -------
95
- list[str]
96
- list of strategies that use the measure
97
- """
98
- # Get all the strategies
99
- strategies = [
100
- self._database.strategies.get(strategy)
101
- for strategy in self._database.strategies.summarize_objects()["name"]
102
- ]
103
-
104
- # Check if measure is used in a strategy
105
- used_in_strategy = [
106
- strategy.name
107
- for strategy in strategies
108
- for measure in strategy.measures
109
- if name == measure
110
- ]
111
- return used_in_strategy
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