Build Model#
Using the python API.#
Here we are going to build a model using the HydroMT-FIAT python API.
[1]:
# Imports
import tempfile
from pathlib import Path
from hydromt._utils import log
from hydromt_fiat import FIATModel
from hydromt_fiat.data import fetch_data
Lets make sure that there is a directory to build to.
Also ensure we have some data to build with, hydromt_fiat comes with a small to function to fetch a small dataset to build with.
[2]:
# Use the built-in tempfile package
temp_dir = tempfile.TemporaryDirectory(delete=False)
p = Path(temp_dir.name)
## Get the build data
data_dir = fetch_data("build-data")
Downloading file 'build-data.tar.gz' from 'doi:10.5281/zenodo.17495611/build-data.tar.gz' to '/home/runner/.cache/hydromt_fiat'.
Untarring contents of '/home/runner/.cache/hydromt_fiat/build-data.tar.gz' to '/home/runner/.cache/hydromt_fiat/build-data'
Now lets setup the Model.
[3]:
# Create a model in write mode.
log._setuplog()
model = FIATModel(root=p, mode="w+", data_libs=Path(data_dir, "data_catalog.yml"))
2025-11-03 12:10:33,515 - hydromt - log - INFO - HydroMT version: 1.2.0
2025-11-03 12:10:33,516 - hydromt.data_catalog.data_catalog - data_catalog - INFO - Parsing data catalog from /home/runner/.cache/hydromt_fiat/build-data/data_catalog.yml
2025-11-03 12:10:34,074 - hydromt.model.root - root - INFO - setting root to /tmp/tmps8oderk8
2025-11-03 12:10:34,085 - hydromt.model.model - model - INFO - Initializing fiat model from hydromt_fiat (v1.0.0.dev0).
Next step is to update the configurations and add a region for the model to know to collect data in.
Luckily a region vector file is incorporated in the small build data directory.
[4]:
# Add some of the configurations
model.setup_config(**{"model.model_type": "geom", "output.path": "output"})
# Add a region to build with
model.setup_region(Path(data_dir, "region.geojson"))
2025-11-03 12:10:34,090 - hydromt.hydromt_fiat.fiat - fiat - INFO - Setting config entries from user input
2025-11-03 12:10:34,091 - hydromt.hydromt_fiat.fiat - fiat - INFO - Setting region from '/home/runner/.cache/hydromt_fiat/build-data/region.geojson'
Lets verify the presence of our region, which is crucial for building our hazard and exposure data.
[5]:
model.region
[5]:
| geometry | |
|---|---|
| 0 | POLYGON ((4.38362 51.97582, 4.38125 51.97865, ... | 
All seems in order, therefore we can move on to setting up the FIAT model data.
Let’s start with the vulnerability, as this data is crucial for the exposure data.
[6]:
# Call the setup method of the component
model.vulnerability.setup(
    vulnerability_fname="vulnerability_curves",
    vulnerability_linking_fname="vulnerability_curves_linking",
    unit="m",
    continent="europe",  # A keyword argument to select data from the
    # vulnerability_fname dataset
)
2025-11-03 12:10:34,117 - hydromt.hydromt_fiat.components.vulnerability - vulnerability - INFO - Setting up the vulnerability curves
2025-11-03 12:10:34,119 - hydromt.data_catalog.drivers.dataframe.pandas_driver - pandas_driver - INFO - Reading using pandas driver from /home/runner/.cache/hydromt_fiat/build-data/vulnerability/jrc_damage_functions.csv
2025-11-03 12:10:34,130 - hydromt.data_catalog.drivers.dataframe.pandas_driver - pandas_driver - INFO - Reading using pandas driver from /home/runner/.cache/hydromt_fiat/build-data/vulnerability/jrc_damage_functions_linking.csv
This should result in damage curve data in our vulnerability component, lets see.
[7]:
model.vulnerability.data.curves
[7]:
| water depth | rs1 | cm1 | in1 | in2 | un1 | |
|---|---|---|---|---|---|---|
| 0 | 0.00 | 0.000 | 0.000 | 0.000 | 0.000 | 0.0000 | 
| 1 | 0.01 | 0.005 | 0.003 | 0.003 | 0.005 | 0.0049 | 
| 2 | 0.02 | 0.010 | 0.006 | 0.006 | 0.010 | 0.0098 | 
| 3 | 0.03 | 0.015 | 0.009 | 0.009 | 0.015 | 0.0146 | 
| 4 | 0.04 | 0.020 | 0.012 | 0.012 | 0.020 | 0.0195 | 
| ... | ... | ... | ... | ... | ... | ... | 
| 996 | 9.96 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 | 
| 997 | 9.97 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 | 
| 998 | 9.98 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 | 
| 999 | 9.99 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 | 
| 1000 | 10.00 | 1.000 | 1.000 | 1.000 | 1.000 | 1.0000 | 
1001 rows × 6 columns
Simply done.
Let’s continue with the hazard data.
Hazard data is easily setup from a raster-based datasource.
[8]:
# Call the setup method from the hazard component
model.hazard.setup(
    hazard_fnames="flood_event",
    hazard_type="water depth",
)
2025-11-03 12:10:34,259 - hydromt.hydromt_fiat.components.hazard - hazard - INFO - Setting up hazard raster data
2025-11-03 12:10:34,346 - hydromt.hydromt_fiat.workflows.hazard - hazard - INFO - Added water depth hazard map: flood_event
2025-11-03 12:10:34,346 - hydromt.hydromt_fiat.workflows.utils - utils - WARNING - No known grid provided to reproject to, defaulting to first specified grid for transform and extent
Let’s take a look a the current state of the hazard data after settting it up with the setup method.
[9]:
model.hazard.data
[9]:
<xarray.Dataset> Size: 4kB
Dimensions:      (y: 34, x: 25)
Coordinates:
  * y            (y) float64 272B 4.458e+05 4.456e+05 ... 4.426e+05 4.424e+05
  * x            (x) float64 200B 8.525e+04 8.535e+04 ... 8.755e+04 8.765e+04
    spatial_ref  int64 8B 0
Data variables:
    flood_event  (y, x) float32 3kB dask.array<chunksize=(34, 25), meta=np.ndarray>
Attributes:
    type:      water depth
    analysis:  event