From 7ee262efc331060c4cefdf4af29be1fb66b4c624 Mon Sep 17 00:00:00 2001 From: Frederique Date: Tue, 31 Oct 2023 09:41:15 +0100 Subject: [PATCH] fix issue of the vulnerability curves with the same name but different damage types --- hydromt_fiat/fiat.py | 2 +- hydromt_fiat/workflows/exposure_vector.py | 9 +++++++- hydromt_fiat/workflows/vulnerability.py | 28 +++++++++++++++-------- tests/test_vulnerability_exposure.py | 8 +++---- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/hydromt_fiat/fiat.py b/hydromt_fiat/fiat.py index a1313510..3be8bbc9 100644 --- a/hydromt_fiat/fiat.py +++ b/hydromt_fiat/fiat.py @@ -281,7 +281,7 @@ def setup_exposure_buildings( unit: str, occupancy_type_field: Union[str, None] = None, extraction_method: str = "centroid", - damage_types: Union[List[str], None] = ["structure", "content"], + damage_types: List[str] = ["structure", "content"], country: Union[str, None] = None, ) -> None: """Setup building exposure (vector) data for Delft-FIAT. diff --git a/hydromt_fiat/workflows/exposure_vector.py b/hydromt_fiat/workflows/exposure_vector.py index 3bee8f9a..db590260 100644 --- a/hydromt_fiat/workflows/exposure_vector.py +++ b/hydromt_fiat/workflows/exposure_vector.py @@ -973,6 +973,13 @@ def link_exposure_vulnerability( exposure_linking_table: pd.DataFrame, damage_types: Optional[List[str]] = ["Structure", "Content"], ): + exposure_linking_table["Damage function name"] = [ + name + "_" + type + for name, type in zip( + exposure_linking_table["FIAT Damage Function Name"].values, + exposure_linking_table["Damage Type"].values, + ) + ] for damage_type in damage_types: linking_per_damage_type = exposure_linking_table.loc[ exposure_linking_table["Damage Type"] == damage_type, : @@ -983,7 +990,7 @@ def link_exposure_vulnerability( linking_dict = dict( zip( linking_per_damage_type["Exposure Link"], - linking_per_damage_type["FIAT Damage Function Name"], + linking_per_damage_type["Damage function name"], ) ) unique_linking_types = set(linking_dict.keys()) diff --git a/hydromt_fiat/workflows/vulnerability.py b/hydromt_fiat/workflows/vulnerability.py index d36bf891..89515178 100644 --- a/hydromt_fiat/workflows/vulnerability.py +++ b/hydromt_fiat/workflows/vulnerability.py @@ -288,23 +288,27 @@ def create_step_function( max_hazard_value: float = 10, step_hazard_value: float = 1.0, ): - #list before threshold + # list before threshold if threshold_value <= 1: - list_bt = np.arange(min_hazard_value,threshold_value, 0.01).tolist() + list_bt = np.arange(min_hazard_value, threshold_value, 0.01).tolist() del list_bt[1:-1] list_bt.append(threshold_value) else: - list_bt = np.arange(0,threshold_value, step_hazard_value).tolist() - list_bt.append(threshold_value-0.01) + list_bt = np.arange(0, threshold_value, step_hazard_value).tolist() + list_bt.append(threshold_value - 0.01) list_bt.append(threshold_value) - list_bt = [ round(elem, 2) for elem in list_bt] + list_bt = [round(elem, 2) for elem in list_bt] # list after threshold - list_at = np.arange(math.ceil(threshold_value), max_hazard_value+1, step_hazard_value).tolist() + list_at = np.arange( + math.ceil(threshold_value), max_hazard_value + 1, step_hazard_value + ).tolist() # merge list before and after threshold - hazard_values = list_bt +list_at + hazard_values = list_bt + list_at # create fraction_values - fraction_values = [0 if value < threshold_value else 1 for value in hazard_values] + fraction_values = [ + 0 if value < threshold_value else 1 for value in hazard_values + ] self.add(name, hazard_values, fraction_values) @@ -346,7 +350,13 @@ def get_vulnerability_functions_from_one_file( if vulnerability_values.max() > 1: vulnerability_values = vulnerability_values / 100 - vf_names = df_identifiers_linking["FIAT Damage Function Name"].values + vf_names = [ + name + "_" + type + for name, type in zip( + df_identifiers_linking["FIAT Damage Function Name"].values, + df_identifiers_linking["Damage Type"].values, + ) + ] self.add_multiple(vf_names, hazard_values, vulnerability_values) diff --git a/tests/test_vulnerability_exposure.py b/tests/test_vulnerability_exposure.py index fdd35cc6..de0731b7 100644 --- a/tests/test_vulnerability_exposure.py +++ b/tests/test_vulnerability_exposure.py @@ -55,8 +55,8 @@ "asset_locations": "NSI", "occupancy_type": "NSI", "max_potential_damage": "NSI", - "damage_types": ["structure"], - "ground_floor_height": 1, + "damage_types": ["structure", "content"], + "ground_floor_height": "NSI", "unit": "ft", }, }, @@ -84,8 +84,8 @@ "asset_locations": "NSI", "occupancy_type": "NSI", "max_potential_damage": "NSI", - "damage_types": ["structure"], - "ground_floor_height": 1, + "damage_types": ["structure", "content"], + "ground_floor_height": "NSI", "unit": "ft", }, "setup_social_vulnerability_index": {