├── README.md └── TWI-filled-plus0.1constant.py /README.md: -------------------------------------------------------------------------------- 1 | Topographic Wetness Index 2 | 2013-11-12 3 | Jeffrey Wolf (EEB); G. Andrew Fricker (GEOG) 4 | UCLA 5 | 6 | This script was written to be used as a tool in ArcGIS. This python script can be imported to create a TWI tool. Inputs are the workspace and the input DEM, output is the TWI layer 7 | We chose to fill all sinks due to some small sinks in a lidar redived DEM. We also add a small constant to the denominator to avoid dividng by zero. 8 | 9 | The original script was based off the arcpy script written by Prasad Pathak. 10 | http://arcscripts.esri.com/details.asp?dbid=16750 11 | 12 | This revised script converts the terrain slope in degrees to radians 13 | This script also uses the default settings for the flow accumulation raster 14 | however different methods to calculate flow accumulation can dramtically change the results of the TWI 15 | -------------------------------------------------------------------------------- /TWI-filled-plus0.1constant.py: -------------------------------------------------------------------------------- 1 | """ 2 | TWI-filled-plus0.1constant.py 3 | Topographic Wetness Index 4 | 2013-11-12 5 | Jeffrey Wolf (EEB); G. Andrew Fricker (GEOG) 6 | UCLA 7 | 8 | This script was written to be used as a tool in ArcGIS. This python script can be imported to create a TWI tool. Inputs are the workspace and the input DEM, output is the TWI layer 9 | We chose to fill all sinks due to some small sinks in a lidar redived DEM. We also add a small constant to the denominator to avoid dividng by zero. 10 | 11 | The original script was based off the arcpy script written by Prasad Pathak. 12 | http://arcscripts.esri.com/details.asp?dbid=16750 13 | 14 | This revised script converts the terrain slope in degrees to radians 15 | This script also uses the default settings for the flow accumulation raster 16 | however different methods to calculate flow accumulation can dramtically change the results of the TWI 17 | 18 | """ 19 | 20 | import arcpy, math 21 | 22 | 23 | if __name__ == '__main__': 24 | arcpy.CheckOutExtension("Spatial") 25 | 26 | # Define workspace and set input and output files 27 | arcpy.env.workspace = arcpy.GetParameterAsText(0) 28 | inDEM = arcpy.GetParameterAsText(1) 29 | outTWI = arcpy.GetParameterAsText(2) 30 | 31 | # Intermediates 32 | arcpy.AddMessage("Filling DEM.\n") 33 | DEM_filled = arcpy.sa.Fill(inDEM) 34 | 35 | arcpy.AddMessage("Creating flow direction.\n") 36 | outFlowDirection = arcpy.sa.FlowDirection(DEM_filled, "FORCE") 37 | 38 | 39 | arcpy.AddMessage("Creating flow accumulation.\n") 40 | #outFlowAccumulation = arcpy.sa.FlowAccumulation(outFlowDirection, "", "FLOAT") + 1 41 | outFlowAccumulation = arcpy.sa.FlowAccumulation(outFlowDirection, "", "INTEGER") + 1 42 | 43 | arcpy.AddMessage("Creating slope.\n") 44 | slope = arcpy.sa.Slope(DEM_filled) 45 | 46 | 47 | arcpy.AddMessage("Converting slope in degrees to slope in radians") 48 | # 2Pi radians = 360 degrees 49 | # Pi radians = 180 degrees 50 | # conversion: Pi radians/180 degress 51 | slope_radians = slope * math.pi/180.0 52 | 53 | # Output 54 | arcpy.AddMessage("Creating TWI\n") 55 | TWI = arcpy.sa.Ln(outFlowAccumulation / (arcpy.sa.Tan(slope_radians)+.01)) 56 | TWI.save(outTWI) 57 | arcpy.AddMessage("Saved TWI. Done.") 58 | 59 | --------------------------------------------------------------------------------