Hi there,

I've been calculating percentiles out of monthly raster values, that is one month/raster at a time. I've been using the RasterToNumPyArray function and all good. Like this:

array = arcpy.RasterToNumPyArray((raster),nodata_to_value=10000000000) marray = numpy.ma.masked_values(array,10000000000) per = 20 percentile_val = numpy.percentile(marray.compressed(),(per)) print percentile_val

Now, I need to do the same but taking all 12 months into the percentile calculation. That is, using all cell values from all 12 rasters to calculate the percentile. Like putting all values from the 12 raster months into a single pool of values. I tried this:

array = arcpy.RasterToNumPyArray([(raster1), (raster2), (raster3), (raster4), (raster5), (raster6), (raster7), (raster8), (raster9), (raster10), (raster11), (raster12)],nodata_to_value=10000000000) marray = numpy.ma.masked_values(array,10000000000) per = 20 percentile_val = numpy.percentile(marray.compressed(),(per)) print percentile_val

But I think the RasterToNumPyArray function does not allow multiple rasters.

I wonder if someone could give me some tips to overcome this issue.

Many thanks in advance

Tony

This is a very helpful code thanks Dan and Toni. Not that it is needed Toni, but if all your raster are in a single workspace and you would like to compress your code you could have something like this:

You could use a wild card to filter raster names and folders as well for the ListRasters function.