Skip to content

Commit

Permalink
add gfh_attribute to setup_exposure_buildings and rename to gfh_attri… (
Browse files Browse the repository at this point in the history
#417)

add gfh_attribute to setup_exposure_buildings and rename to gfh_attribute_name
  • Loading branch information
Santonia27 authored Nov 20, 2024
1 parent ed42cf1 commit bd4e0fc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion hydromt_fiat/api/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hydromt_fiat/api/exposure_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions hydromt_fiat/api/hydromt_fiat_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 8 additions & 8 deletions hydromt_fiat/workflows/exposure_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -808,15 +808,15 @@ 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,
)
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
Expand All @@ -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
Expand Down

0 comments on commit bd4e0fc

Please sign in to comment.