From 5fd9ad3a33746d8dc9d2fd4fa12dc30c39de4cd5 Mon Sep 17 00:00:00 2001 From: Frederique Date: Mon, 23 Oct 2023 18:53:34 +0200 Subject: [PATCH 1/4] Small update --- hydromt_fiat/api/exposure_vm.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hydromt_fiat/api/exposure_vm.py b/hydromt_fiat/api/exposure_vm.py index eff8315d..72e27ac2 100644 --- a/hydromt_fiat/api/exposure_vm.py +++ b/hydromt_fiat/api/exposure_vm.py @@ -73,7 +73,7 @@ def set_asset_locations_source( crs=crs, ) - exposure.setup_from_single_source( + exposure.setup_buildings_from_single_source( input_source, self.exposure_model.ground_floor_height, "centroid", # TODO: MAKE FLEXIBLE @@ -84,10 +84,10 @@ def set_asset_locations_source( secondary_object_types = ( exposure.exposure_db["Secondary Object Type"].unique().tolist() ) - exposure.set_exposure_geoms_from_xy() + gdf = exposure.get_full_gdf(exposure.exposure_db) return ( - exposure.exposure_geoms[0], + gdf, primary_object_types, secondary_object_types, ) From 8cbb71930a5d3049ed85ed940573beabfff90415 Mon Sep 17 00:00:00 2001 From: Frederique Date: Wed, 25 Oct 2023 17:31:53 +0200 Subject: [PATCH 2/4] Update on view model --- hydromt_fiat/api/exposure_vm.py | 25 +++++++++---------------- hydromt_fiat/api/vulnerability_vm.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/hydromt_fiat/api/exposure_vm.py b/hydromt_fiat/api/exposure_vm.py index 72e27ac2..667dac9e 100644 --- a/hydromt_fiat/api/exposure_vm.py +++ b/hydromt_fiat/api/exposure_vm.py @@ -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") @@ -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 @@ -66,25 +66,25 @@ 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_buildings_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() ) - gdf = exposure.get_full_gdf(exposure.exposure_db) + gdf = self.exposure.get_full_gdf(self.exposure.exposure_db) return ( gdf, @@ -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) diff --git a/hydromt_fiat/api/vulnerability_vm.py b/hydromt_fiat/api/vulnerability_vm.py index c46c6d27..633b122b 100644 --- a/hydromt_fiat/api/vulnerability_vm.py +++ b/hydromt_fiat/api/vulnerability_vm.py @@ -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") From 99bbe8a6348bac710038cc96f796f017613e0609 Mon Sep 17 00:00:00 2001 From: Frederique Date: Wed, 25 Oct 2023 17:47:21 +0200 Subject: [PATCH 3/4] update --- hydromt_fiat/api/hydromt_fiat_vm.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hydromt_fiat/api/hydromt_fiat_vm.py b/hydromt_fiat/api/hydromt_fiat_vm.py index affdcf3b..8466bc7f 100644 --- a/hydromt_fiat/api/hydromt_fiat_vm.py +++ b/hydromt_fiat/api/hydromt_fiat_vm.py @@ -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() From 2d5b4e5ff91af05b4b9e8511e270eff9682483d7 Mon Sep 17 00:00:00 2001 From: Frederique Date: Thu, 26 Oct 2023 11:50:03 +0200 Subject: [PATCH 4/4] added to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 7e3a8fb7..b77a8950 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file