Skip to content

Commit

Permalink
Merge pull request #196 from Deltares/fix-vulnerability-curves-damage…
Browse files Browse the repository at this point in the history
…-types

fix issue of the vulnerability curves with the same name but differen…
  • Loading branch information
frederique-hub authored Oct 31, 2023
2 parents 0486132 + 5e2e01c commit 93e11c1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion hydromt_fiat/fiat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion hydromt_fiat/workflows/exposure_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,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, :
Expand All @@ -989,7 +996,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())
Expand Down
28 changes: 19 additions & 9 deletions hydromt_fiat/workflows/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_vulnerability_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"asset_locations": "NSI",
"occupancy_type": "NSI",
"max_potential_damage": "NSI",
"damage_types": ["structure"],
"damage_types": ["structure", "content"],
"ground_floor_height": "NSI",
"unit": "ft",
},
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 93e11c1

Please sign in to comment.