Inundation Dynamics Simulation¶
Create an ArcGIS Pro project¶
Open ArcGIS Pro and create a new project titled inundation
.
Clone the arcgispro-py3 env¶
Clone the arcgispro-py
env to create a new env named arcgispro-py3-clone
.
Install scikit-image¶
Activate the arcgispro-py3-clone
env and install the scikit-image
package into the env.
Import libraries¶
In [ ]:
Copied!
import os
import arcpy
import os
import arcpy
Set workspace¶
Set to working space to the project folder instead of a GeoDatabase.
In [ ]:
Copied!
arcpy.env.workspace = os.path.dirname(arcpy.env.workspace)
print(arcpy.env.workspace)
arcpy.env.workspace = os.path.dirname(arcpy.env.workspace)
print(arcpy.env.workspace)
In [ ]:
Copied!
# Path to the custom toolbox
toolbox_path = r"lidar\lidar\toolbox\ArcGIS Pro Hydrology Analyst.tbx" # Change to your toolbox path
# Import the toolbox
arcpy.ImportToolbox(toolbox_path, "HydroTools")
# Path to the custom toolbox
toolbox_path = r"lidar\lidar\toolbox\ArcGIS Pro Hydrology Analyst.tbx" # Change to your toolbox path
# Import the toolbox
arcpy.ImportToolbox(toolbox_path, "HydroTools")
Set input data and output folder¶
In [ ]:
Copied!
input_dem = os.path.join(arcpy.env.workspace, r"lidar\examples\lidar-dem\dem_full.tif")
out_dir = os.path.join(os.path.expanduser("~\Downloads"), "output")
input_dem = os.path.join(arcpy.env.workspace, r"lidar\examples\lidar-dem\dem_full.tif")
out_dir = os.path.join(os.path.expanduser("~\Downloads"), "output")
In [ ]:
Copied!
if not os.path.exists(out_dir):
os.makedirs(out_dir)
if not os.path.exists(out_dir):
os.makedirs(out_dir)
In [ ]:
Copied!
print(input_dem)
print(input_dem)
In [ ]:
Copied!
print(out_dir)
print(out_dir)
In [ ]:
Copied!
arcpy.env.workspace = out_dir
arcpy.env.workspace = out_dir
Extract sinks¶
In [ ]:
Copied!
arcpy.HydroTools.ExtrackSink(
Input_DEM=input_dem,
Minimum_Sink_Size=1000,
Minimum_Sink_Depth__from_water_surface_to_spill_point_=1,
Buffer_Distance=0,
Output_Sink_Polygon="sink.shp",
)
arcpy.HydroTools.ExtrackSink(
Input_DEM=input_dem,
Minimum_Sink_Size=1000,
Minimum_Sink_Depth__from_water_surface_to_spill_point_=1,
Buffer_Distance=0,
Output_Sink_Polygon="sink.shp",
)
Delineate catchments¶
In [ ]:
Copied!
arcpy.HydroTools.DelineateCatchment(
Input_Partially_Filled_DEM="dem_partially_filled.tif",
Input_Sink_Polygon="sink.shp",
Output_Catchment_Polygon="catchment.shp",
)
arcpy.HydroTools.DelineateCatchment(
Input_Partially_Filled_DEM="dem_partially_filled.tif",
Input_Sink_Polygon="sink.shp",
Output_Catchment_Polygon="catchment.shp",
)
Delineate flowpaths¶
In [ ]:
Copied!
arcpy.HydroTools.DelineateFlowPath(
Input_Fully_Filled_DEM="dem_fully_filled.tif",
Input_Sink_Polygon="sink.shp",
Rainfall_Intensity__cm_h_="5",
Output_Flow_Path="flowpath.shp",
)
arcpy.HydroTools.DelineateFlowPath(
Input_Fully_Filled_DEM="dem_fully_filled.tif",
Input_Sink_Polygon="sink.shp",
Rainfall_Intensity__cm_h_="5",
Output_Flow_Path="flowpath.shp",
)
Delineate depression hierarchy¶
In [ ]:
Copied!
arcpy.HydroTools.DelineateDepressionHierarchy(
Input_DEM_Sink="sink.tif",
Minimum_Depression_Size="1000",
Minimum_Depression_Depth="0.5",
Slicing_Interval="0.2",
Output_Depression_Level_Image="level.tif",
)
arcpy.HydroTools.DelineateDepressionHierarchy(
Input_DEM_Sink="sink.tif",
Minimum_Depression_Size="1000",
Minimum_Depression_Depth="0.5",
Slicing_Interval="0.2",
Output_Depression_Level_Image="level.tif",
)
Delinate catchment hierarchy¶
In [ ]:
Copied!
arcpy.HydroTools.CatchmentHierarchy(
Input_Partially_Filled_DEM="dem_partially_filled.tif",
Input_Depression_Hierarchy_Shapefiles="shp",
Output_Catchment_Hierarchy="catchment_hir.tif",
)
arcpy.HydroTools.CatchmentHierarchy(
Input_Partially_Filled_DEM="dem_partially_filled.tif",
Input_Depression_Hierarchy_Shapefiles="shp",
Output_Catchment_Hierarchy="catchment_hir.tif",
)
Simulate inundation¶
In [ ]:
Copied!
os.makedirs(os.path.join(arcpy.env.workspace, "simulation"), exist_ok=True)
os.makedirs(os.path.join(arcpy.env.workspace, "simulation"), exist_ok=True)
In [ ]:
Copied!
arcpy.HydroTools.SimulateInundation(
Input_Sink_Image="sink.tif",
Input_Catchment_Hierarchy_Image="catchment_hir.tif",
Minimum_Depression_Size="1000",
Minimum_Depression_Depth="0.2",
Slicing_Interval="0.2",
Rainfall_Intensity__cm_h_="5",
Rainfall_Duration__h_="50",
Simulation_Time_Step__h_="1",
Output_Inundation_Image_Folder="simulation",
)
arcpy.HydroTools.SimulateInundation(
Input_Sink_Image="sink.tif",
Input_Catchment_Hierarchy_Image="catchment_hir.tif",
Minimum_Depression_Size="1000",
Minimum_Depression_Depth="0.2",
Slicing_Interval="0.2",
Rainfall_Intensity__cm_h_="5",
Rainfall_Duration__h_="50",
Simulation_Time_Step__h_="1",
Output_Inundation_Image_Folder="simulation",
)
Play the animation¶
In [ ]:
Copied!
arcpy.HydroTools.PlayAnimation(
Input_DEM="dem_partially_filled.tif",
Loops="3",
Input_Inundation_Image_Folder="simulation",
)
arcpy.HydroTools.PlayAnimation(
Input_DEM="dem_partially_filled.tif",
Loops="3",
Input_Inundation_Image_Folder="simulation",
)