import pandas as pd
import geopandas as gpd
from pathlib import Path
from flood_adapt import FloodAdapt, Settings
from flood_adapt.objects import (
FloodProof, FloodWall, Elevate, GreenInfrastructure, Buyout, Pump, Strategy, MeasureType, SelectionType
)from flood_adapt import unit_system as us
📘 Example: Measures and Strategies
In this notebook we will show you all the different options and inputs for creating different measures and how to create a strategy from the different measures.
Measures in FloodAdapt can be categorized into two different categories, which we will cover all in this notebook:
1. Hazard - Mitigate the hazard directly
- Floodwall
- Pump
- Green Infrastructure
2. Impact - Mitiage the impacts of the hazard on the assets
- Elevate properties
- Buyout Properties
- Floodproof Properties
Strategies consist of multiple measures combined for example: StrategyXYZ = Floodwall + Elevated Homes + Pumps
If you want to learn in more detail about measures and what a strategy is, please read the sections on Measures in the FloodAdapt GUI documentation.
Import libraries
🚀 Step 1. Reading-in the FloodAdapt database
Let’s start with initiating the database and FloodAdapt class. 1. Initiate the database class Settings
by defining the DATABASE_ROOT
and DATABASE_NAME
. 2. Initiate the FloodAdapt
class by parsing the Settings().database_path
.
# Define the static data folder
= Path("../../_data/examples/static-data/3_Measures").resolve()
STATIC_DATA_DIR
# Set up the settings for the database
=Settings(
settings=Path("../../_data/examples").resolve(),
DATABASE_ROOT="charleston_test"
DATABASE_NAME
)
# Create the FloodAdapt instance
= FloodAdapt(settings.database_path) fa
🌧️ Step 2. Create Hazard Measures
We can divide the hazard measures into: 1. Hydraulic (grey) measures - structures such as levees, pumps, seawalls that protect infrastructure and residents 2. Green infrastructure measures - integrate natural elements like parks, green roofs, and permeable pavements into city
To create a hazard measure in Floodadapt we need to create a Measure
object. Depending on the type of measure different attributes must be parsed. There are three types of hazard measures: 1. Floodwall 2. Pump 3. Green Infrastructure The green infrastructure class can be divided into sub-categories:
- Greening - Total storage - Water square
Below we will create a Measure
object for each of the three hazard measure.
🧱🌊 Floodwall
When we create a floodwall
object we need to specify the elevation
attribute to capture the height of the floodwall. To define the elevation
we need to parse a UnitfulLength
object which consists of a value
of type float and a unit
which can be one of the UnitTypesLength
. The selection_type
describes the spatial type. This should be of SelectionType.polyline
for a floodwall.
# Create a measure object for a Floodwall
= FloodWall(
floodwall ="seawall_12ft",
name="12ft Seawall",
description=SelectionType.polyline,
selection_type=str(STATIC_DATA_DIR / "seawall.geojson"),
polygon_file=us.UnitfulLength(value=12, units=us.UnitTypesLength.feet)
elevation )
⛽💦 Pump
When we create a pump
object we need to specify the discharge
attribute to capture the total river discharge in the model. To define the discharge
we need to parse a UnitfulLength
object which consists of a value
of type float and a unit
which can be one of the UnitTypesLength
. The selection_type
describes the spatial type. This should be of SelectionType.polygon
for a pump.
# Create a measure object for a Pump
= Pump(
pump = "Pump",
name="Pump",
description=SelectionType.polygon,
selection_type=str(STATIC_DATA_DIR / "pump.geojson"),
polygon_file=us.UnitfulDischarge(value=1, units=us.UnitTypesDischarge.cfs)
discharge )
🌱🖼️ Green infrastructure
When we create a green infrastructure
object we need to specify the volume
attribute to capture the total storage of the green infrastructure. o define the volume
we need to parse a UnitfulVolume
object which consists of a value
of type float and a unit
which can be one of the UnitTypesVolume
. The selection_type
describes the spatial type. This should be of SelectionType.polygon
or SelectionType.aggregation_area
for a green infrastructure. Other attributes like height
and percentage
are optional.
Note:
GreenInfraStructure
is the only measure for which it is required to pass the specifictype
(orsub-category
as described above) to create the object, all other measures have the correct default.
# Create a measure object for Green infrastructure
= GreenInfrastructure(
greening = "green_infrastructure_storage",
name="Storage through green infrastructure",
descriptiontype=MeasureType.greening,
=SelectionType.polygon,
selection_type=str(STATIC_DATA_DIR / "greening.geojson"),
polygon_file=us.UnitfulVolume(value=43975190.31512848, units=us.UnitTypesVolume.cf),
volume=us.UnitfulHeight(value=3, units=us.UnitTypesLength.feet),
height=100.0
percent_area
)
= GreenInfrastructure(
total_storage = "total_storage_aggregation_area",
name="Total Storage through green infrastructure in aggr area",
descriptiontype=MeasureType.total_storage,
=SelectionType.aggregation_area,
selection_type="aggr_lvl_2",
aggregation_area_type="name5",
aggregation_area_name=us.UnitfulVolume(value=100000000.0, units=us.UnitTypesVolume.cf),
volume
)
= GreenInfrastructure(
water_square ="w_square",
name="Water Square",
descriptiontype=MeasureType.water_square,
=SelectionType.polygon,
selection_type=str(STATIC_DATA_DIR / "water_square.geojson"),
polygon_file=us.UnitfulVolume(value=43975190.31512848, units=us.UnitTypesVolume.cf),
volume=us.UnitfulHeight(value=3, units=us.UnitTypesLength.feet)
height )
Let’s have a look at some of the measures. We can for example explore the floodwall. If you want to explore another measure, update the measure
variable in the cell below and re-run it.
= floodwall # or `pump` or `greening` or `total_storage` or `water_square`
measure = gpd.read_file(measure.polygon_file)
gdf gdf.explore()
💾 Step 3. Saving the hazard measures to the database
# # Save the measures to the database
fa.save_measure(floodwall)
fa.save_measure(pump)
fa.save_measure(greening)
fa.save_measure(total_storage) fa.save_measure(water_square)
🏠 Step 4: Create Impact Measures
To create a impact measure in Floodadapt we need to create a Measure
object. In the attributes we define which type of measure we want to apply using the type
attribute. Depending on the type of measure different attributes must be parsed. There are three types of impact measures: 1. Elevate 2. Buy out 3. Floodproof
We can apply measures to a specific building occupancy by defining the occupancy in the property_type
attribute. For example, if we only want to buyout residential homes we can parse the building type of the residential buildings here. Make sure you parse the same string-value as you use in your Delft-FIAT model to describe that type of building.
If we want to apply the measure only in a specific aggregation area, we can define this with the aggregation_area_type
, which describes the name of the aggregation area category, and the aggregation_area_name
, which responds to the name of the specific aggregation area within the category.
Below we will create a Measure
-object for each impact measure.
🏠⬆️ Elevate
When we create a Elevate
object we need to specify the elevation
attribute to capture the height of the elevation. To define the elevation
we need to parse a UnitfulLengthRefValue
object which consists of a value
of type float, a unit
which can be one of the UnitTypesLength
and a vertical reference from which point the elevation should be calculated. This sholud be parsed as VerticalReference
object.
# Create a measure object for elevating buildings
= Elevate(
elevate ="elevate_homes_2ft",
name="Elevate all residential buildings in aggregation area 1 by 2ft.",
description=SelectionType.polygon,
selection_type="residential",
property_type=str(STATIC_DATA_DIR / "raise_property_polygon.geojson"),
polygon_file=us.UnitfulLengthRefValue(value=2, units=us.UnitTypesLength.feet, type=us.VerticalReference.floodmap)
elevation )
👥💰 Buyout
When we create a Buyout
object we need to specify the property_type
and either provide a spatial file for the area boundaries or define the aggregation_area_type
and aggregation_area_name
.
# Create a measure object for buying out buildings
= Buyout(
buyout = "buyout_all_buildings",
name="Buyout all buildings in a specific area.",
description=SelectionType.aggregation_area,
selection_type="aggr_lvl_2",
aggregation_area_type="name5",
aggregation_area_name="ALL",
property_type )
🏠🌊 Floodproof
When we create a FloodProof
object we need to specify the elevation
attribute to capture the height of the elevation. To define the elevation
we need to parse a UnitfulLength
object which consists of a value
of type float, a unit
which can be one of the UnitTypesLength
.
# Create a measure object for flood proofing buildings
= FloodProof(
flood_proof ="floodproof_all_com",
name="Floodproofing all commercial buildings.",
description=SelectionType.all,
selection_type="commercial",
property_type=us.UnitfulLength(value=2, units=us.UnitTypesLength.feet)
elevation )
Let’s have a look at some of the measures. We can for example explore the area in which all buildings will be elevated.
= elevate # or `buyout` or `flood_proof`
measure = gpd.read_file(measure.polygon_file)
gdf gdf.explore()
💾 Step 5. Saving the impact measures to the database
# Save the measures to the database
fa.save_measure(elevate)
fa.save_measure(buyout) fa.save_measure(flood_proof)
Using the get_measures()
method of the FloodAdapt
class, we can check that the measures have been saved to the database.
# Get a df with all strategies
pd.DataFrame(fa.get_measures())
name | description | path | last_modification_date | geometry | |
---|---|---|---|---|---|
0 | buyout_all_buildings | Buyout all buildings in a specific area. | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.556586 | id name ... |
1 | elevate_homes_2ft | Elevate all residential buildings in aggregati... | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.540973 | id ... |
2 | floodproof_all_com | Floodproofing all commercial buildings. | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.588115 | None |
3 | green_infrastructure_storage | Storage through green infrastructure | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.399198 | ge... |
4 | Pump | Pump | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.383536 | ge... |
5 | seawall_12ft | 12ft Seawall | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.383536 | id ... |
6 | total_storage_aggregation_area | Total Storage through green infrastructure in ... | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.414823 | id name ... |
7 | w_square | Water Square | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.446069 | ge... |
✏️ Step 6: Copying and Editing a Measure in the database
If we want to edit small parts of a measure, it is easier to copy an existing measure and edit the copy. This way we do not have to create a new measure from scratch.
A measure can be copied in the database by using the copy_measure()
method of the FloodAdapt
class. This method takes three arguments: the name of the measure to be copied and the name and description of the new measure. Let’s copy the measure we just created, having in mind that we want to make a measure for flood-proofing residential buildings.
# Copy measure
fa.copy_measure(="floodproof_all_com",
old_name="floodproof_all_res",
new_name="Floodproofing all residential buildings."
new_description )
We can see that now a new measure with name “floodproof_all_res” has been created in the database. However, the actual attributes of the measure are still the same as the original measure.
# Inspect Measure
= fa.get_measure("floodproof_all_res")
floodproof_res floodproof_res
FloodProof(name='floodproof_all_res', description='Floodproofing all residential buildings.', type=<MeasureType.floodproof_properties: 'floodproof_properties'>, selection_type=<SelectionType.all: 'all'>, polygon_file=None, aggregation_area_type=None, aggregation_area_name=None, property_type='commercial', elevation=UnitfulLength(value=2.0, units=UnitTypesLength.feet))
We can directly edit the relevant attributes of the measure object. In this case, we want to change the type to “residential”.
# Edit attributes
= "residential" floodproof_res.property_type
Then using the save_measure()
method of the FloodAdapt
class, we can save the changes to the database. This method takes a two arguments which are the Measure
object and an optional boolean overwrite
. The name
field of the measure object provided will be used to identify which measure is going to be updated in the database, with the given Measure object attributes.
# Save updates
=True) fa.save_measure(floodproof_res, overwrite
Now we can verify that the measure has been updated in the database. The property type is now “residential”.
# Verify updates
= fa.get_measure("floodproof_all_res")
floodproof_res floodproof_res.property_type
'residential'
🧩 Step 6. Create a Strategy
Strategies are combinations measures. They allow us to run an test multiple measures in a single model run.
To create a strategy we need to create a Strategy
object. In the measures
attribute we parse a list of all the names of the measures that we want to apply in that strategy.
Note: All measures of a strategy need to be saved in the database before you can save the strategy itself.
# Create a strategy object
= Strategy(
strategy ="pump_greening_flood_proof",
name="Strategy with pump, greening and floodproofing",
description=[pump.name, greening.name, flood_proof.name],
measures
)
# Save the strategy
fa.save_strategy(strategy)
Using the get_strategies()
method of the FloodAdapt
class, we can check that the strategies have been saved to the database.
# Get a df with all strategies
pd.DataFrame(fa.get_strategies())
name | description | path | last_modification_date | |
---|---|---|---|---|
0 | no_measures | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:39:04.622285 | |
1 | pump_greening_flood_proof | Strategy with pump, greening and floodproofing | C:\a\FloodAdapt\FloodAdapt\docs\_data\examples... | 2025-06-12 16:56:12.825110 |
# Inspect strategy
= fa.get_strategy("pump_greening_flood_proof")
strategy strategy
Strategy(name='pump_greening_flood_proof', description='Strategy with pump, greening and floodproofing', measures=['Pump', 'green_infrastructure_storage', 'floodproof_all_com'])
✏️ Step 7. Copying and Editing a Strategy in the database
If we want to edit small parts of a strategy, it is easier to copy an existing strategy and edit the copy. This way we do not have to create a new strategy from scratch.
A strategy can be copied in the database by using the copy_strategy()
method of the FloodAdapt
class. This method takes three arguments: the name of the strategy to be copied and the name and description of the new strategy. Let’s copy the strategy we just created, having in mind that we want to remove the greening from the strategy and add a floodwall instead.
# Copy strategy
fa.copy_strategy(="pump_greening_flood_proof",
old_name="pump_floodwall_flood_proof",
new_name="Strategy with pump, flodwall and floodproofing.",
new_description )
We can see that now a new strategy with name “pump_floodwall_flood_proof” has been created in the database. However, the actual attributes of the strtaegy are still the same as the original srtategy.
# Inspect strategy2
= fa.get_strategy("pump_floodwall_flood_proof")
strategy_2 strategy_2
Strategy(name='pump_floodwall_flood_proof', description='Strategy with pump, flodwall and floodproofing.', measures=['Pump', 'green_infrastructure_storage', 'floodproof_all_com'])
We can directly edit the relevant attributes of the measure object. In this case, we want to change the type to “residential”.
# Remove greening
strategy_2.measures.remove(greening.name) # Add floodwall strategy_2.measures.append(floodwall.name)
Then using the save_strategy(name, overwrite=True)
method of the FloodAdapt
class, we can save the changes to the database. This method takes a single argument which is a Strategy
object. The name
field of the Strategy object provided will be used to identify which strategy is going to be updated in the database, with the given Strategy object attributes.
# Save updates
=True) fa.save_strategy(strategy_2, overwrite
Now we can verify that the strategy has been updated in the database.
# Verify updates
= fa.get_strategy("pump_floodwall_flood_proof")
strategy_2 strategy_2.measures
['Pump', 'floodproof_all_com', 'seawall_12ft']
Finished!
Congratulations you created all measures possible in FloodAdap and combined some of them into a strategy!