import flood_adapt.objects.forcing as f
from pathlib import Path
from datetime import datetime
from flood_adapt.objects import HurricaneEvent, TimeFrame
from flood_adapt.objects.events.hurricane import TranslationModel
from flood_adapt import unit_system as us
from flood_adapt import FloodAdapt, Settings
# Setup FloodAdapt
= Path("../../_data/examples/static-data").resolve()
STATIC_DATA_DIR = Settings(
settings =Path("../../_data/examples").resolve(),
DATABASE_ROOT="charleston_test"
DATABASE_NAME
)= FloodAdapt(database_path=settings.database_path) fa
📘 Example: Creating a Hurricane Event in FloodAdapt
This notebook demonstrates how to create a hurricane event using FloodAdapt. Hurricane events are valuable for controlled testing, sensitivity analysis, and understanding the behavior of flood models under simplified or hypothetical scenarios.
A FloodAdapt Event consists of 2 things:
- a
TimeFrame
describing the start and end time of the hazard simulation(s) - a collection of forcings to be applied to the hazard model(s)
In this example, we construct a full HurricaneEvent
with water level
, rainfall
, wind
, and river discharge
forcings, and then save it to a FloodAdapt database.
⏱️ Step 1. Setup and Imports
We begin by importing the required classes and modules for constructing hurricane forcings and managing event data within the flood_adapt framework.
🗓️ Step 2. Define the Simulation Time Frame
We specify a one-day time frame for the hurricane event, from January 1 to January 2, 2025. Make sure the time frame covers the tinme specified in your hurricane track file.
# Create an time frame for the simulation
= datetime(year=2025, month=1, day=1)
start_time = datetime(year=2025, month=1, day=2)
end_time = TimeFrame(start_time=start_time, end_time=end_time) time_frame
🌊 Step 3. Define Water Level Forcing
Water levels for Hurricane Events are computed by taking the Hurricane Track, and generating a pressure and wind field along its track.
These fields are then used as forcing inputs to the offshore simulation, which generates the storm surge to be used for the overland simulation. So for waterlevels, we only need to specify to use the offshore model as the input, denoted with WaterlevelModel
= f.WaterlevelModel() water_levels
🌧️ Step 3. Obtain a hurricane track
You can include an IBTrACS hurricane database with recent and historic tracks in the FloodAdapt database. You can use any track from the database and optionally shift the track north, southh, east or west.
NOTE: Hurricane events are only available in FloodAdapt when you have an offshore flood hazard model in your database that simulates the surge from the hurricane track.
# Get the cyclone database
= fa.database.static.get_cyclone_track_database()
cyclone_db = cyclone_db.list_names().index("IAN")
ian_index
# Not all cyclone tracks have names, in addition to duplicate names existing, so the index is required
= fa.get_cyclone_track_by_index(index=ian_index)
track = STATIC_DATA_DIR / "IAN.cyc"
track_file =track_file, fmt="ddb_cyc")
track.write_track(filename
# Optionally translate the cyclone track from what is defined in the file
= TranslationModel(
translation =us.UnitfulLength(value=3000, units=us.UnitTypesLength.meters),
eastwest_translation=us.UnitfulLength(value=5000, units=us.UnitTypesLength.meters),
northsouth_translation )
🌧️ Step 4. Define Track forcings
Given a Hurricane track, the wind field is always computer from the track. You can choose to model the rainfall based on a parametric model around the hurricane track or choose any iother rainfall option.
# We want to include the rainfall and wind from the hurricane track
= f.RainfallTrack(path=track_file)
rainfall = f.WindTrack(path=track_file) wind
🏞️ Step 5. Define River Discharge Forcing
Discharge is defined for two pre-configured rivers in this example. These rivers must be registered in the hazard model configuration beforehand, see [Database builder].
# The available rivers are defined in the hazard model when creating the database.
# You cannot add new rivers to the model in an event
# You can only set the discharge of each given river.
= fa.database.site.sfincs.river[0]
river
= f.DischargeConstant(
discharge =river,
river=us.UnitfulDischarge(value=100, units=us.UnitTypesDischarge.cms)
discharge
)
# Inspect
= discharge.to_dataframe(time_frame=time_frame)
df ="Constant Discharge River", xlabel="Time", ylabel="Discharge (cms)", legend=True, figsize=(5, 2)) df.plot(title
🧩 Step 6. Combine Forcings and Create hurricane Event
All defined forcings are collected into a single dictionary, which is used to construct a hurricaneEvent.
NOTE: each event can only have 1 forcing of the types:
water level
,rainfall
andwind
. Fordischarge
however, each river is required to have a forcing associated with it.
# Create a hurricaneEvent with the forcings and time frame
= HurricaneEvent(
event ="example_hurricane_event",
name=time_frame,
time= {
forcings
f.ForcingType.WATERLEVEL: [water_levels],
f.ForcingType.RAINFALL: [rainfall],
f.ForcingType.WIND: [wind],
f.ForcingType.DISCHARGE: [discharge],
},=track.name,
track_name=translation,
hurricane_translation )
💾 Step 7. Save the Event to a FloodAdapt Database
Finally, we save the event to a FloodAdapt database.
# Save the event to the database
=event) fa.save_event(event