Hello, I want to calculate the logarithmic average of the values of points as a raster.

Has anyone ever tried to do this?

-k

FYI:

Geometric mean explained by wikipedia: "The geometric mean, in mathematics, is a type of mean or average, which indicates the central tendency or typical value of a set of numbers. It is similar to the arithmetic mean, which is what most people think of with the word "average", except that the numbers are multiplied and then the nth root (where n is the count of numbers in the set) of the resulting product is taken."

http://en.wikipedia.org/wiki/Geometric_mean

Has anyone ever tried to do this?

-k

FYI:

Geometric mean explained by wikipedia: "The geometric mean, in mathematics, is a type of mean or average, which indicates the central tendency or typical value of a set of numbers. It is similar to the arithmetic mean, which is what most people think of with the word "average", except that the numbers are multiplied and then the nth root (where n is the count of numbers in the set) of the resulting product is taken."

http://en.wikipedia.org/wiki/Geometric_mean

Hi Koreen - did you figure out how to calculate the geometric mean with the raster calculator? Thanks!

The way you'd do this using the 10x Raster Calculator tool would be:

Don't forget to include the "." after the number of rasters (3), as Python division is integer if both inputs are integer.

Hi Curtis - I meant calculate the geometric mean of all the individual cells contained in

oneraster, like this:with each of those being an individual cell of my raster. I think we realized that doing this to 1.2M cells in a raster simply implodes in Python, we couldn't get the script to do more than 50 or so values at one time. Can someone out there with more programming experience explain why, or if there's a better way to do geometric mean in Python or ArcGIS?

thanks!

Not a spatial problem per-se, and the SciPy library does a pretty good job for problems like this. It'll be included in the 10.3 release, but can be downloaded and installed separately in 10.x. With that in place, convert your raster to a NumPy array, then use the statistics built in to SciPy to do the calculation:

Which for a raster of 10M values takes a few seconds for me to run.

Hope that helps,

Shaun

Edit: Michael August I've updated my answer to include 'axis=None' which will compute the geometric mean for the whole matrix (instead of along one axis). With this change, it should work without any further steps.

So I tried the above on integer and float rasters and am not sure what I did wrong there...how do you get to the gm as a single reported value? If you can't tell I am fairly new at this point to Python -thanks you guys for all your help!

once you have the array...check my examples in this thread

So finish it with this part:

In my thread, I outlined two options...one using the cumulative product approach...and the other..the cumulative sum of the logs... the cumulative product approach will fail if you have a large array and/or the numbers in the array contain large numbers due to numeric overflow. The log approach suffers less from this. The only difference is the way in which the final GM is determined. I documented this for teaching purposes and to provide some context on GM use and the calculation pitfalls. I am pretty sure that spreadsheet geometric mean functions don't use the cumulative product approach but rollout the log summation method behind the scenes..... So read my thread carefully...

Great - thanks Shaun!

Once upon a time there was a tool in ArcInfo Workstation GRID called DOCELL that would operate through all the cells of a raster. It was cool:

Talk about a blast from the past.

Shaun Walbridge 's suggestion like a good way to do it nowadays. But if you can't get scipy installed (a bit of a lift actually) you could do something similar by converting the raster to a numpy array with RasterToNumpyArray() and doing the calculation there. That's what Dan did.

I just had a another thought - if the input is an integer grid with a VAT, something like this would work:

It's possible you may run into nasty numerical problems if the grid is very big as the sum gets huge, but this avoids converting the raster to numpy.

This is an alternate example of Curtis's example, not specifically what the OP wants. ...In the example below I created 3 numpy arrays representing your example, assuming everything under the root sign is a grid.

it might be worth considering since you can use Raster to Numpy Array and the reverse to go between numpy and Arc

Now on to the simpler question for the gm of a single raster. You need the cumulative product of each cell, getting the last value in the row column which you do with a np.flatten function if it is a n*m array. For a simple array. the syntax would be

You can also use the alternate formulation to calculate the geometric mean for large numbers and/or arrays to prevent numeric over/under flows. For example, a case of the 3x3 array as before and 1,000,000 int32 integers between 1 and 255

An no other packages need to be installed