Skip to content

Simulate breach

from threedi_api_client.api import ThreediApi
from threedi_api_client.openapi.models import ConstantRain
from threedi_api_client.openapi.models import Breach
from threedi_api_client.openapi.models import BasicPostProcessing
from threedi_api_client.versions import V3Api
env_file = "../.env"
api_client: V3Api = ThreediApi(env_file)

basic input💡

##organisation
organisation_uuid = "b08433fa47c1401eb9cbd4156034c679"

#simulation_name
scenario_name = "My test simulation"

#calculation_duration_hrs
calculation_duration_hrs = 48

create simulation💡

threedimodel = api_client.threedimodels_list(name__icontains='v2_bergermeer').results[0]

# Retrieve first simulation template
simulation_templates = api_client.simulation_templates_list(simulation__threedimodel__id=threedimodel.id)
assert simulation_templates.count > 0, f"No simulation templates found for threedimodel {threedimodel.name}"
simulation_template_id = simulation_templates.results[0].id


sim = api_client.simulations_from_template(
    data={
        "template": simulation_template_id,
        "name": scenario_name,
        "organisation": organisation_uuid,
        "start_datetime": datetime.utcnow(),
        "duration": calculation_duration_hrs*3600
    }
)

set initial water levels from raster💡

# Apply initial water level raster
api_client.simulations_initial2d_water_level_raster_create(
    data={
        "aggregation_method":'min',
        "initial_waterlevel":"25986"
    },
    simulation_pk=sim.id
)

Set Breach💡

### create breach object
breach_uitdam = Breach(
    potential_breach = 9554,
    duration_till_max_depth = 100,
    initial_width = 15,
    offset = 0

)

api_client.simulations_events_breaches_create(sim.id, breach_uitdam)
api_client.simulations_actions_create(simulation_pk=sim.id, data={"name": "start"})