Compiling and binning/counting raster array?

2095
10
12-01-2016 08:15 AM
DonRaymond
New Contributor

I am fairly new to ArcPy/Python and have been asked to do the following:  Generate a histogram of bin counts based on an input 32-bit float raster image. I have generated the array for the image using ArcPy (ArcMap 10.4). The requirement is to determine the mean and stdev for this array (done as well with Numpy) and then set a new upper (max) and lower (min) value based on a 2.5 stdev spread across the mean (done too). This image data range must now go into an array with an arbitrary number of bins (say 20) each with a value width of ((new max - new min)/bins). Then I would need to count the total instances of values that fall within each bin, and plot to a histogram that can be saved. I have seen lots of promising information related to the Numpy and Matplotlib functions that can help in this regard, but can't seem to get it off the ground. At some point I will need to do the same for a variable number of input images (2 - 6 possible), determining the min and max values using stdev from all inputs, then plotting all based on this range. For now a single image would be a great start. Any suggestions greatly appreciated. Thanks.

Tags (4)
0 Kudos
10 Replies
DanPatterson_Retired
MVP Emeritus
>>> number = a[0]
>>> classes = a[1]
>>> a
(array([10,  5,  9,  6]), array([1, 2, 3, 4]))
>>> number
array([10,  5,  9,  6])
>>> classes
array([1, 2, 3, 4])

Just like any list or tuple or array... your can slice

The first element is your counts... the second is the bin values.  If you want to change the bin values to ordinal or nominal classes as in the excel file, simply extrace them then zip them with the desired values.

0 Kudos