From 49512012943032f137fb22f2bdbee8886eb01965 Mon Sep 17 00:00:00 2001 From: Santonia27 Date: Wed, 20 Nov 2024 15:10:22 +0100 Subject: [PATCH] add gfh_attribute to setup_exposure_buildings and rename to gfh_attribute_name --- hydromt_fiat/api/data_types.py | 2 +- hydromt_fiat/api/exposure_vm.py | 4 ++-- hydromt_fiat/api/hydromt_fiat_vm.py | 4 ++-- hydromt_fiat/fiat.py | 8 ++++++-- hydromt_fiat/workflows/exposure_vector.py | 16 ++++++++-------- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/hydromt_fiat/api/data_types.py b/hydromt_fiat/api/data_types.py index 1cf616cb..71c09238 100644 --- a/hydromt_fiat/api/data_types.py +++ b/hydromt_fiat/api/data_types.py @@ -93,7 +93,7 @@ class ExposureBuildingsSettings(BaseModel): class ExposureSetupGroundFloorHeight(BaseModel): source: str - attribute_name: Optional[Union[str, List[str]]] = None + gfh_attribute_name: Optional[Union[str, List[str]]] = None gfh_method: Optional[Union[str, List[str]]] = None max_dist: Optional[Union[float, int]] = None gfh_unit: Units = None diff --git a/hydromt_fiat/api/exposure_vm.py b/hydromt_fiat/api/exposure_vm.py index 64c4281a..9a67d61c 100644 --- a/hydromt_fiat/api/exposure_vm.py +++ b/hydromt_fiat/api/exposure_vm.py @@ -247,13 +247,13 @@ def setup_extraction_method(self, extraction_method): def set_ground_floor_height( self, source: str, - attribute_name: Union[str, List[str], None] = None, + gfh_attribute_name: Union[str, List[str], None] = None, gfh_method: Union[str, List[str], None] = "nearest", max_dist: Union[float, int, None] = 10, ): self.exposure_ground_floor_height_model = ExposureSetupGroundFloorHeight( source=source, - attribute_name=attribute_name, + gfh_attribute_name=gfh_attribute_name, gfh_method=gfh_method, max_dist=max_dist, ) diff --git a/hydromt_fiat/api/hydromt_fiat_vm.py b/hydromt_fiat/api/hydromt_fiat_vm.py index 1114f2aa..a009abfe 100644 --- a/hydromt_fiat/api/hydromt_fiat_vm.py +++ b/hydromt_fiat/api/hydromt_fiat_vm.py @@ -210,13 +210,13 @@ def update_exposure_db(self, config_yaml): def new_ground_floor_height(self, config_yaml): source = config_yaml.model_extra["update_ground_floor_height"].source - attribute_name = config_yaml.model_extra[ + gfh_attribute_name = config_yaml.model_extra[ "update_ground_floor_height" ].attribute_name gfh_method = config_yaml.model_extra["update_ground_floor_height"].gfh_method max_dist = config_yaml.model_extra["update_ground_floor_height"].max_dist self.fiat_model.exposure.setup_ground_floor_height( - source, attribute_name, gfh_method, max_dist + source, gfh_attribute_name, gfh_method, max_dist ) def new_additional_attributes(self, config_yaml): diff --git a/hydromt_fiat/fiat.py b/hydromt_fiat/fiat.py index 2cfa73cf..341675ae 100644 --- a/hydromt_fiat/fiat.py +++ b/hydromt_fiat/fiat.py @@ -313,6 +313,7 @@ def setup_exposure_buildings( ground_floor_height: Union[int, float, str, Path, None], length_unit: Units = None, gfh_unit: Units = None, + gfh_attribute_name: str = None, occupancy_attr: Union[str, None] = None, occupancy_object_type: Union[str, List[str]] = None, extraction_method: str = "centroid", @@ -345,6 +346,9 @@ def setup_exposure_buildings( The unit of the model gfh_unit : Units The unit of the ground_floor_height + gfh_attribute_name : str + The attribute name to be used to set the ground_flht. If None, the + attribute name will be set to 'ground_floor_height'. occupancy_attr : Union[str, None], optional The name of the field in the occupancy type data that contains the occupancy type, by default None (this means that the occupancy type data @@ -521,14 +525,14 @@ def bf_spatial_joins(self): def update_ground_floor_height( self, source: Union[int, float, str, Path, None], - attribute_name: Union[str, List[str], None] = None, + gfh_attribute_name: str = None, gfh_method: Union[str, List[str], None] = "nearest", gfh_unit: Units = None, max_dist: float = 10, ): if self.exposure: self.exposure.setup_ground_floor_height( - source, attribute_name, gfh_method, max_dist, gfh_unit + source, gfh_attribute_name, gfh_method, max_dist, gfh_unit ) def update_max_potential_damage( diff --git a/hydromt_fiat/workflows/exposure_vector.py b/hydromt_fiat/workflows/exposure_vector.py index a5f752e7..12c4538b 100644 --- a/hydromt_fiat/workflows/exposure_vector.py +++ b/hydromt_fiat/workflows/exposure_vector.py @@ -327,7 +327,7 @@ def setup_buildings_from_multiple_sources( occupancy_attr: Union[str, None] = None, damage_types: Union[List[str], None] = None, country: Union[str, None] = None, - attribute_name: Union[str, List[str], None] = None, + gfh_attribute_name: Union[str, List[str], None] = None, gfh_method: Union[str, List[str], None] = "nearest", gfh_unit: Units = None, max_dist: Union[int, float, List[float], List[int], None] = 10, @@ -358,7 +358,7 @@ def setup_buildings_from_multiple_sources( self.exposure_geoms[0], self.exposure_geoms[0].crs ) self.setup_ground_floor_height( - ground_floor_height, attribute_name, gfh_method, max_dist, gfh_unit + ground_floor_height, gfh_attribute_name, gfh_method, max_dist, gfh_unit ) self.setup_extraction_method(extraction_method) self.setup_ground_elevation(ground_elevation, grnd_elev_unit) @@ -747,7 +747,7 @@ def intersection_method( def setup_ground_floor_height( self, ground_floor_height: Union[int, float, None, str, Path, List[str], List[Path]], - attribute_name: Union[str, List[str], None] = None, + gfh_attribute_name: Union[str, List[str], None] = None, gfh_method: Union[str, List[str], None] = "nearest", max_dist: float = 10, gfh_unit: Units = None @@ -763,7 +763,7 @@ def setup_ground_floor_height( list of paths to files that contain the Ground Floor Height of each asset, in the order of preference (the first item in the list gets the highest priority in assigning the values). - attribute_name : Union[str, List[str]], optional + gfh_attribute_name : Union[str, List[str]], optional The name of the attribute that contains the Ground Floor Height in the file(s) that are submitted. If multiple `ground_floor_height` files are submitted, the attribute names are linked to the files in the same order as @@ -796,7 +796,7 @@ def setup_ground_floor_height( columns_to_drop = [ col for col in gfh.columns - if col != attribute_name and col != "geometry" + if col != gfh_attribute_name and col != "geometry" ] gfh = gfh.drop(columns=columns_to_drop) @@ -808,7 +808,7 @@ def setup_ground_floor_height( gdf = join_spatial_data( gdf[~gdf.isin(gdf_roads)].dropna(subset=["geometry"]), gfh, - attribute_name, + gfh_attribute_name, gfh_method, max_dist, self.logger, @@ -816,7 +816,7 @@ def setup_ground_floor_height( gdf = pd.concat([gdf, gdf_roads]) else: gdf = join_spatial_data( - gdf, gfh, attribute_name, gfh_method, max_dist, self.logger + gdf, gfh, gfh_attribute_name, gfh_method, max_dist, self.logger ) # If method is "intersection" rename *"_left" to original exposure_db name @@ -825,7 +825,7 @@ def setup_ground_floor_height( # Update exposure_db self.exposure_db = self._set_values_from_other_column( - gdf, "Ground Floor Height", attribute_name + gdf, "Ground Floor Height", gfh_attribute_name ) # Unit conversion