Here a sniipit of some Python code that builds "accumulated" elevation, slope, curvature, etc. grids - these grids are used as part of a DEM-based stream perdiction model.Note: flowDirLclGrd = a flow direction grid derived from a filled DEM.flowAcc1Grd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\flowacc1"
gp.FlowAccumulation_sa(flowDirLclGrd, flowAcc1Grd, "", "FLOAT"); showGpMessage()
#Process: Builds a flow accumulation grid - accumulated acreage
flowAcc2Grd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\flowacc2"
somaExp = "FlowAccumulation(" + flowDirLclGrd + ") * " + str(int(gp.cellsize) * int(gp.cellsize)) + " / 43560"
gp.SingleOutputMapAlgebra_sa(somaExp, flowAcc2Grd); showGpMessage()
#Process: Builds a flow accumulation grid - of estimated CFS using only watershed area and precip
pcpGrd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\pcp"
gp.Resample_management(precipGrd, pcpGrd, gp.cellsize, "BILINEAR"); showGpMessage()
flowAcc3Grd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\flowacc3"
somaExp = "flowaccumulation(" + flowDirLclGrd + ", " + pcpGrd + ", 'FLOAT') * " + str(int(gp.cellsize) * int(gp.cellsize)) + ") / 12 ) / 31556926" #31556926 = seconds/year
gp.SingleOutputMapAlgebra_sa(somaExp, flowAcc3Grd); showGpMessage()
#Process: Reclassifies any 0s flowAcc1Grd to 1 (which makes it so that we can use division (aka can't divide a grid by another grid if the denominator has a 0 in it)
flowAcc5Grd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\flowacc5"
somaExp = "con(" + flowAcc1Grd + " == 0, 1, " + flowAcc1Grd + ")"
gp.SingleOutputMapAlgebra_sa(somaExp, flowAcc5Grd); showGpMessage()
#Process: Builds an accumulated elevation grid (uses the fil2LclGrd)
accElvGrd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\acc_elev"
somaExp = "flowaccumulation(" + flowDirLclGrd + ", " + fil2LclGrd + ", 'FLOAT') / " + flowAcc5Grd
gp.SingleOutputMapAlgebra_sa(somaExp, accElvGrd); showGpMessage()
#Process: Builds an accumulated slope grid
accSlpGrd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\acc_slp"
somaExp = "flowaccumulation(" + flowDirLclGrd + ", " + slpGrd + ", 'FLOAT') / " + flowAcc5Grd
gp.SingleOutputMapAlgebra_sa(somaExp, accSlpGrd); showGpMessage()
#Process: Builds an accumulated curvature grid - fancy stuff is to deal with negative values
accCurGrd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\acc_cur"
somaExp = "(flowaccumulation(" + flowDirLclGrd + ", max(" + curGrd + ", 0), 'FLOAT') - flowaccumulation(" + flowDirLclGrd + ", max(-1 * " + curGrd + ", 0), 'FLOAT')) / " + flowAcc5Grd
gp.SingleOutputMapAlgebra_sa(somaExp, accCurGrd); showGpMessage()
#Process: Builds an accumulated profile grid
accProGrd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\acc_pro"
somaExp = "(flowaccumulation(" + flowDirLclGrd + ", max(" + proGrd + ", 0), 'FLOAT') - flowaccumulation(" + flowDirLclGrd + ", max(-1 * " + proGrd + ", 0), 'FLOAT')) / " + flowAcc5Grd
gp.SingleOutputMapAlgebra_sa(somaExp, accProGrd); showGpMessage()
#Process: Builds an accumulated plan grid
accPlnGrd = root + "\\" + areaFolderName + "\\" + origOidFolderName + "\\acc_pln"
somaExp = "(flowaccumulation(" + flowDirLclGrd + ", max(" + plnGrd + ", 0), 'FLOAT') - flowaccumulation(" + flowDirLclGrd + ", max(-1 * " + plnGrd + ", 0), 'FLOAT')) / " + flowAcc5Grd
gp.SingleOutputMapAlgebra_sa(somaExp, accPlnGrd); showGpMessage()