Skip to content

Commit

Permalink
fix bugs, all tests running green now
Browse files Browse the repository at this point in the history
  • Loading branch information
frederique-hub committed Dec 8, 2023
1 parent d41ced9 commit 8ec7be7
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 2,281 deletions.
1 change: 0 additions & 1 deletion Shapefiles/45019/2021/tl_2021_45019_faces.cpg

This file was deleted.

Binary file removed Shapefiles/45019/2021/tl_2021_45019_faces.dbf
Binary file not shown.
1 change: 0 additions & 1 deletion Shapefiles/45019/2021/tl_2021_45019_faces.prj

This file was deleted.

Binary file removed Shapefiles/45019/2021/tl_2021_45019_faces.shp
Binary file not shown.
1,567 changes: 0 additions & 1,567 deletions Shapefiles/45019/2021/tl_2021_45019_faces.shp.ea.iso.xml

This file was deleted.

640 changes: 0 additions & 640 deletions Shapefiles/45019/2021/tl_2021_45019_faces.shp.iso.xml

This file was deleted.

Binary file removed Shapefiles/45019/2021/tl_2021_45019_faces.shx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ FIAT Damage Function Name,Exposure Link,Damage Type,type
residential,residential,total,residential
commercial,commercial,total,commercial
industrial,industrial,total,industrial
residential,residential,structure,residential
commercial,commercial,structure,commercial
industrial,industrial,structure,industrial
residential,residential,content,residential
commercial,commercial,content,commercial
industrial,industrial,content,industrial
60 changes: 31 additions & 29 deletions hydromt_fiat/workflows/exposure_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,16 +594,6 @@ def setup_max_potential_damage(
for damage_type in damage_types:
self.exposure_db[f"Max Potential Damage: {damage_type}"] = max_potential_damage

elif isinstance(max_potential_damage, str) or isinstance(
max_potential_damage, Path
):
# A single file is used to assign the ground floor height to the assets
gfh = self.data_catalog.get_geodataframe(max_potential_damage)
gdf = self.get_full_gdf(self.exposure_db)
gdf = join_spatial_data(gdf, gfh, attr_name, method, max_dist, self.logger)
self.exposure_db = self._set_values_from_other_column(
gdf, target_attribute, attr_name
)
elif isinstance(max_potential_damage, list):
# Multiple files are used to assign the ground floor height to the assets
NotImplemented
Expand All @@ -622,27 +612,39 @@ def setup_max_potential_damage(
damage_source = self.data_catalog.get_dataframe(max_potential_damage)
damage_values = preprocess_hazus_damage_values(damage_source)

# Calculate the area of each object
gdf = self.get_full_gdf(self.exposure_db)[["Primary Object Type", "geometry"]]
gdf = get_area(gdf)
# Calculate the area of each object
gdf = self.get_full_gdf(self.exposure_db)[["Primary Object Type", "geometry"]]
gdf = get_area(gdf)

# Set the damage values to the exposure data
for damage_type in damage_types:
# Calculate the maximum potential damage for each object and per damage type
try:
self.exposure_db[
f"Max Potential Damage: {damage_type.capitalize()}"
] = [
damage_values[building_type][damage_type.lower()] * square_meters
for building_type, square_meters in zip(
gdf["Primary Object Type"], gdf["area"]
# Set the damage values to the exposure data
for damage_type in damage_types:
# Calculate the maximum potential damage for each object and per damage type
try:
self.exposure_db[
f"Max Potential Damage: {damage_type.capitalize()}"
] = [
damage_values[building_type][damage_type.lower()] * square_meters
for building_type, square_meters in zip(
gdf["Primary Object Type"], gdf["area"]
)
]
except KeyError as e:
self.logger.warning(
f"Not found in the {max_potential_damage} damage "
f"value data: {e}"
)
]
except KeyError as e:
self.logger.warning(
f"Not found in the {max_potential_damage} damage "
f"value data: {e}"
)
elif isinstance(max_potential_damage, str) or isinstance(
max_potential_damage, Path
):
# When the max_potential_damage is a string but not jrc_damage_values
# or hazus_max_potential_damages. Here, a single file is used to
# assign the ground floor height to the assets
gfh = self.data_catalog.get_geodataframe(max_potential_damage)
gdf = self.get_full_gdf(self.exposure_db)
gdf = join_spatial_data(gdf, gfh, attr_name, method, max_dist, self.logger)
self.exposure_db = self._set_values_from_other_column(
gdf, target_attribute, attr_name
)

def setup_ground_elevation(
self,
Expand Down
72 changes: 36 additions & 36 deletions tests/data/correct/test_hazus_vulnerability_curves.csv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"asset_locations": "NSI",
"occupancy_type": "NSI",
"max_potential_damage": "NSI",
"ground_floor_height": 1,
"ground_floor_height": "NSI",
"unit": "ft",
},
"setup_hazard": {
Expand Down
9 changes: 3 additions & 6 deletions tests/test_vulnerability_exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,9 @@
"census_key": "495a349ce22bdb1294b378fb199e4f27e57471a9",
"codebook_fn": "social_vulnerability",
"state_abbreviation": "SC",
"blockgroup_fn": str(
DATADIR
/ "social_vulnerability"
/ "test_blockgroup_shp"
/ "tl_2022_45_bg.shp"
),
"blockgroup_fn": "blockgroup_shp_data",
"year_data": 2021,
"county": "019"
},
},
"region": _region,
Expand Down
1 change: 1 addition & 0 deletions tests/test_vulnerability_exposure_global_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"occupancy_type": "OSM",
"max_potential_damage": "jrc_damage_values",
"ground_floor_height": 0,
"damage_types": ["structure", "content"],
"unit": "m",
"country": "United Kingdom",
},
Expand Down

0 comments on commit 8ec7be7

Please sign in to comment.