Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(adapter,object-model): Add adapter interfaces and refactor SficnsAdapter to use it. Also refactor events to use modular forcings #473

Open
wants to merge 170 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
11aa91c
refactor: implement IHazardAdapter
LuukBlom Jun 17, 2024
0656943
cleanup of sfincsadapter, make distinction between public and private…
LuukBlom Jun 19, 2024
e9a587c
rename private member variables to start with '_'
LuukBlom Jun 19, 2024
bed4ac1
Implement timeseries class
LuukBlom Jun 20, 2024
a019ede
feat: work on timeseries class + tests
LuukBlom Jun 21, 2024
3ab045e
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Jun 24, 2024
c1346b9
implement minor review comments
LuukBlom Jun 25, 2024
f00d548
Merge branch 'main' of https://github.com/Deltares-research/FloodAdap…
LuukBlom Jun 25, 2024
6c6a879
first implementation of historical events
LuukBlom Jun 25, 2024
08d1c6c
work on historical event & forcing implementation
LuukBlom Jun 26, 2024
d6d275e
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Jul 1, 2024
d02387c
implement historical event class
LuukBlom Jul 1, 2024
877c560
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Jul 2, 2024
0d06b2f
Separate interfaces and concrete implementations
LuukBlom Jul 2, 2024
2793500
fix timeseries tests and fix unitfulvalue conversion factors
LuukBlom Jul 8, 2024
8304c8d
added tests for unitfulvalue
LuukBlom Jul 9, 2024
776220b
add waterlevel synthetic forcing test
LuukBlom Jul 11, 2024
07deed7
change importing of the database to stop circular imports
LuukBlom Jul 12, 2024
eac06b6
implement waterlevelFromModel + 1 test
LuukBlom Jul 12, 2024
06acb05
waterlevel forcings completed
LuukBlom Jul 15, 2024
ea9d0a9
reworked the calculation/adding of synthetic timeseries
LuukBlom Jul 17, 2024
5e1c5a9
add tests for forcings and forcing factory, implement hurricane
LuukBlom Jul 22, 2024
0586d32
cleanup tests
LuukBlom Jul 22, 2024
90cea4d
Implement discharge tests
LuukBlom Jul 23, 2024
38bf63c
add tests for sfincsAdapter::add_discharge_forcing
LuukBlom Jul 24, 2024
29394df
Implement FloodMap class. Refactor scenario.run() to use the new Sfin…
LuukBlom Jul 24, 2024
94a0134
add accidentally removed functions back in sfincsadapter
LuukBlom Jul 25, 2024
9a6b16e
revert Unittypesintensity `_` to `/`
LuukBlom Jul 26, 2024
88dcfb4
add abstract class IDatabaseUser to stop circular imports wrt the Dat…
LuukBlom Jul 26, 2024
54892eb
fix tests so the IDatabaseUser-Children are green again
LuukBlom Jul 26, 2024
47e1dbb
implement tests for measures and projections.
LuukBlom Jul 30, 2024
226ea55
get scneario.run working - hazard part
LuukBlom Jul 31, 2024
dd3eed0
fix errors in other parts of the code
Jul 31, 2024
2e60737
resolve merge conflicts
Jul 31, 2024
538eb7d
create meteo.py with static functions for downloading and reading.
Jul 31, 2024
525335f
add deprecation warnings for old database usages
Jul 31, 2024
7f547bc
add deprecation warnings, black and ruff
Jul 31, 2024
d3f655b
cleanup
Jul 31, 2024
366b147
Add (de-)serialization for forcings.
Aug 1, 2024
d7d73ba
partly implement eventset
Aug 1, 2024
d327acf
eventset implementation now working, fiat crashes unfortunately
Aug 2, 2024
c444cb4
feat: Add CRS field to SiteModel
Aug 5, 2024
97a2a20
added functions to the factories for use in the gui
Aug 6, 2024
4e91e2e
chore: include default methods for different forcing & event types
Aug 8, 2024
939f41e
chore: Refactor default and get_data methods in event and forcing cla…
Aug 15, 2024
3bfafa7
fix discharge synthetic get_data function
Aug 22, 2024
f327b49
implement save_additional()
LuukBlom Sep 19, 2024
d0cc37d
move read_csv to io
LuukBlom Sep 20, 2024
7f868ee
fix tests
LuukBlom Oct 1, 2024
7f60ad4
fix tests for eventset
LuukBlom Oct 2, 2024
fd4e5a5
add tests for meteo and tests for sfincsadapter
LuukBlom Oct 2, 2024
0ea3e3b
Ignore flood_adapt/system in gitignore
LuukBlom Oct 2, 2024
389048d
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Oct 2, 2024
abdfe13
fix merge conflicts
LuukBlom Oct 2, 2024
2490f26
add logic for reading csv timeseries files that contain more data tha…
LuukBlom Oct 4, 2024
03e63d2
add tests for csv module
LuukBlom Oct 7, 2024
b4c49bd
added dditional_files arg to all save() functions of object models.
LuukBlom Oct 11, 2024
618301b
implement saving additional files for all object_models. TODO add tes…
LuukBlom Oct 11, 2024
377fea3
WIP tests additional files. TODO finish event tests
LuukBlom Oct 14, 2024
15b0e8e
finish tests for events and measures
LuukBlom Oct 14, 2024
ba8f5d7
Merge branch 'main' into 553-new-development-area-shapefile-not-copie…
LuukBlom Oct 14, 2024
613e76a
go through PR and fix mistakes
LuukBlom Oct 15, 2024
50f2408
remove dditional_files argument and make default behaviour to always…
LuukBlom Oct 15, 2024
20f8fd7
Merge branch 'main' into 553-new-development-area-shapefile-not-copie…
LuukBlom Oct 15, 2024
1a03896
Whoops huge commit.
LuukBlom Oct 21, 2024
81396ad
small bug fixes + rename of util func
LuukBlom Oct 21, 2024
8ff7f38
moved code from pathbuilder to interface.database
LuukBlom Oct 22, 2024
287a269
revert pathbuilder change due to circular dependency
LuukBlom Oct 22, 2024
54e3dd0
finish implementation and use of IObject subclasses in other parts of…
LuukBlom Oct 22, 2024
5264ab6
temporary fix for until the hazard refactor to prevent trying to read…
LuukBlom Oct 22, 2024
0741ece
go through PR and fix obvious stuff
LuukBlom Oct 22, 2024
2fd69d7
Fix tide gauge implementation. get gui working again so Sarah can do …
LuukBlom Oct 23, 2024
c4dac3d
bugfix read_csv
LuukBlom Oct 24, 2024
6679000
Add MeteoHandler class + tests
LuukBlom Oct 25, 2024
c03dbfe
remove meteohandler from class attribute and construct it in the get_…
LuukBlom Oct 28, 2024
33b7498
corrected small bug when calling the resolve_filepath method
panosatha Oct 29, 2024
658a3e6
fix file handling for events
LuukBlom Oct 30, 2024
1fa9b8d
Merge branch '553-new-development-area-shapefile-not-copied-in-projec…
LuukBlom Oct 30, 2024
3c92acc
remove obsolete api func
LuukBlom Oct 30, 2024
e5f9eb1
Merge branch 'main' into 553-new-development-area-shapefile-not-copie…
LuukBlom Oct 30, 2024
ea23e77
remove duplicate api func
LuukBlom Oct 30, 2024
f0ce9f2
filter invalid datetime from index to stop errors in hydromt-sfincs
LuukBlom Oct 31, 2024
2b6e0a3
move validation of overlapping measures to the save function of dbs_s…
LuukBlom Nov 1, 2024
1b49e25
make sure that shapefiles can correctly be imported to the database
panosatha Nov 1, 2024
900f772
added overlapping measures check to dbs_strategy
LuukBlom Nov 1, 2024
5c00c24
api correction
panosatha Nov 1, 2024
a4c1736
Merge branch '553-new-development-area-shapefile-not-copied-in-projec…
LuukBlom Nov 1, 2024
ac15f72
instead of saving the name, also save the index in the cyc_db as ther…
LuukBlom Nov 1, 2024
a186cd4
hurricanes events expect either a .cyc file in the same dir as the to…
LuukBlom Nov 1, 2024
ca912ca
fixed broken test
LuukBlom Nov 1, 2024
4e52892
fixed error for meteo no data exception raised in hydromt data
LuukBlom Nov 4, 2024
fd285fe
removed mocking in the tests for sfincs adapter.
LuukBlom Nov 4, 2024
8d70785
WIP wind synthetic in the frontend
LuukBlom Nov 5, 2024
e665c5f
fix copying of objects with additional files
LuukBlom Nov 5, 2024
79c10af
update allowed forcings
LuukBlom Nov 5, 2024
1ff540e
wip hurricanes
LuukBlom Nov 6, 2024
9c5d16b
finished hurricane event implementation
LuukBlom Nov 6, 2024
4d909a8
update rainfall_increase attribute to multiplier and improve rainfall…
LuukBlom Nov 7, 2024
a81e22c
save all additional files by default
LuukBlom Nov 11, 2024
87f8ef1
bugfix save_additional
LuukBlom Nov 11, 2024
c82c4f4
fix api output -> infographics to use the FloodMap class
LuukBlom Nov 11, 2024
e1c7dbf
added imports to expose to the api
LuukBlom Nov 11, 2024
85cf446
WIP commit
LuukBlom Nov 14, 2024
6d42bd7
implement discharge forcings to have a rivermodel
LuukBlom Nov 15, 2024
223a191
bugfix hurricane event handling of spw files
LuukBlom Nov 15, 2024
542ee85
cleanup imports
LuukBlom Nov 18, 2024
0194fea
WIP impl save_additional
LuukBlom Nov 18, 2024
ac89988
fix merge conflicts and tests
LuukBlom Nov 18, 2024
2541b2b
added generic typevar to dbstemplate so typechecking works again
LuukBlom Nov 19, 2024
543cf9f
added unitsystem configuration to Settings class
LuukBlom Nov 19, 2024
0bd4d19
added generic T to fix load_file and load_dict return types
LuukBlom Nov 19, 2024
c74bfb0
add get_forcings() to event class
LuukBlom Nov 19, 2024
a352224
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Nov 19, 2024
4933a72
cleanup of functions in sfincsadapter
LuukBlom Nov 20, 2024
2d33c57
?
LuukBlom Nov 20, 2024
1fcee01
remove newlines from template description since they are added in the…
LuukBlom Nov 20, 2024
9e28400
standardize imports
LuukBlom Nov 20, 2024
6915f32
fixed broken property
LuukBlom Nov 20, 2024
5579820
added rainfallCSV
LuukBlom Nov 20, 2024
3561d31
added scs + tests
LuukBlom Nov 21, 2024
2d6e886
improve flexibility for plotting
LuukBlom Nov 21, 2024
f221d94
prevent SameFileError when copying SPW file and add test for SCS shap…
LuukBlom Nov 21, 2024
1aceb44
added a test for 2 rivers
LuukBlom Nov 21, 2024
ede36d2
replace print statements with logger statements
LuukBlom Nov 21, 2024
1ba14e6
WIP commit offshorehandler
LuukBlom Nov 25, 2024
f147d97
added logging statements
LuukBlom Nov 25, 2024
52a3c40
removed logging from database user
LuukBlom Nov 26, 2024
8868dd7
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Nov 26, 2024
441f92a
update .vscode and settings
LuukBlom Nov 26, 2024
380bb55
cleanup commented settings
LuukBlom Nov 26, 2024
3589300
refactor imports in tests to use pytest config
LuukBlom Nov 26, 2024
d3d27ee
use type instead of str
LuukBlom Nov 26, 2024
4041b3b
WIP unitsystem
LuukBlom Nov 27, 2024
4bd0d06
simplify measures in the backend by removing HazardType & ImpactType …
LuukBlom Nov 27, 2024
17bf4b0
refactor: update method signatures and improve type handling across m…
LuukBlom Nov 28, 2024
c21db4d
refactor discharge handling, improve event interfacing / event sets
LuukBlom Dec 2, 2024
0fbffaf
enhance event model by adding SYNTHETIC source to DISCHARGE forcing t…
LuukBlom Dec 2, 2024
5d5dbd2
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Dec 2, 2024
14a9db2
delete hazard.py
LuukBlom Dec 2, 2024
83fd0d7
refactor: implement context management for FiatAdapter and update dir…
LuukBlom Dec 3, 2024
ecaad2f
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Dec 3, 2024
e45b256
improve asserts in tests for sfincs adapter. Added mocking for expens…
LuukBlom Dec 3, 2024
37b9e34
refactor: add_meteo_forcing tests to use mocked download meteo calls
LuukBlom Dec 4, 2024
8fb0df1
reduce the amount of time meteo downloads take in tests
LuukBlom Dec 5, 2024
732a304
improve sfincs adapter tests
LuukBlom Dec 5, 2024
c1b35b3
add imports in api to expose to gui
LuukBlom Dec 5, 2024
5fb360d
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Dec 5, 2024
485e5bb
get latest docs from main
LuukBlom Dec 6, 2024
77b2c8d
fix(object-model,dbs): Extracted draw hurricane track to a function a…
LuukBlom Dec 6, 2024
ad23749
remove obsolete comment
LuukBlom Dec 6, 2024
63b76b9
fix(doc): install tomli_w when building docs in ci
savente93 Dec 9, 2024
c3a07de
fix(doc): fix typo in dependency in ci
savente93 Dec 9, 2024
5e993d9
Implement review comments from Sam
LuukBlom Dec 10, 2024
00b883b
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Dec 10, 2024
524e10d
fix bug in discharge unit conversion
LuukBlom Dec 12, 2024
b78ac9d
fix discharge conversion bug
LuukBlom Dec 12, 2024
ddc81f1
change default cumulative unit from feet to inch and meters to millim…
LuukBlom Dec 12, 2024
5155ff8
Use mean discharge as the default for the constant discharge
LuukBlom Dec 13, 2024
360812f
bugfix constant timeseries
LuukBlom Dec 13, 2024
6c4ef14
bugfixes for the timeseries calculators + added tests
LuukBlom Dec 13, 2024
971edc1
added fill_value in syntheticTimeseries for use as base discharge
LuukBlom Dec 16, 2024
6011c18
Merge branch 'main' into refactor/hazard-adapter-and-events
LuukBlom Dec 16, 2024
29d20a5
bugfix rp_floodmap calculation + tests
LuukBlom Dec 17, 2024
7bad974
WIP move code from forcing get_data to sfincs adapter
LuukBlom Dec 19, 2024
15b2798
WIP remove get_Data functions to be more explicit: forcings contain o…
LuukBlom Dec 20, 2024
7ecf598
add to_dataframe method to forcings where it makes sense
LuukBlom Dec 20, 2024
cd06e87
cleanup to_dataframe function signature
LuukBlom Dec 30, 2024
29cde22
cleanup plotting functions
LuukBlom Dec 30, 2024
c8ddb63
fixed unit conversions for sfincs adapter
LuukBlom Dec 31, 2024
a306238
feat(adapters): ensure there are no forcings in the model since these…
LuukBlom Jan 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions flood_adapt/api/benefits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,47 @@
import geopandas as gpd
import pandas as pd

from flood_adapt.dbs_controller import Database
import flood_adapt.dbs_controller as db
from flood_adapt.object_model.benefit import Benefit
from flood_adapt.object_model.interface.benefits import IBenefit


def get_benefits() -> dict[str, Any]:
# sorting and filtering either with PyQt table or in the API
return Database().benefits.list_objects()
return db.Database().benefits.list_objects()


def get_benefit(name: str) -> IBenefit:
return Database().benefits.get(name)
return db.Database().benefits.get(name)


def create_benefit(attrs: dict[str, Any]) -> IBenefit:
return Benefit.load_dict(attrs, Database().input_path)
return Benefit.load_dict(attrs, db.Database().input_path)


def save_benefit(benefit: IBenefit) -> None:
Database().benefits.save(benefit)
db.Database().benefits.save(benefit)


def edit_benefit(benefit: IBenefit) -> None:
Database().benefits.edit(benefit)
db.Database().benefits.edit(benefit)


def delete_benefit(name: str) -> None:
Database().benefits.delete(name)
db.Database().benefits.delete(name)


def check_benefit_scenarios(benefit: IBenefit) -> pd.DataFrame:
return Database().check_benefit_scenarios(benefit)
return db.Database().check_benefit_scenarios(benefit)


def create_benefit_scenarios(benefit: IBenefit):
Database().create_benefit_scenarios(benefit)
db.Database().create_benefit_scenarios(benefit)


def run_benefit(name: Union[str, list[str]]) -> None:
Database().run_benefit(name)
db.Database().run_benefit(name)


def get_aggregation_benefits(name: str) -> dict[gpd.GeoDataFrame]:
return Database().get_aggregation_benefits(name)
return db.Database().get_aggregation_benefits(name)
108 changes: 26 additions & 82 deletions flood_adapt/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,150 +5,94 @@
import pandas as pd
from cht_cyclones.tropical_cyclone import TropicalCyclone

from flood_adapt.dbs_controller import Database
from flood_adapt.object_model.hazard.event.event import Event
import flood_adapt.dbs_controller as db
from flood_adapt.object_model.hazard.event.event_factory import EventFactory
from flood_adapt.object_model.hazard.event.historical_nearshore import (
HistoricalNearshore,
)
from flood_adapt.object_model.interface.events import (
IEvent,
IHistoricalHurricane,
IHistoricalNearshore,
IHistoricalOffshore,
ISynthetic,
)
from flood_adapt.object_model.hazard.event.historical import HistoricalEvent
from flood_adapt.object_model.hazard.interface.events import IEvent, IEventModel
from flood_adapt.object_model.io.unitfulvalue import UnitTypesLength


def get_events() -> dict[str, Any]:
# use PyQt table / sorting and filtering either with PyQt table or in the API
return Database().events.list_objects()
return db.Database().events.list_objects()


def get_event(name: str) -> IEvent:
return Database().events.get(name)
return db.Database().events.get(name)


def get_event_mode(name: str) -> str:
filename = Database().events.get_database_path() / f"{name}" / f"{name}.toml"
return Event.get_mode(filename)
filename = db.Database().events.get_database_path() / f"{name}" / f"{name}.toml"
return EventFactory.get_mode(filename)


def create_synthetic_event(attrs: dict[str, Any]) -> ISynthetic:
"""Create a synthetic event object from a dictionary of attributes.
def create_event(attrs: dict[str, Any] | IEventModel) -> IEvent:
"""Create a event object from a dictionary of attributes.

Parameters
----------
attrs : dict[str, Any]
attrs : IEventModel [str, Any]
Dictionary of attributes

Returns
-------
Synthetic
Synthetic event object
IEvent
Depending on attrs.template an event object.
Can be of type: Synthetic, Historical_nearshore, Historical_offshore, or Historical_hurricane.
"""
return EventFactory.get_event("Synthetic").load_dict(attrs)


def create_historical_nearshore_event(attrs: dict[str, Any]) -> IHistoricalNearshore:
"""Create a historical nearshore event object from a dictionary of attributes.

Parameters
----------
attrs : dict[str, Any]
Dictionary of attributes

Returns
-------
HistoricalNearshore
Historical nearshore event object
"""
return EventFactory.get_event("Historical_nearshore").load_dict(attrs)


def create_historical_offshore_event(attrs: dict[str, Any]) -> IHistoricalOffshore:
"""Create a historical offshore event object from a dictionary of attributes.

Parameters
----------
attrs : dict[str, Any]
Dictionary of attributes

Returns
-------
HistoricalNearshore
Historical offshore event object
"""
return EventFactory.get_event("Historical_offshore").load_dict(attrs)


def create_historical_hurricane_event(attrs: dict[str, Any]) -> IHistoricalHurricane:
"""Create a historical hurricane event object from a dictionary of attributes.

Parameters
----------
attrs : dict[str, Any]
Dictionary of attributes

Returns
-------
HistoricalHurricane
Historical hurricane event object
"""
return EventFactory.get_event("Historical_hurricane").load_dict(attrs)
return EventFactory.load_dict(attrs)


def save_event_toml(event: IEvent) -> None:
Database().events.save(event)
db.Database().events.save(event)


def save_timeseries_csv(name: str, event: IEvent, df: pd.DataFrame) -> None:
Database().write_to_csv(name, event, df)
db.Database().write_to_csv(name, event, df)


def edit_event(event: IEvent) -> None:
Database().events.edit(event)
db.Database().events.edit(event)


def delete_event(name: str) -> None:
Database().events.delete(name)
db.Database().events.delete(name)


def copy_event(old_name: str, new_name: str, new_description: str) -> None:
Database().events.copy(old_name, new_name, new_description)
db.Database().events.copy(old_name, new_name, new_description)


def download_wl_data(
station_id, start_time, end_time, units: UnitTypesLength, source: str, file=None
) -> pd.DataFrame:
return HistoricalNearshore.download_wl_data(
return HistoricalEvent.download_wl_data(
station_id, start_time, end_time, units, source, file
)


def read_csv(csvpath: Union[str, os.PathLike]) -> pd.DataFrame:
return Event.read_csv(csvpath)
return IEvent.read_csv(csvpath)


def plot_wl(event: IEvent, input_wl_df: pd.DataFrame = None) -> str:
return Database().plot_wl(event, input_wl_df)
return db.Database().plot_wl(event, input_wl_df)


def plot_river(
event: IEvent,
input_river_df: list[pd.DataFrame],
) -> str:
return Database().plot_river(event, input_river_df)
return db.Database().plot_river(event, input_river_df)


def plot_rainfall(event: IEvent, input_rainfall_df: pd.DataFrame = None) -> str:
return Database().plot_rainfall(event, input_rainfall_df)
return db.Database().plot_rainfall(event, input_rainfall_df)


def plot_wind(event: IEvent, input_wind_df: pd.DataFrame = None) -> str:
return Database().plot_wind(event, input_wind_df)
return db.Database().plot_wind(event, input_wind_df)


def save_cyclone_track(event: IEvent, track: TropicalCyclone):
Database().write_cyc(event, track)
db.Database().write_cyc(event, track)
18 changes: 9 additions & 9 deletions flood_adapt/api/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import geopandas as gpd
import pandas as pd

from flood_adapt.dbs_controller import Database
import flood_adapt.dbs_controller as db
from flood_adapt.object_model.direct_impact.measure.buyout import Buyout
from flood_adapt.object_model.direct_impact.measure.elevate import Elevate
from flood_adapt.object_model.direct_impact.measure.floodproof import FloodProof
Expand All @@ -19,11 +19,11 @@


def get_measures() -> dict[str, Any]:
return Database().measures.list_objects()
return db.Database().measures.list_objects()


def get_measure(name: str) -> IMeasure:
return Database().measures.get(name)
return db.Database().measures.get(name)


def create_measure(attrs: dict[str, Any], type: str = None) -> IMeasure:
Expand All @@ -44,7 +44,7 @@ def create_measure(attrs: dict[str, Any], type: str = None) -> IMeasure:
Measure object.
"""
# If a database is provided, use it to set the input path for the measure. Otherwise, set it to None.
database_path = Database().input_path
database_path = db.Database().input_path

if type == "elevate_properties":
return Elevate.load_dict(attrs, database_path)
Expand All @@ -61,19 +61,19 @@ def create_measure(attrs: dict[str, Any], type: str = None) -> IMeasure:


def save_measure(measure: IMeasure) -> None:
Database().measures.save(measure)
db.Database().measures.save(measure)


def edit_measure(measure: IMeasure) -> None:
Database().measures.edit(measure)
db.Database().measures.edit(measure)


def delete_measure(name: str) -> None:
Database().measures.delete(name)
db.Database().measures.delete(name)


def copy_measure(old_name: str, new_name: str, new_description: str) -> None:
Database().measures.copy(old_name, new_name, new_description)
db.Database().measures.copy(old_name, new_name, new_description)


# Green infrastructure
Expand All @@ -90,4 +90,4 @@ def calculate_volume(


def get_green_infra_table(measure_type: str) -> pd.DataFrame:
return Database().static.get_green_infra_table(measure_type)
return db.Database().static.get_green_infra_table(measure_type)
28 changes: 14 additions & 14 deletions flood_adapt/api/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@
from fiat_toolbox.infographics.infographics_factory import InforgraphicFactory
from fiat_toolbox.metrics_writer.fiat_read_metrics_file import MetricsFileReader

from flood_adapt.dbs_controller import Database
import flood_adapt.dbs_controller as db


def get_outputs() -> dict[str, Any]:
# sorting and filtering either with PyQt table or in the API
return Database().get_outputs()
return db.Database().get_outputs()


def get_topobathy_path() -> str:
return Database().get_topobathy_path()
return db.Database().get_topobathy_path()


def get_index_path() -> str:
return Database().get_index_path()
return db.Database().get_index_path()


def get_depth_conversion() -> float:
return Database().get_depth_conversion()
return db.Database().get_depth_conversion()


def get_max_water_level(name: str, rp: int = None) -> np.array:
return Database().get_max_water_level(name, rp)
return db.Database().get_max_water_level(name, rp)


def get_fiat_footprints(name: str) -> gpd.GeoDataFrame:
return Database().get_fiat_footprints(name)
return db.Database().get_fiat_footprints(name)


def get_aggregation(name: str) -> dict[gpd.GeoDataFrame]:
return Database().get_aggregation(name)
return db.Database().get_aggregation(name)


def get_roads(name: str) -> gpd.GeoDataFrame:
return Database().get_roads(name)
return db.Database().get_roads(name)


def get_obs_point_timeseries(name: str) -> gpd.GeoDataFrame:
Expand All @@ -58,7 +58,7 @@ def get_obs_point_timeseries(name: str) -> gpd.GeoDataFrame:
The HTML strings of the water level timeseries
"""
# Get the direct_impacts objects from the scenario
hazard = Database().scenarios.get(name).direct_impacts.hazard
hazard = db.Database().scenarios.get(name).direct_impacts.hazard

# Check if the scenario has run
if not hazard.has_run_check():
Expand All @@ -67,11 +67,11 @@ def get_obs_point_timeseries(name: str) -> gpd.GeoDataFrame:
)

output_path = (
Database()
db.Database()
.scenarios.get_database_path(get_input_path=False)
.joinpath(hazard.name)
)
gdf = Database().static.get_obs_points()
gdf = db.Database().static.get_obs_points()
gdf["html"] = [
str(output_path.joinpath("Flooding", f"{station}_timeseries.html"))
for station in gdf.name
Expand All @@ -96,7 +96,7 @@ def get_infographic(name: str) -> str:
The HTML string of the infographic.
"""
# Get the direct_impacts objects from the scenario
database = Database()
database = db.Database()
impact = database.scenarios.get(name).direct_impacts

# Check if the scenario has run
Expand Down Expand Up @@ -143,7 +143,7 @@ def get_infometrics(name: str) -> pd.DataFrame:
"""
# Create the infographic path
metrics_path = (
Database()
db.Database()
.scenarios.get_database_path(get_input_path=False)
.joinpath(
name,
Expand Down
Loading
Loading