# Import packages
import pandas as pd
import geopandas as gpd
from pathlib import Path
from hydromt_fiat.fiat import FiatModel
from hydromt_sfincs.sfincs import SfincsModel
from flood_adapt import FloodAdapt, Settings
from flood_adapt import unit_system as us
from flood_adapt import database_builder as db
from flood_adapt.objects.forcing import TideGaugeSource
from flood_adapt.config.hazard import ObsPointModel, SlrScenariosModel, FloodModel
%matplotlib inline
π Example: Database Builder with Python
In this notebook, we demonstrate how to use the Database builder API of FloodAdapt to build a FloodAdapt database in a new location! For this, we will use an example area in Charleston, South Carolina, for which we have already generated a SFINCS and a Delft-FIAT model.
In order to use the DatabaseBuilder of FloodAdapt a set of configuration parameters are needed. The configuration parameters can be divided to mandatory and optional ones. Using only the mandatory parameters (i.e., baseline FloodAdapt configuration) will result in a simple but functional version of FloodAdapt. By adding optional parameters to your configuration, you can create a more advanced FloodAdapt database with additional features. If you want to learn more about the configuration parameters, please refer to the Database-Builder of the Setup Guide in the documentation.
The configuration can be either created through available FloodAdapt classes or can be parsed as a simple dictionary. We advice you to work with the FloodAdapt classes, since this can avoid using wrong parameter names or values with the help of type hinting.
Import libraries
The study area is in Charleston, South Carolina, a coastal city on the East Coast of the United States. To run this notebook, we have already prepared a SFINCS model and a Delft-FIAT model for this area. Both these models are meant for demonstration purposes only.
In this notebook we will go through all the mandatory and optional configuration parameters to create a database.
Mandatory configuration parameters
πΎ Database save path
First, we need to define the path where the database will be saved. This is done by defining the database_path
attribute.
# Define the static data folder
= Path("../../../_data/examples/static-data/1_DatabaseBuilder").resolve()
STATIC_DATA_DIR
# Where the database will be stored
= (STATIC_DATA_DIR / "Database").as_posix() database_path
π Overland SFINCS model
One of the mandatory inputs for a FloodAdapt database is an overland SFINCS model. Letβs first inspect the extents of our overland SFINCS model, by loading the model with the HydroMT-SFINCS plugin.
# Get the path of the SFINCS overland model
= STATIC_DATA_DIR / "overland"
fn_sfincs # Use HydroMT-SFINCS to read the SFINCS model
= SfincsModel(root=str(fn_sfincs), mode="r")
sfincs
sfincs.read()# Get the extent of the SFINCS model
= sfincs.region[["geometry"]]
gdf "name"] = "SFINCS Model Extent"
gdf[# Make a map of the SFINCS model extent
gdf.explore(={"fillColor": "blue", "color": "black", "weight": 1, "fillOpacity": 0.2},
style_kwds="CartoDB positron",
tiles="name",
column=True,
legend={"caption": "Region"}
legend_kwds )
The SFINCS model is specified using the sfincs_overland
attribute, which is a FloodModel
class that includes the path to the SFINCS model, defined by the attribute name
and the vertical reference that the model has, defined by reference
. The SFINCS model was build with elevation data in the NAVD88 vertical reference system, so we set the reference
to NAVD88
.
# Define the overland SFINCS model path and vertical reference
= FloodModel(
sfincs_overland =(STATIC_DATA_DIR / "overland").as_posix(),
name="NAVD88"
reference )
π Delft-FIAT model
Another mandatory input is the Delft-FIAT model. We can inspect the exposure objects (buildings and roads) of the Delft-FIAT model, by loading the model with the HydroMT-FIAT plugin.
# Get the path of the FIAT model
= STATIC_DATA_DIR / "fiat"
fn_fiat # Read the FIAT model using HydroMT-FIAT
= FiatModel(root=str(fn_fiat), mode="r")
fiat
fiat.read()# Get the geodataframe with exposure data
= fiat.exposure.get_full_gdf(fiat.exposure.exposure_db)
gdf # Plot the region and the secondary_object_types of the exposure data
gdf.explore(="primary_object_type",
column="Exposure types",
name="CartoDB positron"
tiles )