from datetime import datetime
from pathlib import Path
from flood_adapt import Settings, FloodAdapt
from flood_adapt import unit_system as us
from flood_adapt.config.sfincs import RiverModel
from flood_adapt.objects import (
EventSet,
SubEventModel,
SyntheticEvent,
)from flood_adapt.objects.forcing import (
DischargeConstant,
ForcingType,
TimeFrame,
ShapeType,
TimeseriesFactory,
RainfallSynthetic,
SurgeModel,
TideModel,
WaterlevelSynthetic,
WindConstant,
)
# Configure FloodAdapt
= Settings(
settings =Path("../../_data/examples").resolve(),
DATABASE_ROOT="charleston_test"
DATABASE_NAME
)
= FloodAdapt(database_path=settings.database_path) fa
Event set creation for Risk Analysis
This notebook explains how to create the input files for a risk analysis in the correct format and place them in the correct folder structure. For an explanation on how to derive the (compound) events and their (joint) probabilities, the reader is referred to the FloodAdapt Setup Guide Event Set.
⏱️ Step 1. Setup and Imports
🗓️ Step 2. Set name, frequencies and parameters to build subevents
Set the name of the event set and the parameters for the input events and their frequencies. In this example, we are using three synthetic events with different storm surge heights and peak rainfall intensities. Alternatively, historic gauged and ungauged events or hurricanes are possible as well, see Events for examples on how to set up different subevents.
= "event_set"
name
# Peak surge values in the subevents.
# Surge is timed to always peak at 24.8 hours after the event start, coinciding with high tide at a tidal phase of 0 and lasting for 10 hours.
= [2.5, 1, 3] # in meters
surge_values
# Peak rainfall intensities in the three subevents.
# Rainfall is applied as a 6 hour "block" shape preceding the peak of the storm surge.
= [10, 15, 5] # in mm/hr
rainfall_values
# Occurrence frequencies of the three events
= [0.1, 2, 0.05] freq
🧩 Step 3. Create subevents
Create the subevents from the parameters defined in Step 1.
= []
events = 0
number for surge, rainfall in zip(surge_values, rainfall_values):
+= 1
number
events.append(
SyntheticEvent(= f"subevent_{number}",
name =TimeFrame(start_time=datetime(2020, 1, 1, 0, 0, 0),end_time=datetime(2020, 1, 3, 0, 0, 0)),
time={
forcings# constant wind speed 10 m/, direction 90 degrees (from the East)
ForcingType.WIND: [
WindConstant(=us.UnitfulVelocity(value=10, units=us.UnitTypesVelocity.mps),
speed=us.UnitfulDirection(
direction=90, units=us.UnitTypesDirection.degrees
value
),
)
],# block rainfall starting 18h after event start, duration 6h, intensity 10 mm/hr
ForcingType.RAINFALL: [
RainfallSynthetic(= TimeseriesFactory.from_args(
timeseries =ShapeType.block,
shape_type=us.UnitfulTime(
duration=6, units=us.UnitTypesTime.hours
value
),=us.UnitfulTime(
peak_time=21, units=us.UnitTypesTime.hours
value
),=us.UnitfulIntensity(
peak_value=rainfall, units=us.UnitTypesIntensity.mm_hr
value
),
)
)
],# constant discharge in Cooper River of 5000 cubic feet per second
ForcingType.DISCHARGE: [
DischargeConstant(=RiverModel(
river="cooper",
name="Cooper River",
description=595546.3,
x_coordinate=3675590.6,
y_coordinate=us.UnitfulDischarge(
mean_discharge=5000, units=us.UnitTypesDischarge.cfs
value
),
),=us.UnitfulDischarge(
discharge=5000, units=us.UnitTypesDischarge.cfs
value
),
)
],
ForcingType.WATERLEVEL: [
WaterlevelSynthetic(# storm surge with gaussian shape, duration 10 hours, peak at 24h after event start_time, peak height 3m
=SurgeModel(
surge=TimeseriesFactory.from_args(
timeseries=ShapeType.gaussian,
shape_type=us.UnitfulTime(
duration=10, units=us.UnitTypesTime.hours
value
),=us.UnitfulTime(
peak_time=24, units=us.UnitTypesTime.hours
value
),=us.UnitfulLength(
peak_value=surge, units=us.UnitTypesLength.meters
value
),
)
),# tide with 1m amplitude and 12.4h duration
=TideModel(
tide=us.UnitfulLength(
harmonic_amplitude=1, units=us.UnitTypesLength.meters
value
),=us.UnitfulTime(
harmonic_period=12.4, units=us.UnitTypesTime.hours
value
),=us.UnitfulTime(
harmonic_phase=0, units=us.UnitTypesTime.hours
value
),
),
)
],
},
)
)
print(events)
[SyntheticEvent(name='subevent_1', description='', time=TimeFrame(start_time=datetime.datetime(2020, 1, 1, 0, 0), end_time=datetime.datetime(2020, 1, 3, 0, 0)), template=<Template.Synthetic: 'Synthetic'>, mode=<Mode.single_event: 'single_event'>, forcings={<ForcingType.WIND: 'WIND'>: [WindConstant(type=<ForcingType.WIND: 'WIND'>, source=<ForcingSource.CONSTANT: 'CONSTANT'>, speed=UnitfulVelocity(value=10.0, units=UnitTypesVelocity.mps), direction=UnitfulDirection(value=90.0, units=UnitTypesDirection.degrees))], <ForcingType.RAINFALL: 'RAINFALL'>: [RainfallSynthetic(type=<ForcingType.RAINFALL: 'RAINFALL'>, source=<ForcingSource.SYNTHETIC: 'SYNTHETIC'>, timeseries=BlockTimeseries(shape_type=<ShapeType.block: 'block'>, duration=UnitfulTime(value=6.0, units=UnitTypesTime.hours), peak_time=UnitfulTime(value=21.0, units=UnitTypesTime.hours), peak_value=UnitfulIntensity(value=10.0, units=UnitTypesIntensity.mm_hr), cumulative=None, fill_value=0.0))], <ForcingType.DISCHARGE: 'DISCHARGE'>: [DischargeConstant(type=<ForcingType.DISCHARGE: 'DISCHARGE'>, source=<ForcingSource.CONSTANT: 'CONSTANT'>, river=RiverModel(name='cooper', description='Cooper River', mean_discharge=UnitfulDischarge(value=5000.0, units=UnitTypesDischarge.cfs), x_coordinate=595546.3, y_coordinate=3675590.6), discharge=UnitfulDischarge(value=5000.0, units=UnitTypesDischarge.cfs))], <ForcingType.WATERLEVEL: 'WATERLEVEL'>: [WaterlevelSynthetic(type=<ForcingType.WATERLEVEL: 'WATERLEVEL'>, source=<ForcingSource.SYNTHETIC: 'SYNTHETIC'>, surge=SurgeModel(timeseries=GaussianTimeseries(shape_type=<ShapeType.gaussian: 'gaussian'>, duration=UnitfulTime(value=10.0, units=UnitTypesTime.hours), peak_time=UnitfulTime(value=24.0, units=UnitTypesTime.hours), peak_value=UnitfulLength(value=2.5, units=UnitTypesLength.meters), cumulative=None, fill_value=0.0)), tide=TideModel(harmonic_amplitude=UnitfulLength(value=1.0, units=UnitTypesLength.meters), harmonic_phase=UnitfulTime(value=0.0, units=UnitTypesTime.hours), harmonic_period=UnitfulTime(value=12.4, units=UnitTypesTime.hours)))]}, rainfall_multiplier=1.0), SyntheticEvent(name='subevent_2', description='', time=TimeFrame(start_time=datetime.datetime(2020, 1, 1, 0, 0), end_time=datetime.datetime(2020, 1, 3, 0, 0)), template=<Template.Synthetic: 'Synthetic'>, mode=<Mode.single_event: 'single_event'>, forcings={<ForcingType.WIND: 'WIND'>: [WindConstant(type=<ForcingType.WIND: 'WIND'>, source=<ForcingSource.CONSTANT: 'CONSTANT'>, speed=UnitfulVelocity(value=10.0, units=UnitTypesVelocity.mps), direction=UnitfulDirection(value=90.0, units=UnitTypesDirection.degrees))], <ForcingType.RAINFALL: 'RAINFALL'>: [RainfallSynthetic(type=<ForcingType.RAINFALL: 'RAINFALL'>, source=<ForcingSource.SYNTHETIC: 'SYNTHETIC'>, timeseries=BlockTimeseries(shape_type=<ShapeType.block: 'block'>, duration=UnitfulTime(value=6.0, units=UnitTypesTime.hours), peak_time=UnitfulTime(value=21.0, units=UnitTypesTime.hours), peak_value=UnitfulIntensity(value=15.0, units=UnitTypesIntensity.mm_hr), cumulative=None, fill_value=0.0))], <ForcingType.DISCHARGE: 'DISCHARGE'>: [DischargeConstant(type=<ForcingType.DISCHARGE: 'DISCHARGE'>, source=<ForcingSource.CONSTANT: 'CONSTANT'>, river=RiverModel(name='cooper', description='Cooper River', mean_discharge=UnitfulDischarge(value=5000.0, units=UnitTypesDischarge.cfs), x_coordinate=595546.3, y_coordinate=3675590.6), discharge=UnitfulDischarge(value=5000.0, units=UnitTypesDischarge.cfs))], <ForcingType.WATERLEVEL: 'WATERLEVEL'>: [WaterlevelSynthetic(type=<ForcingType.WATERLEVEL: 'WATERLEVEL'>, source=<ForcingSource.SYNTHETIC: 'SYNTHETIC'>, surge=SurgeModel(timeseries=GaussianTimeseries(shape_type=<ShapeType.gaussian: 'gaussian'>, duration=UnitfulTime(value=10.0, units=UnitTypesTime.hours), peak_time=UnitfulTime(value=24.0, units=UnitTypesTime.hours), peak_value=UnitfulLength(value=1.0, units=UnitTypesLength.meters), cumulative=None, fill_value=0.0)), tide=TideModel(harmonic_amplitude=UnitfulLength(value=1.0, units=UnitTypesLength.meters), harmonic_phase=UnitfulTime(value=0.0, units=UnitTypesTime.hours), harmonic_period=UnitfulTime(value=12.4, units=UnitTypesTime.hours)))]}, rainfall_multiplier=1.0), SyntheticEvent(name='subevent_3', description='', time=TimeFrame(start_time=datetime.datetime(2020, 1, 1, 0, 0), end_time=datetime.datetime(2020, 1, 3, 0, 0)), template=<Template.Synthetic: 'Synthetic'>, mode=<Mode.single_event: 'single_event'>, forcings={<ForcingType.WIND: 'WIND'>: [WindConstant(type=<ForcingType.WIND: 'WIND'>, source=<ForcingSource.CONSTANT: 'CONSTANT'>, speed=UnitfulVelocity(value=10.0, units=UnitTypesVelocity.mps), direction=UnitfulDirection(value=90.0, units=UnitTypesDirection.degrees))], <ForcingType.RAINFALL: 'RAINFALL'>: [RainfallSynthetic(type=<ForcingType.RAINFALL: 'RAINFALL'>, source=<ForcingSource.SYNTHETIC: 'SYNTHETIC'>, timeseries=BlockTimeseries(shape_type=<ShapeType.block: 'block'>, duration=UnitfulTime(value=6.0, units=UnitTypesTime.hours), peak_time=UnitfulTime(value=21.0, units=UnitTypesTime.hours), peak_value=UnitfulIntensity(value=5.0, units=UnitTypesIntensity.mm_hr), cumulative=None, fill_value=0.0))], <ForcingType.DISCHARGE: 'DISCHARGE'>: [DischargeConstant(type=<ForcingType.DISCHARGE: 'DISCHARGE'>, source=<ForcingSource.CONSTANT: 'CONSTANT'>, river=RiverModel(name='cooper', description='Cooper River', mean_discharge=UnitfulDischarge(value=5000.0, units=UnitTypesDischarge.cfs), x_coordinate=595546.3, y_coordinate=3675590.6), discharge=UnitfulDischarge(value=5000.0, units=UnitTypesDischarge.cfs))], <ForcingType.WATERLEVEL: 'WATERLEVEL'>: [WaterlevelSynthetic(type=<ForcingType.WATERLEVEL: 'WATERLEVEL'>, source=<ForcingSource.SYNTHETIC: 'SYNTHETIC'>, surge=SurgeModel(timeseries=GaussianTimeseries(shape_type=<ShapeType.gaussian: 'gaussian'>, duration=UnitfulTime(value=10.0, units=UnitTypesTime.hours), peak_time=UnitfulTime(value=24.0, units=UnitTypesTime.hours), peak_value=UnitfulLength(value=3.0, units=UnitTypesLength.meters), cumulative=None, fill_value=0.0)), tide=TideModel(harmonic_amplitude=UnitfulLength(value=1.0, units=UnitTypesLength.meters), harmonic_phase=UnitfulTime(value=0.0, units=UnitTypesTime.hours), harmonic_period=UnitfulTime(value=12.4, units=UnitTypesTime.hours)))]}, rainfall_multiplier=1.0)]
💾 Step 4. Create and save event set
In this step, we create an event set from the SubEvents
created in Step 2, load the actual Event
objects into it, and save it to the database. This event set can then be used like any other event in a Scenario. Click here to see examples on how to build a scenario.
= []
sub_events for event, frequency in zip(events, freq):
=event.name, frequency=frequency))
sub_events.append(SubEventModel(name
= EventSet(
event_set =name,
name=sub_events,
sub_events
)
event_set.load_sub_events(events)
fa.save_event(event_set)print(fa.get_events()["name"])
['event_set', 'test_set']