Skip to content

Commit

Permalink
Merge pull request #231 from Deltares/fixes_composite_area_ground_ele…
Browse files Browse the repository at this point in the history
…vation

Fixes composite area ground elevation
  • Loading branch information
frederique-hub authored Dec 14, 2023
2 parents 51c209d + 6569f59 commit 5b6cdbb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
Binary file not shown.
42 changes: 32 additions & 10 deletions hydromt_fiat/workflows/exposure_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
get_road_lengths,
)

from hydromt_fiat.workflows.aggregation_areas import join_exposure_aggregation_areas


class ExposureVector(Exposure):
_REQUIRED_COLUMNS = ["Object ID", "Extraction Method", "Ground Floor Height"]
Expand Down Expand Up @@ -913,9 +915,10 @@ def setup_new_composite_areas(
elevation_reference: str,
path_ref: str = None,
attr_ref: str = None,
ground_elevation: Union[
int, float, None, str, Path, List[str], List[Path]
] = None,
ground_elevation: Union[None, str, Path] = None,
aggregation_area_fn: Union[List[str], List[Path], str, Path] = None,
attribute_names: Union[List[str], str] = None,
label_names: Union[List[str], str] = None,
) -> None:
"""Adds one or multiple (polygon) areas to the exposure database with
a composite damage function and a percentage of the total damage.
Expand Down Expand Up @@ -1015,7 +1018,9 @@ def setup_new_composite_areas(
# TODO: Take ground elevation from DEM?
# For water level calculation this will not take into account the
# non-flooded cells separately, just averaged over the whole area.
self.logger.warning("The ground elevation is set to 0.")
self.logger.warning(
"The ground elevation is set to 0 if no DEM is supplied."
)

# Idea: Reduction factor for the part of the area is not build-up?

Expand Down Expand Up @@ -1079,17 +1084,34 @@ def setup_new_composite_areas(
self.crs,
)

# Update the exposure_geoms
self.set_geom_names("new_development_area")
self.set_exposure_geoms(_new_exposure_geoms)

# If the user supplied ground elevation data, assign that to the new
# composite areas
if ground_elevation is not None:
new_objects["Ground Elevation"] = ground_elevation_from_dem(
ground_elevation=ground_elevation,
exposure_db=new_objects,
exposure_geoms=_new_exposure_geoms,
)

# If the user supplied aggregation area data, assign that to the
# new composite areas
if aggregation_area_fn is not None:
new_objects = join_exposure_aggregation_areas(
_new_exposure_geoms.merge(new_objects, on="Object ID"),
aggregation_area_fn=aggregation_area_fn,
attribute_names=attribute_names,
label_names=label_names,
)

# Update the exposure_db
self.exposure_db = pd.concat([self.exposure_db, new_objects]).reset_index(
drop=True
)

# Update the exposure_geoms
self.set_exposure_geoms(_new_exposure_geoms)

# Adding elevation data into the new objects
self.setup_ground_elevation(ground_elevation)

def link_exposure_vulnerability(
self,
exposure_linking_table: pd.DataFrame,
Expand Down
18 changes: 14 additions & 4 deletions tests/test_setup_new_composite_areas_ground_elevation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"type": "datum",
"path_ref": None,
"attr_ref": None,
"ground_elevation_file": DATADIRDEM
/ "charleston_14m.tif",
"ground_elevation_file": None,
"aggregation_area_fn": None,
"attribute_names": None,
"label_names": None,
},
"setup_new_composite_area_geom": {
"dir": "test_read",
Expand All @@ -33,8 +35,10 @@
"type": "geom",
"path_ref": DATADIR / "new_composite_areas" / "reference_groundHeight_test.shp",
"attr_ref": "bfe",
"ground_elevation_file": DATADIRDEM
/ "charleston_14m.tif",
"ground_elevation_file": None,
"aggregation_area_fn": None,
"attribute_names": None,
"label_names": None,
},
"setup_new_composite_area_elevation": {
"dir": "test_read",
Expand All @@ -45,6 +49,9 @@
"attr_ref": None,
"ground_elevation_file": DATADIRDEM
/ "charleston_14m.tif",
"aggregation_area_fn": EXAMPLEDIR.joinpath("test_read", "exposure", "aggregation_areas", "block_groups.gpkg"),
"attribute_names": "GEOID_short",
"label_names": "Aggregation Label: Census Block",
},
}

Expand All @@ -70,6 +77,9 @@ def test_setup_new_composite_areas_ground_elevation(case):
path_ref=_cases[case]["path_ref"],
attr_ref=_cases[case]["attr_ref"],
ground_elevation=_cases[case]["ground_elevation_file"],
aggregation_area_fn=_cases[case]["aggregation_area_fn"],
attribute_names=_cases[case]["attribute_names"],
label_names=_cases[case]["label_names"],
)

if _cases[case]["new_root"].exists():
Expand Down

0 comments on commit 5b6cdbb

Please sign in to comment.