Tip

For an interactive online version click here: Binder badge

Update exposure data with user-input data#

This notebook demonstrates how to update the exposure data in an existing Delft-FIAT model with user-input data. Examples will be shown about how to update the ground_flht and the max potential damages (this will be added later!).

Step 0: Import required packages#

First we need to import the necessary python packages.

[1]:
from hydromt_fiat.fiat import FiatModel
from hydromt.log import setuplog
from pathlib import Path
import shutil
import geopandas as gpd
from hydromt.gis_utils import utm_crs

Step 1: Configure#

The first step is to set up the configuration needed to initialize the FIAT model. Begin by specifying where the model that should be updated is saved, locating the required data catalog, and setting up the logger.

[2]:
model_folder = Path().absolute() / "data" / "update_ground_floor_height" / "fiat_model"
data_catalog = Path().absolute() / "data" / "hydromt_fiat_catalog_USA.yml"
logger = setuplog("hydromt_fiat", log_level=10)
2024-12-11 10:25:57,017 - hydromt_fiat - log - INFO - HydroMT version: 0.9.4

Step 2: Initialize and read existing model#

In this step we initialize HydroMT-FIAT in read-mode (mode="r") with the model_folder, data_catalog, and logger that we defined above. We also read in the existing dummy model.

[3]:
fm = FiatModel(root=model_folder, mode="r", data_libs=[data_catalog], logger=logger)
fm.read()
2024-12-11 10:25:58,277 - hydromt_fiat - data_catalog - INFO - Parsing data catalog from c:\Users\rautenba\repos\hydromt_fiat\examples\data\hydromt_fiat_catalog_USA.yml
2024-12-11 10:25:58,286 - hydromt_fiat - data_catalog - INFO - Parsing data catalog from C:\Users\rautenba\repos\hydromt_fiat\hydromt_fiat\data\hydromt_fiat_catalog_global.yml
2024-12-11 10:25:58,299 - hydromt_fiat - log - DEBUG - Appending log messages to file c:\Users\rautenba\repos\hydromt_fiat\examples\data\update_ground_floor_height\fiat_model\hydromt.log.
2024-12-11 10:25:58,301 - hydromt_fiat - model_api - INFO - Initializing fiat model from hydromt_fiat (v0.3.2.dev0).
2024-12-11 10:25:58,305 - hydromt_fiat - fiat - INFO - Reading model data from c:\Users\rautenba\repos\hydromt_fiat\examples\data\update_ground_floor_height\fiat_model
2024-12-11 10:25:58,308 - hydromt_fiat - model_api - DEBUG - User defined config read from c:\Users\rautenba\repos\hydromt_fiat\examples\data\update_ground_floor_height\fiat_model\settings.toml
2024-12-11 10:25:58,309 - hydromt_fiat - fiat - INFO - Reading model table files.
2024-12-11 10:25:58,311 - hydromt_fiat - fiat - DEBUG - Reading vulnerability table c:\Users\rautenba\repos\hydromt_fiat\examples\data\update_ground_floor_height\fiat_model\vulnerability\vulnerability_curves.csv
2024-12-11 10:25:58,351 - hydromt_fiat - fiat - DEBUG - Reading exposure table c:\Users\rautenba\repos\hydromt_fiat\examples\data\update_ground_floor_height\fiat_model\exposure\exposure.csv
2024-12-11 10:25:58,358 - hydromt_fiat - fiat - INFO - Reading exposure geometries.
2024-12-11 10:25:58,359 - hydromt_fiat - exposure_vector - INFO - Setting geometry name to building_points...
2024-12-11 10:25:58,378 - hydromt_fiat - exposure_vector - INFO - Setting exposure geometries...

Step 3: Update the ground_flht of the exposure data#

Next, we will update the ground_flht of some of the exposure assets in our model. We have created some ficticious data that represents elevation certificates. We will first inspect the current exposure data and ground_flhts and the “elevation certificate” data.

As can be seen below, apparently the ground_flht of all assets is set to 1 (foot).

[4]:
original_exposure = fm.exposure.get_full_gdf(fm.exposure.exposure_db)
original_exposure["ground_flht"].unique()
[4]:
array([1])

Now we will load the “elevation certificate” data and visualize it together with the exposure assets below on the map.

[5]:
elevation_certificates_path = (
    Path().absolute()
    / "data"
    / "update_ground_floor_height"
    / "fake_elevation_certificates.gpkg"
)
elevation_certificates = gpd.read_file(elevation_certificates_path)

# Plot the exposure and elevation certificates data
m = elevation_certificates.explore(column="FFE", cmap="Reds", style_kwds={"radius": 5})
m = original_exposure.explore(m=m, column="ground_flht", cmap="Reds")
m
[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook

We will use a maximum distance of 10 meter to join the elevation certificate data to their nearest building. The attribute in the elevation certificate data that we need to use is FFE, which stands for First Floor Elevation and is often used in the US to indicate the ground_flht with.

[ ]:
attribute = "FFE"
method = "nearest"
max_dist = 50

fm.exposure.setup_ground_floor_height(
    ground_floor_height=elevation_certificates_path,
    gfh_attribute_name=attribute,
    gfh_method=method,
    max_dist=max_dist,
)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 5
      2 method = "nearest"
      3 max_dist = 50
----> 5 fm.exposure.setup_ground_floor_height(
      6     ground_floor_height=elevation_certificates_path,
      7     attr_name=attribute,
      8     method=method,
      9     max_dist=max_dist,
     10 )

TypeError: ExposureVector.setup_ground_floor_height() got an unexpected keyword argument 'attr_name'

Step 4: Check the resulting exposure data#

As you can see below, the ground_flht of the exposure assets also contains other values.

[24]:
updated_exposure = fm.exposure.get_full_gdf(fm.exposure.exposure_db)
updated_exposure["ground_flht"].unique()
[24]:
array([ 1,  2, 11, 20, 10, 12], dtype=int64)

We will make a buffer of 10 meter around the

[39]:
# Check if the Ground Floor Heigh attribute is set correctly
nearest_utm = utm_crs(elevation_certificates.total_bounds)
elevation_certificates_projected = elevation_certificates.to_crs(nearest_utm)
elevation_certificates_projected.geometry = (
    elevation_certificates_projected.geometry.buffer(max_dist)
)

# Plot the exposure and elevation certificates data
m = elevation_certificates_projected.explore(column="FFE", cmap="Reds")
m = updated_exposure.explore(m=m, column="ground_flht", cmap="Reds")
m
[39]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Step 5: Save the updated FIAT model#

Set the folder where you want to save the model to and write it to that folder.

[43]:
save_folder = (
    Path().absolute() / "data" / "update_ground_floor_height" / "updated_fiat_model"
)

# Remove the new root folder if it already exists
if save_folder.exists():
    shutil.rmtree(save_folder)

# Set the new root and write the model
fm.set_root(save_folder)
fm.write()
2023-10-18 15:53:42,160 - hydromt_fiat - log - DEBUG - Writing log messages to new file c:\Repositories\hydromt_fiat\examples\data\update_ground_floor_height\updated_fiat_model\hydromt.log.
2023-10-18 15:53:42,161 - hydromt_fiat - fiat - INFO - Updating all data objects...
2023-10-18 15:53:42,162 - hydromt_fiat - model_api - WARNING - Replacing geom: building_points
2023-10-18 15:53:42,163 - hydromt_fiat - fiat - INFO - Writing model data to c:\Repositories\hydromt_fiat\examples\data\update_ground_floor_height\updated_fiat_model
2023-10-18 15:53:42,163 - hydromt_fiat - model_api - INFO - Writing model config to c:\Repositories\hydromt_fiat\examples\data\update_ground_floor_height\updated_fiat_model\settings.toml
2023-10-18 15:53:42,165 - hydromt_fiat - model_api - DEBUG - Writing file exposure/building_points.gpkg
2023-10-18 15:53:42,256 - hydromt_fiat - fiat - INFO - Writing model vulnerability_curves table file to vulnerability/vulnerability_curves.csv.
2023-10-18 15:53:42,260 - hydromt_fiat - fiat - INFO - Writing model exposure table file to exposure/exposure.csv.