Select to view content in your preferred language

Re: Apply regression for only certain cell values

1217
5
04-03-2013 09:17 PM
AimeeRoach
Deactivated User
Thanks very much, problem solved!

I have one other question, regarding the raster calculator. I'm using the raster calculator to input a regression equation that I've created from my data, using the output I created with the euclidean distance calculator as the x value for the equation. However it predicts unrealistic values outside the range of what I know is possible for the variable I'm measuring. I'm wondering if there's a way that I can limit the output of the output from the raster calculator to only predict within values I know are possible? For instance limit the prediction to within -4 to 1, rather than allowing the calculator to predict values of up to -16, etc.
0 Kudos
5 Replies
curtvprice
MVP Alum
  For instance limit the prediction to within -4 to 1, rather than allowing the calculator to predict values of up to -16, etc.


SetNull and Con can do a lot of handy things like this with cell values. Reclassify is also useful, but Con and SetNull are more flexible and work well with float and integer rasters.

For example, if this is your regression equation, go ahead and calculate all the values to a grid called "results":

(5.0 * factor1) + 0.45

To set all cells outside the range, to NoData you could then do this with a second Raster Calculator run:

SetNull("results" < -4 or "results" > 1, "results")

You can get fancier, for example, to "saturate" at those values and make all the areas below -4 stay at -4, you could do this:

Con("results" < -4, -4, Con("results" > 1, 1, "results")

Hope this helps!
0 Kudos
AimeeRoach
Deactivated User
I'm still having some trouble getting this to work for me. I'm getting a couple of error messages when I try to run the raster calculator with SetNull. When I use both limiting values (-4 and 1), with this calculation SetNull("results" <-4 >1, "results"), I get this error message:

ERROR 000539: Error running expression: rcexec() <type 'exceptions.ValueError'>: The truth value of a raster is ambiguous.

I thought maybe it would only take one limiting value at a time rather than the range I was trying to specify... so I limited the calculation to only limit to < -4 with this calculation SetNull("results" <-4, "results") and got this error message:

000539: Error running expression: rcexec() <type 'exceptions.RuntimeError'>: ERROR 010240: Could not save raster dataset to <Save Location> with output format IMAGINE Image

Perhaps I am inputting the values incorrectly?
0 Kudos
curtvprice
MVP Alum
I'm still having some trouble getting this to work for me. I'm getting a couple of error messages when I try to run the raster calculator with SetNull. When I use both limiting values (-4 and 1), with this calculation SetNull("results" <-4 >1, "results"), I get this error message:

ERROR 000539: Error running expression: rcexec() <type 'exceptions.ValueError'>: The truth value of a raster is ambiguous.


Here are two different ways to do this that should work (at least one anyway):

SetNull("results" < -4 or "results" > 1, "results")
SetNull("results", "results", "VALUE  < -4 OR VALUE > 1")



I limited the calculation to only limit to < -4 with this calculation SetNull("results" <-4, "results") and got this error message:

000539: Error running expression: rcexec() <type 'exceptions.RuntimeError'>: ERROR 010240: Could not save raster dataset to <Save Location> with output format IMAGINE Image


I think this second error has to do with your output path. make sure your output pathname is not the same as an existing dataset with the same name - and that the output location is a folder not a geodatabase workspace.
0 Kudos
AimeeRoach
Deactivated User
Thank you, I double checked save location and got the SetNull function to work properly with the second expression you mentioned above.

However I'm still receiving an error message when I use the Con function. The error message I receive with this is that the "'Raster' object is not callable".
I'm using the expression: ((Con("Results" < -4, -4, "Results")) (Con("Results" > 1, 1, "Results"))) I've tried several variations of the expression to get the calculator to accept the syntax.
0 Kudos
curtvprice
MVP Alum

I'm using the expression: ((Con("Results" < -4, -4, "Results")) (Con("Results" > 1, 1, "Results")))


You need to nest the function to do what you want.  My example before required one more parenthesis, sorry.

Con("Results" < -4, -4, Con("Results" > 1, 1, "Results"))
0 Kudos