Skip to content

Commit

Permalink
Update TippingPointMetrics enum with additional options
Browse files Browse the repository at this point in the history
  • Loading branch information
dumontgoulart committed Jun 11, 2024
2 parents 26ffea2 + 2d2d3d1 commit 8a1a748
Show file tree
Hide file tree
Showing 80 changed files with 1,928 additions and 1,223 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
report.xml
*.cover
*.py,cover
.hypothesis/
Expand Down
8 changes: 0 additions & 8 deletions .typos.toml

This file was deleted.

8 changes: 4 additions & 4 deletions docs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse_content(
parent: object = None,
module: object = None,
):
"""_summary_
"""_summary_.
Parameters
----------
Expand Down Expand Up @@ -79,7 +79,7 @@ def parse_section(
builder: Builder,
rel_dir: Path | str,
):
"""_summary_
"""_summary_.
Parameters
----------
Expand Down Expand Up @@ -118,7 +118,7 @@ def parse_tree_section(
content: list,
sub: bool = False,
):
"""_summary_
"""_summary_.
Parameters
----------
Expand Down Expand Up @@ -151,7 +151,7 @@ def create_tree(
file: Path | str,
filter: str = "*",
):
"""_summary_
"""_summary_.
Parameters
----------
Expand Down
34 changes: 5 additions & 29 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,10 @@ channels:
- numba

dependencies:
# Use conda to install pre-built binaries for geopandas and its C++ dependencies (GDAL, PROJ and fiona)
# Then `pip install .` to install the rest of the dependencies from the pyproj.toml that are on PyPI
- python=3.10
- geopandas
- pip
- pip:
- NDBC
- noaa-coops
- cht-tide
- cht-meteo
- cht-observations
- git+https://github.com/Deltares/hydromt_fiat.git
- git+https://github.com/Deltares/fiat_toolbox.git
- git+https://github.com/Deltares/hydromt_sfincs.git@FA_quadtree
- git+https://github.com/Deltares/cht_cyclones.git
- black
- typos
- ruff
- build
- geopandas
- mypy
- numpy
- pandas
- plotly
- pydantic
- pytest
- python=3.10
- tomli
- tomli-w
- twine
- census
- pre-commit
- numpy-financial
- pyogrio
- geojson
- .[dev]
42 changes: 21 additions & 21 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
from flood_adapt.object_model.benefit import Benefit
from flood_adapt.object_model.interface.benefits import IBenefit
from flood_adapt.object_model.interface.database import IDatabase


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


def get_benefit(name: str, database: IDatabase) -> IBenefit:
return database.benefits.get(name)
def get_benefit(name: str) -> IBenefit:
return Database().benefits.get(name)


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


def save_benefit(benefit: IBenefit, database: IDatabase) -> None:
database.benefits.save(benefit)
def save_benefit(benefit: IBenefit) -> None:
Database().benefits.save(benefit)


def edit_benefit(benefit: IBenefit, database: IDatabase) -> None:
database.benefits.edit(benefit)
def edit_benefit(benefit: IBenefit) -> None:
Database().benefits.edit(benefit)


def delete_benefit(name: str, database: IDatabase) -> None:
database.benefits.delete(name)
def delete_benefit(name: str) -> None:
Database().benefits.delete(name)


def check_benefit_scenarios(benefit: IBenefit, database: IDatabase) -> pd.DataFrame:
return database.check_benefit_scenarios(benefit)
def check_benefit_scenarios(benefit: IBenefit) -> pd.DataFrame:
return Database().check_benefit_scenarios(benefit)


def create_benefit_scenarios(benefit: IBenefit, database: IDatabase):
database.create_benefit_scenarios(benefit)
def create_benefit_scenarios(benefit: IBenefit):
Database().create_benefit_scenarios(benefit)


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


def get_aggregation_benefits(name: str, database: IDatabase) -> dict[gpd.GeoDataFrame]:
return database.get_aggregation_benefits(name)
def get_aggregation_benefits(name: str) -> dict[gpd.GeoDataFrame]:
return Database().get_aggregation_benefits(name)
71 changes: 30 additions & 41 deletions flood_adapt/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas as pd
from cht_cyclones.tropical_cyclone import TropicalCyclone

from flood_adapt.dbs_controller import IDatabase
from flood_adapt.dbs_controller import Database
from flood_adapt.object_model.hazard.event.event import Event
from flood_adapt.object_model.hazard.event.event_factory import EventFactory
from flood_adapt.object_model.hazard.event.historical_nearshore import (
Expand All @@ -21,22 +21,22 @@
from flood_adapt.object_model.io.unitfulvalue import UnitTypesLength


def get_events(database: IDatabase) -> dict[str, Any]:
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 Database().events.list_objects()


def get_event(name: str, database: IDatabase) -> IEvent:
return database.events.get(name)
def get_event(name: str) -> IEvent:
return Database().events.get(name)


def get_event_mode(name: str, database: IDatabase) -> str:
filename = database.input_path / "events" / f"{name}" / f"{name}.toml"
def get_event_mode(name: str) -> str:
filename = Database().input_path / "events" / f"{name}" / f"{name}.toml"
return Event.get_mode(filename)


def create_synthetic_event(attrs: dict[str, Any]) -> ISynthetic:
"""Create a synthetic event object from a dictionary of attributes
"""Create a synthetic event object from a dictionary of attributes.
Parameters
----------
Expand All @@ -52,7 +52,7 @@ def create_synthetic_event(attrs: dict[str, Any]) -> ISynthetic:


def create_historical_nearshore_event(attrs: dict[str, Any]) -> IHistoricalNearshore:
"""Create a historical nearshore event object from a dictionary of attributes
"""Create a historical nearshore event object from a dictionary of attributes.
Parameters
----------
Expand All @@ -68,7 +68,7 @@ def create_historical_nearshore_event(attrs: dict[str, Any]) -> IHistoricalNears


def create_historical_offshore_event(attrs: dict[str, Any]) -> IHistoricalOffshore:
"""Create a historical offshore event object from a dictionary of attributes
"""Create a historical offshore event object from a dictionary of attributes.
Parameters
----------
Expand All @@ -84,7 +84,7 @@ def create_historical_offshore_event(attrs: dict[str, Any]) -> IHistoricalOffsho


def create_historical_hurricane_event(attrs: dict[str, Any]) -> IHistoricalHurricane:
"""Create a historical hurricane event object from a dictionary of attributes
"""Create a historical hurricane event object from a dictionary of attributes.
Parameters
----------
Expand All @@ -99,28 +99,24 @@ def create_historical_hurricane_event(attrs: dict[str, Any]) -> IHistoricalHurri
return EventFactory.get_event("Historical_hurricane").load_dict(attrs)


def save_event_toml(event: IEvent, database: IDatabase) -> None:
database.events.save(event)
def save_event_toml(event: IEvent) -> None:
Database().events.save(event)


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


def edit_event(event: IEvent, database: IDatabase) -> None:
database.events.edit(event)
def edit_event(event: IEvent) -> None:
Database().events.edit(event)


def delete_event(name: str, database: IDatabase) -> None:
database.events.delete(name)
def delete_event(name: str) -> None:
Database().events.delete(name)


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


def download_wl_data(
Expand All @@ -135,31 +131,24 @@ def read_csv(csvpath: Union[str, os.PathLike]) -> pd.DataFrame:
return Event.read_csv(csvpath)


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


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


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


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


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

from flood_adapt.dbs_controller import Database
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 @@ -11,24 +12,21 @@
GreenInfrastructure,
)
from flood_adapt.object_model.hazard.measure.pump import Pump
from flood_adapt.object_model.interface.database import IDatabase
from flood_adapt.object_model.interface.measures import (
IMeasure,
)
from flood_adapt.object_model.interface.site import ISite


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


def get_measure(name: str, database: IDatabase) -> IMeasure:
return database.measures.get(name)
def get_measure(name: str) -> IMeasure:
return Database().measures.get(name)


def create_measure(
attrs: dict[str, Any], type: str, database: IDatabase = None
) -> IMeasure:
def create_measure(attrs: dict[str, Any], type: str = None) -> IMeasure:
"""Create a measure from a dictionary of attributes and a type string.
Parameters
Expand All @@ -45,9 +43,8 @@ def create_measure(
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 if database else None
database_path = Database().input_path

if type == "elevate_properties":
return Elevate.load_dict(attrs, database_path)
Expand All @@ -63,22 +60,20 @@ def create_measure(
return GreenInfrastructure.load_dict(attrs, database_path)


def save_measure(measure: IMeasure, database: IDatabase) -> None:
database.measures.save(measure)
def save_measure(measure: IMeasure) -> None:
Database().measures.save(measure)


def edit_measure(measure: IMeasure, database: IDatabase) -> None:
database.measures.edit(measure)
def edit_measure(measure: IMeasure) -> None:
Database().measures.edit(measure)


def delete_measure(name: str, database: IDatabase) -> None:
database.measures.delete(name)
def delete_measure(name: str) -> None:
Database().measures.delete(name)


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


# Green infrastructure
Expand All @@ -94,5 +89,5 @@ def calculate_volume(
)


def get_green_infra_table(database: IDatabase, measure_type: str) -> pd.DataFrame:
return database.get_green_infra_table(measure_type)
def get_green_infra_table(measure_type: str) -> pd.DataFrame:
return Database().static.get_green_infra_table(measure_type)
Loading

0 comments on commit 8a1a748

Please sign in to comment.