I use an hydro tool developped by the Mineasota Gov.
Description: This script creates a raster whose cells measure the length of time
in seconds, that it takes water to flow across it and then accumulates
the time from the cell to the outlet of the watershed. water velocity
is calculated as a function of hydraulic radius, Manning's N and slope
Using a DEM as a source, flow direction, flow accumulation and slope (percent)
is calculated.
This tool creates a lot of raster by on various imputs and formulas.
I would like to change a formula:, this is the original:
exp = '(' + str(hydRad1) + ' * (' + flowAcc + ' * ' + cellSqMilesStr + ')) + ' + str(hydRad2) + ''
What I would like is : hydRad1 * ((' + flowAcc + ' * ' + cellSqMilesStr + ') ^ hydRad)
Thank you!
exp2 = str(hydRad1) + ' * ((' + str(flowAcc) + ' * ' + atr(cellSqMilesStr) + ') ** ' + str(hydRad) + ')'
import math # In the use of the 'math.pow' method, the value x is raised to the power of y math.pow(x, y)
math.pow() will not work with rasters, only with numbers.
However, the Power tool can take value or raster inputs.
This used to be the pow() function in GRID and Arc 9.x map algebra. I miss that.
and, Python string substitution is your friend. compare these two:
hydRad1 + '* ((' + flowAcc + ' * ' + cellSqMilesStr + ') ^ ' + hydRad + ')'
"{} * (({} * {}) ** {}".format(hydRad1, flowAcc, cellSqMilesStr, hydRad)
And, I should add in Python you should not use the map algebra tool. Best to do Python map algebra directly:
from arcpy.sa import * outras = Raster(hydRad1) * ((Raster(flowAcc) * float(cellSqMilesStr) ** Raster(hydRad) # or outras = Raster(hydRad1) * Power((Raster(flowAcc) * float(cellSqMilesStr), Raster(hydRad)) outras.save("results.tif")
Good point, Curtis.
String substitution aka string formatting can make the whole code much more readable. Especially considering all the options the format method offers.
F.
Filip.... some other links as well Basic fancy formats .... cover simple and other data structures
Alain,
I am interested in the hydro tool that you referenced in your question from 2014. Were you ever able to make it work with the changes to the equation concerning the power. I would be interested in seeing the new code that was created for this tool as we use this tool in Minnesota.
Thanks,
Rick