Skip to content

Commit

Permalink
Merge branch 'gui-updates' of https://github.com/Deltares/hydromt_fiat
Browse files Browse the repository at this point in the history
…into #190-correct-standardize-svi
  • Loading branch information
LiekeMeijer committed Oct 26, 2023
2 parents f0dcb8f + 2d5b4e5 commit 3bce50f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,7 @@ venv.bak/
cache
/examples/FIAT_database
hydromt_fiat/data/damage_functions/flooding/AllDDF_HAZUS_fractions.xlsx
hydromt_fiat/data/damage_functions/flooding/Hazus_IWR_curves.csv
hydromt_fiat/data/damage_functions/flooding/Hazus_IWR_curves.xlsx
examples/data/building_footprints/fiat_model_bfs
examples/data/aggregation_zones/output
27 changes: 10 additions & 17 deletions hydromt_fiat/api/exposure_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(
self.database: IDatabase = database
self.data_catalog: DataCatalog = data_catalog
self.logger: logging.Logger = logger
self.exposure: ExposureVector = None

def create_interest_area(self, **kwargs: str):
fpath = kwargs.get("fpath")
Expand All @@ -57,7 +58,6 @@ def set_asset_locations_source(
):
if input_source == "NSI":
# NSI is already defined in the data catalog
# Add NSI to the configuration file
self.exposure_model.asset_locations = input_source
self.exposure_model.occupancy_type = input_source
self.exposure_model.max_potential_damage = input_source
Expand All @@ -66,28 +66,28 @@ def set_asset_locations_source(

# Download NSI from the database
region = self.data_catalog.get_geodataframe("area_of_interest")
exposure = ExposureVector(
self.exposure = ExposureVector(
data_catalog=self.data_catalog,
logger=self.logger,
region=region,
crs=crs,
)

exposure.setup_from_single_source(
self.exposure.setup_buildings_from_single_source(
input_source,
self.exposure_model.ground_floor_height,
"centroid", # TODO: MAKE FLEXIBLE
)
primary_object_types = (
exposure.exposure_db["Primary Object Type"].unique().tolist()
self.exposure.exposure_db["Primary Object Type"].unique().tolist()
)
secondary_object_types = (
exposure.exposure_db["Secondary Object Type"].unique().tolist()
self.exposure.exposure_db["Secondary Object Type"].unique().tolist()
)
exposure.set_exposure_geoms_from_xy()
gdf = self.exposure.get_full_gdf(self.exposure.exposure_db)

return (
exposure.exposure_geoms[0],
gdf,
primary_object_types,
secondary_object_types,
)
Expand All @@ -110,13 +110,6 @@ def set_asset_locations_source(
print(catalog_entry)
# write to data catalog

def create_extraction_map(self, *args):
# TODO: implement callback
# if no exceptions, then self.exposure_model.extraction_method = args[0]
# else if
# make backend call to api with arguments to set extraction method per object:
# create first with default method. Then get uploaded or drawn area and merge with default methid
# save file to database
# change self.exposure_model.extraction_method to file
...
# change self.exposure_model.extraction_method to file
def setup_extraction_method(self, extraction_method):
if self.exposure:
self.exposure.setup_extraction_method(extraction_method)
6 changes: 5 additions & 1 deletion hydromt_fiat/api/hydromt_fiat_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def build_config_ini(self):
tomli_w.dump(config_ini.dict(exclude_none=True), f)

def run_hydromt_fiat(self):
config_ini = ConfigIni(
setup_vulnerability=self.vulnerability_vm.vulnerability_model,
setup_exposure_buildings=self.exposure_vm.exposure_model,
)
region = self.data_catalog.get_geodataframe("area_of_interest")
self.fiat_model.build(region={"geom": region}, opt=ConfigIni.dict())
self.fiat_model.build(region={"geom": region}, opt=config_ini.dict())
self.fiat_model.write()
11 changes: 9 additions & 2 deletions hydromt_fiat/api/vulnerability_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@ def __init__(
self, database: IDatabase, data_catalog: DataCatalog, logger: logging.Logger
):
self.vulnerability_model = VulnerabilityIni(
vulnerability_fn="", link_table="", units=Units.m.value
vulnerability_fn="", link_table="", units=Units.ft.value
)
self.database: IDatabase = database
self.data_catalog: DataCatalog = data_catalog
self.logger: logging.Logger = logger
self.linking_standard_colnames = ["Name", "Link"]
self.linking_standard_colnames = ["FIAT Damage Function Name", "Exposure Link"] # add "Damage Type" ?
self.linking_colnames = list()
self.linking_list = list()

def get_default_curves_linking_file(self):
return self.data_catalog.get_dataframe("default_hazus_iwr_linking")

def add_vulnerability_curves_to_model(self, vulnerability_fn, link_table):
self.vulnerability_model.vulnerability_fn = vulnerability_fn
self.vulnerability_model.link_table = link_table

def get_hazus_curves(self):
self.logger.info("Getting Hazus curves")
df_vulnerability = self.data_catalog.get_dataframe("hazus_vulnerability_curves")
Expand Down

0 comments on commit 3bce50f

Please sign in to comment.