Suppose I have a 1-band image that represents a species' predicted density and distribution. I'd like to be able to spatially define regions based on density. For instance I'd like to extract pixels that represent the top 10% of of the population. That is, identify the largest valued pixels that when summed are 10% of the total sum of all pixels. Or top 20%, top 30% and so on.

I don't know if this is the best way but in my mind I see the workflow as the following possibility: 1) convert image to array, 2) sort those values from min to max and calculate a cumulative sum, 4) convert back to an image and divide by the maximum value...now any pixel value greater than .9 represents a pixel in the top 10%.

This is the script I've been playing with.



You can use the .percentile reducer in combination with .reduceRegion to get the percentile values of all pixels within your study area.

With those you can mask values higher/lower than the desired percentile.

Here is an example calculating the percentiles at reduced resolution of 300m and masking the top 70%: https://code.earthengine.google.com/1ed53b53c8712fad7bedbc031c0022e2

var abundance_perc = bird_abundance.reduceRegion(ee.Reducer.percentile([10, 20, 30, 40, 50, 60, 70, 80, 90]), geometry, 300)

var top70 = bird_abundance.gte(ee.Number(abundance_perc.get("landcover_p70")))

Map.addLayer(top70, {min:0, max:10}, "top70")
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.