Help with Raster Calculator

1585
8
10-29-2017 05:28 PM
AlecBiles
New Contributor II

I've been trying to learn the raster calculator but have been stuck on this equation for a couple days. I am in an intro to python class but I still do not understand it all that well.  Can anyone help??

this is the equation I need to put in and this is what I have in the calculator. 

 

I've been changing things around a lot but nothing seems to work. 

if it helps this is the error I keep having 

Thanks.

0 Kudos
8 Replies
DanPatterson_Retired
MVP Emeritus

power is normally ** not ^

0 Kudos
AlecBiles
New Contributor II

Unfortunately that did not work, any other suggestions? 

0 Kudos
DanPatterson_Retired
MVP Emeritus

well I am not quite sure why you had the %... % in the first case... and in the other dialog you have the grid name within a list ... ie square brackets [ grid name ] perhaps get rid of the brackets as well, it may be failing on the 'list'... and check the raster calculator to see if they do use the ^ operator for power (**).  There are so many 'standards' it is hard to keep track of them (I rarely use the raster calculator, opting for python instead)

0 Kudos
curtvprice
MVP Esteemed Contributor

Alec, brackets denote lists in Python. You need to use parentheses even though your math equation uses brackets. Dan is correct that ** is used for exponentiation in Python, not ^ which is a bitwise not (not what you want to do!).

Dan, I'm pretty sure the "%raster%" syntax is because Alec is using the Spatial Analyst Raster Calculator tool inside Model Builder.  The values inside %s are model variables. The double quotes around that are critical, as this delivers something like "ingrid" to the Raster Calculator tool, which then will see the string and interpret as a raster name, and convert this to a raster object with the Raster() function: Raster("ingrid") before it runs using python. You can see the Python expression in the messages when the tool executes above. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Curtis... didn't see modelbuilder mentioned, but I suspect that would account for it.

curtvprice
MVP Esteemed Contributor

(I rarely use the raster calculator, opting for python instead)

IMHO Raster Calculator is very powerful inside Model Builder, I think that's the most appropriate environment for it. As I described above it really maps to Python, all the operators are Python. The only differences is strings in the proper context get wrapped with Raster() for you as I described, which is handy in that environment.

My students use Raster Calculator inside Model Builder for a classic weighted layer exercise. They have to do a binary (sieve mapping) model followed by a weighted overlay model. (I am mean and don't let them use the weighted overlay tool so they can see how weighted combinations work.)

0 Kudos
DanPatterson_Retired
MVP Emeritus

I should have clarified... I use numpy instead

JayantaPoddar
MVP Esteemed Contributor

Could you test the following expression?

(0.4+1)*((("%FlowAcc%")*(30/22.1))**0.4)*(((Sin(("%Slope%")*(0.01745))/(0.09))**1.3))

or the below one

(0.4+1)*(Float((("%FlowAcc%")*(30/22.1))**0.4))*(((Sin(("%Slope%")*(0.01745))/(0.09))**1.3))


Think Location